Quellcode durchsuchen

[java/cs] fix String#toString()

Cauê Waneck vor 11 Jahren
Ursprung
Commit
499b831b13
5 geänderte Dateien mit 15 neuen und 1 gelöschten Zeilen
  1. 2 0
      gencs.ml
  2. 2 0
      genjava.ml
  3. 5 0
      std/cs/internal/StringExt.hx
  4. 5 0
      std/java/internal/StringExt.hx
  5. 1 1
      tests/unit/Test.hx

+ 2 - 0
gencs.ml

@@ -402,6 +402,8 @@ struct
         | TCall( { eexpr = TField(ef, FInstance({ cl_path = [], "String" }, { cf_name = ("substring" as field) })) }, args )
         | TCall( { eexpr = TField(ef, FInstance({ cl_path = [], "String" }, { cf_name = ("substr" as field) })) }, args ) ->
           { e with eexpr = TCall(mk_static_field_access_infer string_ext field e.epos [], [run ef] @ (List.map run args)) }
+        | TCall( { eexpr = TField(ef, FInstance({ cl_path = [], "String" }, { cf_name = ("toString" as field) })) }, [] ) ->
+          run ef
         | TNew( { cl_path = ([], "String") }, [], [p] ) -> run p (* new String(myString) -> myString *)
 
         | TCast(expr, _) when is_int_float e.etype && not (is_int_float expr.etype) && not (is_null e.etype) ->

+ 2 - 0
genjava.ml

@@ -562,6 +562,8 @@ struct
             | _ ->
               { e with eexpr = TCall(run efield, List.map run args) }
           )
+        | TCall( { eexpr = TField(ef, FInstance({ cl_path = [], "String" }, { cf_name = ("toString" as field) })) }, [] ) ->
+          run ef
 
         | TCast(expr, m) when is_boxed_type e.etype ->
           (* let unboxed_type gen t tbyte tshort tchar tfloat = match follow t with *)

+ 5 - 0
std/cs/internal/StringExt.hx

@@ -176,6 +176,11 @@ private typedef NativeString = String;
 		return null;
 	}
 
+	public static function toString(me:NativeString):NativeString
+	{
+		return me;
+	}
+
 	@:functionCode('
 			return me.ToLower();
 	')

+ 5 - 0
std/java/internal/StringExt.hx

@@ -169,6 +169,11 @@ private typedef NativeString = String;
 		return null;
 	}
 
+	public static function toString(me:NativeString):NativeString
+	{
+		return me;
+	}
+
 	@:functionCode('
 			return me.toLowerCase();
 	')

+ 1 - 1
tests/unit/Test.hx

@@ -204,7 +204,7 @@ class Test #if swf_mark implements mt.Protect #end {
 	}
 
 	static function resetTimer() {
-		#if (neko || php || cpp)
+		#if (neko || php || cpp || java || cs)
 		#else
 		if( timer != null ) timer.stop();
 		timer = new haxe.Timer(10000);