-
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
Overriding a non-abstract var is compiled in Scala 3 / fails in Scala 2 #15491
Labels
Comments
makingthematrix
added
itype:bug
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Jun 21, 2022
Kordyjan
added
compat:scala2
area:refchecks
and removed
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Jun 21, 2022
It is correctly giving a compilation error on both 3.1.3 and 3.2.0-RC1. |
Still, a test is a good idea. |
We already have a test for this exact case. |
Okay, great. Sorry for the noise. I didn't think about that the fix for this specific error could have been made between 3.1.1 and 3.1.3. What are the odds :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler version
3.1.1
Minimized code
Output
Compilation works.
Expectation
In Scala 2.13.8 compilation of this code fails with:
Here’s a Scastie for it.
I have already seen this ticket and I can confirm it is fixed now, but the code above is a bit different - the var in the superclass is not abstract. You can modify the Scastie linked above to see how that changes how Scala 3 reacts. As far as I can tell, the only case where Scala 3 shows an error is when the field in the subclass is also a
var
:override var cat = "cat".
I asked about it on the contributors forum and was advised to open a ticket: https://contributors.scala-lang.org/t/a-possible-issue-with-overriding-vars-in-scala-3/5768
It feels to me as if it was an overlooked detail and Scala 3 should behave exactly as Scala 2.
The text was updated successfully, but these errors were encountered: