Skip to content

Top-level package objects are incorrectly inserted in the empty package #7932

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

Closed
smarter opened this issue Jan 8, 2020 · 2 comments
Closed
Assignees
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug stat:revisit

Comments

@smarter
Copy link
Member

smarter commented Jan 8, 2020

The empty package should only be used for definitions which have no parent package, so this is clearly incorrect, but I don't know what kind of problems this may cause:

package object foo

dotty:

result of try/tl.scala after typer:
package <empty> {
  package foo {
    final lazy module val package: foo.package$ = new foo.package$()
    final module class package$() extends Object(), _root_.scala.Serializable {
      this: foo.package.type =>
    }
  }
}

scalac:

[[syntax trees at end of                     typer]] // tl.scala
package foo {
  object `package` extends scala.AnyRef {
    def <init>(): foo.package.type = {
      `package`.super.<init>();
      ()
    };
    <empty>
  }
}

This is important to get right since the standard library defines the top-level package object scala /cc @odersky

@smarter smarter added itype:bug area:desugar Desugaring happens after parsing but before typing, see desugar.scala labels Jan 8, 2020
@odersky odersky self-assigned this Jan 9, 2020
@som-snytt
Copy link
Contributor

FWIW, dotty correctly handles separate compilation of toplevel empty package object

object `package`

but scala 2 requires an anomalous

import `package`._

scala/bug#10927

@odersky
Copy link
Contributor

odersky commented Feb 16, 2020

This would be messy to change. If a source file has no package clause, it is wrapped in the empty package. If there are then local package clauses that's where they go. I'd like to see whether this causes some actual problems before complicating this scheme.

@odersky odersky closed this as completed Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug stat:revisit
Projects
None yet
Development

No branches or pull requests

3 participants