Skip to content

Commit

Permalink
Loader: Emit a proper error when binding to module properties
Browse files Browse the repository at this point in the history
... in Project items.
This can only happen for the pseudo-qbs module that we load for Project
items.

Fixes: QBS-1752
Change-Id: I34fae59e14bcd2d3c06aedcf43d5c93583a3a5de
Reviewed-by: Ivan Komissarov <[email protected]>
  • Loading branch information
ckandeler committed Oct 18, 2023
1 parent cb0e12a commit b239b3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/corelib/loader/modulepropertymerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ void ModulePropertyMerger::mergePropertyFromLocalInstance(
Item *loadingItem, const QString &loadingName, Item *globalInstance,
const QString &name, const ValuePtr &value)
{
if (loadingItem->type() == ItemType::Project) {
throw ErrorInfo(Tr::tr("Module properties cannot be set in Project items."),
value->location());
}

const PropertyDeclaration decl = globalInstance->propertyDeclaration(name);
if (!decl.isValid()) {
if (value->type() == Value::ItemValueType || value->createdByPropertiesBlock())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Project {
qbs.sysroot: "/"
}
2 changes: 2 additions & 0 deletions tests/auto/language/tst_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ void TestLanguage::erroneousFiles_data()
<< "missing-js-file-module.qbs.*Cannot open '.*javascriptfile.js'";
QTest::newRow("frozen-object") << "'key' is read-only";
QTest::newRow("frozen-object-list") << "object is not extensible";
QTest::newRow("module-property-binding-in-project")
<< "Module properties cannot be set in Project items";
}

void TestLanguage::erroneousFiles()
Expand Down

0 comments on commit b239b3a

Please sign in to comment.