Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Surprising parsing behaviour for objects ending with _  #16072

@keynmol

Description

@keynmol

Objects ending with _ that have a body are parsed in a surprising way.
I only narrowed it down accidentally, but the symptoms were lots of compiler errors because of the defs I expected to be in the companion actually being at top level.

Compiler version

3.2.0

Minimized code

You can see how Hello_: is defined instead, and x is treated as a top-level definition

object Hello_:
  def x = 1

object `Byte_`:
  def x = 1

@main def hello = 
  println(Byte_)
  println(Hello_:)
  println(x)

Output

This parsing warning is the only indication that helped me figure out that something was off:

[warn] ./test.scala:2:3: Line is indented too far to the right, or a `{` or `:` is missing
[warn]   def x = 1
[warn]   ^

Expectation

The code either parses correctly, or fails to parse, or gives a meaningful warning

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions