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!
rosarinjroySat 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:
If the given name is a declared variable in the Func object.
If the given name is a declared variable in the enclosing scope.
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.
yachrisSat 30 Oct 2010
rosarinjroy -- thanks for the clarification. I stand corrected.
yachris Sat 30 Oct 2010
Trying to track something else down, I found that this works:
but if I change the
main
method to:It won't compile:
Changing the
b
variable inmain
tobb
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:
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.