arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Improve const assignment errors

Open wrongnull opened this issue 9 months ago • 6 comments

Closes https://github.com/Vexu/arocc/issues/422

wrongnull avatar Apr 18 '25 08:04 wrongnull

The type printing changes look correct at least compared to clang. Did you compare with gcc?

I did. But gcc issues diagnostics in a different way compared to clang.

void foo() {
    const int a[2];
    a[2] = 1;
}
error: assignment of read-only location 'a[2]'

wrongnull avatar Apr 22 '25 08:04 wrongnull

There are probably other cases where the type is printed but just matching Clang is also fine.

Vexu avatar Apr 22 '25 19:04 Vexu

Sorry for the delay, just didn't have enough time. Looks like CI failure is unrelated to this pr @Vexu

wrongnull avatar May 24 '25 19:05 wrongnull

This still doesn't cover every case:

void foo(void) {
    const int arr[2][2] = { 0, 1, 2, 3};
    arr[0][0] = 1;
}

This is quite close to being ready though so if you want I can take it over and fix the few remaining issues.

Looks like CI failure is unrelated to this pr

I fixed it in https://github.com/Vexu/arocc/pull/860/commits/891adc96b1067b8189daed59a6f601c2e361e8d6

Vexu avatar May 24 '25 20:05 Vexu

This still doesn't cover every case:

void foo(void) {
    const int arr[2][2] = { 0, 1, 2, 3};
    arr[0][0] = 1;
}

This is quite close to being ready though so if you want I can take it over and fix the few remaining issues.

Looks like CI failure is unrelated to this pr

I fixed it in 891adc9

Tbh I want to finish it myself. To save time, it would be great if you listed all the code snippets that should issue the diagnostic. After that, I'll be ready to send the final commit

wrongnull avatar May 24 '25 21:05 wrongnull

Tbh I want to finish it myself.

That's fine too.

To save time, it would be great if you listed all the code snippets that should issue the diagnostic. After that, I'll be ready to send the final commit

Every case that would previously cause a .not_assignable diagnostic should still produce some diagnostic after this, easiest way to achieve that is to just fall back on .not_assignable if you can't give a more specific diagnostic.

It'd also be nice if you could replace all those inline fors with loop: switch like constructs.

Vexu avatar May 24 '25 21:05 Vexu

@Vexu can you take a look at it now?

wrongnull avatar Jun 11 '25 13:06 wrongnull

Still missing cases:

void foo(void) {
   const struct {
      struct {
         int a;
      } a;
   } a = {1};
   a.a.a = 2;
}
int const* foo(void);
void bar(void) {
   foo()[0] = 1;
}

Vexu avatar Jun 13 '25 09:06 Vexu

@Vexu can you take a look at it now please?

wrongnull avatar Jul 29 '25 11:07 wrongnull

Thanks!

Vexu avatar Jul 29 '25 18:07 Vexu