diff --git a/src/hx/cppia/Cppia.cpp b/src/hx/cppia/Cppia.cpp index 06375a1ec..594af71a0 100644 --- a/src/hx/cppia/Cppia.cpp +++ b/src/hx/cppia/Cppia.cpp @@ -4805,6 +4805,8 @@ struct DataVal : public CppiaExprWithValue } const char *getName() HXCPP_OVERRIDE { return "DataVal"; } + bool isBoolInt() HXCPP_OVERRIDE { return ExprTypeIsBool::value; } + ExprType getType() HXCPP_OVERRIDE { return (ExprType)ExprTypeOf::value; } void runVoid(CppiaCtx *ctx) HXCPP_OVERRIDE { } diff --git a/test/cppia/Client.hx b/test/cppia/Client.hx index 710373f4b..6189441d8 100644 --- a/test/cppia/Client.hx +++ b/test/cppia/Client.hx @@ -14,6 +14,23 @@ class ClientFoo implements IFoo { } } +class ClientBoolConst { + + public static function constToDynamic():String { + var d:Dynamic = true; + + return Std.string(d); + } + + public static function anyArrayWithConsts():Array { + return [true, false]; + } + + public static function anyArrayWithComparison(i:Int):Array { + return [i > 1]; + } +} + class Client { public static var clientBool0 = true; diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx index eaacb5a76..eb1111b6c 100644 --- a/test/cppia/cases/TestCommon.hx +++ b/test/cppia/cases/TestCommon.hx @@ -59,6 +59,43 @@ class TestCommon extends Test { Assert.equals(2, Common.callbackSet, 'Bad cppia closure'); } + function callBoolConst(name:String, args:Array):Dynamic { + final cls = Type.resolveClass('ClientBoolConst'); + + if (!Assert.notNull(cls, 'Unable to resolve ClientBoolConst')) { + return null; + } + + return Reflect.callMethod(null, Reflect.field(cls, name), args); + } + + @:depends(testStatus) + function testBoolConstToDynamic() { + Assert.equals('true', callBoolConst('constToDynamic', []), + 'Bool constant boxed as a number'); + } + + @:depends(testStatus) + function testBoolConstInAnyArray() { + final arr:Array = callBoolConst('anyArrayWithConsts', []); + + if (Assert.notNull(arr, 'No array returned')) { + Assert.isTrue(Std.isOfType(arr[0], Bool), 'Bool constant did not store as a Bool'); + Assert.isTrue(Std.isOfType(arr[1], Bool), 'Bool constant did not store as a Bool'); + Assert.equals('true', Std.string(arr[0]), 'Bool constant stored in an Any array as a number'); + Assert.equals('false', Std.string(arr[1]), 'Bool constant stored in an Any array as a number'); + } + } + + @:depends(testStatus) + function testBoolComparisonInAnyArray() { + final arr:Array = callBoolConst('anyArrayWithComparison', [3]); + + if (Assert.notNull(arr, 'No array returned')) { + Assert.equals('true', Std.string(arr[0]), 'Bool comparison stored in an Any array as a number'); + } + } + @:depends(testStatus) function testInterfaceCalling() { final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);