Skip to content

Commit 81c240a

Browse files
authored
Merge pull request #7026 from dotty-staging/fix-sjs-lazy-vals
In Scala.js mode, compile all lazy vals as thread-unsafe.
2 parents b534eb2 + 5e9891e commit 81c240a

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,13 @@ class JSCodeGen()(implicit ctx: Context) {
936936
js.Skip()
937937
case BooleanTag =>
938938
js.BooleanLiteral(value.booleanValue)
939-
case ByteTag | ShortTag | CharTag | IntTag =>
939+
case ByteTag =>
940+
js.ByteLiteral(value.byteValue)
941+
case ShortTag =>
942+
js.ShortLiteral(value.shortValue)
943+
case CharTag =>
944+
js.CharLiteral(value.charValue)
945+
case IntTag =>
940946
js.IntLiteral(value.intValue)
941947
case LongTag =>
942948
js.LongLiteral(value.longValue)
@@ -2156,7 +2162,7 @@ class JSCodeGen()(implicit ctx: Context) {
21562162

21572163
val genBody = {
21582164
val call = if (isStaticCall) {
2159-
genApplyStatic(sym, formalCaptures.map(_.ref))
2165+
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
21602166
} else {
21612167
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
21622168
genApplyMethodMaybeStatically(thisCaptureRef, sym,

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,24 @@ object JSEncoding {
258258
if (sym.asClass.isPrimitiveValueClass) {
259259
if (sym == defn.BooleanClass)
260260
jstpe.BooleanType
261+
else if (sym == defn.CharClass)
262+
jstpe.CharType
263+
else if (sym == defn.ByteClass)
264+
jstpe.ByteType
265+
else if (sym == defn.ShortClass)
266+
jstpe.ShortType
267+
else if (sym == defn.IntClass)
268+
jstpe.IntType
269+
else if (sym == defn.LongClass)
270+
jstpe.LongType
261271
else if (sym == defn.FloatClass)
262272
jstpe.FloatType
263273
else if (sym == defn.DoubleClass)
264274
jstpe.DoubleType
265-
else if (sym == defn.LongClass)
266-
jstpe.LongType
267275
else if (sym == defn.UnitClass)
268276
jstpe.NoType
269277
else
270-
jstpe.IntType
278+
throw new AssertionError(s"unknown primitive value class $sym")
271279
} else {
272280
if (sym == defn.ObjectClass || isJSType(sym))
273281
jstpe.AnyType

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
7676
if (isField) {
7777
if (sym.isAllOf(SyntheticModule))
7878
transformSyntheticModule(tree)
79-
else if (sym.isThreadUnsafe) {
80-
if (sym.is(Module)) {
79+
else if (sym.isThreadUnsafe || ctx.settings.scalajs.value) {
80+
if (sym.is(Module) && !ctx.settings.scalajs.value) {
8181
ctx.error(em"@threadUnsafe is only supported on lazy vals", sym.sourcePos)
8282
transformMemberDefThreadSafe(tree)
8383
}
@@ -453,6 +453,3 @@ object LazyVals {
453453
val retry: TermName = "retry".toTermName
454454
}
455455
}
456-
457-
458-

project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ object Build {
937937
val dir = fetchScalaJSSource.value / "test-suite"
938938
(
939939
(dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** "IntTest.scala").get
940+
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/util" ** "Base64Test.scala").get
940941
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
941942
)
942943
}

0 commit comments

Comments
 (0)