Ver Fonte

[typer] check enum constraints for qualified paths too

closes #8787
Simon Krajewski há 5 anos atrás
pai
commit
22d51d0761

+ 5 - 5
src/typing/fields.ml

@@ -118,10 +118,6 @@ let field_type ctx c pl f p =
 		if not (Meta.has Meta.Generic f.cf_meta) then add_constraint_checks ctx c.cl_params pl f monos p;
 		apply_params l monos f.cf_type
 
-let fast_enum_field e ef p =
-	let et = mk (TTypeExpr (TEnumDecl e)) (mk_anon (ref (EnumStatics e))) p in
-	TField (et,FEnum (e,ef))
-
 let get_constructor ctx c params p =
 	match c.cl_kind with
 	| KAbstractImpl a ->
@@ -490,7 +486,11 @@ let rec type_field cfg ctx e i p mode =
 			end;
 			let fmode, ft = (match !(a.a_status) with
 				| Statics c -> FStatic (c,f), field_type ctx c [] f p
-				| EnumStatics e -> FEnum (e,try PMap.find f.cf_name e.e_constrs with Not_found -> die "" __LOC__), Type.field_type f
+				| EnumStatics e ->
+					let ef = try PMap.find f.cf_name e.e_constrs with Not_found -> die "" __LOC__ in
+					let monos = List.map (fun _ -> mk_mono()) e.e_params in
+					let monos2 = List.map (fun _ -> mk_mono()) ef.ef_params in
+					FEnum (e,ef), enum_field_type ctx e ef monos monos2 p
 				| _ ->
 					match f.cf_params with
 					| [] ->

+ 9 - 0
tests/misc/projects/Issue8787/Main1.hx

@@ -0,0 +1,9 @@
+enum E<T:String> {
+	C(t:T);
+}
+
+class Main {
+	static public function main() {
+		E.C(12); // doesn't fail
+	}
+}

+ 9 - 0
tests/misc/projects/Issue8787/Main2.hx

@@ -0,0 +1,9 @@
+enum E {
+	C<T:String>(t : T);
+}
+
+class Main {
+	static public function main() {
+		E.C(12);
+	}
+}

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

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

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

@@ -0,0 +1,2 @@
+Main1.hx:7: characters 3-6 : Constraint check failure for E.T
+Main1.hx:7: characters 3-6 : Int should be String

+ 2 - 0
tests/misc/projects/Issue8787/compile2-fail.hxml

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

+ 2 - 0
tests/misc/projects/Issue8787/compile2-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main2.hx:7: characters 3-6 : Constraint check failure for C.T
+Main2.hx:7: characters 3-6 : Int should be String