-
Notifications
You must be signed in to change notification settings - Fork 21
Investigate use of super-accessors in traits in the standard library #11420
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
Comments
With traits becoming more powerful and class-like, does it even make sense that an unqualified 'super' in a trait refers to the implementing class's linearization order rather than the linearization as seen by the trait? |
It's necessary to implement some patterns, but I think it should be more explicit, e.g. |
I think https://github.com/scala/scala/blob/d6455592055ce1729ab7ac11d69da3a5a5f3d9dc/src/library/scala/collection/Seq.scala#L187 is correct and requires dynamic resolution. I looked through all 184 uses of unqualified
There is not a single one where I would feel 100% confident restricting it to a static supertrait. In most cases the dynamic look-up is clearly desirable. |
There doesn't appear to be anything more to do about this so I'm closing the issue. |
Hmm, in that case why is concat in that file marked as "TODO: ... Uncomment final" ? (Also the associated issue is closed now, not sure what the status of that is). |
A
super.foo
call in a trait will require a super-accessor in every class that implements the trait since the super will be resolved based on the linearization order of the class. In most cases this is probably not what you want, e.g. in https://github.com/scala/scala/blob/d6455592055ce1729ab7ac11d69da3a5a5f3d9dc/src/library/scala/collection/Seq.scala#L187I suspect what you really meant was:
Besides possible unwanted semantics and performance impact, super-accessors are also problematic because they cannot always be implemented (this is now detected as of scala/scala3#5604 / scala/scala3#5604), so I think it's worht reviewing their use before RC1 ships since adding or removing super-accesors is binary-incompatible.
The text was updated successfully, but these errors were encountered: