aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-03-09 09:46:12 +0100
committerMartin Odersky <odersky@gmail.com>2016-03-12 16:08:39 +0100
commit13e3d59937ddcb9819904593cb7c6417af8eedd2 (patch)
treea676e3455112c20681b853812da7f94dfe5a4a47 /src/dotty/tools/dotc/typer/Typer.scala
parent13a376c80c21ddb28789530091bb54f7fa58e785 (diff)
downloaddotty-13e3d59937ddcb9819904593cb7c6417af8eedd2.tar.gz
dotty-13e3d59937ddcb9819904593cb7c6417af8eedd2.tar.bz2
dotty-13e3d59937ddcb9819904593cb7c6417af8eedd2.zip
Fix two rewrite patches.
1. trailing `_`: `x _` is rewritten to `(() => x)` not to `x` 2. lazy vals: Rewrites are done in Typer, not LazyVals. Later on we are too much at risk to hit synthetically generated lazy vals.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index b9940e367..1a0525c6d 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -34,6 +34,8 @@ import Implicits._
import util.Stats.{track, record}
import config.Printers._
import rewrite.Rewrites.patch
+import NavigateAST._
+import transform.SymUtils._
import language.implicitConversions
object Typer {
@@ -985,7 +987,18 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe
case rhs => typedExpr(rhs, tpt1.tpe)
}
- assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
+ val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
+ patchIfLazy(vdef1)
+ vdef1
+ }
+
+ /** Add a @volitile to lazy vals when rewriting from Scala2 */
+ private def patchIfLazy(vdef: ValDef)(implicit ctx: Context): Unit = {
+ val sym = vdef.symbol
+ if (sym.is(Lazy, butNot = Deferred | Module | Synthetic) && !sym.isVolatile &&
+ ctx.scala2Mode && ctx.settings.rewrite.value.isDefined &&
+ !ctx.isAfterTyper)
+ patch(ctx.compilationUnit.source, Position(toUntyped(vdef).envelope.start), "@volatile ")
}
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = track("typedDefDef") {
@@ -1143,8 +1156,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
if (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) {
def msg = i"not a function: ${res.tpe}; cannot be followed by `_'"
if (ctx.scala2Mode) {
+ // Under -rewrite, patch `x _` to `(() => x)`
ctx.migrationWarning(msg, tree.pos)
- patch(ctx.compilationUnit.source, Position(qual.pos.end, tree.pos.end), "")
+ patch(ctx.compilationUnit.source, Position(tree.pos.start), "(() => ")
+ patch(ctx.compilationUnit.source, Position(qual.pos.end, tree.pos.end), ")")
res = typed(untpd.Function(Nil, untpd.TypedSplice(res)))
}
else ctx.error(msg, tree.pos)