Browse Source

[generic] don't forget about non-statics

see #10635
Simon Krajewski 3 years ago
parent
commit
dea9899e5f

+ 1 - 0
src/typing/generic.ml

@@ -455,6 +455,7 @@ let type_generic_function ctx fa fcc with_type p =
 					{fa with fa_field = cf2}
 				end
 			end else begin
+				set_type_parameter_dependencies c.cl_module monos;
 				let cf2 = mk_cf2 name in
 				if has_class_field_flag cf CfOverride then add_class_field_flag cf2 CfOverride;
 				c.cl_fields <- PMap.add cf2.cf_name cf2 c.cl_fields;

+ 23 - 2
tests/server/src/cases/display/issues/Issue10635.hx

@@ -53,10 +53,31 @@ class Issue10635 extends DisplayTestCase {
 		var contexts:Array<HaxeServerContext> = Json.parse(lastResult.stderr).result.result;
 		utest.Assert.equals(1, contexts.length);
 		var sig = contexts[0].signature;
-		runHaxeJson(args, ServerMethods.Type, { signature: sig, modulePath: "GenericMethod", typeName: "GenericMethod"});
+		runHaxeJson(args, ServerMethods.Type, {signature: sig, modulePath: "GenericMethod", typeName: "GenericMethod"});
 		var type:JsonModuleType<JsonClass> = Json.parse(lastResult.stderr).result.result;
 		var statics = type.args.statics;
 		Assert.isTrue(statics.exists(cf -> cf.name == "f"));
 		Assert.isTrue(statics.exists(cf -> cf.name == "f_Class<Main>"));
 	}
-}
+
+	function testGenericInstanceAddition(_) {
+		var args = ["-main", "Main"];
+		vfs.putContent("GenericInstanceMethod.hx", getTemplate("GenericInstanceMethod.hx"));
+		vfs.putContent("Main.hx", getTemplate("issues/Issue10635/MainInstanceBefore.hx"));
+		runHaxe(args);
+		vfs.putContent("Main.hx", getTemplate("issues/Issue10635/MainInstanceAfter.hx"));
+		runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")});
+		// Note: We only have to run this once to reproduce because ServerMethods.Type will call cl_restore anyway
+		runHaxe(args);
+		var contexts = null;
+		runHaxeJsonCb(args, ServerMethods.Contexts, null, r -> contexts = r);
+		Assert.notNull(contexts);
+		utest.Assert.equals(1, contexts.length);
+		var sig = contexts[0].signature;
+		var type:JsonModuleType<JsonClass> = null;
+		runHaxeJsonCb(args, ServerMethods.Type, {signature: sig, modulePath: "GenericInstanceMethod", typeName: "GenericInstanceMethod"}, r -> type = r);
+		var fields = type.args.fields;
+		Assert.isTrue(fields.exists(cf -> cf.name == "f"));
+		Assert.isTrue(fields.exists(cf -> cf.name == "f_Class<Main>"));
+	}
+}

+ 5 - 0
tests/server/test/templates/GenericInstanceMethod.hx

@@ -0,0 +1,5 @@
+class GenericInstanceMethod {
+	public function new() {}
+
+	@:generic public function f<T>(t:T) {}
+}

+ 6 - 0
tests/server/test/templates/issues/Issue10635/MainInstanceAfter.hx

@@ -0,0 +1,6 @@
+class Main {
+	static function main() {
+		var c = new GenericInstanceMethod();
+		c.f(Main);
+	}
+}

+ 5 - 0
tests/server/test/templates/issues/Issue10635/MainInstanceBefore.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main() {
+		var c = new GenericInstanceMethod();
+	}
+}