浏览代码

fixed typing of arrow funcs with empty bodies (closes #9843)

Aleksandr Kuzmenko 5 年之前
父节点
当前提交
86f150a091
共有 3 个文件被更改,包括 19 次插入1 次删除
  1. 1 0
      extra/CHANGES.txt
  2. 2 1
      src/typing/typer.ml
  3. 16 0
      tests/display/src/cases/Issue9843.hx

+ 1 - 0
extra/CHANGES.txt

@@ -7,6 +7,7 @@
 	Bugfixes:
 	Bugfixes:
 
 
 	all : fixed `switch` typing error for arrow functions with `Void` return type (#9813)
 	all : fixed `switch` typing error for arrow functions with `Void` return type (#9813)
+	all : fixed typing of arrow functions with empty blocks as bodies (closes #9843)
 	macro : fixed `haxe.macro.Context.getResources()` (#9838)
 	macro : fixed `haxe.macro.Context.getResources()` (#9838)
 	php : fixed false detection of `catch` vars in anonymous functions as captured from outer scope
 	php : fixed false detection of `catch` vars in anonymous functions as captured from outer scope
 	php : fixed return type of extern definition for `fseek` function
 	php : fixed return type of extern definition for `fseek` function

+ 2 - 1
src/typing/typer.ml

@@ -2219,7 +2219,8 @@ and type_return ?(implicit=false) ctx e with_type p =
 		end;
 		end;
 		try
 		try
 			let with_expected_type =
 			let with_expected_type =
-				if implicit then WithType.of_implicit_return ctx.ret
+				if ExtType.is_void (follow ctx.ret) then WithType.no_value
+				else if implicit then WithType.of_implicit_return ctx.ret
 				else WithType.with_type ctx.ret
 				else WithType.with_type ctx.ret
 			in
 			in
 			let e = type_expr ctx e with_expected_type in
 			let e = type_expr ctx e with_expected_type in

+ 16 - 0
tests/display/src/cases/Issue9843.hx

@@ -0,0 +1,16 @@
+package cases;
+
+class Issue9843 extends DisplayTestCase {
+	/**
+		class Main {
+			static function main() {
+				test(() -> {});
+			}
+
+			static function test(fn:()->Void) {}
+		}
+	**/
+	function test() {
+		arrayEq([], diagnostics());
+	}
+}