Improve lvalue handling in the compiler. #1357

This commit is contained in:
Christoffer Lerno
2024-09-07 03:19:17 +02:00
parent 78c60ae695
commit 7649738618
3 changed files with 21 additions and 1 deletions

View File

@@ -13,6 +13,7 @@
- Converting a slice to a vector/array would copy too little data.
- Crash when reading an empty 'manifest.json'.
- "optsize" did not work correctly in project.json.
- `l[0].a = 1` now supported for overloads due to better lvalue handling #1357.
### Stdlib changes
- Additional init functions for hashmap.

View File

@@ -4449,7 +4449,7 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
if (missing_ref) *missing_ref = false;
// 1. Resolve the left hand
if (!sema_analyse_expr_check(context, parent, check)) return false;
if (!sema_analyse_expr_check(context, parent, check != CHECK_VALUE ? CHECK_ADDRESS : CHECK_VALUE)) return false;
// 2. The right hand side may be a @ident or ident
Expr *child = expr->access_expr.child;

View File

@@ -0,0 +1,19 @@
module lvalue_handling;
import std;
struct Foo
{
int a;
}
def IntList = List(<Foo>);
fn void subscript_overload() @test
{
IntList x;
x.push({ 3 });
int* a = &x[0].a;
assert(*a == 3);
assert(x[0].a == 3);
*a = 4;
assert(x[0].a == 4);
x[0].a = 5;
assert(x[0].a == 5);
}