From 8c0a9936923f457ed2a59bdcd01602797eca4f88 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 8 Nov 2026 12:11:38 +0000 Subject: [PATCH 1/2] [tests] Check Type.createEmptyInstance(String) --- tests/unit/src/unit/teststd/TestType.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/src/unit/teststd/TestType.hx b/tests/unit/src/unit/teststd/TestType.hx index 38738131e59..e297ce6621e 100644 --- a/tests/unit/src/unit/teststd/TestType.hx +++ b/tests/unit/src/unit/teststd/TestType.hx @@ -68,7 +68,9 @@ class TestType extends unit.Test { //eq(t.b, "bar"); // createEmptyInstance - //eq(Type.createEmptyInstance(String),"foo"); + #if (!js && !neko && !lua) + eq(Type.createEmptyInstance(String),""); + #end //eq(Type.createEmptyInstance(null, []), null); var c = Type.createEmptyInstance(ClassWithCtorDefaultValues); eq(c.a, null); From 1b938d81328ad94ffed3b48f48a192bbf53b1204 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 8 Nov 2026 12:16:52 +0000 Subject: [PATCH 2/2] [js, neko, lua] Fix createEmptyInstance of String --- std/js/_std/Type.hx | 2 ++ std/lua/_std/Type.hx | 9 +++++---- std/neko/_std/Type.hx | 2 ++ tests/unit/src/unit/teststd/TestType.hx | 2 -- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/std/js/_std/Type.hx b/std/js/_std/Type.hx index 64230639b79..7d5c9c9d0d3 100644 --- a/std/js/_std/Type.hx +++ b/std/js/_std/Type.hx @@ -94,6 +94,8 @@ enum ValueType { } public static inline function createEmptyInstance(cl:Class):T { + if (String == cast cl) + return cast ""; return js.lib.Object.create((cast cl).prototype); } diff --git a/std/lua/_std/Type.hx b/std/lua/_std/Type.hx index 7fdcaddfff5..444961f63ac 100644 --- a/std/lua/_std/Type.hx +++ b/std/lua/_std/Type.hx @@ -91,10 +91,11 @@ enum ValueType { return __new__(cl, lua.TableTools.unpack(cast args, 0)); } - public static function createEmptyInstance(cl:Class):T - untyped { - return _hx_new(cl.prototype); - } + public static function createEmptyInstance(cl:Class):T { + if (String == cast cl) + return cast ""; + return untyped _hx_new(cl.prototype); + } public static function createEnum(e:Enum, constr:String, ?params:Array):T { var f:Dynamic = Reflect.field(e, constr); diff --git a/std/neko/_std/Type.hx b/std/neko/_std/Type.hx index 48f6477de50..3ba9f6a2f30 100644 --- a/std/neko/_std/Type.hx +++ b/std/neko/_std/Type.hx @@ -111,6 +111,8 @@ enum ValueType { } public static function createEmptyInstance( cl : Class ) : T untyped { + if (String == cast cl) + return cast ""; var o = __dollar__new(null); __dollar__objsetproto(o,cl.prototype); return o; diff --git a/tests/unit/src/unit/teststd/TestType.hx b/tests/unit/src/unit/teststd/TestType.hx index e297ce6621e..724e3080500 100644 --- a/tests/unit/src/unit/teststd/TestType.hx +++ b/tests/unit/src/unit/teststd/TestType.hx @@ -68,9 +68,7 @@ class TestType extends unit.Test { //eq(t.b, "bar"); // createEmptyInstance - #if (!js && !neko && !lua) eq(Type.createEmptyInstance(String),""); - #end //eq(Type.createEmptyInstance(null, []), null); var c = Type.createEmptyInstance(ClassWithCtorDefaultValues); eq(c.a, null);