Skip to content

Private field with non-alphanumeric identifier exhibits incorrect behavior at runtime #14667

Closed
@FlorianCassayre

Description

@FlorianCassayre

Compiler version

Affects 3.0.0 to 3.1.2-RC1.

Does not affect 2.13.8.

Minimized code

trait A {
  private val ? = ""
  def a = ?
}

@main def run(): Unit = println(new A {}.a)

Link to 3.1.1 Scastie

Output

null

Expectation

This program should print an empty line, not null.

Observations: the problem does not occur when

  • ? is renamed to an alphanumeric identifier (!)
  • ? is a definition instead of a value
  • A is a class instead of a trait
  • ? is protected or public

The ? can be replaced with any other symbol e.g. *, |||, ... (all of those will trigger the same problem)

When replacing "" by e.g. 1, the program prints 0 which confirms that it is a problem related to initialization.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions