Skip to content

[Type checker] Use GSB to handle dependent members of concrete type. #13246

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

Closed
Closed
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
25 changes: 22 additions & 3 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,28 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
concrete->getDeclContext()
->getAsProtocolOrProtocolExtensionContext()) {
tc.validateDecl(proto);
auto subMap = SubstitutionMap::getProtocolSubstitutions(
proto, baseTy, ProtocolConformanceRef(proto));
return concrete->getDeclaredInterfaceType().subst(subMap);
Type depTy = DependentMemberType::get(baseTy, concrete->getName());

auto memberEquivClass =
builder.resolveEquivalenceClass(
depTy,
ArchetypeResolutionKind::CompleteWellFormed);
if (memberEquivClass->concreteType) {
return memberEquivClass->concreteType.transformRec(
[&](TypeBase *type) -> Optional<Type> {
if (auto gp = dyn_cast<GenericTypeParamType>(type)) {
auto genericParams = genericSig->getGenericParams();
unsigned index =
GenericParamKey(gp).findIndexIn(genericParams);
return Type(genericParams[index]);
}

return None;
});
}

return memberEquivClass->getAnchor(builder,
genericSig->getGenericParams());
}

if (auto superclass = baseEquivClass->superclass) {
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')}}