Sending to channel taken from array fails in for loop without braces
Take a look at the following pseuCo program (available here):
intchan10[10] test;
void a1() {
for (int i = 0; i < 10; i++)
test[i] <! 42;
}
void a2() {
for (int i = 0; i < 10; i++) {
test[i] <! 42;
};
}
mainAgent {
}
The compiler generates the following code (extract from Main.java
):
public static Intchan[] test = PseuCo_initArrayIntchan1(new int[] {10}, 10);
public static void PseuCo_a1(){
{
int i = 0
Work work = new Work(test[i], false, 42, Thread.currentThread(), 1);
for ( ; i < 10; i++){
test[i].handleSelect(work);
}}
}
public static void PseuCo_a2(){
for (int i = 0; i < 10; i++){
Work work1 = new Work(test[i], false, 42, Thread.currentThread(), 1);
test[i].handleSelect(work1);
}
;
}
public static Intchan[] PseuCo_initArrayIntchan1(int[] length, int sizeOfBufchan){
Intchan[] arrayName = new Intchan[length[0]];
for(int i0 = 0; i0 < length[0]; i0++){
arrayName[i0] = new Intchan(sizeOfBufchan);
}
return arrayName;
}
public static void main(String[] args) {
}
The generated code differs if the body of the for
loop is wrapped in braces or not. It seems that the code generation is correct if braces are used, but broken without them.