Quellcode durchsuchen

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

Aleksandr Kuzmenko vor 5 Jahren
Ursprung
Commit
615e0d1dc3
3 geänderte Dateien mit 31 neuen und 1 gelöschten Zeilen
  1. 2 1
      extra/CHANGES.txt
  2. 2 0
      src/generators/genpy.ml
  3. 27 0
      tests/unit/src/unit/issues/Issue6448.hx

+ 2 - 1
extra/CHANGES.txt

@@ -6,8 +6,9 @@
 	macro : fixed compiler crash if `@:genericBuild` meta is removed by a macro during building (#9391)
 	flash : fixed var shadowing issue for variables captured in a closure inside of a loop (#9624)
 	flash : fixed `VerifyError` exception when `Void` end up as an argument type after inlining (#9678)
-	php : support @:native("") for extern classes (#6448)
 	php : fixed runtime error "cannot use temporary expression in write context" for call arguments passed by reference
+	php : support @:native("") for extern classes (#6448)
+	python : support @:native("") for extern classes (#6448)
 	nullsafety: fixed `@:nullSafety(Off)` in closures inside of constructors (#9643)
 	nullsafety: fixed "Type not found NullSafetyMode_Impl_" (#9483)
 

+ 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
 }