Browse Source

[typeload] lazyfy default type parameter loading

see #11161
Simon Krajewski 2 years ago
parent
commit
b6d9e55572
2 changed files with 31 additions and 10 deletions
  1. 14 10
      src/typing/typeload.ml
  2. 17 0
      tests/unit/src/unit/issues/Issue11161.hx

+ 14 - 10
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 ->

+ 17 - 0
tests/unit/src/unit/issues/Issue11161.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+
+import haxe.ds.Option;
+
+private class TestDefaultTypeParameter<T = Option<String>> {
+	final data:T;
+
+	public function new(data) {
+		this.data = data;
+	}
+}
+
+class Issue11161 extends Test {
+	function test() {
+		utest.Assert.pass();
+	}
+}