Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/hx/cppia/Cppia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions test/cppia/ClientUnlinked.hx
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class TestCommon extends Test {
Assert.equals(2, Common.callbackSet, 'Bad cppia closure');
}

// Loads its own module, so it does not need client.cppia to have run (testStatus).
function testNewOfUnlinkedClass() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this doesn't have @:depends(testStatus), unlike the others?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: testStatus checks that client.cppia ran, and this test doesn't use it, it loads its own module (bin/unlinked.cppia). With the dependency, a failure in the main script would skip it even though what it checks still holds. I added a comment saying so in 88b11c7.

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'), []);
Expand Down
7 changes: 6 additions & 1 deletion test/cppia/compile-client.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-m Client
-D dll_import=host_classes.info
--cppia bin/client.cppia
--cppia bin/client.cppia

--next

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually not a fan of having --next in hxmls, but I guess in this case it makes it more convenient to compile all the .cppia files needed for the test, so it's fine.


-m ClientUnlinked
--cppia bin/unlinked.cppia