forked from qt-creator/qt-creator
QmlJS checks: Allow calling some builtin constructors as functions.
String, Boolean, Number and Object perform type conversion. Date returns the current date. Change-Id: I51e5bcbb0fa85ceb30b3ee3749f96c3e3b12ca21 Reviewed-on: http://codereview.qt-project.org/6043 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -1173,7 +1173,12 @@ bool Check::visit(CallExpression *ast)
|
|||||||
// check for capitalized function name being called
|
// check for capitalized function name being called
|
||||||
SourceLocation location;
|
SourceLocation location;
|
||||||
const QString name = functionName(ast->base, &location);
|
const QString name = functionName(ast->base, &location);
|
||||||
if (!name.isEmpty() && name.at(0).isUpper()) {
|
if (!name.isEmpty() && name.at(0).isUpper()
|
||||||
|
&& name != QLatin1String("String")
|
||||||
|
&& name != QLatin1String("Boolean")
|
||||||
|
&& name != QLatin1String("Date")
|
||||||
|
&& name != QLatin1String("Number")
|
||||||
|
&& name != QLatin1String("Object")) {
|
||||||
addMessage(WarnExpectedNewWithUppercaseFunction, location);
|
addMessage(WarnExpectedNewWithUppercaseFunction, location);
|
||||||
}
|
}
|
||||||
if (cast<IdentifierExpression *>(ast->base) && name == QLatin1String("eval"))
|
if (cast<IdentifierExpression *>(ast->base) && name == QLatin1String("eval"))
|
||||||
|
|||||||
@@ -11,5 +11,9 @@ Item {
|
|||||||
function foo() {
|
function foo() {
|
||||||
a = A() // 306 13 13
|
a = A() // 306 13 13
|
||||||
a = a()
|
a = a()
|
||||||
|
a = Number("abc")
|
||||||
|
a = String(12)
|
||||||
|
a = Boolean(12)
|
||||||
|
a = Date()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user