Browse Source

fix issue with implicit toString failing due to private visibility (closes #5856)

Simon Krajewski 8 years ago
parent
commit
75c0f05a78

+ 3 - 4
src/typing/typer.ml

@@ -1801,10 +1801,10 @@ let unify_int ctx e k =
 	with Typeload.Generic_Exception (msg,p) ->
 	with Typeload.Generic_Exception (msg,p) ->
 		error msg p)
 		error msg p)
 
 
-let call_to_string ctx e =
+let call_to_string ctx ?(resume=false) e =
 	(* Ignore visibility of the toString field. *)
 	(* Ignore visibility of the toString field. *)
 	ctx.meta <- (Meta.PrivateAccess,[],e.epos) :: ctx.meta;
 	ctx.meta <- (Meta.PrivateAccess,[],e.epos) :: ctx.meta;
-	let acc = type_field ctx e "toString" e.epos MCall in
+	let acc = type_field ~resume ctx e "toString" e.epos MCall in
 	ctx.meta <- List.tl ctx.meta;
 	ctx.meta <- List.tl ctx.meta;
 	!build_call_ref ctx acc [] (WithType ctx.t.tstring) e.epos
 	!build_call_ref ctx acc [] (WithType ctx.t.tstring) e.epos
 
 
@@ -4077,8 +4077,7 @@ and type_call ctx e el (with_type:with_type) p =
 					| TDynamic _ -> raise Not_found
 					| TDynamic _ -> raise Not_found
 					| _ -> ()
 					| _ -> ()
 				end;
 				end;
-				let acc = type_field ~resume:true ctx e "toString" p MCall in
-				build_call ctx acc [] (WithType ctx.t.tstring) p
+				call_to_string ~resume:true ctx e
 			with Not_found ->
 			with Not_found ->
 				e
 				e
 			in
 			in

+ 11 - 0
tests/misc/projects/Issue5856/Main.hx

@@ -0,0 +1,11 @@
+class Main {
+    static function main() {
+        var hmm = new Hmm();
+        trace(hmm);
+    }
+}
+
+class Hmm {
+    public function new() {}
+    function toString() return 'Hmm!';
+}

+ 3 - 0
tests/misc/projects/Issue5856/compile.hxml

@@ -0,0 +1,3 @@
+-main Main
+--no-output
+-js js.js