Skip to content

Should top level definitions access their wrapper objects and members of Any from Predef? #7713

Open
@som-snytt

Description

@som-snytt

minimized code

$ cat anything.scala

def f = toString

def g = this.toString

class C(val name: String) {
  def this() = this(getClass.getName)
}

object Test {
  def main(args: Array[String]): Unit = {
    println(f)
    println(g)
    println(C().name)
  }
}
$ dotr Test
dotty.DottyPredef$@76707e36
anything$package$@184f6be2
dotty.DottyPredef$

expectation

Scala 2 recently stopped including members of Any in root imports from Predef.

That was previously visible in import ne.scala.

Using getClass in a constructor context was noticed in Akka test code.

Crafting a package from the compilation unit looks intentional here, so perhaps this is as well. And maybe there is nothing which says toString must mean this.toString in any context.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions