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 38738131e59..724e3080500 100644 --- a/tests/unit/src/unit/teststd/TestType.hx +++ b/tests/unit/src/unit/teststd/TestType.hx @@ -68,7 +68,7 @@ class TestType extends unit.Test { //eq(t.b, "bar"); // createEmptyInstance - //eq(Type.createEmptyInstance(String),"foo"); + eq(Type.createEmptyInstance(String),""); //eq(Type.createEmptyInstance(null, []), null); var c = Type.createEmptyInstance(ClassWithCtorDefaultValues); eq(c.a, null);