Browse Source

fix bad position when typing if condition

closes #12355
Simon Krajewski 6 days ago
parent
commit
3394e5a8ef

+ 1 - 1
src/typing/typer.ml

@@ -1480,7 +1480,7 @@ and type_if ctx e e1 e2 with_type is_ternary p =
 		| TConst TNull -> raise_typing_error "Cannot use null as ternary condition" e.epos
 		| _ -> ()
 	end;
-	let e = AbstractCast.cast_or_unify ctx ctx.t.tbool e p in
+	let e = AbstractCast.cast_or_unify ctx ctx.t.tbool e e.epos in
 	let e1 = type_expr ctx (Expr.ensure_block e1) with_type in
 	match e2 with
 	| None ->

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

@@ -0,0 +1,5 @@
+function main() {
+	if ("") {
+		trace("!");
+	}
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:2: characters 6-8 : String should be Bool