Skip to content

Commit b614a4d

Browse files
committed
Sema: Don't look through nested typealiases when checking for unsupported member reference
It appears that a long time ago, we didn't enforce that a member reference to a typealias nested inside a generic type would supply the generic arguments at all. To avoid breaking source compatibility, we carved out some exceptions. Tighten up the exception to prohibit the case where a typealias references another typealias, to fix a crash. While this worked in 5.1, it would crash in 5.2 and 5.3, and at this point it's more trouble than it is worth to make it work again, because of subtle representational issues. So let's just ban it. Fixes <rdar://problem/63535194>.
1 parent 241c5d9 commit b614a4d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) {
353353
// underlying type is not dependent.
354354
if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
355355
if (!aliasDecl->isGeneric() &&
356-
aliasDecl->getUnderlyingType()->getCanonicalType()
357-
->hasTypeParameter()) {
356+
aliasDecl->getUnderlyingType()->hasTypeParameter()) {
358357
return true;
359358
}
360359
}

test/decl/typealias/dependent_types.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ struct X1<T> : P1 {
2323
}
2424
}
2525

26-
struct GenericStruct<T> { // expected-note 2{{generic type 'GenericStruct' declared here}}
26+
struct GenericStruct<T> { // expected-note 3{{generic type 'GenericStruct' declared here}}
2727
typealias Alias = T
2828
typealias MetaAlias = T.Type
2929

3030
typealias Concrete = Int
31+
typealias ReferencesConcrete = Concrete
3132

3233
func methodOne() -> Alias.Type {}
3334
func methodTwo() -> MetaAlias {}
@@ -59,6 +60,9 @@ let _: GenericStruct.MetaAlias = metaFoo()
5960
// we are OK.
6061
let _: GenericStruct.Concrete = foo()
6162

63+
let _: GenericStruct.ReferencesConcrete = foo()
64+
// expected-error@-1 {{reference to generic type 'GenericStruct' requires arguments in <...>}}
65+
6266
class SuperG<T, U> {
6367
typealias Composed = (T, U)
6468
}

0 commit comments

Comments
 (0)