#906 Obj.super.trap() from within a Mixin

msl Tue 12 Jan 2010

I came across this gem of a compilation error while trying to provide a mixin implementation of sys::Obj.trap:

Cannot use Obj.super inside mixin (yeah I know - take it up with Sun)

Tracking back through the code, it comes from src/compiler/fan/steps/CheckErrors.fan but there's no real discussion of what the cause of the issue is.

Is this another form of the invokespecial issue mentioned (but not really discussed) in docLang:

Mixins cannot use unnamed super because that would be a non-virtual call on Obj (which is itself really just a problem with Java's lame rules on invokespecial)

... or something else?

(I suspect the answer here is going to go down a rat hole of JVM bytecode discussion that I won't follow, but I'll still ask the question)

As a work around, I've ripped off the content of the doTrap method from fan/sys/FanObj.java and reimplemented it in Fantom mixin - see github for details. I can now call MixinTrap^.super.trap(args, name) from any mixin code and everything compiles/runs as expected.

Other than performance are there any issues I've missed with this approach?

M

^ Quite possibly the worse type name I've come up with in a while

brian Tue 12 Jan 2010

Code looks good, basically just duplicating the Java code as you said.

The general problem with Java is that it doesn't have a proper invokenonvirtual bytecode. Instead it has this lame invokespecial bytecode which is esstentially the used to invoke methods non-virtually but with all these restrictions that make it impossible to use between classes.

JVM Lang Discussion

msl Wed 13 Jan 2010

As expected - that thread just made my head explode... but thanks for the info! :)

Login or Signup to reply.