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

Fix selecting terms using _root_ #18335

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,7 @@ object Parsers {

/** Accept identifier and return Ident with its name as a term name. */
def termIdent(): Ident =
val t = makeIdent(in.token, in.offset, ident())
if t.name == nme.ROOTPKG then
syntaxError(em"Illegal use of root package name.")
t
makeIdent(in.token, in.offset, ident())

/** Accept identifier and return Ident with its name as a type name. */
def typeIdent(): Ident =
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree = {
val ValDef(name, tpt, _) = vdef
if name == nme.ROOTPKG then report.error(em"Illegal use of root package name.", vdef)
completeAnnotations(vdef, sym)
if (sym.isOneOf(GivenOrImplicit)) checkImplicitConversionDefOK(sym)
if sym.is(Module) then checkNoModuleClash(sym)
Expand Down Expand Up @@ -2505,6 +2506,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// hence we special case it until `erased` is no longer experimental.
sym.setFlag(Erased)
val DefDef(name, paramss, tpt, _) = ddef
if name == nme.ROOTPKG then report.error(em"Illegal use of root package name.", ddef)
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
completeAnnotations(ddef, sym)
val paramss1 = paramss.nestedMapConserve(typed(_)).asInstanceOf[List[ParamClause]]
for case ValDefs(vparams) <- paramss1 do
Expand Down
6 changes: 3 additions & 3 deletions tests/neg/i18020.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ def barVal: Unit =

// i18050
package p {
package _root_ { // error
package _root_ { // not-reported
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
object X // error
}
}

// scala/bug#12508
package _root_ { // error
package _root_ { // ok
class C {
val _root_ = 42 // error
}
}
package _root_.p { // error
package _root_.p { // ok
class C
}

Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i18275.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package foo

enum MyEnum derives _root_.foo.Eq:
case One

trait Eq[T]
object Eq:
inline def derived[T](using m: scala.deriving.Mirror.Of[T]): Eq[T] = ???