Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3655,29 +3655,28 @@ enum class DeclTypeKind : unsigned {
static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) {
ASTContext &ctx = decl->getASTContext();

// Get the parent type.
Type Ty;
// If `decl` is a nested type, find the parent type.
Type ParentTy;
DeclContext *dc = decl->getDeclContext();
if (!isa<ProtocolDecl>(decl) && dc->isTypeContext()) {
switch (kind) {
case DeclTypeKind::DeclaredType: {
auto *nominal = dc->getSelfNominalTypeDecl();
if (nominal)
Ty = nominal->getDeclaredType();
if (auto *nominal = dc->getSelfNominalTypeDecl())
ParentTy = nominal->getDeclaredType();
break;
}
case DeclTypeKind::DeclaredInterfaceType:
Ty = dc->getDeclaredInterfaceType();
if (Ty->is<ErrorType>())
Ty = Type();
ParentTy = dc->getDeclaredInterfaceType();
if (ParentTy->is<ErrorType>())
ParentTy = Type();
break;
}
}

if (!isa<ProtocolDecl>(decl) && decl->getGenericParams()) {
switch (kind) {
case DeclTypeKind::DeclaredType:
return UnboundGenericType::get(decl, Ty, ctx);
return UnboundGenericType::get(decl, ParentTy, ctx);
case DeclTypeKind::DeclaredInterfaceType: {
// Note that here, we need to be able to produce a type
// before the decl has been validated, so we rely on
Expand All @@ -3687,13 +3686,13 @@ static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) {
for (auto param : decl->getGenericParams()->getParams())
args.push_back(param->getDeclaredInterfaceType());

return BoundGenericType::get(decl, Ty, args);
return BoundGenericType::get(decl, ParentTy, args);
}
}

llvm_unreachable("Unhandled DeclTypeKind in switch.");
} else {
return NominalType::get(decl, Ty, ctx);
return NominalType::get(decl, ParentTy, ctx);
}
}

Expand Down