mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Confusing error message when type has [] overloaded but not []= #2453
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
### Fixes
|
||||
- Compiler assert with var x @noinit = 0 #2452
|
||||
- Confusing error message when type has [] overloaded but not []= #2453
|
||||
|
||||
### Stdlib changes
|
||||
|
||||
|
||||
@@ -3807,11 +3807,15 @@ static inline bool sema_expr_resolve_subscript_index(SemaContext *context, Expr
|
||||
if (!subscript_type)
|
||||
{
|
||||
if (check_valid) return false;
|
||||
if (overload_type == OVERLOAD_ELEMENT_REF)
|
||||
switch (overload_type)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "Getting a reference to a subscript of %s is not possible.", type_quoted_error_string(subscripted->type));
|
||||
case OVERLOAD_ELEMENT_REF:
|
||||
RETURN_SEMA_ERROR(expr, "Getting a reference to a subscript of %s is not possible.", type_quoted_error_string(subscripted->type));
|
||||
case OVERLOAD_ELEMENT_SET:
|
||||
RETURN_SEMA_ERROR(expr, "Assigning to a subscript of %s is not possible.", type_quoted_error_string(subscripted->type));
|
||||
default:
|
||||
RETURN_SEMA_ERROR(expr, "Indexing a value of type %s is not possible.", type_quoted_error_string(subscripted->type));
|
||||
}
|
||||
RETURN_SEMA_ERROR(expr, "Indexing a value of type %s is not possible.", type_quoted_error_string(subscripted->type));
|
||||
}
|
||||
if (!overload) current_type = type_flatten(current_expr->type);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fn void test(int* array, usz n)
|
||||
{
|
||||
array[n] = 33;
|
||||
n[array] = 33; // #error: Indexing a value of type
|
||||
n[array] = 33; // #error: Assigning to a subscript of
|
||||
}
|
||||
|
||||
14
test/test_suite/methods/subscript_set_error.c3
Normal file
14
test/test_suite/methods/subscript_set_error.c3
Normal 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;
|
||||
Reference in New Issue
Block a user