#2121 Runtime error when using Map as a type

katox Mon 1 Apr 2013

Hey,

lately I found out that Fantom produces rather strange errors when using Map as an interface type. Unlike specifying the direct [KeyType:ValueType] using just Map can throw a runtime error because the runtime can't infer types used.

fansh> list := [[30:1],[20:2],[10:3]]
[[30:1], [20:2], [10:3]]
fansh> list.typeof
[sys::Int:sys::Int][]

fansh> list.max |a,b->Int| { a.vals[0] <=> b.vals[0] }
[10:3]

fansh> list.max |[Int:Int] a, [Int:Int] b -> Int| { a.vals[0] <=> b.vals[0] }
[10:3]

fansh> list.max |[Obj:Obj] a, [Obj:Obj] b -> Int| { a.vals[0] <=> b.vals[0] }
[10:3]

fansh> list.max |Map a, Map b->Int| { a.vals[0] <=> b.vals[0] }
sys::UnknownTypeErr: sys::V
  fan.sys.Pod.type (Pod.java:284)
  fan.sys.FanClassLoader.findFanClass (FanClassLoader.java:174)
  fan.sys.FanClassLoader.findClass (FanClassLoader.java:92)
  java.lang.ClassLoader.loadClass (ClassLoader.java:423)
  java.lang.ClassLoader.loadClass (ClassLoader.java:356)
  fan.sys.FanClassLoader.findFanClass (FanClassLoader.java:148)
  fan.sys.FanClassLoader.findClass (FanClassLoader.java:92)
  java.lang.ClassLoader.loadClass (ClassLoader.java:423)
  java.lang.ClassLoader.loadClass (ClassLoader.java:356)

I don't think it should result into a runtime error. There is no reason making it a compile error either (a breaking change). The best solution seems to be let the compiler infer the type sys::Obj. Then it would behave as expected.

brian Mon 1 Apr 2013

Promoted to ticket #2121 and assigned to brian

brian Mon 20 May 2013

Ticket resolved in 1.0.65

Login or Signup to reply.