-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:desugarDesugaring happens after parsing but before typing, see desugar.scalaDesugaring happens after parsing but before typing, see desugar.scalaarea:value-classesIssues tied to value classes.Issues tied to value classes.itype:bug
Description
Compiler version
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).
scala3/compiler/src/dotty/tools/dotc/ast/Desugar.scala
Lines 597 to 601 in cc38962
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.scalaDesugaring happens after parsing but before typing, see desugar.scalaarea:value-classesIssues tied to value classes.Issues tied to value classes.itype:bug