Skip to content

Commit c8fbba0

Browse files
retronympaulp
authored andcommitted
Check named-args-for-clarity incur no extra bytecode
When named arguments correspond the the parameter declaration order, the compiler should not lift out assignments before the method call, as it would have to do for out-of-order arguments. Confirm this with a bytecode comparison test.
1 parent 9179c88 commit c8fbba0

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bytecode identical
2+
bytecode identical
3+
bytecode identical
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class SameBytecode {
2+
def foo(a: Int, b: String) = 0
3+
def foo(a: Int, b: Any) = 0
4+
5+
def a = foo(0, "")
6+
def b = foo(a = 0, "")
7+
def c = foo(0, b = "")
8+
def d = foo(a = 0, b = "")
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.tools.partest.BytecodeTest
2+
3+
object Test extends BytecodeTest {
4+
def show: Unit = {
5+
val classNode = loadClassNode("SameBytecode")
6+
def sameAsA(meth: String) =
7+
sameBytecode(getMethod(classNode, "a"), getMethod(classNode, meth))
8+
Seq("b", "c", "d").foreach(sameAsA)
9+
}
10+
}

0 commit comments

Comments
 (0)