Do not warn about expected missing positions in quotes.reflect.Symbol #21677
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.
Related to #19250
In the PR above it is said that trees and symbols always have to have a position. I think certain cases of the quotes.reflect.Symbol.pos method might have been overlooked, since the doc for Symbol.span (internally in the compiler) explicitly states that the Symbol might not have a position assigned if it was not loaded from source or TASTy. It is true however for quotes.reflect.Tree.pos - the trees always have a position since they have to be loaded from source or TASTy.
Thankfully, quotes.reflect.Symbol.pos returns
Option[Symbol]
, so we can just return None in the cases where the position does not exist. Previously we would only return None if the symbol itself did not exist, however this was not specified anywhere in the Quotes docs, so I think it's fine to change that now (or at least better then any other alternatives), even if this change would go into 3.3.5.As a comparison, the output of
println(TypeRepr.of[String].typeSymbol.pos.toString)
would be:Before #19250:
Some(?)
(Some(NoSource) without set span/position - can cause crashes)After #19250:
Some(?)
(Some(NoSource) with span/position - can still cause crashes)After this PR:
None
Fixes #21672