Skip to content

[Type checker] Short-circuit uses of concrete typealiases in protocols. #13250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
if (auto proto =
concrete->getDeclContext()
->getAsProtocolOrProtocolExtensionContext()) {
// Fast path: if there are no type parameters in the concrete type, just
// return it.
if (!concrete->getInterfaceType()->hasTypeParameter())
return concrete->getInterfaceType();

tc.validateDecl(proto);
auto subMap = SubstitutionMap::getProtocolSubstitutions(
proto, baseTy, ProtocolConformanceRef(proto));
Expand Down
7 changes: 7 additions & 0 deletions test/decl/typealias/protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,10 @@ struct CandyEdible : Edible {
// Edible.Snack is witnessed by 'typealias Snack' inside the
// constrained extension of CandyWrapper above
extension CandyBar : Edible {}

protocol P9 {
typealias A = Int
}

func testT9a<T: P9, U>(_: T, _: U) where T.A == U { }
func testT9b<T: P9>(_: T) where T.A == Float { } // expected-error{{'T.A' cannot be equal to both 'Float' and 'P9.A' (aka 'Int')}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

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