Skip to content
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

Hygiene of _root_ in user definitions #18050

Closed
som-snytt opened this issue Jun 23, 2023 · 1 comment · Fixed by #18187
Closed

Hygiene of _root_ in user definitions #18050

som-snytt opened this issue Jun 23, 2023 · 1 comment · Fixed by #18187
Labels
area:typer itype:bug Spree Suitable for a future Spree
Milestone

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.3.0

Minimized code

package p {
  package _root_ {
    object X
  }
}

Output

4 |    object X
  |    ^
  |    Not found: type X

Expectation

_root_ is an ordinary identifier except in a selection _root_.x, so this should just work, especially since the example below works.

Example is from https://github.com/scala/scala/blob/2.13.x/test/files/neg/t6217c.scala

Dotty compiles the example in scala/bug#12508 where the user packaging is top-level:

package _root_ {
  class C {
    val _root_ = 42
  }
}
package _root_.p {
  class C
}

That produces packages _root_ and _root_.p.

The latter example is "harder" in the sense that user's _root_ does clash with any possible selection; that is, _root_._root_.C is required to disambiguate.

Of course, no one writes code like this, but maybe it indicates an issue with lookups for the definition of object X.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 23, 2023
@odersky
Copy link
Contributor

odersky commented Jun 24, 2023

It's because of this clause in Typer.typedIdent:

    // Shortcut for the root package, this is not just a performance
    // optimization, it also avoids forcing imports thus potentially avoiding
    // cyclic references.
    if (name == nme.ROOTPKG)
      return tree.withType(defn.RootPackage.termRef)

See also: #18020 (comment)

@odersky odersky added area:typer prio:low and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 24, 2023
@odersky odersky added Spree Suitable for a future Spree and removed prio:low labels Jun 24, 2023
smarter added a commit that referenced this issue Jul 14, 2023
References #18020, didn't actually fix that, because it addressed
aspects of using `_root_` in definitions. Adding more details to that
ticket.
Fixes #17757
Fixes #18050
Includes the code in scala/bug#12508
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants