2
0
Эх сурвалжийг харах

[java/cs] cast detection enabled for @:overload fields that don't have type parameters. Related to Issue #921

Caue Waneck 13 жил өмнө
parent
commit
4ec698ec0d

+ 10 - 0
gencommon.ml

@@ -4303,7 +4303,17 @@ struct
           | _ ->
           | _ ->
             let ecall = match e with | None -> trace f; trace cf.cf_name; gen.gcon.error "This field should be called immediately" ef.epos; assert false | Some ecall -> ecall in
             let ecall = match e with | None -> trace f; trace cf.cf_name; gen.gcon.error "This field should be called immediately" ef.epos; assert false | Some ecall -> ecall in
             match cf.cf_params with
             match cf.cf_params with
+              | [] when cf.cf_overloads <> [] ->
+                let args, ret = get_args e1.etype in
+                let args, ret = List.map (fun (n,o,t) -> (n,o,gen.greal_type t)) args, gen.greal_type ret in
+                (try
+                  handle_cast gen { ecall with eexpr = TCall({ e1 with eexpr = TField(ef, f) }, List.map2 (fun param (_,_,t) -> handle_cast gen param (gen.greal_type t) (gen.greal_type param.etype)) elist args) } (gen.greal_type ecall.etype) (gen.greal_type ret)
+                with | Invalid_argument("List.map2") ->
+                  gen.gcon.warning "This expression may be invalid" ecall.epos;
+                  handle_cast gen ({ ecall with eexpr = TCall({ e1 with eexpr = TField(ef, f) }, elist )  }) (gen.greal_type ecall.etype) (gen.greal_type ret)
+                )
               | _ when cf.cf_overloads <> [] ->
               | _ when cf.cf_overloads <> [] ->
+                (* this case still needs Issue #915 to be solved, so we will just ignore the need to cast any parameter by now *)
                 mk_cast ecall.etype { ecall with eexpr = TCall({ e1 with eexpr = TField(ef, f) }, elist ) }
                 mk_cast ecall.etype { ecall with eexpr = TCall({ e1 with eexpr = TField(ef, f) }, elist ) }
               | [] ->
               | [] ->
                 let args, ret = get_args actual_t in
                 let args, ret = get_args actual_t in

+ 2 - 2
std/cs/StringBuilder.hx

@@ -7,9 +7,9 @@ package cs;
 
 
 	function new():Void;
 	function new():Void;
 	
 	
-	@:overload(function(obj:Dynamic):cs.StringBuilder {})
+	@:overload(function(char:cs.StdTypes.Char16):cs.StringBuilder {})
 	@:overload(function(str:String, startIndex:Int, len:Int):cs.StringBuilder {})
 	@:overload(function(str:String, startIndex:Int, len:Int):cs.StringBuilder {})
-	function Append(char:cs.StdTypes.Char16):StringBuilder;
+	function Append(obj:Dynamic):StringBuilder;
 	
 	
 	function ToString():String;
 	function ToString():String;
 }
 }