#1190 compile error on list of java arrays

vkuzkokov Sun 29 Aug 2010

Code:

matrix := [ByteArray(0)]

gives interesing CE:

sys::CastErr: Adding '[java]::byte[]' into '[java]fanx.interop::ByteArray?[]'
  fan.sys.List.insert (List.java:380)
  fan.sys.List.add (List.java:347)
  mine::NativeExample.main (NativeExample.fan:13)

Workaround is:

matrix := Obj[ByteArray(0)]

What I see happening here is that compiler doesn't completely follow equivalence of byte[] and ByteArray?. I'm pretty sure something similar can happen with maps and closures.

brian Mon 30 Aug 2010

Promoted to ticket #1190 and assigned to brian

That probably isn't a compiler issue - the fcode the compiler generates for that looks correct:

main () -> sys::Void [const public static]
[Local 0] matrix -> [java]fanx.interop::ByteArray?[]
[Code]
  0: LoadType            [java]fanx.interop::ByteArray?
  3: LoadInt             1
  6: CallNew             sys::List.make(sys::Type, sys::Int) -> sys::Void
  9: LoadInt             0
 12: Coerce              sys::Int => [java]::int
 17: CallStatic          [java]fanx.interop::ByteArray.make([java]::int) ->
                           [java]fanx.interop::ByteArray?
 20: CallVirtual         sys::List.add(sys::Obj) -> sys::List
 23: StoreVar            0
 26: Return

This problem is probably associated with the fact that we changed the implementation of List to use a typed array backing store to catch runtime type errors. That code needs to be enhanced to handle these special interop JavaTypes.

brian Wed 8 Sep 2010

Ticket resolved in 1.0.55

I reworked the Java runtime a bit to consistently handle primary arrays such that the Fantom reflection representation of a class like byte[] (which is really [B) will always be [java]fanx.interop::ByteArray.

changeset

Login or Signup to reply.