-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Fix a couple of issues related to variance of protocol 'Self' #41757
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: Fix a couple of issues related to variance of protocol 'Self' #41757
Conversation
… for generic context We don't want to pass in the outer generic signature here. The base type's constraint type is written in terms of archetypes, and we run generic signature queries against it with types appearing in the protocol member. Since the protocol member has Self at depth 0, index 0, prepending the outer generic signature to the opened existential signature would produce incorrect results.
// Make sure this also works in a generic context! | ||
struct G<X, Y, Z> { | ||
func doIt() { | ||
let exist: any UnfulfillableGenericRequirements | ||
|
||
exist.method8(false) | ||
// expected-error@-1 {{member 'method8' cannot be used on value of type 'any UnfulfillableGenericRequirements'; consider using a generic constraint instead}} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, if only these declarations could just be anonymous.
…elated case There are three kinds of invariant 'Self' uses here: - 'Self' appears as the left hand side of a same-type requirement between type parameters - 'Self' appears as a structural component of the right hand side of a concrete type requirement - 'Self' appears as a structural component of the right hand side of a superclass requirement My previous fix only handled the first case. Generalize it to handle all three. Fixes rdar://problem/74944514.
318ea19
to
599bb79
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if the new variance check in the conformance checker, findExistentialSelfReferences() and Sema's doesMemberHaveUnfulfillableConstraintsWithExistentialBase() can all be unified somehow.
Unifying the first and last sounds simple enough, I could see to that in a follow-up. I think the type signature check should have its own entry point: apparently there are places like this one where only generic requirements are of interest (and vice versa?).
The first one is a fix for a regression from #41677. The second one is rdar://problem/74944514, which is a follow-up to #41545.
I'm wondering if the new variance check in the conformance checker, findExistentialSelfReferences() and Sema's doesMemberHaveUnfulfillableConstraintsWithExistentialBase() can all be unified somehow.