Skip to content

Commit af3e581

Browse files
committed
don't recheck in -Ycheck
1 parent abb9aa8 commit af3e581

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

compiler/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]

compiler/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
*/
@@ -406,6 +407,43 @@ object Checking {
406407
notPrivate.errors.foreach { case (msg, pos) => ctx.errorOrMigrationWarning(msg, pos) }
407408
info
408409
}
410+
411+
/** Verify classes extending AnyVal meet the requirements */
412+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = {
413+
def checkValueClassMember(stat: Tree) = stat match {
414+
case _: ValDef if !stat.symbol.is(ParamAccessor) =>
415+
ctx.error(s"value class may not define non-parameter field", stat.pos)
416+
case d: DefDef if d.symbol.isConstructor =>
417+
ctx.error(s"value class may not define secondary constructor", stat.pos)
418+
case _: MemberDef | _: Import | EmptyTree =>
419+
// ok
420+
case _ =>
421+
ctx.error(s"value class may not contain initialization statements", stat.pos)
422+
}
423+
if (isDerivedValueClass(clazz)) {
424+
if (clazz.is(Trait))
425+
ctx.error("Only classes (not traits) are allowed to extend AnyVal", clazz.pos)
426+
if (clazz.is(Abstract))
427+
ctx.error("`abstract' modifier cannot be used with value classes", clazz.pos)
428+
if (!clazz.isStatic)
429+
ctx.error(s"value class may not be a ${if (clazz.owner.isTerm) "local class" else "member of another class"}", clazz.pos)
430+
if (isCyclic(clazz.asClass))
431+
ctx.error("value class cannot wrap itself", clazz.pos)
432+
else {
433+
val clParamAccessors = clazz.asClass.paramAccessors.filter(_.isTerm)
434+
clParamAccessors match {
435+
case List(param) =>
436+
if (param.is(Mutable))
437+
ctx.error("value class parameter must not be a var", param.pos)
438+
439+
case _ =>
440+
ctx.error("value class needs to have exactly one val parameter", clazz.pos)
441+
}
442+
}
443+
stats.foreach(checkValueClassMember)
444+
}
445+
446+
}
409447
}
410448

411449
trait Checking {
@@ -553,6 +591,10 @@ trait Checking {
553591
errorTree(tpt, ex"Singleton type ${tpt.tpe} is not allowed $where")
554592
}
555593
else tpt
594+
595+
/** Verify classes extending AnyVal meet the requirements */
596+
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) =
597+
Checking.checkDerivedValueClass(clazz, stats)
556598
}
557599

558600
trait NoChecking extends Checking {
@@ -568,4 +610,5 @@ trait NoChecking extends Checking {
568610
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
569611
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt
570612
override def checkNotSingleton(tpt: Tree, where: String)(implicit ctx: Context): Tree = tpt
613+
override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = ()
571614
}

compiler/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._
@@ -688,42 +687,6 @@ object RefChecks {
688687
}
689688
}
690689

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

729692
class OptLevelInfo extends DotClass {

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

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

12731273
// check value class constraints
1274-
RefChecks.checkDerivedValueClass(cls, body1)
1274+
checkDerivedValueClass(cls, body1)
12751275

12761276
cdef1
12771277

0 commit comments

Comments
 (0)