Compilers can't always be expected to understand every kind of error, and
that error message isn't the worst I've seen :) Still, if the opportunity os
there to change it to something better, now harm done. The situation can be
translated to this:
int x;
1 => x[1];
which gives the same subscript error message. Hans's code is otherwise
without problems - ChucK allows (like many other languages) to reuse a
variable identifier in a new block, so x can be redeclared as an int in the
inner while loop, overshadowing the outer x which is an array.
/Stefan
On Wed, Apr 22, 2009 at 5:55 PM, Hans Aberg
On 22 Apr 2009, at 17:17, Kassen wrote:
I think ChucK can get pretty confused about this line:
x[msg.which] => int x;
...in which x is treated both as an array and as a newly declared integer variable. I would rename the array to avoid confusion.
... I do think ChucK could come up with a better complaint than this;
[unnamed1]:line(20): array subscripts (1) exceeds defined dimension (0)
With this test code it goes right;
int x[2]; int x;
And we get a rather appropriate
[unnamed1]:line(2): 'x' has already been defined in the same scope...
The problem is really that if I remove the second line of: x[msg.which] => int x; x[msg.which] => int x0; then the first x[msg.which] => int x; is accepted.
So when I add the second line, I get a confusing error message about that, not about the first one, which seemed a legal name overload (though differing from C++).
Hans
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!