mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve lvalue handling in the compiler. #1357
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
19
test/unit/regression/lvalue_handling.c3
Normal file
19
test/unit/regression/lvalue_handling.c3
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user