aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-03-09 08:28:22 +0100
committerMartin Odersky <odersky@gmail.com>2016-03-12 16:08:39 +0100
commitbde5e4dfeb54601755f09983e3893e1679a4b920 (patch)
treeb1fc625e3c09b3df0a10d9e9b2b8015cf0c1b3c5 /src
parent6ddc9112d0eb8a0f32b82c236244defdaeec5ce8 (diff)
downloaddotty-bde5e4dfeb54601755f09983e3893e1679a4b920.tar.gz
dotty-bde5e4dfeb54601755f09983e3893e1679a4b920.tar.bz2
dotty-bde5e4dfeb54601755f09983e3893e1679a4b920.zip
Add patch for variance errors
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/typer/VarianceChecker.scala17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/typer/VarianceChecker.scala b/src/dotty/tools/dotc/typer/VarianceChecker.scala
index b257ee192..1769835da 100644
--- a/src/dotty/tools/dotc/typer/VarianceChecker.scala
+++ b/src/dotty/tools/dotc/typer/VarianceChecker.scala
@@ -6,6 +6,8 @@ import core._
import Types._, Contexts._, Flags._, Symbols._, Annotations._, Trees._, NameOps._
import Decorators._
import Variances._
+import util.Positions._
+import rewrite.Rewrites.patch
import config.Printers.variances
/** Provides `check` method to check that all top-level definitions
@@ -108,11 +110,13 @@ class VarianceChecker()(implicit ctx: Context) {
}
private object Traverser extends TreeTraverser {
- def checkVariance(sym: Symbol) = Validator.validateDefinition(sym) match {
+ def checkVariance(sym: Symbol, pos: Position) = Validator.validateDefinition(sym) match {
case Some(VarianceError(tvar, required)) =>
def msg = i"${varianceString(tvar.flags)} $tvar occurs in ${varianceString(required)} position in type ${sym.info} of $sym"
- if (ctx.scala2Mode && sym.owner.isConstructor)
- ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", sym.pos)
+ if (ctx.scala2Mode && sym.owner.isConstructor) {
+ ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg, pos = ${sym.pos}", sym.pos)
+ patch(ctx.compilationUnit.source, Position(pos.end), " @scala.annotation.unchecked.uncheckedVariance") // TODO use an import or shorten if possible
+ }
else ctx.error(msg, sym.pos)
case None =>
}
@@ -128,12 +132,11 @@ class VarianceChecker()(implicit ctx: Context) {
case defn: MemberDef if skip =>
ctx.debuglog(s"Skipping variance check of ${sym.showDcl}")
case tree: TypeDef =>
- checkVariance(sym)
- traverseChildren(tree)
+ checkVariance(sym, tree.envelope)
case tree: ValDef =>
- checkVariance(sym)
+ checkVariance(sym, tree.envelope)
case DefDef(_, tparams, vparamss, _, _) =>
- checkVariance(sym)
+ checkVariance(sym, tree.envelope)
tparams foreach traverse
vparamss foreach (_ foreach traverse)
case Template(_, _, _, body) =>