[chuck-users] Inner loop array index bug

Hans Aberg haberg at math.su.se
Wed Apr 22 16:19:06 EDT 2009


On 22 Apr 2009, at 21:01, Stefan Blixt wrote:

> 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.

The problem is really that 'chuck' accepts
    x[msg.which] => int x;
Then when a line after that is added
    x[msg.which] => int x0;
it complains about this line, giving that cryptic message, despite the  
fact that it is correct.

When the first line is accepted, that gives the impression that this  
name overloading is legal, though it differs from C++. Thus I started  
to use it.

Chuck needs to make up its mind: is this name overloading legal or  
not. If it is not, it should always be rejected.

   Hans




More information about the chuck-users mailing list