mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Prevent foo.bar = {} when bar is a flexible array member.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
- Issue not correctly aborting compilation on recursive generics.
|
- Issue not correctly aborting compilation on recursive generics.
|
||||||
- Crash during codegen when taking the typeid of an empty enum with associated values.
|
- Crash during codegen when taking the typeid of an empty enum with associated values.
|
||||||
- Assert when the binary doesn't get created and --run-once is used. #2502
|
- Assert when the binary doesn't get created and --run-once is used. #2502
|
||||||
|
- Prevent `foo.bar = {}` when `bar` is a flexible array member.
|
||||||
|
|
||||||
### Stdlib changes
|
### Stdlib changes
|
||||||
- Added generic `InterfaceList` to store a list of values that implement a specific interface
|
- Added generic `InterfaceList` to store a list of values that implement a specific interface
|
||||||
|
|||||||
@@ -6862,6 +6862,10 @@ static bool sema_expr_analyse_assign(SemaContext *context, Expr *expr, Expr *lef
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (left->type && left->type->type_kind == TYPE_FLEXIBLE_ARRAY)
|
||||||
|
{
|
||||||
|
RETURN_SEMA_ERROR(left, "You can't assign to a flexible array member, but you may index into it and mutate it that way.");
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Check assignability
|
// 2. Check assignability
|
||||||
if (!sema_expr_check_assign(context, left, failed_ref)) return false;
|
if (!sema_expr_check_assign(context, left, failed_ref)) return false;
|
||||||
@@ -7174,7 +7178,13 @@ static bool sema_expr_analyse_op_assign(SemaContext *context, Expr *expr, Expr *
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (left->type->type_kind == TYPE_FLEXIBLE_ARRAY)
|
||||||
|
{
|
||||||
|
RETURN_SEMA_ERROR(left, "You can't assign to a flexible array member, but you may index into it and mutate it that way.");
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Verify that the left side is assignable.
|
// 2. Verify that the left side is assignable.
|
||||||
|
|
||||||
if (!sema_expr_check_assign(context, left, NULL)) return false;
|
if (!sema_expr_check_assign(context, left, NULL)) return false;
|
||||||
|
|
||||||
Type *left_type_canonical = left->type->canonical;
|
Type *left_type_canonical = left->type->canonical;
|
||||||
|
|||||||
@@ -275,6 +275,8 @@ static inline StorageType sema_resolve_storage_type(SemaContext *context, Type *
|
|||||||
if (!sema_analyse_decl(context, type->decl)) return false;
|
if (!sema_analyse_decl(context, type->decl)) return false;
|
||||||
type = type->decl->distinct->type;
|
type = type->decl->distinct->type;
|
||||||
goto RETRY;
|
goto RETRY;
|
||||||
|
case TYPE_FLEXIBLE_ARRAY:
|
||||||
|
return STORAGE_UNKNOWN;
|
||||||
default:
|
default:
|
||||||
return STORAGE_NORMAL;
|
return STORAGE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|||||||
25
test/test_suite/struct/flex_more_errors.c3
Normal file
25
test/test_suite/struct/flex_more_errors.c3
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module main;
|
||||||
|
|
||||||
|
struct OwnedString
|
||||||
|
{
|
||||||
|
usz len;
|
||||||
|
char[*] data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void test1()
|
||||||
|
{
|
||||||
|
OwnedString owned;
|
||||||
|
owned.data = {}; // #error: You can't assign to a flexible array member
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void test2()
|
||||||
|
{
|
||||||
|
$typefrom(OwnedString.data.typeid) x = 1; // #error: 'char[*]' has unknown size, and
|
||||||
|
}
|
||||||
|
|
||||||
|
fn int main()
|
||||||
|
{
|
||||||
|
OwnedString owned;
|
||||||
|
owned.data[0] = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user