aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-26 20:50:28 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-05-27 16:41:37 +0200
commit8f08b714424b3ada8a12156bdc3fd43e13ad09ee (patch)
tree2d874cd0d7f2775e8d6ce1a67b954d3601f5beac
parent87b779bc96e10adc6a05635393cecc9ecbb2b4ea (diff)
downloaddotty-8f08b714424b3ada8a12156bdc3fd43e13ad09ee.tar.gz
dotty-8f08b714424b3ada8a12156bdc3fd43e13ad09ee.tar.bz2
dotty-8f08b714424b3ada8a12156bdc3fd43e13ad09ee.zip
Annotate repeated params with `case` flag to indicate that they are legal
One drawback with this approach is that the type seems to propagate. I.e. if the return type of an expression is `repeated` then the enclosing variable will get the `repeated` type instead of getting the expected `Seq` type
-rw-r--r--src/dotty/tools/dotc/transform/TreeChecker.scala12
-rw-r--r--src/dotty/tools/dotc/typer/ReTyper.scala1
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala3
-rw-r--r--tests/disabled/pos/t3480.scala2
-rw-r--r--tests/pos/vararg-pattern.scala5
5 files changed, 14 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala
index a27c9c5f3..0dce0fd36 100644
--- a/src/dotty/tools/dotc/transform/TreeChecker.scala
+++ b/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -119,7 +119,12 @@ class TreeChecker extends Phase with SymTransformer {
val prevPhase = ctx.phase.prev // can be a mini-phase
val squahsedPhase = ctx.squashed(prevPhase)
ctx.echo(s"checking ${ctx.compilationUnit} after phase ${squahsedPhase}")
- val checkingCtx = ctx.fresh.setReporter(new ThrowingReporter(ctx.reporter))
+
+ val checkingCtx = ctx
+ .fresh
+ .setMode(Mode.ImplicitsEnabled)
+ .setReporter(new ThrowingReporter(ctx.reporter))
+
val checker = new Checker(previousPhases(phasesToRun.toList)(ctx))
try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
catch {
@@ -307,7 +312,9 @@ class TreeChecker extends Phase with SymTransformer {
}.apply(tp)
def checkNotRepeated(tree: Tree)(implicit ctx: Context): tree.type = {
- assert(!tree.tpe.widen.isRepeatedParam, i"repeated parameter type not allowed here: $tree")
+ def allowedRepeated = (tree.symbol.flags is Case) && tree.tpe.widen.isRepeatedParam
+
+ assert(!tree.tpe.widen.isRepeatedParam || allowedRepeated, i"repeated parameter type not allowed here: $tree")
tree
}
@@ -322,6 +329,7 @@ class TreeChecker extends Phase with SymTransformer {
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
assert(tree.isType || !needsSelect(tree.tpe), i"bad type ${tree.tpe} for $tree # ${tree.uniqueId}")
assertDefined(tree)
+
checkNotRepeated(super.typedIdent(tree, pt))
}
diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala
index 225451886..a4f92271a 100644
--- a/src/dotty/tools/dotc/typer/ReTyper.scala
+++ b/src/dotty/tools/dotc/typer/ReTyper.scala
@@ -23,6 +23,7 @@ import config.Printers
class ReTyper extends Typer {
import tpd._
+ /** Checks that the given tree has been typed */
protected def promote(tree: untpd.Tree)(implicit ctx: Context): tree.ThisTree[Type] = {
assert(tree.hasType, i"$tree ${tree.getClass} ${tree.uniqueId}")
tree.withType(tree.typeOpt)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 88b6746d6..9f38ac0f0 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -427,7 +427,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
if (untpd.isWildcardStarArg(tree))
cases(
- //ifPat = ascription(TypeTree(defn.SeqType.appliedTo(pt :: Nil)), isWildcard = true),
ifPat = ascription(TypeTree(defn.RepeatedParamType.appliedTo(pt)), isWildcard = true),
ifExpr = seqToRepeated(typedExpr(tree.expr, defn.SeqType)),
wildName = nme.WILDCARD_STAR)
@@ -976,7 +975,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
typed(untpd.Bind(tree.name, arg).withPos(tree.pos), arg.tpe) :: Nil)
case _ =>
val flags = if (tree.isType) BindDefinedType else EmptyFlags
- val sym = ctx.newSymbol(ctx.owner, tree.name, flags, body1.tpe, coord = tree.pos)
+ val sym = ctx.newSymbol(ctx.owner, tree.name, flags | Case, body1.tpe, coord = tree.pos)
assignType(cpy.Bind(tree)(tree.name, body1), sym)
}
}
diff --git a/tests/disabled/pos/t3480.scala b/tests/disabled/pos/t3480.scala
index ba2e1a4b8..55dde6634 100644
--- a/tests/disabled/pos/t3480.scala
+++ b/tests/disabled/pos/t3480.scala
@@ -1,4 +1,4 @@
object Test {
val List(_: _*) = List(1)
- val Array( who, what : _* ) = "Eclipse plugin cannot not handle this" split (" ")
+ val Array(who, what: _*) = "Eclipse plugin cannot not handle this" split (" ")
}
diff --git a/tests/pos/vararg-pattern.scala b/tests/pos/vararg-pattern.scala
index 314d6460f..430973a28 100644
--- a/tests/pos/vararg-pattern.scala
+++ b/tests/pos/vararg-pattern.scala
@@ -1,12 +1,9 @@
object Test {
-
List(1, 2, 3, 4) match {
case List(1, 2, xs: _*) =>
val ys: Seq[Int] = xs
println(ys)
}
- val List(1, 2, x: _*) = List(1, 2, 3, 4)
+ val List(1, 2, x: _*) = List(1, 2, 3, 4)
}
-
-