Skip to content

Commit da4a38c

Browse files
committed
Sema: StructuralTypeRequest wraps the resolved type in a TypeAliasType
This fixes an issue with protocol compositions using a typealias of anoter protocol composition causing a difference between the flat structural type and the nested underlying TypeRepr.
1 parent 92bec03 commit da4a38c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,5 +1030,17 @@ swift::StructuralTypeRequest::evaluate(Evaluator &evaluator,
10301030

10311031
auto typeRepr = D->getUnderlyingTypeLoc().getTypeRepr();
10321032
auto resolution = TypeResolution::forStructural(D);
1033-
return resolution.resolveType(typeRepr, options);
1033+
auto resolvedType = resolution.resolveType(typeRepr, options);
1034+
1035+
// Wrap the resolved type in a TypeAliasType
1036+
auto *genericSig = D->getGenericSignature();
1037+
SubstitutionMap subs;
1038+
if (genericSig)
1039+
subs = genericSig->getIdentitySubstitutionMap();
1040+
1041+
Type parent;
1042+
auto parentDC = D->getDeclContext();
1043+
if (parentDC->isTypeContext())
1044+
parent = parentDC->getSelfInterfaceType();
1045+
return TypeAliasType::get(D, parent, subs, resolvedType);
10341046
}

test/type/protocol_composition.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,10 @@ takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift
178178
typealias T08 = P1 & inout P2 // expected-error {{'inout' may only be used on parameters}}
179179
typealias T09 = P1 & __shared P2 // expected-error {{'__shared' may only be used on parameters}}
180180
typealias T10 = P1 & __owned P2 // expected-error {{'__owned' may only be used on parameters}}
181+
182+
// Using a typealias of a protocol composition in a protocol composition
183+
protocol C { }
184+
protocol DA { }
185+
protocol DB { }
186+
typealias DD = DA & DB
187+
func composeTypealiasOfComposition<T: C & DD>(x: T) {}

0 commit comments

Comments
 (0)