Browse Source

Fix soundness bug for lists

David Peter 1 year ago
parent
commit
6cb8766eee
2 changed files with 8 additions and 1 deletions
  1. 3 1
      numbat/src/typechecker/mod.rs
  2. 5 0
      numbat/src/typechecker/tests.rs

+ 3 - 1
numbat/src/typechecker/mod.rs

@@ -1006,7 +1006,9 @@ impl TypeChecker {
                     if element_types[0].is_closed() {
                         element_types[0].clone()
                     } else {
-                        self.fresh_type_variable()
+                        let type_ = self.fresh_type_variable();
+                        self.add_equal_constraint(&element_types[0], &type_).ok();
+                        type_
                     }
                 };
 

+ 5 - 0
numbat/src/typechecker/tests.rs

@@ -703,6 +703,11 @@ fn lists() {
         get_typecheck_error("[[1 a], [1 b]]"),
         TypeCheckError::IncompatibleTypesInList(..)
     ));
+
+    assert!(matches!(
+        get_typecheck_error("fn f(x) = [[x], x]"),
+        TypeCheckError::ConstraintSolverError(..)
+    ));
 }
 
 #[test]