From 83915ec95f19ae3c8d764d719f97840170ea2cd5 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Tue, 18 Feb 2025 18:21:37 +0000 Subject: [PATCH] Add test for toString of nullable abstract --- tests/unit/src/unit/issues/Issue12019.hx | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/unit/src/unit/issues/Issue12019.hx diff --git a/tests/unit/src/unit/issues/Issue12019.hx b/tests/unit/src/unit/issues/Issue12019.hx new file mode 100644 index 00000000000..4c3a7e75cc1 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue12019.hx @@ -0,0 +1,48 @@ +package unit.issues; + +private abstract MyStringA(Null) from Null { + function toString() { + if (this == null) + return "EMPTY"; + return this; + } +} + +private typedef NullableString = Null; + +private abstract MyStringB(NullableString) from NullableString { + function toString() { + if (this == null) + return "EMPTY"; + return this; + } +} + +class Issue12019 extends unit.Test { + final a:MyStringA = null; + final b:MyStringB = null; + + var oldTrace:(Dynamic, ?Null) -> Void; + + function setup() { + oldTrace = haxe.Log.trace; + } + + function teardown() { + haxe.Log.trace = oldTrace; + } + + function testTrace() { + haxe.Log.trace = function(v, ?infos) { + eq("EMPTY", v); + }; + + trace(a); + trace(b); + } + + function testConcatenate() { + eq("Concatenated: EMPTY", "Concatenated: " + a); + eq("Concatenated: EMPTY", "Concatenated: " + b); + } +}