Skip to content

Commit 7f83f16

Browse files
committed
AST: Simplify and optimize getTypeOfMember()
1 parent 74b2b03 commit 7f83f16

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,21 +1022,17 @@ Type TypeBase::getTypeOfMember(const VarDecl *member) {
10221022

10231023
Type TypeBase::getTypeOfMember(const ValueDecl *member,
10241024
Type memberType) {
1025-
assert(memberType);
1026-
assert(!memberType->is<GenericFunctionType>() &&
1027-
"Generic function types are not supported");
1025+
auto *dc = member->getDeclContext();
10281026

1029-
if (is<ErrorType>())
1030-
return ErrorType::get(getASTContext());
1027+
ASSERT(dc->isTypeContext());
1028+
ASSERT(!memberType->is<GenericFunctionType>() &&
1029+
"Generic function types are not supported");
1030+
ASSERT(isa<VarDecl>(member) || isa<EnumElementDecl>(member));
10311031

1032-
if (auto *lvalue = getAs<LValueType>()) {
1033-
auto objectTy = lvalue->getObjectType();
1034-
return objectTy->getTypeOfMember(member, memberType);
1035-
}
1032+
if (!memberType->hasTypeParameter())
1033+
return memberType;
10361034

1037-
// Perform the substitution.
1038-
auto substitutions = getMemberSubstitutionMap(member);
1039-
return memberType.subst(substitutions);
1035+
return memberType.subst(getContextSubstitutionMap(dc));
10401036
}
10411037

10421038
Type TypeBase::adjustSuperclassMemberDeclType(const ValueDecl *baseDecl,

0 commit comments

Comments
 (0)