-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTPrinter] Fix issue printing Self
resolved to a generic type
#36784
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
Conversation
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 think this will mask other bugs. Types should never contain a mix of archetypes and interface types. Can we fix the downstream issue in the IDE code instead?
Thanks, for that info @slavapestov. I wasn’t sure if these mixed types really should never occur or if they just happened to not occur so far. I have updated the PR to compute the interface type first before substituting it in for |
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.
Thanks, this is more maintainable, in my opinion at least!
Self
resolved to a generic type
I agree. @akyrtzi This change caused some USRs to change. Could you take a look if this is can be considered a fix, problem or something we don’t have to care about? In this definition extension S3: P6 where Wrapped: P6 {} The USR of the - s:4cake2S3VA2A2P6RzrlE7Wrappedxmfp ---> (extension in cake):cake.S3< where A: cake.P6>.Wrapped
+ s4cake2S3V7Wrappedxmfp ---> cake.S3.Wrapped And here extension D: _SomeProto where T: Equatable {
public typealias Item = T
} The USR of - s:16UnderscoredProto1DVAASQRzrlE1Txmfp ---> (extension in UnderscoredProto):UnderscoredProto.D< where A: Swift.Equatable>.T
+ s:16UnderscoredProto1DV1Txmfp ---> UnderscoredProto.D.T |
After quite a bit of investigation, I think there is a bigger underlying issue with the USRs here that’s out of the scope of this PR to fix. Each extension that makes restrictions on generic parameters redeclares those parameters with implicit With this change, things start falling apart once we introduce class MyClass<T> {
typealias MyAlias = T
}
extension MyClass where T: Equatable {
var x: MyAlias
} There are two ways we can interpret My proposal would be to
and in a follow-up PR
@akyrtzi What do you think? |
@swift-ci Please smoke test |
SGTM! Thanks for digging into this and discovering the issue! |
When printing a type in type through `ASTPrinter::printTransformedTypeWithOptions`, we are removing any contextual types by mapping the type out of context. However, when substituting `Self` (or any other type member) with their concrete type from `CurrentType`, we might re-introduce contextual types. To fix this, make sure that `CurrentType` is always an interface type that has all contextual types removed. Fixes rdar://76021569
f3d4ebb
to
9ba892c
Compare
@swift-ci Please test |
Build failed |
@swift-ci Please test macOS |
In some situations (see added test case), we end up with types that contain both an archetype and a generic type parameter. Trying to map them out of context would fail because
mapTypeOutOfContext
asserts that there are no type parameters in the type.IIUC leaving the generic type parameters unchanged in
MapTypeOutOfContext
and removing the assertion should be the intended behaviour.Fixes rdar://76021569