diff options
| author | Sami Shalayel <sami.shalayel@qt.io> | 2025-07-04 14:42:12 +0200 |
|---|---|---|
| committer | Sami Shalayel <sami.shalayel@qt.io> | 2025-07-21 15:21:58 +0200 |
| commit | 9a907040a041c64d7e88e5a825c627111279c7ed (patch) | |
| tree | dc855e1ee36bdde3b234b24d43ca3f503d43aad1 /src/qmlcompiler/qqmljsimportvisitor.cpp | |
| parent | d232d16c79c0b8cd26ad45e9c24b75c8c3e9dd35 (diff) | |
qqmljsimportvisitor: give base types to attached scopes
It seems that our attached scopes have no base type: they don't inherit
the attached properties or methods because their baseTypeName is not
set.
Therefore, set their baseTypeName, and move the resolveTypes calls
inside of setScopeName() instead of potentially forgetting them after
enterEnvironment/RootScope() calls.
With the (resolved) base type, we know about inherited signals, like
in:
```
Keys.onPressed: { /*here is the "event" argument available*/ }
```
for example where we can insert the "event" JS identifier inside the
QQmlJSScope of the block of the signal handler, now that we now that
"Keys" has a "pressed"-method with one argument "event" on its base
type.
Add a test to make sure that the body of an attached signal handler
contains the JS identifier of the arguments of the attached signal to be
handled. This JS identifier is used later on in qmlls to provide
completions in the body of the attached signal handler.
Also fix LinterVisitor::leaveEnvironment() that starts complaining
about "Component" attached properties that have no child, now that
attached properties have base types.
Pick-to: 6.10 6.9 6.8
Fixes: QTBUG-137736
Change-Id: I8de0158ca9946d5e0e4f4f0a46614385f0edca69
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimportvisitor.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 14596e144e..c86a358503 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -116,14 +116,31 @@ bool QQmlJSImportVisitor::safeInsertJSIdentifier(QQmlJSScope::Ptr &scope, const \internal Sets the name of \a scope to \a name based on \a type. */ -inline void setScopeName(QQmlJSScope::Ptr &scope, QQmlJSScope::ScopeType type, const QString &name) +void QQmlJSImportVisitor::setScopeName(QQmlJSScope::Ptr &scope, QQmlJSScope::ScopeType type, + const QString &name) { Q_ASSERT(scope); - if (type == QQmlSA::ScopeType::GroupedPropertyScope - || type == QQmlSA::ScopeType::AttachedPropertyScope) + switch (type) { + case QQmlSA::ScopeType::GroupedPropertyScope: + scope->setInternalName(name); + return; + case QQmlSA::ScopeType::AttachedPropertyScope: scope->setInternalName(name); - else scope->setBaseTypeName(name); + QQmlJSScope::resolveTypes(scope, m_rootScopeImports.contextualTypes(), &m_usedTypes); + return; + case QQmlSA::ScopeType::QMLScope: + scope->setBaseTypeName(name); + QQmlJSScope::resolveTypes(scope, m_rootScopeImports.contextualTypes(), &m_usedTypes); + return; + case QQmlSA::ScopeType::JSFunctionScope: + case QQmlSA::ScopeType::BindingFunctionScope: + case QQmlSA::ScopeType::SignalHandlerFunctionScope: + case QQmlSA::ScopeType::JSLexicalScope: + case QQmlSA::ScopeType::EnumScope: + scope->setBaseTypeName(name); + return; + }; } /*! @@ -224,10 +241,10 @@ void QQmlJSImportVisitor::populateCurrentScope( QQmlJSScope::ScopeType type, const QString &name, const QQmlJS::SourceLocation &location) { m_currentScope->setScopeType(type); - setScopeName(m_currentScope, type, name); m_currentScope->setIsComposite(true); m_currentScope->setFilePath(m_logger->filePath()); m_currentScope->setSourceLocation(location); + setScopeName(m_currentScope, type, name); m_scopesByIrLocation.insert({ location.startLine, location.startColumn }, m_currentScope); } @@ -1754,8 +1771,7 @@ bool QQmlJSImportVisitor::visit(UiObjectDefinition *definition) m_currentScope->setIsSingleton(m_rootIsSingleton); } - const QTypeRevision revision = QQmlJSScope::resolveTypes( - m_currentScope, m_rootScopeImports.contextualTypes(), &m_usedTypes); + const QTypeRevision revision = m_currentScope->baseTypeRevision(); if (auto base = m_currentScope->baseType(); base) { if (isRoot && base->internalName() == u"QQmlComponent") { m_logger->log(u"Qml top level type cannot be 'Component'."_s, qmlTopLevelComponent, @@ -3034,7 +3050,6 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob) enterEnvironment(QQmlSA::ScopeType::QMLScope, typeName, uiob->qualifiedTypeNameId->identifierToken); - QQmlJSScope::resolveTypes(m_currentScope, m_rootScopeImports.contextualTypes(), &m_usedTypes); m_qmlTypes.append(m_currentScope); // new QMLScope is created here, so add it m_objectBindingScopes << m_currentScope; |
