Skip to content

Commit

Permalink
SI-9256 check companions in same compilation unit only if same run
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz authored and retronym committed Jun 6, 2016
1 parent 59d6dbc commit e108429
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Expand Up @@ -431,6 +431,7 @@ trait Namers extends MethodSynthesis {
&& !(module isCoDefinedWith clazz)
&& module.exists
&& clazz.exists
&& (currentRun.compiles(clazz) == currentRun.compiles(module))
)
if (fails) {
reporter.error(tree.pos, (
Expand Down
12 changes: 12 additions & 0 deletions test/junit/scala/tools/nsc/backend/jvm/DirectCompileTest.scala
Expand Up @@ -99,4 +99,16 @@ class DirectCompileTest extends BytecodeTesting {
compiler.compileToBytes(a)
compiler.compileToBytes(b)
}

@Test
def residentMultipleRunsNotCompanions(): Unit = {
val compiler = newCompiler()
val a = List(("public class A { }", "A.java"))
// when checking that a class and its companion are defined in the same compilation unit, the
// compiler would also emit a warning if the two symbols are defined in separate runs. this
// would lead to an error message when compiling the scala class A.
val b = "class A"
compiler.compileToBytes("", a)
compiler.compileToBytes(b)
}
}
24 changes: 12 additions & 12 deletions test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala
Expand Up @@ -97,7 +97,7 @@ class InlineWarningTest extends BytecodeTesting {
@Test
def cannotInlinePrivateCallIntoDifferentClass(): Unit = {
val code =
"""class M {
"""class A {
| @inline final def f = {
| @noinline def nested = 0
| nested
Expand All @@ -106,15 +106,15 @@ class InlineWarningTest extends BytecodeTesting {
| def t = f // ok
|}
|
|class N {
| def t(a: M) = a.f // not possible
|class B {
| def t(a: A) = a.f // not possible
|}
""".stripMargin

val warn =
"""M::f()I is annotated @inline but could not be inlined:
|The callee M::f()I contains the instruction INVOKESTATIC M.nested$1 ()I
|that would cause an IllegalAccessError when inlined into class N""".stripMargin
"""A::f()I is annotated @inline but could not be inlined:
|The callee A::f()I contains the instruction INVOKESTATIC A.nested$1 ()I
|that would cause an IllegalAccessError when inlined into class B""".stripMargin

var c = 0
compileToBytes(code, allowMessage = i => { c += 1; i.msg contains warn })
Expand All @@ -124,24 +124,24 @@ class InlineWarningTest extends BytecodeTesting {
@Test
def dontWarnWhenNotIlnineAnnotated(): Unit = {
val code =
"""class M {
"""class A {
| final def f(t: Int => Int) = {
| @noinline def nested = 0
| nested + t(1)
| }
| def t = f(x => x + 1)
|}
|
|class N {
| def t(a: M) = a.f(x => x + 1)
|class B {
| def t(a: A) = a.f(x => x + 1)
|}
""".stripMargin
compileToBytes(code, allowMessage = _ => false) // no warnings allowed

val warn =
"""M::f(Lscala/Function1;)I could not be inlined:
|The callee M::f(Lscala/Function1;)I contains the instruction INVOKESTATIC M.nested$1 ()I
|that would cause an IllegalAccessError when inlined into class N""".stripMargin
"""A::f(Lscala/Function1;)I could not be inlined:
|The callee A::f(Lscala/Function1;)I contains the instruction INVOKESTATIC A.nested$1 ()I
|that would cause an IllegalAccessError when inlined into class B""".stripMargin

var c = 0
compilerWarnAll.compileToBytes(code, allowMessage = i => { c += 1; i.msg contains warn })
Expand Down
10 changes: 5 additions & 5 deletions test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
Expand Up @@ -835,11 +835,11 @@ class InlinerTest extends BytecodeTesting {
@Test
def inlineInvokeSpecial(): Unit = {
val code =
"""class Aa {
"""class A {
| def f1 = 0
|}
|class B extends Aa {
| @inline final override def f1 = 1 + super.f1 // invokespecial Aa.f1
|class B extends A {
| @inline final override def f1 = 1 + super.f1 // invokespecial A.f1
|
| private def f2m = 0 // public B$$f2m in bytecode
| @inline final def f2 = f2m // invokevirtual B.B$$f2m
Expand All @@ -863,13 +863,13 @@ class InlinerTest extends BytecodeTesting {

val warn =
"""B::f1()I is annotated @inline but could not be inlined:
|The callee B::f1()I contains the instruction INVOKESPECIAL Aa.f1 ()I
|The callee B::f1()I contains the instruction INVOKESPECIAL A.f1 ()I
|that would cause an IllegalAccessError when inlined into class T.""".stripMargin
var c = 0
val List(a, b, t) = compile(code, allowMessage = i => {c += 1; i.msg contains warn})
assert(c == 1, c)

assertInvoke(getMethod(b, "t1"), "Aa", "f1")
assertInvoke(getMethod(b, "t1"), "A", "f1")
assertInvoke(getMethod(b, "t2"), "B", "B$$f2m")
assertInvoke(getMethod(b, "t3"), "B", "<init>")
assertInvoke(getMethod(b, "t4"), "B", "<init>")
Expand Down

0 comments on commit e108429

Please sign in to comment.