Skip to content

Commit

Permalink
check default type parameter constraints
Browse files Browse the repository at this point in the history
closes #115566
  • Loading branch information
Simn committed Feb 7, 2024
1 parent 5aac7ea commit 060ff56
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 t = load_complex_type ctx true LoadNormal ct in
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;
check_param_constraints ctx t (fun t -> t) ttp (pos ct);
t
) "default" in
ttp.ttp_default <- Some (TLazy r)
Expand Down
7 changes: 7 additions & 0 deletions tests/misc/projects/Issue11556/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Foo<T:EnumValue = Void> {
public var data:T;

public final function new() {}
}

function main() {}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11556/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--main Main
-neko neko.n
--no-output
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11556/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 060ff56

Please sign in to comment.