Skip to content

Commit b66c1a0

Browse files
committed
[Type checker] Maintain "base" type sugar for typealiases.
1 parent 253bd10 commit b66c1a0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,8 @@ Type TypeResolver::buildProtocolType(
31543154
Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
31553155
TypeDecl *member,
31563156
Type baseTy) {
3157+
Type sugaredBaseTy = baseTy;
3158+
31573159
// For type members of a base class, make sure we use the right
31583160
// derived class as the parent type.
31593161
if (auto *ownerClass = member->getDeclContext()
@@ -3207,7 +3209,8 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
32073209
// If we're referring to a typealias within a generic context, build
32083210
// a sugared alias type.
32093211
if (aliasDecl && aliasDecl->getGenericSignature()) {
3210-
resultType = BoundNameAliasType::get(aliasDecl, baseTy, subs, resultType);
3212+
resultType = BoundNameAliasType::get(aliasDecl, sugaredBaseTy, subs,
3213+
resultType);
32113214
}
32123215

32133216
return resultType;

test/decl/typealias/dependent_types.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ let _: GenericStruct.MetaAlias = metaFoo()
5858
// ... but if the typealias has a fully concrete underlying type,
5959
// we are OK.
6060
let _: GenericStruct.Concrete = foo()
61+
62+
class SuperG<T, U> {
63+
typealias Composed = (T, U)
64+
}
65+
66+
class SubG<T> : SuperG<T, T> { }
67+
68+
typealias SubGX<T> = SubG<T?>
69+
70+
func checkSugar(gs: SubGX<Int>.Composed) {
71+
let i4: Int = gs // expected-error{{cannot convert value of type 'SubGX<Int>.Composed' (aka '(Optional<Int>, Optional<Int>)') to specified type 'Int'}}
72+
}

0 commit comments

Comments
 (0)