- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
marking methods as synthetic in generated bytecode
Sun, 2011-07-31, 11:34
I just noticed that the menagerie of methods synthesized by scalac
generates isn't marked as synthetic in the bytecode.
I couldn't google up prior discussions on this matter. Is this done
deliberately, or by default?
As motivation, the debugger in IntelliJ or Eclipse can be configured
to skip synthetic methods in the "Step Into" action.
-jason
scala> class A { 1 match { case x if x > 0 => x } }
defined class A
scala> classOf[A].getDeclaredMethods
res10: Array[java.lang.reflect.Method] = Array(private final boolean
A.gd1$1(int))
scala> classOf[A].getDeclaredMethods.last.isSynthetic
res11: Boolean = false
scala> class A { def foo(a: Int = 0) = 0 }
defined class A
scala> classOf[A].getDeclaredMethods
res12: Array[java.lang.reflect.Method] = Array(public int A.foo(int),
public int A.foo$default$1())
scala> classOf[A].getDeclaredMethods.last.isSynthetic
res13: Boolean = false
scala> case class A(a: Int)
defined class A
scala> classOf[A].getDeclaredMethods.find(_.getName == "copy").get.isSynthetic
res16: Boolean = false
Sun, 2011-07-31, 18:17
#2
Re: marking methods as synthetic in generated bytecode
On Sun, Jul 31, 2011 at 6:57 PM, Paul Phillips wrote:
> On 7/31/11 3:34 AM, Jason Zaugg wrote:
>>
>> I just noticed that the menagerie of methods synthesized by scalac
>> generates isn't marked as synthetic in the bytecode.
>>
>> I couldn't google up prior discussions on this matter. Is this done
>> deliberately, or by default?
>
> The reasons are here:
>
> https://issues.scala-lang.org/browse/SI-1128
>
> The problem is java interop.
Thanks. I'd stumbled over some related tickets on Groovy which stemmed
from the linked thread on jvm-lang.
Perhaps the IDE can be coaxed into using heuristics based on the
method names, instead.
-jason
Wed, 2011-08-03, 17:37
#3
Re: marking methods as synthetic in generated bytecode
On Sun, Jul 31, 2011 at 12:34 PM, Jason Zaugg <jzaugg@gmail.com> wrote:
I just noticed that the menagerie of methods synthesized by scalacIt's deliberate. I think we experimented very early on with making some of these methods synthetic, but there were some bad interactions with the JVM. Details elude me now, I am afraid. One could try to make some more methods synthetic, but one would have to be very careful.
generates isn't marked as synthetic in the bytecode.
I couldn't google up prior discussions on this matter. Is this done
deliberately, or by default?
Cheers
-- Martin
On 7/31/11 3:34 AM, Jason Zaugg wrote:
> I just noticed that the menagerie of methods synthesized by scalac
> generates isn't marked as synthetic in the bytecode.
>
> I couldn't google up prior discussions on this matter. Is this done
> deliberately, or by default?
The reasons are here:
https://issues.scala-lang.org/browse/SI-1128
The problem is java interop.