mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve "const" error message #1079.
This commit is contained in:
committed by
Christoffer Lerno
parent
0d1eab5c15
commit
a46bf4fbe0
@@ -387,7 +387,7 @@ static void print_all_targets(void)
|
||||
|
||||
static void print_version(void)
|
||||
{
|
||||
OUTPUT("C3 Compiler Version (pre-alpha): %s", COMPILER_VERSION);
|
||||
OUTPUT("C3 Compiler Version (alpha): %s", COMPILER_VERSION);
|
||||
OUTPUT("Installed directory: %s", find_executable_path());
|
||||
OUTPUT("LLVM version: %s", llvm_version);
|
||||
OUTPUT("LLVM default target: %s", llvm_target);
|
||||
|
||||
@@ -416,13 +416,11 @@ static bool sema_binary_is_expr_lvalue(Expr *top_expr, Expr *expr)
|
||||
Decl *decl = expr->identifier_expr.decl;
|
||||
if (decl->decl_kind != DECL_VAR)
|
||||
{
|
||||
SEMA_ERROR(top_expr, "You cannot assign a value to %s.", decl_to_a_name(decl));
|
||||
return false;
|
||||
RETURN_SEMA_ERROR(top_expr, "You cannot assign a value to %s.", decl_to_a_name(decl));
|
||||
}
|
||||
if (decl->var.kind == VARDECL_CONST)
|
||||
{
|
||||
SEMA_ERROR(top_expr, "You cannot assign to a constant.");
|
||||
return false;
|
||||
RETURN_SEMA_ERROR(top_expr, "You cannot assign to a constant.");
|
||||
}
|
||||
decl = decl_raw(decl);
|
||||
switch (decl->var.kind)
|
||||
@@ -469,16 +467,16 @@ static bool sema_binary_is_expr_lvalue(Expr *top_expr, Expr *expr)
|
||||
case EXPR_SUBSCRIPT_ADDR:
|
||||
if (IS_OPTIONAL(expr))
|
||||
{
|
||||
SEMA_ERROR(top_expr, "You cannot assign to an optional value.");
|
||||
return false;
|
||||
RETURN_SEMA_ERROR(top_expr, "You cannot assign to an optional value.");
|
||||
}
|
||||
return true;
|
||||
case EXPR_HASH_IDENT:
|
||||
SEMA_ERROR(top_expr, "You cannot assign to an unevaluated expression.");
|
||||
return false;
|
||||
RETURN_SEMA_ERROR(top_expr, "You cannot assign to an unevaluated expression.");
|
||||
case EXPR_EXPRESSION_LIST:
|
||||
if (!vec_size(expr->expression_list)) return false;
|
||||
return sema_binary_is_expr_lvalue(top_expr, VECLAST(expr->expression_list));
|
||||
case EXPR_CONST:
|
||||
RETURN_SEMA_ERROR(top_expr, "You cannot assign to a constant expression.");
|
||||
case EXPR_POISONED:
|
||||
case EXPR_ASM:
|
||||
case EXPR_BINARY:
|
||||
@@ -491,7 +489,6 @@ static bool sema_binary_is_expr_lvalue(Expr *top_expr, Expr *expr)
|
||||
case EXPR_COMPILER_CONST:
|
||||
case EXPR_COMPOUND_LITERAL:
|
||||
case EXPR_COND:
|
||||
case EXPR_CONST:
|
||||
case EXPR_CT_ARG:
|
||||
case EXPR_CT_CALL:
|
||||
case EXPR_CT_AND_OR:
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.5.0"
|
||||
#define COMPILER_VERSION "0.5.1"
|
||||
|
||||
8
test/test_suite/constants/assign_to_const.c3
Normal file
8
test/test_suite/constants/assign_to_const.c3
Normal file
@@ -0,0 +1,8 @@
|
||||
module test;
|
||||
import std::io;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
const NUM = 4;
|
||||
NUM += 1; // #error: You cannot assign to a constant expression
|
||||
}
|
||||
@@ -17,32 +17,32 @@ fn void test9()
|
||||
|
||||
fn void test10()
|
||||
{
|
||||
10 = 20; // #error: An assignable expression
|
||||
10 = 20; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test11()
|
||||
{
|
||||
'10' = '20'; // #error: An assignable expression
|
||||
'10' = '20'; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test12()
|
||||
{
|
||||
true = false; // #error: An assignable expression
|
||||
true = false; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test13()
|
||||
{
|
||||
"a" = "b"; // #error: An assignable expression
|
||||
"a" = "b"; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test14()
|
||||
{
|
||||
1.2 = 1.3; // #error: An assignable expression
|
||||
1.2 = 1.3; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test15()
|
||||
{
|
||||
null = null; // #error: An assignable expression
|
||||
null = null; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test16()
|
||||
|
||||
@@ -2,27 +2,27 @@ def Number = int;
|
||||
|
||||
fn void test1()
|
||||
{
|
||||
10 = 20; // #error: An assignable expression
|
||||
10 = 20; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test2()
|
||||
{
|
||||
"foo" = "bar"; // #error: An assignable expression
|
||||
"foo" = "bar"; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test3()
|
||||
{
|
||||
true = false; // #error: An assignable expression
|
||||
true = false; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test4()
|
||||
{
|
||||
'c' = 'd'; // #error: An assignable expression
|
||||
'c' = 'd'; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test5()
|
||||
{
|
||||
3.14 = 2.14; // #error: An assignable expression
|
||||
3.14 = 2.14; // #error: to a constant expression
|
||||
}
|
||||
|
||||
fn void test21()
|
||||
|
||||
Reference in New Issue
Block a user