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