Skip to content

Commit 6ac3bc1

Browse files
committed
Merge pull request #92 from bantonsson/wip-ban-add-test-for-anonymous-lambdas
Ignore added/removed and changed anonymous lambdas for Scala 2.12.x
2 parents 86792af + ec87be9 commit 6ac3bc1

File tree

12 files changed

+59
-11
lines changed

12 files changed

+59
-11
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,8 @@ object ClassfileParser {
378378
(flags & JAVA_ACC_ABSTRACT) != 0
379379
@inline final def isFinal(flags: Int) =
380380
(flags & JAVA_ACC_FINAL) != 0
381+
@inline final def isSynthetic(flags: Int) =
382+
(flags & JAVA_ACC_SYNTHETIC) != 0
383+
@inline final def isBridge(flags: Int) =
384+
(flags & JAVA_ACC_BRIDGE) != 0
381385
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class MemberInfo(val owner: ClassInfo, val bytecodeName: String, override val fl
6666

6767
def hasSyntheticName: Boolean = decodedName contains '$'
6868

69-
def isAccessible: Boolean = isPublic && !hasSyntheticName
69+
def isAccessible: Boolean = isPublic && !isSynthetic && !hasSyntheticName
70+
71+
def nonAccessible: Boolean = !isAccessible
7072

7173
/** The name of the getter corresponding to this setter */
7274
private def getterName: String = {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ abstract class PackageInfo(val owner: PackageInfo) {
7272
}
7373

7474
def isAccessible(clazz: ClassInfo, prefix: Set[ClassInfo]) = {
75-
val idx = clazz.decodedName.lastIndexOf("$")
76-
lazy val isReachable =
77-
if (idx < 0) prefix.isEmpty // class name contains no $
78-
else (prefix exists (_.decodedName == clazz.decodedName.substring(0, idx))) // prefix before dollar is an accessible class detected previously
75+
def isReachable = {
76+
if (clazz.isSynthetic) false
77+
else {
78+
val idx = clazz.decodedName.lastIndexOf("$")
79+
if (idx < 0) prefix.isEmpty // class name contains no $
80+
else prefix exists (_.decodedName == clazz.decodedName.substring(0, idx)) // prefix before dollar is an accessible class detected previously
81+
}
82+
}
7983
clazz.isPublic && isReachable
8084
}
8185

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ trait WithLocalModifier extends HasAccessFlags {
88
def isFinal: Boolean = ClassfileParser.isFinal(flags)
99

1010
def nonFinal: Boolean = !isFinal
11-
}
11+
12+
def isSynthetic: Boolean = ClassfileParser.isSynthetic(flags)
13+
14+
def isBridge: Boolean = ClassfileParser.isBridge(flags)
15+
16+
def nonBridge: Boolean = !isBridge
17+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
class A was concrete; is declared abstract in new version
2-
method apply()java.lang.Object in object A does not have a correspondent in new version
32
method apply()A in object A does not have a correspondent in new version
43
the type hierarchy of object A has changed in new version. Missing types {scala.runtime.AbstractFunction0}

reporter/functional-tests/src/test/ignore-changed-and-added-anonymous-lambdas-ok/problems.txt

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
private var a = 5
3+
def foo() {
4+
val f1 = () => a.toString
5+
val f2 = (x: Int) => x * a
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
private var a = 5
3+
def foo() {
4+
val f1 = () => a
5+
val f2 = (x: Int) => (x * a).toString
6+
val f3 = (x: Float) => x * a.toFloat
7+
}
8+
}

reporter/functional-tests/src/test/ignore-changed-and-removed-anonymous-lambdas-ok/problems.txt

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
private var a = 5
3+
def foo() {
4+
val f1 = () => a.toString
5+
val f2 = (x: Int) => x * a
6+
val f3 = (x: Float) => x * a.toFloat
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
private var a = 5
3+
def foo() {
4+
val f1 = () => a
5+
val f2 = (x: Int) => (x * a).toString
6+
}
7+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ private[analyze] abstract class BaseMethodChecker extends Checker[MemberInfo, Cl
3737

3838
private[analyze] class ClassMethodChecker extends BaseMethodChecker {
3939
def check(method: MemberInfo, inclazz: ClassInfo): Option[Problem] = {
40-
if (method.isDeferred)
40+
if (method.nonAccessible)
41+
None
42+
else if (method.isDeferred)
4143
super.check(method, inclazz.lookupMethods(method.bytecodeName))
4244
else
4345
super.check(method, inclazz.lookupClassMethods(method.bytecodeName))
@@ -46,11 +48,12 @@ private[analyze] class ClassMethodChecker extends BaseMethodChecker {
4648

4749
private[analyze] class TraitMethodChecker extends BaseMethodChecker {
4850
def check(method: MemberInfo, inclazz: ClassInfo): Option[Problem] = {
49-
if (method.owner.hasStaticImpl(method)) {
51+
if (method.nonAccessible)
52+
None
53+
else if (method.owner.hasStaticImpl(method))
5054
checkStaticImplMethod(method, inclazz)
51-
} else {
55+
else
5256
super.check(method, inclazz.lookupMethods(method.bytecodeName))
53-
}
5457
}
5558

5659
private def checkStaticImplMethod(method: MemberInfo, inclazz: ClassInfo) = {

0 commit comments

Comments
 (0)