Confusing error message when type has [] overloaded but not []= #2453

This commit is contained in:
Christoffer Lerno
2025-09-02 23:56:15 +02:00
parent 02d1486af9
commit 14a929588a
4 changed files with 23 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
fn int main(String[] args)
{
MyArray a = {{1, 4, 3, 6, 5}};
a[0] = a[1]; // #error: Assigning to a subscript of 'MyArray' is not possible
return 0;
}
struct MyArray
{
int[] val;
}
fn int MyArray.get(self, usz idx) @operator([]) => self.val[idx];
fn usz MyArray.len(self) @operator(len) => self.val.len;