vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
549 stars 90 forks source link

Defining struct in a loop gives confusing error message #443

Open user202729 opened 5 months ago

user202729 commented 5 months ago
for(int i=0; i<10; ++i){
    struct A{int x;}
    A f(A a, int y){ a.x+=i; return a; }
    A a;
    A b=f(a,1);
}

Error message:

        A b=f(a,1);
      ^
a.asy: 5.7: cannot cast 'A' to 'A'
success

Why is the f function not redefined anyway?

johncbowman commented 3 months ago

For the record, here's a more minimal example:

while(true) {
  struct A {
    int x;
  }
  A f(A a){ return a; }
  A a;
  a=f(a);
}