aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/Decorators.scala1
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala10
-rw-r--r--tests/pos/typers.scala11
3 files changed, 13 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala
index ca601cddf..cd9680e64 100644
--- a/src/dotty/tools/dotc/core/Decorators.scala
+++ b/src/dotty/tools/dotc/core/Decorators.scala
@@ -115,6 +115,7 @@ object Decorators {
implicit class ListOfListDecorator[T](val xss: List[List[T]]) extends AnyVal {
def nestedMap[U](f: T => U): List[List[U]] = xss map (_ map f)
+ def nestedMapconserve[U](f: T => U): List[List[U]] = xss mapconserve (_ mapconserve f)
}
implicit class TextToString(val text: Text) extends AnyVal {
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 6b6252638..b59832602 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -394,7 +394,7 @@ class Typer extends Namer with Applications with Implicits {
def typedNew(tree: untpd.New, pt: Type)(implicit ctx: Context) = track("typedNew") {
tree.tpt match {
- case templ: Template =>
+ case templ: untpd.Template =>
import untpd._
val x = tpnme.ANON_CLASS
val clsDef = TypeDef(Modifiers(Final), x, templ)
@@ -426,7 +426,7 @@ class Typer extends Namer with Applications with Implicits {
cpy.Typed(tree, expr1, tpt1).withType(tpt1.tpe)
}
tree.expr match {
- case id: Ident if (ctx.mode is Mode.Pattern) && isVarPattern(id) =>
+ case id: untpd.Ident if (ctx.mode is Mode.Pattern) && isVarPattern(id) =>
if (id.name == nme.WILDCARD) regularTyped(isWildcard = true)
else {
import untpd._
@@ -759,7 +759,7 @@ class Typer extends Namer with Applications with Implicits {
val DefDef(mods, name, tparams, vparamss, tpt, rhs) = ddef
val mods1 = typedModifiers(mods)
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
- val vparamss1 = vparamss mapconserve(_ mapconserve (typed(_).asInstanceOf[ValDef]))
+ val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
cpy.DefDef(ddef, mods1, name, tparams1, vparamss1, tpt1, rhs1).withType(sym.termRefWithSig)
@@ -930,7 +930,7 @@ class Typer extends Namer with Applications with Implicits {
val nestedCtx = if (exprOwner == ctx.owner) ctx else ctx.fresh.withOwner(exprOwner)
buf += typed(stat)(nestedCtx)
traverse(rest)
- case _ =>
+ case nil =>
buf.toList
}
traverse(stats)
@@ -938,7 +938,7 @@ class Typer extends Namer with Applications with Implicits {
def typedExpr(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =
typed(tree, pt)(ctx retractMode Mode.PatternOrType)
- def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =
+ def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = // todo: retract mode between Type and Pattern?
typed(tree, pt)(ctx addMode Mode.Type)
def typedPattern(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =
typed(tree, pt)(ctx addMode Mode.Pattern)
diff --git a/tests/pos/typers.scala b/tests/pos/typers.scala
index 66c10f4b0..b2d1d50e1 100644
--- a/tests/pos/typers.scala
+++ b/tests/pos/typers.scala
@@ -1,4 +1,4 @@
-import annotation.tailrec
+import annotation.{tailrec, switch}
object typers {
@@ -46,11 +46,14 @@ object typers {
class C {
- @tailrec def factorial(acc: Int, n: Int): Int =
- if (n == 0) acc
- else factorial(acc * n, n - 1)
+ @tailrec def factorial(acc: Int, n: Int): Int = (n: @switch) match {
+ case 0 => acc
+ case _ => factorial(acc * n, n - 1)
+ }
println(factorial(1, 10))
+
+
}
class Refinements {