Skip to content

Compiler wrongly identify value classes during desugaring (dual of #21918) #21943

Open
@hamzaremmal

Description

@hamzaremmal

Compiler version

bed0e86

Minimized code

class AnyVal
class Foo extends AnyVal

Output

During typer, the desugaring assumes we are implementing a value class and generates the companion object for Foo

[[syntax trees at end of                     typer]] // t.scala
package <empty> {
  class AnyVal() extends Object() {}
  class Foo() extends AnyVal() {}
  final lazy module val Foo: Foo = new Foo()
  final module class Foo() extends AnyRef() { this: Foo.type =>}
}

Expectation

Should behave the same way as extending any other reference class:

[[syntax trees at end of                     typer]] // t.scala
package <empty> {
  class Anyval() extends Object() {}
  class Foo() extends Anyval() {}
}

Note

This is has the same root problem as #21918. In #21918, it was a case where isAnyVal wrongly unidentify value classes (false negative) while this issue is the case where the same check wrongly identify value classes (false positive).

def isAnyVal(tree: Tree): Boolean = tree match {
case Ident(tpnme.AnyVal) => true
case Select(qual, tpnme.AnyVal) => isScala(qual)
case _ => false
}

Metadata

Metadata

Assignees

Labels

area:desugarDesugaring happens after parsing but before typing, see desugar.scalaarea:value-classesIssues tied to value classes.itype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions