Selaa lähdekoodia

[php] fix typed casts in assign op (fixes #5135)

Alexander Kuzmenko 8 vuotta sitten
vanhempi
commit
d5be8c5ac1

+ 5 - 1
src/generators/genphp.ml

@@ -1670,6 +1670,8 @@ and gen_expr ctx e =
 	| TCast (e,None) ->
 		gen_expr ctx e
 	| TCast (e1,Some t) ->
+		let error_message pos message = (Lexer.get_error_pos (Printf.sprintf "%s:%d:") pos) ^ ": " ^ message in
+		print_endline (error_message e1.epos "!!!TYPED CAST!!!");
 		let mk_texpr = function
 			| TClassDecl c -> TAnon { a_fields = PMap.empty; a_status = ref (Statics c) }
 			| TEnumDecl e -> TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics e) }
@@ -1784,7 +1786,9 @@ and gen_value ctx e =
 		gen_value ctx e1
 	| TBlock [] ->
 		()
-	| TCast (e, _)
+	| TCast (_, Some _) ->
+		gen_expr ctx e
+	| TCast (e, None)
 	| TBlock [e] ->
 		gen_value ctx e
 	| TIf (cond,e,eelse) when (cangen_ternary e eelse) ->

+ 21 - 0
tests/unit/src/unit/issues/Issue5135.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+class Issue5135 extends unit.Test {
+	var obj2:Object2;
+	function test() {
+		try {
+			obj2 = cast(new Object1(), Object2);
+			t(false);
+		} catch(e:Dynamic) {
+			t(true);
+		}
+	}
+}
+
+private class Object1 {
+	public function new() {}
+}
+
+private class Object2 {
+	public function new() {}
+}

+ 7 - 3
tests/unit/src/unit/issues/Issue5383.hx

@@ -2,14 +2,18 @@ package unit.issues;
 
 class Issue5383 extends unit.Test {
 #if php
-	static var sys = Sys;
     static var issue = Issue5383;
 
     function test() {
         //Should generate instance access
-        sys.print('TEST');
-        issue.sys.print('TEST');
+        issue.doStuff();
+        issue.issue.doStuff();
         t(true);
     }
+
+    static var anchor:Float;
+    static function doStuff() {
+        anchor = Math.random();
+    }
 #end
 }