Skip to content

Wrong codegen transform for final val with literal type but not literal rhs inside trait #17549

Closed
@pweisenburger

Description

@pweisenburger

Was: Scala.js backend crashes for final val with literal type inside trait

Compiler version

3.2.2, 3.3.0-RC3

Minimized code

The following code crashes the compiler when using the Scala.js backend:

trait T:
  final val x: 1 = ???

Similar for this example:

trait T:
  def f(): Unit = ()
  final val x: "test" = { f(); "test" }

To trigger the issue, the field needs to be in a trait, it has to be a final val, the field needs a literal type and the right-hand-side needs to different from just being the literal itself (e.g., it compiles for final val x: 1 = 1).

Output

dotty.tools.FatalError: Illegal tree in gen of genInterface(): private val x: Int
class = trait T extends Object {
  def <init>(): Unit = 
    {
      this.x = ???()
      ()
    }
  private val x: Int
  final def x(): Int = this.x
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions