Skip to content

Confusing parsing error when defining a val named _root_ with a type #18020

Open
@Linyxus

Description

@Linyxus

Compiler version

main (and also in Scala 2)

Minimized code

def foo: Unit =
  val _root_: String = "abc"

Output

-- [E032] Syntax Error: issues/i17757.scala:2:21 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 |  val _root_: String = "abc"
  |                     ^
  |                     pattern expected
  |
  | longer explanation available when compiling with `-explain`

Expectation

If you leave out the type, it will compile:

val _root_ = "abc"

So this one with a type annotation should compile as well?

Found together with @jan-pieter @nmcb when working on #18019

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions