浏览代码

[jvm] generate Void expression as `void`

closes #8717
Simon Krajewski 5 年之前
父节点
当前提交
ceedb2c3a5
共有 3 个文件被更改,包括 36 次插入1 次删除
  1. 3 1
      src/generators/genjvm.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue8717.hx
  3. 25 0
      tests/unit/src/unit/issues/misc/Issue8717Foo.hx

+ 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
 			let _,load,_ = self#get_local v in
 			load()
 			load()
 		| TTypeExpr mt ->
 		| 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) ->
 		| TUnop(op,flag,e1) ->
 			begin match op with
 			begin match op with
 			| Not | Neg | NegBits when ret = RVoid -> self#texpr ret e1
 			| 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";
+	}
+}