Przeglądaj źródła

[python] Fix python vector syntax issue (#11060)

* [python] Wrap vector in brackets

Avoid error with inline vector index expression

* Add missing semicolon

* [tests] Add tests for python inlined vectors
tobil4sk 2 lat temu
rodzic
commit
6818afe276

+ 3 - 3
std/haxe/ds/Vector.hx

@@ -41,7 +41,7 @@ private typedef VectorData<T> =
 	eval.Vector<T>
 	#else
 	Array<T>
-	#end
+	#end;
 
 /**
 	A Vector is a storage of fixed size. It can be faster than Array on some
@@ -75,7 +75,7 @@ abstract Vector<T>(VectorData<T>) {
 		#elseif cpp
 		this = NativeArray.create(length);
 		#elseif python
-		this = python.Syntax.code("[{0}]*{1}", null, length);
+		this = python.Syntax.code("([{0}]*{1})", null, length);
 		#elseif lua
 		this = untyped __lua_table__({length: length});
 		#elseif eval
@@ -97,7 +97,7 @@ abstract Vector<T>(VectorData<T>) {
 		#if js
 		this = [for (_ in 0...length) defaultValue];
 		#elseif python
-		this = python.Syntax.code("[{0}]*{1}", defaultValue, length);
+		this = python.Syntax.code("([{0}]*{1})", defaultValue, length);
 		#else
 
 		#if flash10

+ 3 - 0
tests/misc/python/projects/Issue11060/Main.hx

@@ -0,0 +1,3 @@
+function main() {
+	trace(new haxe.ds.Vector(1)[0]);
+}

+ 3 - 0
tests/misc/python/projects/Issue11060/build.hxml

@@ -0,0 +1,3 @@
+-python bin/main.py
+--main Main
+-cmd python3 bin/main.py

+ 1 - 0
tests/misc/python/projects/Issue11060/build.hxml.stdout

@@ -0,0 +1 @@
+None