diff --git a/src/hx/cppia/Cppia.cpp b/src/hx/cppia/Cppia.cpp index ba68a29fa..e6e164a2a 100644 --- a/src/hx/cppia/Cppia.cpp +++ b/src/hx/cppia/Cppia.cpp @@ -1507,6 +1507,13 @@ struct NewExpr : public CppiaDynamicExpr if (!type->cppiaClass && type->haxeClass.mPtr) constructor = type->haxeClass.mPtr->mConstructArgs; + // Nothing to construct: runObject and genCode would dereference the null cppiaClass. + if (!type->arrayType && !constructor && !type->cppiaClass) + { + CPPIALOG("Could not link new %s\n", type->name.c_str()); + throw "Bad link"; + } + LinkExpressions(args,inModule); return this; } diff --git a/test/cppia/ClientUnlinked.hx b/test/cppia/ClientUnlinked.hx new file mode 100644 index 000000000..c48769c07 --- /dev/null +++ b/test/cppia/ClientUnlinked.hx @@ -0,0 +1,13 @@ +// The host does not have this class: a module constructing it must fail to link. +extern class Unlinked +{ + public function new(); +} + +class ClientUnlinked +{ + public static function main() + { + new Unlinked(); + } +} diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx index eaacb5a76..fdcb86d2f 100644 --- a/test/cppia/cases/TestCommon.hx +++ b/test/cppia/cases/TestCommon.hx @@ -59,6 +59,12 @@ class TestCommon extends Test { Assert.equals(2, Common.callbackSet, 'Bad cppia closure'); } + function testNewOfUnlinkedClass() { + final source = sys.io.File.getBytes('bin/unlinked.cppia'); + + Assert.raises(() -> cpp.cppia.Module.fromData(source.getData()), String, 'Linked a new of a class the host does not have'); + } + @:depends(testStatus) function testInterfaceCalling() { final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []); diff --git a/test/cppia/compile-client.hxml b/test/cppia/compile-client.hxml index 4c9c3e0c5..854e92b93 100644 --- a/test/cppia/compile-client.hxml +++ b/test/cppia/compile-client.hxml @@ -1,3 +1,8 @@ -m Client -D dll_import=host_classes.info ---cppia bin/client.cppia \ No newline at end of file +--cppia bin/client.cppia + +--next + +-m ClientUnlinked +--cppia bin/unlinked.cppia