Răsfoiți Sursa

[jvm] generate Void expression as `void`

closes #8717
Simon Krajewski 5 ani în urmă
părinte
comite
ceedb2c3a5

+ 3 - 1
src/generators/genjvm.ml

@@ -1849,7 +1849,9 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 			let _,load,_ = self#get_local v in
 			load()
 		| TTypeExpr mt ->
-			self#type_expr (jsignature_of_type (type_of_module_type mt))
+			let t = type_of_module_type mt in
+			if ExtType.is_void (follow t) then self#basic_type_path "Void"
+			else self#type_expr (jsignature_of_type t)
 		| TUnop(op,flag,e1) ->
 			begin match op with
 			| Not | Neg | NegBits when ret = RVoid -> self#texpr ret e1

+ 8 - 0
tests/unit/src/unit/issues/Issue8717.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue8717 extends Test {
+	function test() {
+		var instance = Type.createInstance(unit.issues.misc.Issue8717Foo, []);
+		t(Std.isOfType(instance, unit.issues.misc.Issue8717Foo));
+	}
+}

+ 25 - 0
tests/unit/src/unit/issues/misc/Issue8717Foo.hx

@@ -0,0 +1,25 @@
+package unit.issues.misc;
+
+class Base
+{
+	public var name(default, null):String;
+
+	public function new(name:String)
+	{
+		this.name = name;
+	}
+}
+
+@:keep
+class Issue8717Foo extends Base
+{
+	public function new()
+	{
+		super(createName());
+	}
+
+	private function createName():String
+	{
+		return "foo";
+	}
+}