From b614a4d33596cb5b63d5c564cca5e8b50e2c7a8a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 8 Jul 2020 15:50:32 -0400 Subject: [PATCH] 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 . --- lib/Sema/TypeCheckNameLookup.cpp | 3 +-- test/decl/typealias/dependent_types.swift | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Sema/TypeCheckNameLookup.cpp b/lib/Sema/TypeCheckNameLookup.cpp index a5b1bd0bc9b3e..6068b1a2c527f 100644 --- a/lib/Sema/TypeCheckNameLookup.cpp +++ b/lib/Sema/TypeCheckNameLookup.cpp @@ -353,8 +353,7 @@ bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) { // underlying type is not dependent. if (auto *aliasDecl = dyn_cast(typeDecl)) { if (!aliasDecl->isGeneric() && - aliasDecl->getUnderlyingType()->getCanonicalType() - ->hasTypeParameter()) { + aliasDecl->getUnderlyingType()->hasTypeParameter()) { return true; } } diff --git a/test/decl/typealias/dependent_types.swift b/test/decl/typealias/dependent_types.swift index c854388e0f669..4334f3d71734e 100644 --- a/test/decl/typealias/dependent_types.swift +++ b/test/decl/typealias/dependent_types.swift @@ -23,11 +23,12 @@ struct X1 : P1 { } } -struct GenericStruct { // expected-note 2{{generic type 'GenericStruct' declared here}} +struct GenericStruct { // expected-note 3{{generic type 'GenericStruct' declared here}} typealias Alias = T typealias MetaAlias = T.Type typealias Concrete = Int + typealias ReferencesConcrete = Concrete func methodOne() -> Alias.Type {} func methodTwo() -> MetaAlias {} @@ -59,6 +60,9 @@ let _: GenericStruct.MetaAlias = metaFoo() // we are OK. let _: GenericStruct.Concrete = foo() +let _: GenericStruct.ReferencesConcrete = foo() +// expected-error@-1 {{reference to generic type 'GenericStruct' requires arguments in <...>}} + class SuperG { typealias Composed = (T, U) }