Skip to content

Commit d5bdea8

Browse files
authored
Merge pull request #9181 from dotty-staging/fix-1441b
Fix #1441: init MODULE$ in <clinit>
2 parents b8825a2 + 745d53c commit d5bdea8

19 files changed

+329
-114
lines changed

Diff for: .github/workflows/ci.yaml

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
container: lampepfl/dotty:2020-04-24
1616

1717
steps:
18+
- name: Set JDK 11 as default
19+
run: echo "::add-path::/usr/lib/jvm/java-11-openjdk-amd64/bin"
20+
1821
- name: Checkout cleanup script
1922
uses: actions/checkout@v2
2023

@@ -55,6 +58,9 @@ jobs:
5558
container: lampepfl/dotty:2020-04-24
5659

5760
steps:
61+
- name: Set JDK 11 as default
62+
run: echo "::add-path::/usr/lib/jvm/java-11-openjdk-amd64/bin"
63+
5864
- name: Checkout cleanup script
5965
uses: actions/checkout@v2
6066

@@ -174,7 +180,7 @@ jobs:
174180
- name: Test
175181
run: ./project/scripts/sbt sbt-dotty/scripted
176182

177-
test_java11:
183+
test_java8:
178184
runs-on: self-hosted
179185
container: lampepfl/dotty:2020-04-24
180186
if: (
@@ -184,6 +190,9 @@ jobs:
184190
github.event_name == 'schedule'
185191

186192
steps:
193+
- name: Set JDK 8 as default
194+
run: echo "::add-path::/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin"
195+
187196
- name: Checkout cleanup script
188197
uses: actions/checkout@v2
189198

@@ -215,14 +224,12 @@ jobs:
215224
restore-keys: ${{ runner.os }}-general-
216225

217226
- name: Test
218-
run: |
219-
export PATH="/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH"
220-
./project/scripts/sbt ";compile ;test"
227+
run: ./project/scripts/sbt ";compile ;test"
221228

222229
publish_nightly:
223230
runs-on: self-hosted
224231
container: lampepfl/dotty:2020-04-24
225-
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
232+
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
226233
if: github.event_name == 'schedule'
227234
env:
228235
NIGHTLYBUILD: yes
@@ -323,7 +330,7 @@ jobs:
323330
publish_release:
324331
runs-on: self-hosted
325332
container: lampepfl/dotty:2020-04-24
326-
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
333+
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
327334
if: github.event_name == 'push' &&
328335
startsWith(github.event.ref, 'refs/tags/') &&
329336
!startsWith(github.event.ref, 'refs/tags/sbt-dotty-')
@@ -475,7 +482,7 @@ jobs:
475482
publish_sbt_release:
476483
runs-on: self-hosted
477484
container: lampepfl/dotty:2020-04-24
478-
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
485+
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
479486
if: github.event_name == 'push' &&
480487
startsWith(github.event.ref, 'refs/tags/sbt-dotty-')
481488

Diff for: compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

+11-22
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,13 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
364364
}
365365
else {
366366
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
367-
generatedType =
368-
if (tree.symbol == defn.ArrayClass) ObjectReference
369-
else classBTypeFromSymbol(claszSymbol)
367+
// When compiling Array.scala, the constructor invokes `Array.this.super.<init>`. The expectedType
368+
// is `[Object` (computed by typeToBType, the type of This(Array) is `Array[T]`). If we would set
369+
// the generatedType to `Array` below, the call to adapt at the end would fail. The situation is
370+
// similar for primitives (`I` vs `Int`).
371+
if (tree.symbol != defn.ArrayClass && !tree.symbol.isPrimitiveValueClass) {
372+
generatedType = classBTypeFromSymbol(claszSymbol)
373+
}
370374
}
371375

372376
case DesugaredSelect(Ident(nme.EMPTY_PACKAGE), module) =>
@@ -710,33 +714,18 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
710714
if (t.symbol ne defn.Object_synchronized) genTypeApply(t)
711715
else genSynchronized(app, expectedType)
712716

713-
case Apply(fun @ DesugaredSelect(Super(_, _), _), args) =>
714-
def initModule(): Unit = {
715-
// we initialize the MODULE$ field immediately after the super ctor
716-
if (!isModuleInitialized &&
717-
jMethodName == INSTANCE_CONSTRUCTOR_NAME &&
718-
fun.symbol.javaSimpleName == INSTANCE_CONSTRUCTOR_NAME &&
719-
claszSymbol.isStaticModuleClass) {
720-
isModuleInitialized = true
721-
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
722-
mnode.visitFieldInsn(
723-
asm.Opcodes.PUTSTATIC,
724-
thisName,
725-
str.MODULE_INSTANCE_FIELD,
726-
"L" + thisName + ";"
727-
)
728-
}
729-
}
717+
case Apply(fun @ DesugaredSelect(Super(superQual, _), _), args) =>
730718
// 'super' call: Note: since constructors are supposed to
731719
// return an instance of what they construct, we have to take
732720
// special care. On JVM they are 'void', and Scala forbids (syntactically)
733721
// to call super constructors explicitly and/or use their 'returned' value.
734722
// therefore, we can ignore this fact, and generate code that leaves nothing
735723
// on the stack (contrary to what the type in the AST says).
736-
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
724+
725+
// scala/bug#10290: qual can be `this.$outer()` (not just `this`), so we call genLoad (not just ALOAD_0)
726+
genLoad(superQual)
737727
genLoadArguments(args, paramTKs(app))
738728
generatedType = genCallMethod(fun.symbol, InvokeStyle.Super, app.span)
739-
initModule()
740729

741730
// 'new' constructor call: Note: since constructors are
742731
// thought to return an instance of what they construct,

Diff for: compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ trait BCodeIdiomatic {
2929
case "jvm-1.6" => asm.Opcodes.V1_6
3030
case "jvm-1.7" => asm.Opcodes.V1_7
3131
case "jvm-1.8" => asm.Opcodes.V1_8
32+
case "jvm-9" => asm.Opcodes.V9
3233
}
3334

3435
lazy val majorVersion: Int = (classfileVersion & 0xFF)

0 commit comments

Comments
 (0)