From de1d8c3a89e95e1b934da05453f8e1fed925c838 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 15 Aug 2013 15:02:18 -0700 Subject: Expand the understanding of bytecode tests. The new method is the same as sameMethodAndFieldSignatures, but ignores generic signatures. This allows for testing methods which receive the same descriptor but differing generic signatures. In particular, this happens with value classes, which get a generic signature where a method written in terms of the underlying values does not. --- src/partest/scala/tools/partest/AsmNode.scala | 7 ++++--- src/partest/scala/tools/partest/BytecodeTest.scala | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/partest/scala/tools/partest/AsmNode.scala b/src/partest/scala/tools/partest/AsmNode.scala index d181436676..e6a91498d1 100644 --- a/src/partest/scala/tools/partest/AsmNode.scala +++ b/src/partest/scala/tools/partest/AsmNode.scala @@ -16,10 +16,11 @@ sealed trait AsmNode[+T] { def visibleAnnotations: List[AnnotationNode] def invisibleAnnotations: List[AnnotationNode] def characteristics = f"$name%15s $desc%-30s$accessString$sigString" + def erasedCharacteristics = f"$name%15s $desc%-30s$accessString" - private def accessString = if (access == 0) "" else " " + Modifier.toString(access) - private def sigString = if (signature == null) "" else " " + signature - override def toString = characteristics + private def accessString = if (access == 0) "" else " " + Modifier.toString(access) + private def sigString = if (signature == null) "" else " " + signature + override def toString = characteristics } object AsmNode { diff --git a/src/partest/scala/tools/partest/BytecodeTest.scala b/src/partest/scala/tools/partest/BytecodeTest.scala index 2690b784d1..7650a892fd 100644 --- a/src/partest/scala/tools/partest/BytecodeTest.scala +++ b/src/partest/scala/tools/partest/BytecodeTest.scala @@ -48,7 +48,18 @@ abstract class BytecodeTest extends ASMConverters { // descriptors and generic signatures? Method bodies are not considered, and // the names of the classes containing the methods are substituted so they do // not appear as differences. - def sameMethodAndFieldSignatures(clazzA: ClassNode, clazzB: ClassNode): Boolean = { + def sameMethodAndFieldSignatures(clazzA: ClassNode, clazzB: ClassNode) = + sameCharacteristics(clazzA, clazzB)(_.characteristics) + + // Same as sameMethodAndFieldSignatures, but ignoring generic signatures. + // This allows for methods which receive the same descriptor but differing + // generic signatures. In particular, this happens with value classes, + // which get a generic signature where a method written in terms of the + // underlying values does not. + def sameMethodAndFieldDescriptors(clazzA: ClassNode, clazzB: ClassNode) = + sameCharacteristics(clazzA, clazzB)(_.erasedCharacteristics) + + private def sameCharacteristics(clazzA: ClassNode, clazzB: ClassNode)(f: AsmNode[_] => String): Boolean = { val ms1 = clazzA.fieldsAndMethods.toIndexedSeq val ms2 = clazzB.fieldsAndMethods.toIndexedSeq val name1 = clazzA.name @@ -59,8 +70,8 @@ abstract class BytecodeTest extends ASMConverters { false } else (ms1, ms2).zipped forall { (m1, m2) => - val c1 = m1.characteristics - val c2 = m2.characteristics.replaceAllLiterally(name2, name1) + val c1 = f(m1) + val c2 = f(m2).replaceAllLiterally(name2, name1) if (c1 == c2) println(s"[ok] $m1") else -- cgit v1.2.3