@@ -729,6 +729,16 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
729729 if (!DC)
730730 return TheCU;
731731
732+ auto createContext = [&](NominalTypeDecl &NTD) {
733+ GenericContextScope scope (
734+ IGM, NTD.getGenericSignature ().getCanonicalSignature ());
735+
736+ auto Ty = NTD.getDeclaredInterfaceType ();
737+ // Create a Forward-declared type.
738+ auto DbgTy = DebugTypeInfo::getForwardDecl (Ty);
739+ return getOrCreateType (DbgTy);
740+ };
741+
732742 if (isa<FuncDecl>(DC))
733743 if (auto *Decl = IGM.getSILModule ().lookUpFunction (SILDeclRef (
734744 cast<AbstractFunctionDecl>(DC), SILDeclRef::Kind::Func)))
@@ -742,7 +752,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
742752
743753 // We don't model these in DWARF.
744754 case DeclContextKind::Initializer:
745- case DeclContextKind::ExtensionDecl:
746755 case DeclContextKind::SubscriptDecl:
747756 case DeclContextKind::EnumElementDecl:
748757 case DeclContextKind::TopLevelCodeDecl:
@@ -761,16 +770,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
761770 return getOrCreateContext (DC->getParent ());
762771 case DeclContextKind::MacroDecl:
763772 return getOrCreateContext (DC->getParent ());
773+ case DeclContextKind::ExtensionDecl: {
774+ auto *ED = cast<ExtensionDecl>(DC);
775+ if (auto *NTD = ED->getExtendedNominal ())
776+ return createContext (*NTD);
777+ return getOrCreateContext (DC->getParent ());
778+ }
764779 case DeclContextKind::GenericTypeDecl: {
765- // The generic signature of this nominal type has no relation to the current
766- // function's generic signature.
780+ // The generic signature of this nominal type has no relation to the
781+ // current function's generic signature.
767782 auto *NTD = cast<NominalTypeDecl>(DC);
768- GenericContextScope scope (IGM, NTD->getGenericSignature ().getCanonicalSignature ());
769-
770- auto Ty = NTD->getDeclaredInterfaceType ();
771- // Create a Forward-declared type.
772- auto DbgTy = DebugTypeInfo::getForwardDecl (Ty);
773- return getOrCreateType (DbgTy);
783+ return createContext (*NTD);
774784 }
775785 }
776786 return TheCU;
0 commit comments