SI-6181 method mirrors now support by-name args#1052
SI-6181 method mirrors now support by-name args#1052xeno-by wants to merge 3 commits intoscala:2.10.xfrom
Conversation
In Scala there are some methods that only exist in symbol tables, but don't have corresponding method entries in Java class files. To the best of my knowledge, these methods can be subdivided into four groups: 1) stuff weaved onto Any, AnyVal and AnyRef, 2) magic methods that Scala exposes to fix Java arrays, 3) compile-time methods (such as classOf and all kinds of macros), 4) miscellaneous stuff (currently only String_+). To support these magic symbols, I've modified the `checkMemberOf` validator to special case Any/AnyVal/AnyRef methods and adjusted MethodMirror and ConstructorMirror classes to use special invokers for those instead of relying on Java reflection.
Arguments provided in by-name positions are now automatically wrapped in Function0 instances by method mirrors.
|
The pull request depends on #1048, because both of them touch the method mirror, so separating them would lead to merge conflicts. |
|
Started jenkins job pr-rangepos at https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/60/ |
|
Started jenkins job pr-scala-testsuite-linux-opt at https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/764/ |
|
jenkins job pr-rangepos: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/60/ |
There was a problem hiding this comment.
varargs can also match when fewer arguments are provided.
scala> def foo(a: Any*) = a; foo()
foo: (a: Any*)Seq[Any]
res13: Seq[Any] = List()There was a problem hiding this comment.
Sure, hence the minus one
There was a problem hiding this comment.
Assuming paramss is flattening multiple parameter lists, here's one which needs a -3.
scala> def f(xs: Any*)(ys: Any*)(zs: Any*) = 5
f: (xs: Any*)(ys: Any*)(zs: Any*)Int
scala> f()()()
res0: Int = 5
There was a problem hiding this comment.
Multiple vararg parameter lists are not supported anyway: https://issues.scala-lang.org/browse/SI-6182. I figured we can do minus three when fixing that issue, and for now we are fine.
|
jenkins job pr-scala-testsuite-linux-opt: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/764/ |
|
PLS REBUILD ALL |
|
Started jenkins job pr-rangepos at https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/72/ |
|
Started jenkins job pr-scala-testsuite-linux-opt at https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/775/ |
|
jenkins job pr-rangepos: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/72/ |
|
jenkins job pr-scala-testsuite-linux-opt: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/775/ |
|
I think this could use some staging. Performance is critical for method mirror application. E.g. like this: def transform(ps: List[Params]): List[Any] => List[Any] = lazy val trans = transform(ps) invoke(meth, trans(args)) |
|
Superceded by #1067 |
Arguments provided in by-name positions are now automatically wrapped
in Function0 instances by method mirrors.