Browse Source

[typer] treat empty blocks as object declarations in array comprehension (fixes #9971)

Aleksandr Kuzmenko 4 years ago
parent
commit
87bd136440

+ 1 - 0
extra/CHANGES.txt

@@ -7,6 +7,7 @@
 
 	Bugfixes:
 
+	all : fixed empty object declarations in array comprehension (#9971)
 	jvm : fixed equality checks for `Null<Float>` and `Null<Int>` (#9897)
 	hl : fixed crash if a thread finishes without invoking `sendMessage`/`readMessage` (#9920)
 	php : fixed local vars with certain names (_SERVER, _GET etc) overriding super global values (#9924)

+ 1 - 0
src/typing/typer.ml

@@ -2174,6 +2174,7 @@ and type_array_comprehension ctx e with_type p =
 		| EIf (cond,e2,None) -> (EIf (cond,map_compr e2,None),p)
 		| EIf (cond,e2,Some e3) -> (EIf (cond,map_compr e2,Some (map_compr e3)),p)
 		| EBlock [e] -> (EBlock [map_compr e],p)
+		| EBlock [] -> map_compr (EObjectDecl [],p)
 		| EBlock el -> begin match List.rev el with
 			| e :: el -> (EBlock ((List.rev el) @ [map_compr e]),p)
 			| [] -> e,p

+ 5 - 0
tests/misc/projects/Issue9971/Main.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main() {
+		var a:Array<{ foo: Int, bar: String }> = [for (i in 0...1+Std.random(9)) {}];
+	}
+}

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

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

+ 2 - 0
tests/misc/projects/Issue9971/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:3: characters 76-78 : Object requires fields: foo, bar
+Main.hx:3: characters 76-78 : ... For function argument 'x'