diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-16 11:15:38 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-16 10:42:57 +0000 |
commit | ee89a8c052db0fa3dffe3e01c4c0309cf9ec80d0 (patch) | |
tree | 281e0baf0ae8f69408f438dac87952805f8504af /tests/auto/qml/qqmllanguage | |
parent | d7b361bc33992ed61310b709df476cc4fa9f67e5 (diff) |
Fix lookup of enums declared in QML singletons
Given the following expression
var x = MySingleton.MyEnumValue
where MySingleton is a QML (composite) singleton and MyEnumValue comes
from a QML declared enum, we had code in place up to (and including)
5.10 to attempt to optimize that expression to a enum constant at
compile time. In 5.10 that optimization does not exist anymore. In <=
5.10 we would also skip the optimization under certain circumstances
(too many statementes, etc.). The fallback that is in place for handling
this at run-time tried to be smart by avoiding the
QQmlContextWrapper::get lookup and return straight a reference to the
singleton as QObject. That works for regular property lookups, but it
fails when trying to look up something like an enum, that isn't a
meta-object property.
Change-Id: I1819b9d8ae06a3f595e067bf5b018c4065be76bb
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
3 files changed, 9 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml b/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml index 7763c783f1..2913ceca08 100644 --- a/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml +++ b/tests/auto/qml/qqmllanguage/data/lib/org/qtproject/MixedModule/SingletonType.qml @@ -2,4 +2,7 @@ import QtQuick 2.0 pragma Singleton Item { + enum EnumInSingleton { + EnumValue = 42 + } } diff --git a/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml b/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml index 2509fc0df1..43e54bbf1d 100644 --- a/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml +++ b/tests/auto/qml/qqmllanguage/data/usingTypeWithEnum.qml @@ -1,8 +1,10 @@ import QtQuick 2.0 +import org.qtproject.MixedModule 1.0 QtObject { property int enumValue: TypeWithEnum.EnumValue2 property int enumValue2: -1 property int scopedEnumValue: TypeWithEnum.MyEnum.EnumValue3 + property int enumValueFromSingleton: { var x = SingletonType.EnumValue; return x; } Component.onCompleted: enumValue2 = TypeWithEnum.EnumValue1 } diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 8bc631fbdd..f1f35f9fd4 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -3752,6 +3752,9 @@ void tst_qqmllanguage::scopedEnum() void tst_qqmllanguage::qmlEnums() { + QQmlEngine engine; + engine.setImportPathList(QStringList(defaultImportPathList) << testFile("lib")); + { QQmlComponent component(&engine, testFileUrl("TypeWithEnum.qml")); QScopedPointer<QObject> o(component.create()); @@ -3774,6 +3777,7 @@ void tst_qqmllanguage::qmlEnums() QCOMPARE(o->property("enumValue").toInt(), 1); QCOMPARE(o->property("enumValue2").toInt(), 0); QCOMPARE(o->property("scopedEnumValue").toInt(), 2); + QCOMPARE(o->property("enumValueFromSingleton").toInt(), 42); } } |