瀏覽代碼

check constraints of inferred `@:generic` constructions (closes #4775)

Simon Krajewski 9 年之前
父節點
當前提交
eaf67c8bff

+ 11 - 0
tests/misc/projects/Issue4775/Main1.hx

@@ -0,0 +1,11 @@
+@:generic class Contain<T:String> {
+	public function new(t:T) { }
+}
+
+class Main {
+	static function main() {
+		new Contain(new Main());
+	}
+
+	function new() { }
+}

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

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

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

@@ -0,0 +1,2 @@
+Main1.hx:7: characters 8-31 : Constraint check failure for Contain.T
+Main1.hx:7: characters 8-31 : Main should be String

+ 4 - 1
typer.ml

@@ -3483,7 +3483,10 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				let ct, f = get_constructor ctx c monos p in
 				ignore (unify_constructor_call c monos f ct);
 				begin try
-					Codegen.build_generic ctx c p monos
+					let t = Codegen.build_generic ctx c p monos in
+					let map = apply_params c.cl_params monos in
+					check_constraints ctx (s_type_path c.cl_path) c.cl_params monos map true p;
+					t
 				with Codegen.Generic_Exception _ as exc ->
 					(* If we have an expected type, just use that (issue #3804) *)
 					begin match with_type with