Quellcode durchsuchen

follow with_type when constructing map literals (closes #2960)

Simon Krajewski vor 11 Jahren
Ursprung
Commit
7a5026822d
2 geänderte Dateien mit 22 neuen und 4 gelöschten Zeilen
  1. 13 0
      tests/unit/issues/Issue2960.hx
  2. 9 4
      typer.ml

+ 13 - 0
tests/unit/issues/Issue2960.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue2960 extends Test {
+	static var map:Map<String, haxe.Constraints.Function>;
+
+	static function call(m) {
+		map = m;
+	}
+
+	function test() {
+		call(["a" => function() {}]);
+	}
+}

+ 9 - 4
typer.ml

@@ -2635,10 +2635,15 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		]) v.v_type p
 	| EArrayDecl ((EBinop(OpArrow,_,_),_) as e1 :: el) ->
 		let keys = Hashtbl.create 0 in
-		let tkey,tval,resume = match with_type with
-			| WithType (TAbstract({a_path=[],"Map"},[tk;tv])) -> tk,tv,false
-			| WithTypeResume (TAbstract({a_path=[],"Map"},[tk;tv])) -> tk,tv,true
-			| _ -> mk_mono(),mk_mono(),false
+		let (tkey,tval),resume =
+			let get_map_params t = match follow t with
+				| TAbstract({a_path=[],"Map"},[tk;tv]) -> tk,tv
+				| _ -> mk_mono(),mk_mono()
+			in
+			match with_type with
+			| WithType t -> get_map_params t,false
+			| WithTypeResume t -> get_map_params t,true
+			| _ -> (mk_mono(),mk_mono()),false
 		in
 		let unify_with_resume ctx a b p =
 			if resume then try unify_raise ctx a b p with Error (Unify l,p) -> raise (WithTypeError(l,p))