Skip to content

[AST] add a source location for GenericTypeParamDecls #64688

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
Mar 29, 2023

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://105982860

When a method contains both a generic type parameter and a parameter with an existential type (some MyProtocol), the mixture creates a situation where the SourceEntityWalker tries to calculate the source range of the existential, which trips an assertion. This is because GenericTypeParamDecls are not given a source location for their "name", but are given an "inherited" constraint, which is used to calculate the source range:

https://github.com/apple/swift/blob/a9491f6bfe0f83c7d05e06dc0523fbade0b39de4/lib/AST/NameLookup.cpp#L3054-L3072

https://github.com/apple/swift/blob/9f38648b789787e1b5963b6c4d193c45e7111bb6/lib/AST/Decl.cpp#L5001-L5012

This combination of "invalid start location" with "valid end location" fails an assertion in the construction of a SourceRange for the resulting GenericTypeParamDecl.

This PR attempts to resolve this issue by providing a source location for the decl, that points to the beginning of the some/any keyword, so that the source range can cover the whole some MyProtocol span.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus QuietMisdreavus merged commit e450302 into main Mar 29, 2023
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/opaque-param-mix branch March 29, 2023 16:17
etcwilde pushed a commit to etcwilde/swift that referenced this pull request Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants