浏览代码

clean up ctx.type_params initialization

closes #11528
Simon Krajewski 1 年之前
父节点
当前提交
c5f913ca14

+ 4 - 6
src/typing/typeloadFields.ml

@@ -557,7 +557,7 @@ let create_typer_context_for_class ctx cctx p =
 	let ctx = {
 		ctx with
 		curclass = c;
-		type_params = c.cl_params;
+		type_params = (match c.cl_kind with KAbstractImpl a -> a.a_params | _ -> c.cl_params);
 		pass = PBuildClass;
 		tthis = (match cctx.abstract with
 			| Some a ->
@@ -636,7 +636,9 @@ let create_typer_context_for_field ctx cctx fctx cff =
 		monomorphs = {
 			perfunction = [];
 		};
+		type_params = if fctx.is_static && not fctx.is_abstract_member then [] else ctx.type_params;
 	} in
+
 	let c = cctx.tclass in
 	if (fctx.is_abstract && not (has_meta Meta.LibType c.cl_meta)) then begin
 		if fctx.is_static then
@@ -1356,7 +1358,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	let is_override = Option.is_some fctx.override in
 	if (is_override && fctx.is_static) then invalid_modifier_combination fctx ctx.com fctx "override" "static" p;
 
-	ctx.type_params <- if fctx.is_static && not fctx.is_abstract_member then params else params @ ctx.type_params;
+	ctx.type_params <- params @ ctx.type_params;
 	let args,ret = setup_args_ret ctx cctx fctx (fst f.cff_name) fd p in
 	let t = TFun (args#for_type,ret) in
 	let cf = {
@@ -1632,10 +1634,6 @@ let init_field (ctx,cctx,fctx) f =
 			);
 		| None -> ()
 	end;
-	begin match cctx.abstract with
-		| Some a when fctx.is_abstract_member -> ctx.type_params <- a.a_params;
-		| _ -> ()
-	end;
 	let cf =
 		match f.cff_kind with
 		| FVar (t,e) ->

+ 9 - 0
tests/misc/projects/Issue11528/Main.hx

@@ -0,0 +1,9 @@
+class MyClass<T> {
+	public static var Null = new MyClass<T>();
+
+	public function new() {}
+}
+
+function main() {
+	trace(MyClass.Null);
+}

+ 1 - 0
tests/misc/projects/Issue11528/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

+ 1 - 0
tests/misc/projects/Issue11528/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:2: characters 39-40 : Type not found : T