#1382 js: closure type const field assigment to null problem

ilya Wed 12 Jan 2011

One more Javascript problem. If we have a

@Js 
const class C
{
  const |Obj, Obj -> Int|? comparator
  new make(|Obj, Obj -> Int|? comparator := null) 
  {
    this.comparator = comparator
  }
  Str foo() { "foo" }
}

and then try to make

Button 
{ 
  text = "foo"
  onAction.add |Event e|
  {
    try
    {
      Dialog.openInfo(e.window, C().foo)
    }
    catch (Err err)
    {
      Dialog.openErr(e.window, err.traceToStr)
    }
  }
}

we'll get a "type is undefined" error in sys.js:11053 at

fan.sys.ObjUtil.coerce = function(obj, type)
{
if (obj == null)
{
if (type.isNullable()) return obj;

If field is not const - all is fine. And one more workaround is available, if we declare const Obj? field, everything will work fine too:

@Js 
const class C
{
  const Obj? comparator
  new make(|Obj, Obj -> Int|? comparator := null) 
  {
    this.comparator = comparator
  }
  Str foo() { "foo" }
}

andy Wed 12 Jan 2011

Promoted to ticket #1382 and assigned to andy

Thanks @ilya - will take a look.

Login or Signup to reply.