Browse Source

unify void returns properly

closes #11450
Simon Krajewski 1 year ago
parent
commit
6ab9980d46

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -88,7 +88,7 @@ let type_function ctx (args : function_arguments) ret e do_display p =
 		   don't have a return expression we can link the monomorph to Void. We
 		   can _not_ use type_iseq to avoid the Void check above because that
 		   would turn Dynamic returns to Void returns. *)
-		| TMono t when not (has_return e) -> ignore(link t ret ctx.t.tvoid)
+		| TMono m when not (has_return e) -> unify ctx ctx.t.tvoid ret p
 		| _ -> (try TypeloadCheck.return_flow ctx e with Exit -> ())
 	end;
 	let rec loop e =

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

@@ -0,0 +1,5 @@
+function main() {
+	Lambda.fold([], function(a, acc) {
+		a.v = acc.v;
+	}, {v: 1});
+}

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

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

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

@@ -0,0 +1,2 @@
+Main.hx:2: lines 2-4 : Void should be { v : Unknown<0> }
+Main.hx:2: lines 2-4 : ... For function argument 'f'