mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Using [] or .foo on $$ functions would not raise error but instead crash #2919.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
- Update to dstring.append_string to take any type converting to String.
|
||||
- Flag `--cpu-flags` doesn't work if the first item is an exclusion. #2905
|
||||
- Reallocating overaligned memory with the LibcAllocator was unsafe.
|
||||
- Using [] or .foo on $$ functions would not raise error but instead crash
|
||||
|
||||
## 0.7.9 Change list
|
||||
|
||||
|
||||
@@ -4198,7 +4198,10 @@ DEFAULT:
|
||||
}
|
||||
|
||||
if (!sema_expr_check_assign(context, expr, NULL)) return false;
|
||||
|
||||
if (subscripted->expr_kind == EXPR_BUILTIN)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "Builtins cannot be subscripted.");
|
||||
}
|
||||
Expr *index = exprptr(expr->subscript_expr.index.expr);
|
||||
|
||||
// 3. Check failability due to value.
|
||||
@@ -4295,7 +4298,10 @@ static inline bool sema_expr_analyse_subscript(SemaContext *context, Expr *expr,
|
||||
// Evaluate the expression to index.
|
||||
Expr *subscripted = exprptr(expr->subscript_expr.expr);
|
||||
if (!sema_analyse_expr(context, subscripted)) return false;
|
||||
|
||||
if (subscripted->expr_kind == EXPR_BUILTIN)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "Builtins cannot be subscripted.");
|
||||
}
|
||||
// 3. Check failability due to value.
|
||||
bool optional = IS_OPTIONAL(subscripted);
|
||||
|
||||
@@ -4752,6 +4758,10 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr)
|
||||
ASSERT_SPAN(expr, expr->expr_kind == EXPR_SLICE);
|
||||
Expr *subscripted = exprptr(expr->slice_expr.expr);
|
||||
if (!sema_analyse_expr(context, subscripted)) return false;
|
||||
if (subscripted->expr_kind == EXPR_BUILTIN)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "A builtin cannot be sliced.");
|
||||
}
|
||||
bool optional = IS_OPTIONAL(subscripted);
|
||||
Type *type = type_flatten(subscripted->type);
|
||||
Type *original_type = type_no_optional(subscripted->type);
|
||||
|
||||
5
test/test_suite/builtins/builtin_props.c3
Normal file
5
test/test_suite/builtins/builtin_props.c3
Normal file
@@ -0,0 +1,5 @@
|
||||
fn int main()
|
||||
{
|
||||
if ($$veccompne.type == int.typeid) // #error: A builtin has no support for properties
|
||||
return 0;
|
||||
}
|
||||
13
test/test_suite/builtins/builtin_subscript.c3
Normal file
13
test/test_suite/builtins/builtin_subscript.c3
Normal file
@@ -0,0 +1,13 @@
|
||||
fn void main()
|
||||
{
|
||||
$$veccompgt[1]; // #error: Builtins cannot be subscripted.
|
||||
}
|
||||
fn void test()
|
||||
{
|
||||
$$veccompeq[1] = 33; // #error: Builtins cannot be subscripted.
|
||||
}
|
||||
|
||||
fn void test2()
|
||||
{
|
||||
$$veccomple[..] = 52; // #error: A builtin cannot be sliced.
|
||||
}
|
||||
Reference in New Issue
Block a user