Skip to content

Commit 47edffb

Browse files
committed
don't recheck in -Ycheck
1 parent 146e9db commit 47edffb

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TreeChecker extends Phase with SymTransformer {
135135
}
136136
}
137137

138-
class Checker(phasesToCheck: Seq[Phase]) extends ReTyper {
138+
class Checker(phasesToCheck: Seq[Phase]) extends ReTyper with NoChecking {
139139

140140
val nowDefinedSyms = new mutable.HashSet[Symbol]
141141
val everDefinedSyms = new mutable.HashMap[Symbol, Tree]

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ErrorReporting.{err, errorType}
2929
import config.Printers.typr
3030
import collection.mutable
3131
import SymDenotations.NoCompleter
32+
import dotty.tools.dotc.transform.ValueClasses._
3233

3334
object Checking {
3435
import tpd._
@@ -56,7 +57,7 @@ object Checking {
5657
checkBounds(args, poly.paramBounds, _.substParams(poly, _))
5758

5859
/** Check applied type trees for well-formedness. This means
59-
* - all arguments are within their corresponding bounds
60+
* - all arguments are within their corresponding bounds
6061
* - if type is a higher-kinded application with wildcard arguments,
6162
* check that it or one of its supertypes can be reduced to a normal application.
6263
* Unreducible applications correspond to general existentials, and we
@@ -88,12 +89,12 @@ object Checking {
8889
checkWildcardHKApply(tp.superType, pos)
8990
}
9091
case _ =>
91-
}
92+
}
9293
def checkValidIfHKApply(implicit ctx: Context): Unit =
9394
checkWildcardHKApply(tycon.tpe.appliedTo(args.map(_.tpe)), tree.pos)
9495
checkValidIfHKApply(ctx.addMode(Mode.AllowLambdaWildcardApply))
9596
}
96-
97+
9798
/** Check that `tp` refers to a nonAbstract class
9899
* and that the instance conforms to the self type of the created class.
99100
*/
@@ -392,6 +393,43 @@ object Checking {
392393
notPrivate.errors.foreach { case (msg, pos) => ctx.errorOrMigrationWarning(msg, pos) }
393394
info
394395
}
396+
397+
/** Verify classes extending AnyVal meet the requirements */
398+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
399+
def checkValueClassMember(stat: Tree) = stat match {
400+
case _: ValDef if !stat.symbol.is(ParamAccessor) =>
401+
ctx.error(s"value class may not define non-parameter field", stat.pos)
402+
case d: DefDef if d.symbol.isConstructor =>
403+
ctx.error(s"value class may not define secondary constructor", stat.pos)
404+
case _: MemberDef | _: Import | EmptyTree =>
405+
// ok
406+
case _ =>
407+
ctx.error(s"value class may not contain initialization statements", stat.pos)
408+
}
409+
if (isDerivedValueClass(clazz)) {
410+
if (clazz.is(Trait))
411+
ctx.error("Only classes (not traits) are allowed to extend AnyVal", clazz.pos)
412+
if (clazz.is(Abstract))
413+
ctx.error("`abstract' modifier cannot be used with value classes", clazz.pos)
414+
if (!clazz.isStatic)
415+
ctx.error(s"value class may not be a ${if (clazz.owner.isTerm) "local class" else "member of another class"}", clazz.pos)
416+
if (isCyclic(clazz.asClass))
417+
ctx.error("value class cannot wrap itself", clazz.pos)
418+
else {
419+
val clParamAccessors = clazz.asClass.paramAccessors.filter(_.isTerm)
420+
clParamAccessors match {
421+
case List(param) =>
422+
if (param.is(Mutable))
423+
ctx.error("value class parameter must not be a var", param.pos)
424+
425+
case _ =>
426+
ctx.error("value class needs to have exactly one val parameter", clazz.pos)
427+
}
428+
}
429+
stats.foreach(checkValueClassMember)
430+
}
431+
432+
}
395433
}
396434

397435
trait Checking {
@@ -539,6 +577,10 @@ trait Checking {
539577
errorTree(tpt, ex"Singleton type ${tpt.tpe} is not allowed $where")
540578
}
541579
else tpt
580+
581+
/** Verify classes extending AnyVal meet the requirements */
582+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) =
583+
Checking.checkDerivedValueClass(clazz, stats)
542584
}
543585

544586
trait NoChecking extends Checking {
@@ -554,4 +596,5 @@ trait NoChecking extends Checking {
554596
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
555597
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt
556598
override def checkNotSingleton(tpt: Tree, where: String)(implicit ctx: Context): Tree = tpt
599+
override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = ()
557600
}

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import config.{ScalaVersion, NoScalaVersion}
1818
import Decorators._
1919
import typer.ErrorReporting._
2020
import DenotTransformers._
21-
import ValueClasses.{isDerivedValueClass, isCyclic}
2221

2322
object RefChecks {
2423
import tpd._
@@ -695,42 +694,6 @@ object RefChecks {
695694
}
696695
}
697696

698-
/** Verify classes extending AnyVal meet the requirements */
699-
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
700-
def checkValueClassMember(stat: Tree) = stat match {
701-
case _: ValDef if !stat.symbol.is(ParamAccessor) =>
702-
ctx.error(s"value class may not define non-parameter field", stat.pos)
703-
case _: DefDef if stat.symbol.isConstructor =>
704-
ctx.error(s"value class may not define secondary constructor", stat.pos)
705-
case _: MemberDef | _: Import | EmptyTree =>
706-
// ok
707-
case _ =>
708-
ctx.error(s"value class may not contain initialization statements", stat.pos)
709-
}
710-
if (isDerivedValueClass(clazz)) {
711-
if (clazz.is(Trait))
712-
ctx.error("Only classes (not traits) are allowed to extend AnyVal", clazz.pos)
713-
if (clazz.is(Abstract))
714-
ctx.error("`abstract' modifier cannot be used with value classes", clazz.pos)
715-
if (!clazz.isStatic)
716-
ctx.error(s"value class may not be a ${if (clazz.owner.isTerm) "local class" else "member of another class"}", clazz.pos)
717-
if (isCyclic(clazz.asClass))
718-
ctx.error("value class cannot wrap itself", clazz.pos)
719-
else {
720-
val clParamAccessors = clazz.asClass.paramAccessors.filter(_.isTerm)
721-
clParamAccessors match {
722-
case List(param) =>
723-
if (param.is(Mutable))
724-
ctx.error("value class parameter must not be a var", param.pos)
725-
726-
case _ =>
727-
ctx.error("value class needs to have exactly one val parameter", clazz.pos)
728-
}
729-
}
730-
stats.foreach(checkValueClassMember)
731-
}
732-
}
733-
734697
type LevelAndIndex = immutable.Map[Symbol, (LevelInfo, Int)]
735698

736699
class OptLevelInfo extends DotClass {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12651265
}
12661266

12671267
// check value class constraints
1268-
RefChecks.checkDerivedValueClass(cls, body1)
1268+
checkDerivedValueClass(cls, body1)
12691269

12701270
cdef1
12711271

0 commit comments

Comments
 (0)