Skip to content

Commit 9a92d27

Browse files
committed
Fix selecting terms using _root_
1 parent fa38cb8 commit 9a92d27

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,18 @@ object Parsers {
10711071
nme.ERROR
10721072
}
10731073

1074+
def checkNotRoot(tree: Tree): tree.type =
1075+
tree match
1076+
case Ident(nme.ROOTPKG) => syntaxError(em"Illegal use of root package name.")
1077+
case _ =>
1078+
tree
1079+
1080+
def rootOrTermIdent(): Ident =
1081+
makeIdent(in.token, in.offset, ident())
1082+
10741083
/** Accept identifier and return Ident with its name as a term name. */
10751084
def termIdent(): Ident =
1076-
val t = makeIdent(in.token, in.offset, ident())
1077-
if t.name == nme.ROOTPKG then
1078-
syntaxError(em"Illegal use of root package name.")
1079-
t
1085+
checkNotRoot(rootOrTermIdent())
10801086

10811087
/** Accept identifier and return Ident with its name as a type name. */
10821088
def typeIdent(): Ident =
@@ -4091,7 +4097,7 @@ object Parsers {
40914097
val derived =
40924098
if (isIdent(nme.derives)) {
40934099
in.nextToken()
4094-
commaSeparated(() => convertToTypeId(qualId()))
4100+
commaSeparated(() => convertToTypeId(dotSelectors(rootOrTermIdent())))
40954101
}
40964102
else Nil
40974103
possibleTemplateStart()

tests/pos/i18275.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package foo
2+
3+
enum MyEnum derives _root_.foo.Eq:
4+
case One
5+
6+
trait Eq[T]
7+
object Eq:
8+
inline def derived[T](using m: scala.deriving.Mirror.Of[T]): Eq[T] = ???

0 commit comments

Comments
 (0)