#1998 Dynamic Typing -> sys::UnknownTypeErr

SlimerDude Thu 9 Aug 2012

I have a method:

override Void drawImage(Obj gfx) {
  ...
  gfx->copyImage(... blah ...)
  ...
}

which gives:

sys::UnknownTypeErr: fwt::FwtGraphics
  fan.sys.Pod.type (Pod.java:284)
  fanx.util.FanUtil.toFanType (FanUtil.java:40)
  fan.sys.FanObj.typeof (FanObj.java:143)
  fan.sys.FanObj.trap (FanObj.java:179)
  afFantomMappy::FmaRenderer.drawImage (FmaRenderer.fan:47) 

I can change it to

(gfx as gfx::Graphics).copyImage(... blah ...)

but that kinda defeats the point of duck typing!

Here's a simple test case to re-produce err:

using gfx
using fwt

class WonkyDuck {
  static Void main(Str[] args) {
    window := Window(null) {
      onFocus.add { 
        i := Image.makePainted(Size(16, 16)) |gfx| {
          stuff(gfx)
        }        
      }
    }.open
  }

  static Void stuff(Obj gfx) {
    rain := Image.make(`fan://icons/x16/rain.png`)
    gfx->copyImage(rain, Rect(0, 0, 16, 16), Rect(0, 0, 16, 16))
  }
}

SlimerDude Thu 9 Aug 2012

And in JS get an:

uncaught exception: sys::UnknownSlotErr: sys::Obj.copyImage

But it all works fine when the gfx Obj is one of my own classes...?

i.e. this runs with no probs;

using gfx
using fwt

class WonkyDuck {
  static Void main(Str[] args) {
    window := Window(null) {
      onFocus.add { 
        i := Image.makePainted(Size(16, 16)) |gfx| {
          stuff(MyGfx(gfx))
        }        
      }
    }.open
  }

  static Void stuff(Obj gfx) {
    rain := Image.make(`fan://icons/x16/rain.png`)
    gfx->copyImage(rain, Rect(0, 0, 16, 16), Rect(0, 0, 16, 16))
  }
}

class MyGfx {
  Graphics g
  new make(Graphics g) { this.g = g }
  Void copyImage(Image i, Rect s, Rect d) {
    g.copyImage(i, s, d)
  }
}

brian Thu 9 Aug 2012

On the JVM side weird stuff happens because I hand code the classes. But usually a simple fix. I will take a look.

Not sure on the JS side, but Andy will take a look (it could just be that method isn't implemented)

brian Fri 24 Aug 2012

Was missing the Fantom stub class for native Java code. I pushed a fix - changeset

andy Fri 24 Aug 2012

JS implementation wasn't properly hooking into Fantom type system. Fixed as well - changeset.

Login or Signup to reply.