Skip to content

Commit 04a9714

Browse files
committed
[Type checker] Short-circuit uses of concrete typealiases in protocols.
Hack to allow IndexDistance to become a deprecated typealias. The actual fix here involves deeper surgery into the substitution machinery.
1 parent fde0d92 commit 04a9714

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
202202
if (auto proto =
203203
concrete->getDeclContext()
204204
->getAsProtocolOrProtocolExtensionContext()) {
205+
// Fast path: if there are no type parameters in the concrete type, just
206+
// return it.
207+
if (!concrete->getInterfaceType()->hasTypeParameter())
208+
return concrete->getInterfaceType();
209+
205210
tc.validateDecl(proto);
206211
auto subMap = SubstitutionMap::getProtocolSubstitutions(
207212
proto, baseTy, ProtocolConformanceRef(proto));

test/decl/typealias/protocol.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,10 @@ struct CandyEdible : Edible {
245245
// Edible.Snack is witnessed by 'typealias Snack' inside the
246246
// constrained extension of CandyWrapper above
247247
extension CandyBar : Edible {}
248+
249+
protocol P9 {
250+
typealias A = Int
251+
}
252+
253+
func testT9a<T: P9, U>(_: T, _: U) where T.A == U { }
254+
func testT9b<T: P9>(_: T) where T.A == Float { } // expected-error{{'T.A' cannot be equal to both 'Float' and 'P9.A' (aka 'Int')}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
protocol P{func a:Self.a.a{}class a{class a

0 commit comments

Comments
 (0)