-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix Scaladoc crash when extending non-Scala-3 classes (long-term fix for 3.4.0) #16761
Conversation
…hods are not safe to call on non-existing Spans. Fixes scala#15927
As expected, MiMa fails for this change. |
(marking as draft for now since it's #16759 that should be merged first) |
I believe we need to do something about that, but I'm not clear on what the right thing to do is. If we believe the change is safe, then we can mollify CI by adding it an exclusion to But I think the change isn't safe, because adding a method to a trait isn't backwards binary compatible unless you include a default implementation. And it matters because Can we just In practice, I don't think there is any realistic scenario in which the default method — or the abstract method, if we leave it abstract — would end up being called. The only call to In short, I think it would be safe to simply add a MiMa exclusion. I also think it would be safe to have In short, I suggest we add the MiMa exclusion and be done with it. @dwijnand Do you agree with this analysis? I've written the above without hedging, as if I were 100% sure, but I'm not really that sure my reasoning is correct and complete. |
Also, we don't need to worry about forwards compatibility across minor versions because we are free to break it: code that was compiled against 3.4.0 (and used Position#exists) cannot be consumed by code being compiled with 3.3.0 because of tasty versions. |
Adding an abstract method to a trait breaks the compatibility in the backwards direction: existing code like But I agree with your point that we should probably not worry too much about the |
You're right.
Don't even think it's worth release noting. Perhaps it's worth a sentence in the Quotes doc, as in "not intended to be implemented inherited/implemented". It also has a self type with traits that are in scala.quotes.runtime which, if we use scala.runtime as well as their docs, implies it's not public for extending/implementing, making it impossible to legally implement Quotes. |
We had a similar issue with position when working on #14810, Since this is the long term solution, I encourage you to also refactor This might also be the place to solve #16619, for example by adding an assert to |
@@ -2850,6 +2850,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
|
|||
given PositionMethods: PositionMethods with | |||
extension (self: Position) | |||
def exists: Boolean = self.exists |
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.
Could these be an extension export ?
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.
We should not add Position.exists
to the reflection API. All trees should have a position. If a tree has a nonexistent position, it is a bug that needs to be fixed at the source.
What's the issue with accepting that some positions don't exist? I'm all with you on your ideal, but the reality seems like trees with non-existing positions crop up and either there's some support for identifying them or people are stuck doing hack arounds or making their users suffer crashes. Seems like an uphill battle and not a hill to die on - to me. |
The missing position bug was already fixed. We follow up with #19250, where we make the API resilient to missing positions. There is no need to have |
Extend the PositionMethods with an exists method, since the other methods are not safe to call on non-existing Spans.
Not eligible for backport to 3.3 because of API addition. See #16759 for a workaround that uses the current API.
Fixes #15927