Przeglądaj źródła

use pattern type instead of subterm type to find remaining constructors because it might have applied GADT type parameters (closes #2778)

Simon Krajewski 11 lat temu
rodzic
commit
b3eab6f783
3 zmienionych plików z 29 dodań i 3 usunięć
  1. 2 2
      matcher.ml
  2. 1 1
      tests/unit/issues/Issue2580.hx
  3. 26 0
      tests/unit/issues/Issue2778.hx

+ 2 - 2
matcher.ml

@@ -535,7 +535,7 @@ let to_pattern ctx e t =
 					with Invalid_argument _ ->
 						error ("Invalid number of arguments: expected " ^ (string_of_int (List.length tl)) ^ ", found " ^ (string_of_int (List.length el))) p
 					in
-					mk_pat (PTuple (Array.of_list pl)) t_dynamic p
+					mk_pat (PTuple (Array.of_list pl)) t p
 				| _ ->
 					error ((s_type t) ^ " should be Array") p
 			end
@@ -920,7 +920,7 @@ let rec compile mctx stl pmat toplevel =
 			let st_head,st_tail = match stl with st :: stl -> st,stl | _ -> assert false in
 			let pmat = expand_or mctx pmat in
 			let sigma,bl = column_sigma mctx st_head pmat in
-			let all,inf = all_ctors mctx st_head.st_type in
+			let all,inf = all_ctors mctx pv.(0).p_type in
 			let cases = List.map (fun (c,g) ->
 				if not g then all := PMap.remove c.c_def !all;
 				let spec = spec mctx c pmat in

+ 1 - 1
tests/unit/issues/Issue2580.hx

@@ -11,7 +11,7 @@ class Issue2580 extends Test {
 			return switch (t) {
 				case T1(T1(_)): 0;
 				case T1(T2(_)): 1;
-				case T1(_): 2;
+				case T1(null): 2;
 				case T2(_): 3;
 			}
 		}

+ 26 - 0
tests/unit/issues/Issue2778.hx

@@ -0,0 +1,26 @@
+package unit.issues;
+
+enum E<T> {
+    BoolLit(b:Bool):E<Bool>;
+    IntLit(i:Int):E<Int>;
+}
+
+class Issue2778 extends Test {
+
+	function test() {
+		eq(true, sameType(BoolLit(true), BoolLit(true)));
+		eq(false, sameType(BoolLit(false), BoolLit(true)));
+		eq(false, sameType(BoolLit(true), BoolLit(false)));
+		eq(false, sameType(BoolLit(false), BoolLit(false)));
+		eq(12, sameType(IntLit(1), IntLit(11)));
+		t(unit.TestType.typeError(sameType(IntLit(1), BoolLit(true))));
+		t(unit.TestType.typeError(sameType(BoolLit(true), IntLit(1))));
+	}
+
+    static function sameType<S>(o1:E<S>, o2:E<S>):S {
+        return switch [o1, o2] {
+            case [BoolLit(b1), BoolLit(b2)]: b1 && b2;
+            case [IntLit(i1), IntLit(i2)]: i1 + i2;
+        }
+    }
+}