Skip to content
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

Sema: Do not drop reference to type paramater if it reduces to ErrorType #79065

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Sema: Do not drop reference to type paramater if it reduces to `Error…
…Type`
  • Loading branch information
AnthonyLatsis committed Jan 30, 2025
commit 697150880ee76fb88e0b2eecd23578e512617931
3 changes: 2 additions & 1 deletion lib/Sema/OpenedExistentials.cpp
Original file line number Diff line number Diff line change
@@ -315,7 +315,8 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
return GenericParameterReferenceInfo();
}

if (auto reducedTy = genericSig.getReducedType(type)) {
auto reducedTy = genericSig.getReducedType(type);
if (reducedTy && !reducedTy->is<ErrorType>()) {
if (!reducedTy->isEqual(type)) {
// Note: origParam becomes openedParam for the recursive call,
// because concreteTy is written in terms of genericSig and not
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple

// https://github.com/swiftlang/swift/issues/77840
do {
struct G<T> {}

protocol P {
associatedtype A where A == Undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the behavior here any different than the case where Undefined exists?

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I think about it is that if reduction returns an error type, then it makes sense to ignore the constraint that caused it to error out. That is, to not treat that error type as concrete when searching for type parameter references.

// expected-error@-1 {{cannot find type 'Undefined' in scope}}
associatedtype B where B == G<Undefined>
// expected-error@-1 {{cannot find type 'Undefined' in scope}}

func fooTakesA(_: A)
func fooTakesB(_: B)

func fooReturnsA() -> A
func fooReturnsB() -> B
}

let p: any P
let _ = p.fooTakesA
// expected-error@-1 {{member 'fooTakesA' cannot be used on value of type 'any P'; consider using a generic constraint instead}}
let _ = p.fooTakesB
// expected-error@-1 {{member 'fooTakesB' cannot be used on value of type 'any P'; consider using a generic constraint instead}}
let _ = p.fooReturnsA()
let _ = p.fooReturnsB()
}