#1187 [bug] inline var leads to wrong results

Akcelisto Sat 28 Aug 2010

using [java]fanx.interop::Interop
using [java]java.util::ArrayList

class TestList : Test{
  Void test(){
    arrList := ArrayList()
    arrList.add(ArrayList())
    arrList.add(ArrayList())
    arrList.add(ArrayList())
    // case 1    
    ArrayList[] inlineMe := Interop.toFan(arrList.iterator)
    row := inlineMe.map|tr|{tr.toString}
    // case 2
    row2 := Interop.toFan(arrList.iterator).map|ArrayList tr|{tr.toString}    
    // failed
    verifyEq(row,row2)    
  }  
}

Output:

TEST FAILED
sys::TestErr: Test failed: sys::Obj?[[], [], []] != sys::Obj?[null, null, null] 

vkuzkokov Sat 28 Aug 2010

It's not inlining. It's type inference. You explicitly say that inlineMe is ArrayList[], while toFan returns Obj?[]. If you will delete explicit ArrayList[] you'll get compilation error on the next line. It's because tr type will be resolved as Obj? and therefore won't have toString.

The idea of the above is that case 1 and case 2 are not supposed to do the same.

Here, case 1 gives us what is expected. [] is the value of toString for empty list in java. You can use non-empty list for clarification. when you write:

row := inlineMe.map|tr|{tr.toString}

it's understood as:

row := inlineMe.map|ArrayList tr->Obj?| { tr.toString }

Note that it's different from

inlineMe.map|ArrayList tr| { tr.toString }

because latter returns Void. Thus row2 is an array of Voids which are interpreted as nulls (we can't have Void[] indeed).

Akcelisto Sat 28 Aug 2010

Thanks to vkuzkokov. I understood: case 1 and case 2 is not equivalent.

using [java]fanx.interop::Interop
using [java]java.util::ArrayList

class TestList : Test{
  Void test(){
    arrList := ArrayList()
    arrList.add(ArrayList())
    arrList.add(ArrayList())
    arrList.add(ArrayList())
    // case 1
    ArrayList[] inlineMe := Interop.toFan(arrList.iterator)
    row := inlineMe.map|tr|{tr.toString}
    // case 2
    row2 := Interop.toFan(arrList.iterator).map|ArrayList tr->Obj?|{tr.toString}
    // passed
    verifyEq(row,row2)
  }
}

Now test passed.

Login or Signup to reply.