Skip to content

[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

Closed

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Dec 26, 2022

@som-snytt som-snytt marked this pull request as ready for review December 26, 2022 21:57
@SethTisue SethTisue added this to the 2.13.11 milestone Jan 5, 2023
@som-snytt som-snytt force-pushed the issue/5187-object-override-lazyval branch from 573cc2f to bb94c13 Compare January 18, 2023 07:10
@@ -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
Copy link
Member

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")
Copy link
Member

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')

Copy link
Contributor Author

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.

@som-snytt som-snytt marked this pull request as draft January 21, 2023 15:33
@SethTisue SethTisue modified the milestones: 2.13.11, 2.13.12 Feb 28, 2023
@som-snytt som-snytt closed this Jun 5, 2023
@SethTisue SethTisue removed this from the 2.13.12 milestone Jun 10, 2023
@som-snytt som-snytt changed the title RefChecks takes object as lazy [WIP] RefChecks takes object as lazy Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

objects should override lazy values
3 participants