-
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
Fix #8617: Check that there is no inheritance/definition shadowing #8622
Conversation
An example of the first exception is this: class C(x: T):
class D extends C(2):
println(x) Here |
feabc40
to
b58ed5c
Compare
This was actually less cumbersome than I anticipated. Only a handful of places had to be updated, and the updates were straightforward (just insert a So in the end we produce errors for 3.0 and migration warnings under -laguage:Scala2Compat. |
@biboudis Unfortunately we got out of sync with this on scalatest now. There were two branches that are now in conflict. Can you please rebase and make sure it passes? |
This implements the additional rule for name resolution: It is an error if an identifier `x` is available as an inherited member in an inner scope and the same name `x` is defined in an outer scope, unless - the inherited member (has an overloaded alternative that) coincides with (an overloaded alternative of) the definition `x` - `x` is global, i.e. a member of a package.
And offer an automatic rewrite rule.
bed6633
to
617b95c
Compare
In that, avoid infix & varargs expansion in Console.printf: [error] 280 | def printf(text: String, args: Any*): Unit = { out.print(text format (args : _*)) } [error] | ^ [error] | `_*` can be used only for last argument of method application. [error] | It is no longer allowed in operands of infix operations. Also, avoid ambiguity errors after scala/scala3#8622
there is a backport of this to 2.13 in progress by @som-snytt. I'm testing it on a large codebase, and it would be helpful to skip the warning when the two symbols are aliases. Here are two minimized real-world examples that don't compile with Scala 3.2.1: 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 // ambiguous, `this.c` vs `B.this.c`
}
}
class C[T] { type TT = T }
object O {
type TT = String
class D extends C[TT] {
def n(x: TT) = x // ambiguous, `this.TT` vs `O.TT`
}
} Proposal to fix that: #16401 |
Follow-up for #8622, which introduced a new lookup ambiguity if a name is inherited from a parent and also found in an outer scope. The error is avoided if the two symbols are aliases.
This implements the additional rule for name resolution:
It is an error if an identifier
x
is available as an inherited memberin an inner scope and the same name
x
is defined in an outer scope, unless(an overloaded alternative of) the definition
x
x
is global, i.e. a member of a package.