diff options
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 6 | ||||
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 4 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilercontext_p.h | 4 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 6 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 8 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 1 |
9 files changed, 31 insertions, 13 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index a9eae5958d..a94a448ec0 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -909,13 +909,13 @@ bool IRBuilder::visit(QQmlJS::AST::UiSourceElement *node) f->index = index; f->nameIndex = registerString(funDecl->name.toString()); - const QStringList formals = funDecl->formals ? funDecl->formals->formals() : QStringList(); + const QQmlJS::AST::BoundNames formals = funDecl->formals ? funDecl->formals->formals() : QQmlJS::AST::BoundNames(); int formalsCount = formals.size(); f->formals.allocate(pool, formalsCount); int i = 0; - for (const QString &arg : formals) { - f->formals[i] = registerString(arg); + for (const auto &arg : formals) { + f->formals[i] = registerString(arg.id); ++i; } diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index b378c294b7..7329d526c1 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -269,7 +269,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorO for (Context *f : qAsConst(module->functions)) { registerString(f->name); for (int i = 0; i < f->arguments.size(); ++i) - registerString(f->arguments.at(i)); + registerString(f->arguments.at(i).id); for (int i = 0; i < f->locals.size(); ++i) registerString(f->locals.at(i)); } @@ -467,7 +467,7 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte // write formals quint32_le *formals = (quint32_le *)(f + function->formalsOffset); for (int i = 0; i < irFunction->arguments.size(); ++i) - formals[i] = getStringId(irFunction->arguments.at(i)); + formals[i] = getStringId(irFunction->arguments.at(i).id); // write locals quint32_le *locals = (quint32_le *)(f + function->localsOffset); diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h index f56942fffa..e7ba13ec20 100644 --- a/src/qml/compiler/qv4compilercontext_p.h +++ b/src/qml/compiler/qv4compilercontext_p.h @@ -189,7 +189,7 @@ struct Context { MemberMap members; QSet<QString> usedVariables; QQmlJS::AST::FormalParameterList *formals = nullptr; - QStringList arguments; + QQmlJS::AST::BoundNames arguments; QStringList locals; QStringList moduleRequests; QVector<ImportEntry> importEntries; @@ -288,7 +288,7 @@ struct Context { { // search backwards to handle duplicate argument names correctly for (int i = arguments.size() - 1; i >= 0; --i) { - if (arguments.at(i) == name) + if (arguments.at(i).id == name) return i; } return -1; diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index da22a2d826..9eaf0adf70 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -696,10 +696,14 @@ bool ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete bool isSimpleParameterList = formals && formals->isSimpleParameterList(); - _context->arguments = formals ? formals->formals() : QStringList(); + _context->arguments = formals ? formals->formals() : BoundNames(); const BoundNames boundNames = formals ? formals->boundNames() : BoundNames(); for (int i = 0; i < boundNames.size(); ++i) { + if (auto type = boundNames.at(i).typeAnnotation) { + _cg->throwSyntaxError(type->firstSourceLocation(), QLatin1String("Type annotations are not supported (yet).")); + return false; + } const QString &arg = boundNames.at(i).id; if (_context->isStrict || !isSimpleParameterList) { bool duplicate = (boundNames.indexOf(arg, i + 1) != -1); diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index f68381ce44..4f70bf0004 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -984,9 +984,9 @@ FunctionExpression *FunctionExpression::asFunctionDefinition() return this; } -QStringList FormalParameterList::formals() const +BoundNames FormalParameterList::formals() const { - QStringList formals; + BoundNames formals; int i = 0; for (const FormalParameterList *it = this; it; it = it->next) { if (it->element) { @@ -994,9 +994,9 @@ QStringList FormalParameterList::formals() const int duplicateIndex = formals.indexOf(name); if (duplicateIndex >= 0) { // change the name of the earlier argument to enforce the lookup semantics from the spec - formals[duplicateIndex] += QLatin1String("#") + QString::number(i); + formals[duplicateIndex].id += QLatin1String("#") + QString::number(i); } - formals += name; + formals += {name, it->element->typeAnnotation}; } ++i; } diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index cdee4843b0..da8d0bcd8d 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -850,6 +850,11 @@ struct BoundNames : public QVector<BoundName> return -1; return found - constBegin(); } + + bool contains(const QString &name) const + { + return indexOf(name) != -1; + } }; class QML_PARSER_EXPORT PatternElement : public Node @@ -2410,7 +2415,7 @@ public: return false; } - QStringList formals() const; + BoundNames formals() const; BoundNames boundNames() const; diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt new file mode 100644 index 0000000000..141ea9c7bc --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.errors.txt @@ -0,0 +1 @@ +4:26:Type annotations are not supported (yet). diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml new file mode 100644 index 0000000000..03272e9d50 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeAnnotations.3.qml @@ -0,0 +1,7 @@ +import QtQml 2.0 + +QtObject { + function notYet(param: string) { + return param + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index cc7935f383..ac7874b701 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -625,6 +625,7 @@ void tst_qqmllanguage::errors_data() QTest::newRow("typeAnnotations") << "typeAnnotations.qml" << "typeAnnotations.errors.txt" << false; QTest::newRow("typeAnnotations.2") << "typeAnnotations.2.qml" << "typeAnnotations.2.errors.txt" << false; + QTest::newRow("typeAnnotations.3") << "typeAnnotations.3.qml" << "typeAnnotations.3.errors.txt" << false; } |