Explorar el Código

[typer] cast inline vars to field type if it is different from the expression

closes #7132
Simon Krajewski hace 7 años
padre
commit
12ef7f7ed2
Se han modificado 2 ficheros con 11 adiciones y 1 borrados
  1. 2 1
      src/typing/calls.ml
  2. 9 0
      tests/unit/src/unit/issues/Issue7132.hx

+ 2 - 1
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

+ 9 - 0
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.);
+	}
+}