Skip to content

Commit e8a36a1

Browse files
committed
Add @volatile when rewriting lazy vals from Scala2.
1 parent 8375113 commit e8a36a1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import Symbols._
1111
import Decorators._
1212
import NameOps._
1313
import StdNames.nme
14+
import rewrite.Rewrites.patch
15+
import util.Positions.Position
1416
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransformer, MiniPhaseTransform}
17+
import dotty.tools.dotc.ast.NavigateAST._
1518
import dotty.tools.dotc.ast.Trees._
1619
import dotty.tools.dotc.ast.{untpd, tpd}
1720
import dotty.tools.dotc.core.Constants.Constant
@@ -64,11 +67,14 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with Nee
6467
val sym = tree.symbol
6568
if (!(sym is Flags.Lazy) || sym.owner.is(Flags.Trait) || (sym.isStatic && sym.is(Flags.Module))) tree
6669
else {
67-
6870
val isField = sym.owner.isClass
69-
7071
if (isField) {
7172
if (sym.isVolatile ||
73+
ctx.scala2Mode && {
74+
if (ctx.settings.rewrite.value.isDefined)
75+
patch(ctx.compilationUnit.source, Position(toUntyped(tree).envelope.start), "@volatile ")
76+
true // cannot assume volatile because of problems with compilestdlib. See #1149
77+
} ||
7278
(sym.is(Flags.Module) && !sym.is(Flags.Synthetic)))
7379
// module class is user-defined.
7480
// Should be threadsafe, to mimic safety guaranteed by global object

0 commit comments

Comments
 (0)