Skip to content

Commit 92bec03

Browse files
committed
TypeChecker: resolveTypeDecl use the structural type of alias decls
1 parent d2e3df4 commit 92bec03

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,18 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, SourceLoc loc,
979979
auto &diags = ctx.Diags;
980980
auto lazyResolver = ctx.getLazyResolver();
981981

982+
Type type = Type();
983+
984+
// Use only the structural type of an alias decl in structural mode
985+
auto aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl);
986+
if (resolution.getStage() == TypeResolutionStage::Structural &&
987+
aliasDecl && !aliasDecl->getGenericParams() &&
988+
!aliasDecl->getUnderlyingTypeLoc().wasValidated()) {
989+
type = aliasDecl->getStructuralType();
990+
982991
// Don't validate nominal type declarations during extension binding.
983-
if (!options.is(TypeResolverContext::ExtensionBinding) ||
984-
!isa<NominalTypeDecl>(typeDecl)) {
992+
} else if (!options.is(TypeResolverContext::ExtensionBinding) ||
993+
!isa<NominalTypeDecl>(typeDecl)) {
985994
// Validate the declaration.
986995
if (lazyResolver)
987996
lazyResolver->resolveDeclSignature(typeDecl);
@@ -998,9 +1007,10 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, SourceLoc loc,
9981007

9991008
// Resolve the type declaration to a specific type. How this occurs
10001009
// depends on the current context and where the type was found.
1001-
Type type =
1002-
TypeChecker::resolveTypeInContext(typeDecl, foundDC, resolution, options,
1003-
generic);
1010+
if (!type)
1011+
type =
1012+
TypeChecker::resolveTypeInContext(typeDecl, foundDC, resolution,
1013+
options, generic);
10041014

10051015
if (type->is<UnboundGenericType>() && !generic &&
10061016
!options.is(TypeResolverContext::TypeAliasDecl) &&

0 commit comments

Comments
 (0)