Skip to content

Commit 7b81701

Browse files
authored
Merge pull request swiftlang#30387 from gribozavr/computeNominalType
2 parents a1bab0b + 5873b04 commit 7b81701

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3655,29 +3655,28 @@ enum class DeclTypeKind : unsigned {
36553655
static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) {
36563656
ASTContext &ctx = decl->getASTContext();
36573657

3658-
// Get the parent type.
3659-
Type Ty;
3658+
// If `decl` is a nested type, find the parent type.
3659+
Type ParentTy;
36603660
DeclContext *dc = decl->getDeclContext();
36613661
if (!isa<ProtocolDecl>(decl) && dc->isTypeContext()) {
36623662
switch (kind) {
36633663
case DeclTypeKind::DeclaredType: {
3664-
auto *nominal = dc->getSelfNominalTypeDecl();
3665-
if (nominal)
3666-
Ty = nominal->getDeclaredType();
3664+
if (auto *nominal = dc->getSelfNominalTypeDecl())
3665+
ParentTy = nominal->getDeclaredType();
36673666
break;
36683667
}
36693668
case DeclTypeKind::DeclaredInterfaceType:
3670-
Ty = dc->getDeclaredInterfaceType();
3671-
if (Ty->is<ErrorType>())
3672-
Ty = Type();
3669+
ParentTy = dc->getDeclaredInterfaceType();
3670+
if (ParentTy->is<ErrorType>())
3671+
ParentTy = Type();
36733672
break;
36743673
}
36753674
}
36763675

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

3690-
return BoundGenericType::get(decl, Ty, args);
3689+
return BoundGenericType::get(decl, ParentTy, args);
36913690
}
36923691
}
36933692

36943693
llvm_unreachable("Unhandled DeclTypeKind in switch.");
36953694
} else {
3696-
return NominalType::get(decl, Ty, ctx);
3695+
return NominalType::get(decl, ParentTy, ctx);
36973696
}
36983697
}
36993698

0 commit comments

Comments
 (0)