Browse Source

check default type parameter constraints

closes #115566
Simon Krajewski 1 year ago
parent
commit
060ff56560

+ 9 - 8
src/typing/typeload.ml

@@ -755,15 +755,16 @@ and type_type_params ctx host path p tpl =
 				let r = make_lazy ctx.g ttp.ttp_type (fun r ->
 				let r = make_lazy ctx.g ttp.ttp_type (fun r ->
 					let t = load_complex_type ctx true LoadNormal ct in
 					let t = load_complex_type ctx true LoadNormal ct in
 					begin match host with
 					begin match host with
-					| TPHType ->
-						()
-					| TPHConstructor
-					| TPHMethod
-					| TPHEnumConstructor
-					| TPHAnonField
-					| TPHLocal ->
-						display_error ctx.com "Default type parameters are only supported on types" (pos ct)
+						| TPHType ->
+							()
+						| TPHConstructor
+						| TPHMethod
+						| TPHEnumConstructor
+						| TPHAnonField
+						| TPHLocal ->
+							display_error ctx.com "Default type parameters are only supported on types" (pos ct)
 					end;
 					end;
+					check_param_constraints ctx t (fun t -> t) ttp (pos ct);
 					t
 					t
 				) "default" in
 				) "default" in
 				ttp.ttp_default <- Some (TLazy r)
 				ttp.ttp_default <- Some (TLazy r)

+ 7 - 0
tests/misc/projects/Issue11556/Main.hx

@@ -0,0 +1,7 @@
+class Foo<T:EnumValue = Void> {
+	public var data:T;
+
+	public final function new() {}
+}
+
+function main() {}

+ 3 - 0
tests/misc/projects/Issue11556/compile-fail.hxml

@@ -0,0 +1,3 @@
+--main Main
+-neko neko.n
+--no-output

+ 2 - 0
tests/misc/projects/Issue11556/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:1: characters 25-29 : Constraint check failure for Foo.T
+Main.hx:1: characters 25-29 : ... Void should be EnumValue