Skip to content

Commit 21d41a1

Browse files
committed
fix #1670: move the check of value class to typer
1 parent adb37ee commit 21d41a1

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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 =>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12631263
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true,
12641264
cls, isRequired, cdef.pos)
12651265
}
1266+
1267+
1268+
// check value class constraints
1269+
RefChecks.checkDerivedValueClass(cls, body1)
1270+
12661271
cdef1
12671272

12681273
// 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)