Skip to content

Commit 1e3b0c0

Browse files
committed
fix scala#1670: move the check of value class to typer
1 parent 2d18af6 commit 1e3b0c0

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
@@ -696,7 +696,7 @@ object RefChecks {
696696
}
697697

698698
/** Verify classes extending AnyVal meet the requirements */
699-
private def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
699+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
700700
def checkValueClassMember(stat: Tree) = stat match {
701701
case _: ValDef if !stat.symbol.is(ParamAccessor) =>
702702
ctx.error(s"value class may not define non-parameter field", stat.pos)
@@ -843,7 +843,6 @@ class RefChecks extends MiniPhase { thisTransformer =>
843843
checkParents(cls)
844844
checkCompanionNameClashes(cls)
845845
checkAllOverrides(cls)
846-
checkDerivedValueClass(cls, tree.body)
847846
tree
848847
} catch {
849848
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)