Skip to content

Commit 7c956c5

Browse files
authored
Merge pull request #123 from szeiger/wip/scala-2.12
Add Scala 2.12 support
2 parents 534198e + 807b940 commit 7c956c5

File tree

23 files changed

+39
-9
lines changed

23 files changed

+39
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
- TEST_COMMAND="scripted"
2121
- TEST_COMMAND="testFunctional"
2222
- TEST_COMMAND="-Dmima.testScalaVersion=2.11.7 testFunctional"
23-
- TEST_COMMAND="-Dmima.testScalaVersion=2.12.0-M3 testFunctional"
23+
- TEST_COMMAND="-Dmima.testScalaVersion=2.12.0-RC1 testFunctional"
2424

2525
script:
2626
- sbt -J-XX:ReservedCodeCacheSize=256M $TEST_COMMAND

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ After doing that, `reload` if you are in a `sbt` console session (if that makes
9090

9191
Tests within the `functional-tests` folder should always pass.
9292

93-
Note: The `problems.txt` is the test oracle. Expected errors are declared using the MiMa's reporting output (i.e., the output of the tool and the expected errors should match perfectly). Admittedly, this coupling is an issue since the testing framework is highly coupled with the tool output used to report errors to the user. We should improve this and make the two independent. Until then, mind that by changing the output of the tool you will likely have to update some of the test oracles (i.e., problems.txt file).
93+
Note: The `problems.txt` is the test oracle. Expected errors are declared using the MiMa's reporting output (i.e., the output of the tool and the expected errors should match perfectly). Admittedly, this coupling is an issue since the testing framework is highly coupled with the tool output used to report errors to the user. We should improve this and make the two independent. Until then, mind that by changing the output of the tool you will likely have to update some of the test oracles (i.e., problems.txt file). When running tests against Scala 2.12 or higher, `problems-2.12.txt` is preferred over `problems.txt` if the former exists.
9494

9595
FAQ
9696
-------

core/src/main/scala/com/typesafe/tools/mima/core/ClassInfo.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ abstract class ClassInfo(val owner: PackageInfo) extends HasDeclarationName with
155155

156156
/** The concrete methods of this trait */
157157
lazy val concreteMethods: List[MemberInfo] = {
158-
if(isTrait) methods.iterator.filter(hasStaticImpl(_)).toList
159-
else if(isClass) methods.iterator.filter(!_.isDeferred).toList
158+
if(isTrait) methods.iterator.filter(m => hasStaticImpl(m) || !m.isDeferred).toList
159+
else if(isClass || isInterface) methods.iterator.filter(!_.isDeferred).toList
160160
else Nil
161161
}
162162

163+
/** The subset of concrete methods of this trait that are abstract at the JVM level.
164+
* This corresponds to the pre-Scala-2.12 trait encoding where all `concreteMethods`
165+
* are `emulatedConcreteMethods`. In 2.12 most concrete trait methods are translated
166+
* to concrete interface methods. */
167+
lazy val emulatedConcreteMethods: List[MemberInfo] =
168+
concreteMethods.filter(_.isDeferred)
169+
163170
/** The deferred methods of this trait */
164171
lazy val deferredMethods: List[MemberInfo] = {
165172
val concreteSet = concreteMethods.toSet

project/Build.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ object MimaBuild extends Build {
221221
lazy val runTest =
222222
(fullClasspath in (reporterFunctionalTests, Compile), // the test classpath from the functionalTest project for the test
223223
thisProjectRef, // gives us the ProjectRef this task is defined in
224-
scalaInstance, // get a reference to the already loaded Scala classes so we get the advantage of a warm jvm
224+
scalaInstance in core, // get a reference to the already loaded Scala classes so we get the advantage of a warm jvm
225225
packageBin in v1Config, // package the v1 sources and get the configuration used
226226
packageBin in v2Config, // same for v2
227-
streams) map { (cp, proj, si, v1, v2, streams) =>
227+
scalaVersion,
228+
streams) map { (cp, proj, si, v1, v2, scalaV, streams) =>
228229
val urls = Attributed.data(cp).map(_.toURI.toURL).toArray
229230
val loader = new java.net.URLClassLoader(urls, si.loader)
230231

@@ -238,9 +239,14 @@ object MimaBuild extends Build {
238239

239240
val projectPath = proj.build.getPath + "reporter" + "/" + "functional-tests" + "/" + "src" + "/" + "test" + "/" + proj.project
240241

241-
val oraclePath = projectPath + "/problems.txt"
242+
val oraclePath = {
243+
val p = projectPath + "/problems.txt"
244+
val p212 = projectPath + "/problems-2.12.txt"
245+
if(!(scalaV.startsWith("2.10.") || scalaV.startsWith("2.11.")) && new java.io.File(p212).exists) p212
246+
else p
247+
}
242248

243-
try {
249+
try {
244250
import scala.language.reflectiveCalls
245251
testRunner.runTest(testClasspath, proj.project, v1.getAbsolutePath, v2.getAbsolutePath, oraclePath)
246252
streams.log.info("Test '" + proj.project + "' succeeded.")

reporter/functional-tests/src/test/abstract-class-extending-new-trait-with-concrete-method-ok/problems-2.12.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declaration of class A is interface A in new version; changing class to interface breaks client code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in new version there is abstract method foo()Int in class B, which does not have a correspondent
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
method foo()Int in interface B does not have a correspondent in new version

reporter/functional-tests/src/test/trait-abstract-method-becomes-concrete2-ok/problems-2.12.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abstract synthetic method A$_setter_$foo_=(Int)Unit in interface A is present only in new version

reporter/functional-tests/src/test/trait-added-method-in-new-version-nok/problems-2.12.txt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abstract synthetic method A$_setter_|_=(Int)Unit in interface A is present only in new version
2+
abstract method bar()Int in interface A is present only in new version
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abstract method bar_=(Int)Unit in interface A is present only in new version
2+
abstract method bar()Int in interface A is present only in new version

reporter/functional-tests/src/test/trait-deleting-concrete-methods-is-nok/problems-2.12.txt

Whitespace-only changes.

reporter/functional-tests/src/test/trait-extending-new-trait-with-concrete-method-nok/problems-2.12.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abstract method foo(Int)Int in interface A does not have a correspondent in new version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
abstract method foo()Int in interface AA is inherited by class A in new version.
2+
abstract synthetic method AA$_setter_|_=(Int)Unit in interface AA is inherited by class A in new version.
3+
abstract method bar()Int in interface AA is inherited by class A in new version.
4+
abstract method foo()Int in interface AA is inherited by class B in new version.
5+
abstract synthetic method AA$_setter_|_=(Int)Unit in interface AA is inherited by class B in new version.
6+
abstract method bar()Int in interface AA is inherited by class B in new version.

reporter/functional-tests/src/test/trait-inherits-new-trait-with-concrete-method-nok/problems-2.12.txt

Whitespace-only changes.

reporter/functional-tests/src/test/trait-method-overloading-is-ok/problems-2.12.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
method foo()Int in interface A does not have a correspondent in new version
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
method foo()Int in interface A does not have a correspondent in new version

reporter/functional-tests/src/test/trait-pushing-up-concrete-methods-is-nok/problems-2.12.txt

Whitespace-only changes.

reporter/src/main/scala/com/typesafe/tools/mima/lib/analyze/Analyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private[analyze] class TraitAnalyzer extends Analyzer {
130130
override def analyzeNewClassMethods(oldclazz: ClassInfo, newclazz: ClassInfo): List[Problem] = {
131131
val res = collection.mutable.ListBuffer.empty[Problem]
132132

133-
for (newmeth <- newclazz.concreteMethods if !oldclazz.hasStaticImpl(newmeth)) {
133+
for (newmeth <- newclazz.emulatedConcreteMethods if !oldclazz.hasStaticImpl(newmeth)) {
134134
if (!oldclazz.lookupMethods(newmeth.bytecodeName).exists(_.sig == newmeth.sig)) {
135135
// this means that the method is brand new and therefore the implementation
136136
// has to be injected

0 commit comments

Comments
 (0)