forked from qt-creator/qt-creator
QmlJSCheck: Do not allow object in when condition
This is syntactically correct and can be hard to spot, but is not valid QtQuick. Task-number: QDS-13452 Change-Id: I010e44e33147c97edbd992c3452ba1c086fb42cb Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -953,6 +953,13 @@ bool Check::visit(UiObjectBinding *ast)
|
|||||||
//addMessage(ErrBehavioursNotSupportedInQmlUi, locationFromRange(ast->firstSourceLocation(), ast->lastSourceLocation()));
|
//addMessage(ErrBehavioursNotSupportedInQmlUi, locationFromRange(ast->firstSourceLocation(), ast->lastSourceLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_typeStack.isEmpty() && m_typeStack.last() == "State"
|
||||||
|
&& toString(ast->qualifiedId) == "when") {
|
||||||
|
addMessage(
|
||||||
|
ErrWhenConditionCannotBeObject,
|
||||||
|
locationFromRange(ast->firstSourceLocation(), ast->lastSourceLocation()));
|
||||||
|
}
|
||||||
|
|
||||||
visitQmlObject(ast, ast->qualifiedTypeNameId, ast->initializer);
|
visitQmlObject(ast, ast->qualifiedTypeNameId, ast->initializer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -238,6 +238,7 @@ StaticAnalysisMessages::StaticAnalysisMessages()
|
|||||||
Tr::tr("Do not reference the root item as alias."));
|
Tr::tr("Do not reference the root item as alias."));
|
||||||
newMsg(WarnAliasReferRootHierarchy, Warning,
|
newMsg(WarnAliasReferRootHierarchy, Warning,
|
||||||
Tr::tr("Avoid referencing the root item in a hierarchy."));
|
Tr::tr("Avoid referencing the root item in a hierarchy."));
|
||||||
|
newMsg(ErrWhenConditionCannotBeObject, Error, Tr::tr("When condtion cannot contain an object."));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
@@ -113,7 +113,8 @@ enum Type {
|
|||||||
WarnComponentRequiresChildren = 327,
|
WarnComponentRequiresChildren = 327,
|
||||||
WarnDuplicateImport = 400,
|
WarnDuplicateImport = 400,
|
||||||
ErrAliasReferRoot = 401,
|
ErrAliasReferRoot = 401,
|
||||||
WarnAliasReferRootHierarchy = 402
|
WarnAliasReferRootHierarchy = 402,
|
||||||
|
ErrWhenConditionCannotBeObject = 403,
|
||||||
};
|
};
|
||||||
|
|
||||||
class QMLJS_EXPORT PrototypeMessageData {
|
class QMLJS_EXPORT PrototypeMessageData {
|
||||||
|
Reference in New Issue
Block a user