@@ -34,6 +34,8 @@ import Implicits._
34
34
import util .Stats .{track , record }
35
35
import config .Printers ._
36
36
import rewrite .Rewrites .patch
37
+ import NavigateAST ._
38
+ import transform .SymUtils ._
37
39
import language .implicitConversions
38
40
39
41
object Typer {
@@ -984,7 +986,18 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
984
986
case rhs @ Ident (nme.WILDCARD ) => rhs withType tpt1.tpe
985
987
case rhs => typedExpr(rhs, tpt1.tpe)
986
988
}
987
- assignType(cpy.ValDef (vdef)(name, tpt1, rhs1), sym)
989
+ val vdef1 = assignType(cpy.ValDef (vdef)(name, tpt1, rhs1), sym)
990
+ patchIfLazy(vdef1)
991
+ vdef1
992
+ }
993
+
994
+ /** Add a @volitile to lazy vals when rewriting from Scala2 */
995
+ private def patchIfLazy (vdef : ValDef )(implicit ctx : Context ): Unit = {
996
+ val sym = vdef.symbol
997
+ if (sym.is(Lazy , butNot = Deferred | Module | Synthetic ) && ! sym.isVolatile &&
998
+ ctx.scala2Mode && ctx.settings.rewrite.value.isDefined &&
999
+ ! ctx.isAfterTyper)
1000
+ patch(ctx.compilationUnit.source, Position (toUntyped(vdef).envelope.start), " @volatile " )
988
1001
}
989
1002
990
1003
def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(implicit ctx : Context ) = track(" typedDefDef" ) {
@@ -1142,8 +1155,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1142
1155
if (pt1.eq(AnyFunctionProto ) && ! defn.isFunctionClass(res.tpe.classSymbol)) {
1143
1156
def msg = i " not a function: ${res.tpe}; cannot be followed by `_' "
1144
1157
if (ctx.scala2Mode) {
1158
+ // Under -rewrite, patch `x _` to `(() => x)`
1145
1159
ctx.migrationWarning(msg, tree.pos)
1146
- patch(ctx.compilationUnit.source, Position (qual.pos.end, tree.pos.end), " " )
1160
+ patch(ctx.compilationUnit.source, Position (tree.pos.start), " (() => " )
1161
+ patch(ctx.compilationUnit.source, Position (qual.pos.end, tree.pos.end), " )" )
1147
1162
res = typed(untpd.Function (Nil , untpd.TypedSplice (res)))
1148
1163
}
1149
1164
else ctx.error(msg, tree.pos)
0 commit comments