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