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
[SUPERSEDED] Inherited members can induce ambiguity #10177
Conversation
I forgot whether |
8e21785
to
9913f83
Compare
We don't have a convention for the spec change, which applies to Scala 3 source. It would still be nice to have a page listing what behaviors are controlled by |
This is an edge case where |
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.
LGTM, thank you! Just the spec change should be revised.
I pushed |
I was wondering if it would pass bootstrap on the first try. I didn't expect more sbt fragility:
This is no doubt because the sbt code is never seen, but slinks by in a dark alley, brokering its shady deals. Actually, this is just an ordinary member, but it looks like it is fooled by the self type! I'll add a test. |
The update approximates WWDD at scala/scala3#8622 Follow-up for bootstrapping to follow. Some edits are not entirely boring:
where the local code odor is
Another good one, which tree is intended? There is no guarantee that the tree in the completer is the tree we passed in. It would be nice if there were syntax for that,
An actual bug in a test:
That's my fault for not reviewing the contribution (which I suggested). It intends to enforce that the collection is not iterated twice. It's not even iterated once, because |
You don't often get to edit
|
@lrytz This is why I was looking at this code recently. Could you comment on the idea that this was a spec bug and that fixing it finds a few code bugs without breaking legitimate code? Probably some Community Build experience will say more.
|
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.
This is not going to be a trivial change to push through a minor release, but because it's a clear improvement and it is likely to flag actual bugs, I think we should give it a try.
People will get compilation errors when upgrading Scala on code that previously compiled, so let's add a very specific message to the error. Something like this:
Since 2.13.11, symbols inherited by a superclass no longer take precedence over symbols defined in an outer scope.
Typically this is fixed by writing `this.coll`. Use `-Ylegacy-binding` to revert to the previous behavior.
That's a good idea, to mitigate the migration effort with an explanatory message. I also would not be opposed to releasing 2.14 next 14.2 with default |
Testing this change on a codebase that might or might not have similarities to https://github.com/morganstanley/optimus-cirrus. It would really help if the error could be skipped in case the compiler knows the two symbols are aliases. Type example: class C[T] { type TT = T }
object O { type TT = String
class D extends C[TT] {
def n(x: TT) = x // now ambiguous
def m(x: O.TT): this.TT = x // but they are aliases
}
} Term example: trait Context
class A[C <: Context](val c: C)
class B(val c: Context) { b =>
val a = new A[c.type](c) {
def m = c // now ambiguous
def t: this.c.type = b.c // but they are aliases
}
} What do you think? |
That is a design goal, which I assume Dotty achieves. |
Scala 3.2.1 issues an ambiguity error for both of these examples. But if it's actually correct it would be helpful, and could be forward ported. The disambiguation could be extended to other cases, not only the new one added here. |
Maybe take the last thing I said and assume the opposite. I remember seeing the dealiasing in dotty and made a mental note but did not follow up. I'll give it more thought or ponderance (made-up word). |
Oh actually, just back from cooking lunch, I did test this or similar case, and was relieved that dotty didn't require me to notice the aliasing. Edit: or I'm thinking of pos/t11921c.scala where package-level is an escape hatch. |
13ae402
to
f0be08a
Compare
f0be08a
to
00710a2
Compare
@@ -267,6 +267,8 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett | |||
val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly() | |||
val Ydelambdafy = ChoiceSetting ("-Ydelambdafy", "strategy", "Strategy used for translating lambdas into JVM code.", List("inline", "method"), "method") | |||
|
|||
val legacyBinding = BooleanSetting("-Ylegacy-binding", "Observe legacy name binding preference for inherited member competing with local definition.") |
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.
"local"!
00710a2
to
04cfad9
Compare
Spec binding precedence of inherited definition. Use -Ylegacy-binding for old precedence.
04cfad9
to
22acb93
Compare
Tweaked the code comment and rebased. @lrytz merge for parity with dotty? Then your de-aliasing improvement with de-this follows hard upon. |
Let's wait and see, instead of merging a new error and later narrowing it down. I'm also conidering whether it should maybe be a warning (on by default), an error only under -Xsource:3. |
subsumed and superseded by #10220 |
The language specification is clarified so that an inherited class member cannot shadow a local definition.
The following reference
m
is ambiguous:The previous behavior is available under
-Ylegacy-binding
.Fixes scala/bug#11921