From 12ef7f7ed2f12bea6554bbd5462f0ea50febfb3d Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Wed, 6 Jun 2018 13:34:09 +0200 Subject: [PATCH] [typer] cast inline vars to field type if it is different from the expression closes #7132 --- src/typing/calls.ml | 3 ++- tests/unit/src/unit/issues/Issue7132.hx | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/unit/src/unit/issues/Issue7132.hx diff --git a/src/typing/calls.ml b/src/typing/calls.ml index 36ae1bb3dcd..e14f09dd0f5 100644 --- a/src/typing/calls.ml +++ b/src/typing/calls.ml @@ -501,7 +501,8 @@ let rec acc_get ctx g p = let rec loop e = Type.map_expr loop { e with epos = p } in let e = loop e in let e = Optimizer.inline_metadata e f.cf_meta in - e + if not (type_iseq f.cf_type e.etype) then mk (TCast(e,None)) f.cf_type e.epos + else e end | AKMacro _ -> assert false diff --git a/tests/unit/src/unit/issues/Issue7132.hx b/tests/unit/src/unit/issues/Issue7132.hx new file mode 100644 index 00000000000..017dbd62896 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue7132.hx @@ -0,0 +1,9 @@ +package unit.issues; + +class Issue7132 extends unit.Test { + static inline var x:Float = 20; + + function test() { + HelperMacros.typedAs(x, 0.); + } +} \ No newline at end of file