#1282 Pretty sure this is a bug

yachris Sat 30 Oct 2010

Trying to track something else down, I found that this works:

class BugTest
{
  static Void main()
  {
    b := BugExample { a = [1, 2, 3]; b = [4, 5, 6] }
    echo(b.a)
    echo(b.b)
    echo(b.c)
  }
}

class BugExample
{
  new make(|This| f)
  {
    a = [,]
    b = [,]
    f(this)
    c = a.dup.addAll(b)
  }

  Int[] a
  Int[] b
  Int[] c
}

but if I change the main method to:

static Void main()
{
  b := BugExample { a = [1, 2, 3]; b = [4, 5, 6] }
  echo(b.a)
  echo(b.b)
  echo(b.c)

  d := BugExample { a = [1, 2, 3]; b = [4, 5, 6] }
  echo(d.a)
  echo(d.b)
  echo(d.c)
}

It won't compile:

/path/BugTest.fan(10,40): 'sys::Int[]' is not assignable to 'BugTest_0::BugExample'
ERROR: cannot compile script

Changing the b variable in main to bb and it compiles happily. Okay, so the message is use descriptive variable names :-) but...

Thanks!

rosarinjroy Sat 30 Oct 2010

Hi yachris: I think this is not a bug. In your second example, you are using name "b" in the Func object. The order of scope resolution is to check:

  1. If the given name is a declared variable in the Func object.
  2. If the given name is a declared variable in the enclosing scope.
  3. If the given name is in the context where the Func object will be executed.

Going by that order, before the compiler sees field "b" in BugExample, it will see "b" in main method. Upon that, the compiler finds that the declared "b" is of type BugExample, but you are attempting to assign it an Int array.

Hence this is not a bug. And the messages seems to be descriptive as well.

yachris Sat 30 Oct 2010

rosarinjroy -- thanks for the clarification. I stand corrected.

Login or Signup to reply.