Skip to content

Commit

Permalink
Fix null coal bug involving implicit casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apprentice-Alchemist committed Jul 18, 2024
1 parent c918b3a commit 597230a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,9 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
| TAbstract({a_path = [],"Null"},[t]) -> tmin
| _ -> follow_null tmin
in
let e1 = vr#as_var "tmp" {e1 with etype = ctx.t.tnull tmin} in
let e_null = Builder.make_null e1.etype e1.epos in
let e1_null_t = if is_nullable e1.etype then e1.etype else ctx.t.tnull e1.etype in
let e1 = vr#as_var "tmp" {e1 with etype = e1_null_t} in
let e_null = Builder.make_null e1_null_t e1.epos in
let e_cond = mk (TBinop(OpNotEq,e1,e_null)) ctx.t.tbool e1.epos in
let e_if = mk (TIf(e_cond,cast e1,Some e2)) iftype p in
vr#to_texpr e_if
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/src/unit/issues/Issue11425.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ class Issue11425 extends Test {
// generated: variant1 != null ? Variant.toFloat(variant1) : 1.0
var testValue9:Float = variant1 ?? cast 1.0; // Works fine.
// generated: Variant.toFloat(variant1 != null ? variant1 : 1.0)
// testValue10 is inferred as Variant
// and hxcpp does not like casting Float to that
#if !cpp
var testValue10 = variant1 ?? cast 1.0; // Works fine.
// generated: variant1 != null ? variant1 : 1.0
#end

utest.Assert.pass();
}
Expand Down

0 comments on commit 597230a

Please sign in to comment.