Using [] or .foo on $$ functions would not raise error but instead crash #2919.

This commit is contained in:
Christoffer Lerno
2026-02-11 02:53:17 +01:00
parent 40e6a2c4a3
commit e2f17a770b
4 changed files with 31 additions and 2 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -0,0 +1,5 @@
fn int main()
{
if ($$veccompne.type == int.typeid) // #error: A builtin has no support for properties
return 0;
}

View 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.
}