Skip to content

False positive ambiguity warning #12816

Closed
scala/scala
#10456
@lrytz

Description

@lrytz
trait U { def m: Int = 0 }
package object p extends U

package p {
  trait T { def m = 1 }
  class C extends T { def t = m }
}

With 2.13.11 and -Xsource:3, this emits a false ambiguity warning:

➜ sandbox sc A.scala -Xsource:3 -deprecation
A.scala:4: warning: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
package object p extends U
                 ^
A.scala:8: warning: reference to m is ambiguous;
it is both defined in the enclosing trait U and inherited in the enclosing class C as method m (defined in trait T)
In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.
Such references are ambiguous in Scala 3. To continue using the inherited symbol, write `this.m`.
Or use `-Wconf:msg=legacy-binding:s` to silence this warning.
  class C extends T { def t = m }
                              ^
2 warnings

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions