Skip to content

Commit 8592af1

Browse files
committed
fix #1670: move the check of value class to typer
1 parent 3599c24 commit 8592af1

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ object RefChecks {
689689
}
690690

691691
/** Verify classes extending AnyVal meet the requirements */
692-
private def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
692+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
693693
def checkValueClassMember(stat: Tree) = stat match {
694694
case _: ValDef if !stat.symbol.is(ParamAccessor) =>
695695
ctx.error(s"value class may not define non-parameter field", stat.pos)
@@ -836,7 +836,6 @@ class RefChecks extends MiniPhase { thisTransformer =>
836836
checkParents(cls)
837837
checkCompanionNameClashes(cls)
838838
checkAllOverrides(cls)
839-
checkDerivedValueClass(cls, tree.body)
840839
tree
841840
} catch {
842841
case ex: MergeError =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12691269
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true,
12701270
cls, isRequired, cdef.pos)
12711271
}
1272+
1273+
1274+
// check value class constraints
1275+
RefChecks.checkDerivedValueClass(cls, body1)
1276+
12721277
cdef1
12731278

12741279
// todo later: check that

tests/neg/i1670.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class A(a:Int, b:Int) extends AnyVal

0 commit comments

Comments
 (0)