Skip to content

Empty package visibility underspecified or just confusing #7891

Closed
@som-snytt

Description

@som-snytt

minimized code

// ok in one compilation unit
def f = "hello, world"

package p {
  @main def m = println(f)
}
// fonly.scala
def f = "hello, world"

// ponly.scala
package p {
  @main def m = println(f)
}

Compiled together or separately:

➜  dotc ponly.scala fonly.scala
-- [E006] Unbound Identifier Error: ponly.scala:5:24 ---------------------------
5 |  @main def m = println(f)
  |                        ^
  |                        Not found: f

longer explanation available when compiling with `-explain`
1 error found

expectation

Binding of f shouldn't depend on compilation unit, but moreover, members of the empty package should be visible only to members of the empty package; or specify that they are visible in the current compilation unit.

Other restrictions may apply. Cf #7650

Related confusion in Scala 2: scala/bug#10927

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions