Skip to content

Commit d2e3df4

Browse files
committed
TypeChecker: substMemberTypeWithBase respects structural type validation
1 parent da6cf5e commit d2e3df4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,11 @@ Type TypeChecker::resolveTypeInContext(
645645
}
646646
}
647647
}
648-
648+
649649
// Finally, substitute the base type into the member type.
650650
return substMemberTypeWithBase(fromDC->getParentModule(), typeDecl,
651-
selfType, resolution.usesArchetypes());
651+
selfType, resolution.usesArchetypes(),
652+
resolution.getStage());
652653
}
653654

654655
static TypeResolutionOptions
@@ -3362,7 +3363,8 @@ Type TypeResolver::buildProtocolType(
33623363
Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
33633364
TypeDecl *member,
33643365
Type baseTy,
3365-
bool useArchetypes) {
3366+
bool useArchetypes,
3367+
TypeResolutionStage stage) {
33663368
Type sugaredBaseTy = baseTy;
33673369

33683370
// For type members of a base class, make sure we use the right
@@ -3422,8 +3424,9 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
34223424
}
34233425

34243426
Type resultType;
3425-
auto memberType = aliasDecl ? aliasDecl->getUnderlyingTypeLoc().getType()
3427+
auto memberType = aliasDecl ? aliasDecl->getStructuralType()
34263428
: member->getDeclaredInterfaceType();
3429+
34273430
SubstitutionMap subs;
34283431
if (baseTy) {
34293432
// Cope with the presence of unbound generic types, which are ill-formed

lib/Sema/TypeChecker.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/LazyResolver.h"
2727
#include "swift/AST/NameLookup.h"
2828
#include "swift/AST/TypeRefinementContext.h"
29+
#include "swift/AST/TypeResolutionStage.h"
2930
#include "swift/Parse/Lexer.h"
3031
#include "swift/Basic/OptionSet.h"
3132
#include "swift/Config.h"
@@ -865,8 +866,11 @@ class TypeChecker final : public LazyResolver {
865866
/// member.
866867
/// \param useArchetypes Whether to use context archetypes for outer generic
867868
/// parameters if the class is nested inside a generic function.
869+
/// \param stage The type resolution stage for type validation,
870+
/// defaults to Interface.
868871
static Type substMemberTypeWithBase(ModuleDecl *module, TypeDecl *member,
869-
Type baseTy, bool useArchetypes = true);
872+
Type baseTy, bool useArchetypes = true,
873+
TypeResolutionStage stage = TypeResolutionStage::Interface);
870874

871875
/// Determine whether one type is a subtype of another.
872876
///

0 commit comments

Comments
 (0)