Skip to content

Sema: Implement missing case in existential erasure #70496

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 1 commit into from
Dec 16, 2023
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
14 changes: 14 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,20 @@ static Type typeEraseExistentialSelfReferences(Type refTy, Type baseTy,
}
}

// Parameterized protocol types whose arguments involve this type
// parameter are erased to the base type.
if (auto parameterized = dyn_cast<ParameterizedProtocolType>(t)) {
for (auto argType : parameterized->getArgs()) {
auto erasedArgType =
typeEraseExistentialSelfReferences(
argType, baseTy, TypePosition::Covariant,
existentialSig, containsFn, predicateFn, projectionFn,
force, metatypeDepth);
if (erasedArgType.getPointer() != argType.getPointer())
return parameterized->getBaseType();
}
}

if (auto lvalue = dyn_cast<LValueType>(t)) {
auto objTy = lvalue->getObjectType();
auto erasedTy =
Expand Down
28 changes: 28 additions & 0 deletions test/Constraints/issue-67337.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking

protocol P<T> {
associatedtype T
func foo() -> any P<T>
}

struct A: P {
typealias T = Int
func foo() -> any P<T> {
self
}
}

struct B: P {
typealias T = Int
func foo() -> any P<T> {
self
}
}

struct G<T> {
let t: T
}

let p: any P = A()
let g = G(t: p.foo())
let gg: G<any P> = g