@@ -403,25 +403,27 @@ std::optional<CheapUnresolvedName> extractUnresolvedNameCheaply(
403403 if (auto *Nested = SS->getScopeRep ()) {
404404 if (Nested->getKind () == NestedNameSpecifier::Global) {
405405 Result.ResolvedScope = " " ;
406- } else if (const auto *NS = Nested->getAsNamespace ()) {
407- std::string SpecifiedNS = printNamespaceScope (*NS);
408- std::optional<std::string> Spelling = getSpelledSpecifier (*SS, SM);
409-
410- // Check the specifier spelled in the source.
411- // If the resolved scope doesn't end with the spelled scope, the
412- // resolved scope may come from a sema typo correction. For example,
413- // sema assumes that "clangd::" is a typo of "clang::" and uses
414- // "clang::" as the specified scope in:
415- // namespace clang { clangd::X; }
416- // In this case, we use the "typo" specifier as extra scope instead
417- // of using the scope assumed by sema.
418- if (!Spelling || llvm::StringRef (SpecifiedNS).ends_with (*Spelling)) {
419- Result.ResolvedScope = std::move (SpecifiedNS);
406+ } else if (const NamespaceBaseDecl *NSB = Nested->getAsNamespace ()) {
407+ if (const auto *NS = dyn_cast<NamespaceDecl>(NSB)) {
408+ std::string SpecifiedNS = printNamespaceScope (*NS);
409+ std::optional<std::string> Spelling = getSpelledSpecifier (*SS, SM);
410+
411+ // Check the specifier spelled in the source.
412+ // If the resolved scope doesn't end with the spelled scope, the
413+ // resolved scope may come from a sema typo correction. For example,
414+ // sema assumes that "clangd::" is a typo of "clang::" and uses
415+ // "clang::" as the specified scope in:
416+ // namespace clang { clangd::X; }
417+ // In this case, we use the "typo" specifier as extra scope instead
418+ // of using the scope assumed by sema.
419+ if (!Spelling || llvm::StringRef (SpecifiedNS).ends_with (*Spelling)) {
420+ Result.ResolvedScope = std::move (SpecifiedNS);
421+ } else {
422+ Result.UnresolvedScope = std::move (*Spelling);
423+ }
420424 } else {
421- Result.UnresolvedScope = std::move (*Spelling );
425+ Result.ResolvedScope = printNamespaceScope (*cast<NamespaceAliasDecl>(NSB)-> getNamespace () );
422426 }
423- } else if (const auto *ANS = Nested->getAsNamespaceAlias ()) {
424- Result.ResolvedScope = printNamespaceScope (*ANS->getNamespace ());
425427 } else {
426428 // We don't fix symbols in scopes that are not top-level e.g. class
427429 // members, as we don't collect includes for them.
0 commit comments