Browse Source

give better error when constructing nonsense (closes #4764)

Simon Krajewski 9 năm trước cách đây
mục cha
commit
32c6bf3e79

+ 1 - 1
codegen.ml

@@ -924,7 +924,7 @@ module AbstractCast = struct
 					   let's construct the underlying type. *)
 					match Abstract.get_underlying_type a pl with
 					| TInst(c,tl) as t -> {e with eexpr = TNew(c,tl,el); etype = t}
-					| _ -> assert false
+					| _ -> error ("Cannot construct " ^ (s_type (print_context()) (TAbstract(a,pl)))) e.epos
 				end else begin
 					(* a TNew of an abstract implementation is only generated if it is a multi type abstract *)
 					let cf,m = find_multitype_specialization ctx.com a pl e.epos in

+ 12 - 0
tests/misc/projects/Issue4764/Main1.hx

@@ -0,0 +1,12 @@
+class F {
+    @:generic
+    public static function make<T:haxe.Constraints.Constructible<Void->Void>>() {
+        return new T();
+    }
+}
+
+class Main1 {
+    static function main() {
+        F.make();
+    }
+}

+ 2 - 0
tests/misc/projects/Issue4764/compile1-fail.hxml

@@ -0,0 +1,2 @@
+-main Main1
+--interp

+ 1 - 0
tests/misc/projects/Issue4764/compile1-fail.hxml.stderr

@@ -0,0 +1 @@
+Main1.hx:4: characters 15-22 : Cannot construct haxe.Constructible<Void -> Void>