Skip to content

Commit 64eefea

Browse files
committed
Add @volatile when rewriting lazy vals from Scala2.
1 parent 31a6a26 commit 64eefea

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
@@ -12,7 +12,10 @@ import Symbols._
1212
import Decorators._
1313
import NameOps._
1414
import StdNames.nme
15+
import rewrite.Rewrites.patch
16+
import util.Positions.Position
1517
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransformer, MiniPhaseTransform}
18+
import dotty.tools.dotc.ast.NavigateAST._
1619
import dotty.tools.dotc.ast.Trees._
1720
import dotty.tools.dotc.ast.{untpd, tpd}
1821
import dotty.tools.dotc.core.Constants.Constant
@@ -65,11 +68,14 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with Nee
6568
val sym = tree.symbol
6669
if (!(sym is Flags.Lazy) || sym.owner.is(Flags.Trait) || (sym.isStatic && sym.is(Flags.Module))) tree
6770
else {
68-
6971
val isField = sym.owner.isClass
70-
7172
if (isField) {
7273
if (sym.isVolatile ||
74+
ctx.scala2Mode && {
75+
if (ctx.settings.rewrite.value.isDefined)
76+
patch(ctx.compilationUnit.source, Position(toUntyped(tree).envelope.start), "@volatile ")
77+
true // cannot assume volatile because of problems with compilestdlib. See #1149
78+
} ||
7379
(sym.is(Flags.Module) && !sym.is(Flags.Synthetic)))
7480
// module class is user-defined.
7581
// Should be threadsafe, to mimic safety guaranteed by global object

0 commit comments

Comments
 (0)