Browse Source

Prevent abstract casts handler for Std.string in inlined code (#9380)

Aleksandr Kuzmenko 5 years ago
parent
commit
e91aae8a68
2 changed files with 27 additions and 0 deletions
  1. 11 0
      src/optimization/inline.ml
  2. 16 0
      tests/unit/src/unit/issues/Issue9355.hx

+ 11 - 0
src/optimization/inline.ml

@@ -506,6 +506,17 @@ class inline_state ctx ethis params cf f p = object(self)
 				with Not_found ->
 				with Not_found ->
 					e
 					e
 				end
 				end
+			(*
+				This case is a hack for https://github.com/HaxeFoundation/haxe/issues/9355
+				on top of a hack for https://github.com/HaxeFoundation/haxe/issues/2401
+			*)
+			| TCall({eexpr = TField(_,FStatic({cl_path=[],"Std"},{cf_name = "string"}))} as e1,[e2]) ->
+				let e2' = inline_params true false e2 in
+				let e2' =
+					if fast_eq (follow e2.etype) (follow e2'.etype) then e2'
+					else {e2 with eexpr = TCast (e2',None) }
+				in
+				{e with eexpr = TCall(e1,[e2'])}
 			| TCall(e1,el) ->
 			| TCall(e1,el) ->
 				let e1 = inline_params true false e1 in
 				let e1 = inline_params true false e1 in
 				let el = List.map (inline_params false false) el in
 				let el = List.map (inline_params false false) el in

+ 16 - 0
tests/unit/src/unit/issues/Issue9355.hx

@@ -0,0 +1,16 @@
+package unit.issues;
+
+class Issue9355 extends unit.Test {
+	function test() {
+		var o:Opacity = 0.5;
+		eq('0.5', writeFloat(o));
+	}
+
+	static inline function writeFloat(f:Float)
+		return Std.string(f);
+}
+
+private abstract Opacity(Float) from Float to Float {
+	@:to public function toString():String
+		return 'huh?';
+}