diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-06 12:48:30 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-06 12:48:30 +0100 |
commit | 34dad77513d08535adaf26989bd0cd84993ceab1 (patch) | |
tree | 5fb4e31c2ca9f9d2c5c7f4eb365d6381c0367f3f /test/junit/scala/tools/nsc/symtab | |
parent | ee1c02b374a4b8a053e9a8b14af5e205afa67e14 (diff) | |
download | scala-34dad77513d08535adaf26989bd0cd84993ceab1.tar.gz scala-34dad77513d08535adaf26989bd0cd84993ceab1.tar.bz2 scala-34dad77513d08535adaf26989bd0cd84993ceab1.zip |
SI-10093 don't move member traits to constructor body in constructors
Fixes a regression introduced in c8e6050. Member traits with only
abstract definitions (`isInterface`) were moved into the primary
constructor by mistake. (Flatten moved the classes back.)
The member trait was duplicated into the constructor of specialized
subclasses, causing it to be generated multiple times.
Also removes some unnecessary `isMixinConstructor` checks: the mixin
constructor is always the primary constructor.
This commit also clarifies (and tests) what `isInterface` means: for
scala-defined traits, it means there are only abstract members. For
java-defined interfaces, it is always true.
Diffstat (limited to 'test/junit/scala/tools/nsc/symtab')
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/FlagsTest.scala | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/FlagsTest.scala b/test/junit/scala/tools/nsc/symtab/FlagsTest.scala index e88b3f9e96..4e78ca7f22 100644 --- a/test/junit/scala/tools/nsc/symtab/FlagsTest.scala +++ b/test/junit/scala/tools/nsc/symtab/FlagsTest.scala @@ -2,15 +2,17 @@ package scala.tools.nsc package symtab import org.junit.Assert._ -import scala.tools.testing.AssertUtil._ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import scala.tools.testing.BytecodeTesting + @RunWith(classOf[JUnit4]) -class FlagsTest { +class FlagsTest extends BytecodeTesting { object symbolTable extends SymbolTableForUnitTesting import symbolTable._ + import Flags._ def sym = NoSymbol.newTermSymbol(nme.EMPTY) @@ -87,4 +89,38 @@ class FlagsTest { val dep = typeOf[java.lang.Deprecated].typeSymbol assertTrue(dep.isJavaAnnotation && dep.isJava) } + + @Test + def interfaceFlag(): Unit = { + // scala traits are `isInterface` if they have only type defs and abstract methods / fields. + // java interfaces are always `isInterface`. + val scalaCode = + """package p + |trait T1 { + | import scala.collection + | def m: Int + | val f: Int + | type T <: AnyRef + |} + |trait T2 { + | def m = 1 + |} + |trait T3 { + | val f = 1 + |} + |trait T4 { + | println() + |} + """.stripMargin + val javaI1 = "package p; interface I1 { int m(); }" + val javaI2 = "package p; interface I2 { default int m() { return 1; } }" + compiler.compileClasses(code = scalaCode, javaCode = (javaI1, "I1.java") :: (javaI2, "I2.java") :: Nil) + import compiler.global.rootMirror._ + assert( getRequiredClass("p.T1").isInterface) + assert(!getRequiredClass("p.T2").isInterface) + assert(!getRequiredClass("p.T3").isInterface) + assert(!getRequiredClass("p.T4").isInterface) + assert( getRequiredClass("p.I1").isInterface) + assert( getRequiredClass("p.I2").isInterface) + } } |