From b6d9e555724199de3025e8add10e9fbb08764ef7 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 18 Apr 2023 11:12:29 +0200 Subject: [PATCH] [typeload] lazyfy default type parameter loading see #11161 --- src/typing/typeload.ml | 24 ++++++++++++++---------- tests/unit/src/unit/issues/Issue11161.hx | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 tests/unit/src/unit/issues/Issue11161.hx diff --git a/src/typing/typeload.ml b/src/typing/typeload.ml index 385b52b18d3..569c31bef0a 100644 --- a/src/typing/typeload.ml +++ b/src/typing/typeload.ml @@ -773,16 +773,20 @@ let rec type_type_param ctx host path get_params p tp = | None -> None | Some ct -> - let t = load_complex_type ctx true ct in - begin match host with - | TPHType -> - () - | TPHConstructor - | TPHMethod - | TPHEnumConstructor -> - display_error ctx.com "Default type parameters are only supported on types" (pos ct) - end; - Some t + let r = exc_protect ctx (fun r -> + r := lazy_processing (fun() -> t); + let t = load_complex_type ctx true ct in + begin match host with + | TPHType -> + () + | TPHConstructor + | TPHMethod + | TPHEnumConstructor -> + display_error ctx.com "Default type parameters are only supported on types" (pos ct) + end; + t + ) "default" in + Some (TLazy r) in match tp.tp_constraints with | None -> diff --git a/tests/unit/src/unit/issues/Issue11161.hx b/tests/unit/src/unit/issues/Issue11161.hx new file mode 100644 index 00000000000..c80d55dc95a --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11161.hx @@ -0,0 +1,17 @@ +package unit.issues; + +import haxe.ds.Option; + +private class TestDefaultTypeParameter> { + final data:T; + + public function new(data) { + this.data = data; + } +} + +class Issue11161 extends Test { + function test() { + utest.Assert.pass(); + } +}