diff options
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/polymorphicFunctionLookup.qml | 14 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 13 |
3 files changed, 36 insertions, 5 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 883b21ab07..9021fd0284 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1947,11 +1947,7 @@ QQmlPropertyData *JSCodeGen::lookupQmlCompliantProperty(QQmlPropertyCache *cache { QQmlPropertyData *pd = cache->property(name, /*object*/nullptr, /*context*/nullptr); - // Q_INVOKABLEs can't be FINAL, so we have to look them up at run-time - if (!pd || pd->isFunction()) - return nullptr; - - if (!cache->isAllowedInRevision(pd)) + if (pd && !cache->isAllowedInRevision(pd)) return nullptr; return pd; @@ -2280,6 +2276,10 @@ QV4::Compiler::Codegen::Reference JSCodeGen::fallbackNameLookup(const QString &n if (_scopeObject) { QQmlPropertyData *data = lookupQmlCompliantProperty(_scopeObject, name); if (data) { + // Q_INVOKABLEs can't be FINAL, so we have to look them up at run-time + if (data->isFunction()) + return Reference::fromName(this, name); + Reference base = Reference::fromStackSlot(this, _qmlContextSlot); Reference::PropertyCapturePolicy capturePolicy; if (!data->isConstant() && !data->isQmlBinding()) @@ -2293,6 +2293,10 @@ QV4::Compiler::Codegen::Reference JSCodeGen::fallbackNameLookup(const QString &n if (_contextObject) { QQmlPropertyData *data = lookupQmlCompliantProperty(_contextObject, name); if (data) { + // Q_INVOKABLEs can't be FINAL, so we have to look them up at run-time + if (data->isFunction()) + return Reference::fromName(this, name); + Reference base = Reference::fromStackSlot(this, _qmlContextSlot); Reference::PropertyCapturePolicy capturePolicy; if (!data->isConstant() && !data->isQmlBinding()) diff --git a/tests/auto/qml/qqmllanguage/data/polymorphicFunctionLookup.qml b/tests/auto/qml/qqmllanguage/data/polymorphicFunctionLookup.qml new file mode 100644 index 0000000000..4a3cc52793 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/polymorphicFunctionLookup.qml @@ -0,0 +1,14 @@ +import QtQml 2.0 +QtObject { + id: root + property bool testFunc; + property bool ok: false + property QtObject subObject: QtObject { + function testFunc() + { + root.ok = true + } + + Component.onCompleted: testFunc() + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 157fd500ad..7a8de739f4 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -298,6 +298,8 @@ private slots: void retrieveQmlTypeId(); + void polymorphicFunctionLookup(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -5049,6 +5051,17 @@ void tst_qqmllanguage::retrieveQmlTypeId() QVERIFY(qmlTypeId("Test", 1, 0, "MyTypeObjectSingleton") >= 0); } +void tst_qqmllanguage::polymorphicFunctionLookup() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("polymorphicFunctionLookup.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + + QVERIFY(o->property("ok").toBool()); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |