-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[WIP] RefChecks takes object as lazy #10250
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
[WIP] RefChecks takes object as lazy #10250
Conversation
573cc2f
to
bb94c13
Compare
@@ -39,8 +39,8 @@ class C extends A { | |||
override object oneArg // fail | |||
} | |||
class C0 extends A0 { | |||
override object value // !!! this succeeds, but should fail (lazy over strict) | |||
override object lazyvalue // !!! this fails, but should succeed (lazy over lazy) | |||
override object value // fail |
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.
it's a deprecation now, could add // scalac: -deprecation
to the test
other.isValue && other.hasFlag(STABLE) && !(other.isDeferred || other.isLazy)) { | ||
overrideErrorWithMemberInfo("concrete non-lazy value cannot be overridden:") | ||
if (member.isModule && !currentRun.isScala3) | ||
runReporting.deprecationWarning(member.pos, member, member.owner, "overriding concrete non-lazy value with an object member will be disallowed under -Xsource:3", "2.13.11") |
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.
Hmm, it seems this comes too early now and prevents override checking for compatible types:
scala> class A { val value = 0 }
class A
scala> object O extends A { override object value }
^
warning: overriding concrete non-lazy value with an object member will be disallowed under -Xsource:3
object O
scala> (O: A).value
java.lang.ClassCastException: class O$value$ cannot be cast to class java.lang.Integer (O$value$ is in unnamed module of loader scala.tools.nsc.interpreter.IMain$TranslatingClassLoader @475646d4; java.lang.Integer is in module java.base of loader 'bootstrap')
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.
Sorry, I mean to revisit. I think I said I'd break the if-else.
Fixes scala/bug#5187