Răsfoiți Sursa

[python] support @:native("") on extern classes (closes #6448)

Aleksandr Kuzmenko 5 ani în urmă
părinte
comite
ea5ede14cc
2 a modificat fișierele cu 29 adăugiri și 0 ștergeri
  1. 2 0
      src/generators/genpy.ml
  2. 27 0
      tests/unit/src/unit/issues/Issue6448.hx

+ 2 - 0
src/generators/genpy.ml

@@ -1459,6 +1459,8 @@ module Printer = struct
 				Printf.sprintf "python_Boot.createClosure(%s, python_internal_ArrayImpl.%s)" obj name
 			| FInstance (c,_,cf) when ((is_type "" "str")(TClassDecl c)) ->
 				Printf.sprintf "python_Boot.createClosure(%s, HxString.%s)" obj name
+			| FStatic (c,cf) when c.cl_extern && c.cl_path = ([],"") ->
+				Printf.sprintf "%s" name
 			| FInstance _ | FStatic _ ->
 				do_default ()
 			| FAnon cf when is_assign && call_override(name) ->

+ 27 - 0
tests/unit/src/unit/issues/Issue6448.hx

@@ -16,6 +16,21 @@ private extern class Lib {
 		js.Syntax.code("function ___hx_returnTrue() { return true; }");
 	}
 }
+
+#elseif python
+
+@:native("")
+private extern class Ext {
+	static public function len(s:String):Int;
+}
+
+#elseif php
+
+@:native("")
+private extern class Ext {
+	static public function strlen(s:String):Int;
+}
+
 #end
 
 class Issue6448 extends unit.Test {
@@ -28,5 +43,17 @@ class Issue6448 extends unit.Test {
 		function ___hx_returnTrue() return false;
 		t(Lib.returnTrue());
 	}
+
+	#elseif python
+
+	function test() {
+		eq(4, Ext.len('1234'));
+	}
+
+	#elseif php
+
+	function test() {
+		eq(4, Ext.strlen('1234'));
+	}
 	#end
 }