[AST] add a source location for GenericTypeParamDecls #64688
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wholesome MyProtocol
span.