diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-21 15:59:32 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-21 15:59:32 +0200 |
commit | 59b9c661cbdf125b0a17f8f955158a1f77f163f8 (patch) | |
tree | 36c5b0abe4bb8202f6b23c30759706cd1c0f8a49 /tests | |
parent | d336498c7cf397de496fa46fccc31883480ecb1d (diff) | |
download | bdl-59b9c661cbdf125b0a17f8f955158a1f77f163f8.tar.gz bdl-59b9c661cbdf125b0a17f8f955158a1f77f163f8.zip |
Add semantic checking for enum constructs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conditionals.bad | 17 | ||||
-rw-r--r-- | tests/semantics.bad | 84 |
2 files changed, 58 insertions, 43 deletions
diff --git a/tests/conditionals.bad b/tests/conditionals.bad index e1a456e..b5ef61f 100644 --- a/tests/conditionals.bad +++ b/tests/conditionals.bad | |||
@@ -34,12 +34,17 @@ enum flags { | |||
34 | node_div = 1 << 2 | 34 | node_div = 1 << 2 |
35 | node_mul | 35 | node_mul |
36 | } | 36 | } |
37 | let a:flags = flags.node_add | 37 | let f:flags = flags.node_add |
38 | 38 | ||
39 | ; No need to qualify enum fields inside match-case. | 39 | ; TODO: No need to qualify enum fields inside match-case. |
40 | ; match (a) { | ||
41 | ; case node_add = "adding something..." | ||
42 | ; case node_add = "subbing something..." | ||
43 | ; else = "default case" | ||
44 | ; } | ||
40 | match (a) { | 45 | match (a) { |
41 | case node_add = "adding something..." | 46 | case flags.node_add = "adding something..." |
42 | case node_add = "subbing something..." | 47 | case flags.node_add = "subbing something..." |
43 | else = "default case" | 48 | else = "default case" |
44 | } | 49 | } |
45 | 50 | ||
@@ -47,6 +52,6 @@ match (a) { | |||
47 | ; statements. | 52 | ; statements. |
48 | let msg:str = cond { | 53 | let msg:str = cond { |
49 | case a == b = "hello" | 54 | case a == b = "hello" |
50 | case a != c = "world" | 55 | case a != f = "world" |
51 | else = "what" | 56 | else = "what" |
52 | } | 57 | } |
diff --git a/tests/semantics.bad b/tests/semantics.bad index 4ce40b9..29c91c4 100644 --- a/tests/semantics.bad +++ b/tests/semantics.bad | |||
@@ -1,49 +1,59 @@ | |||
1 | fun foo(): nil { | 1 | enum field { |
2 | bar() | 2 | a |
3 | b | ||
4 | ; a | ||
5 | ; c = field.a | ||
6 | ; c = field.c | ||
7 | ; c = c | ||
8 | ; c = a | ||
3 | } | 9 | } |
4 | 10 | ||
5 | fun bar(): nil { | 11 | ; fun foo(): nil { |
6 | foo() | 12 | ; bar() |
7 | } | 13 | ; } |
8 | 14 | ||
9 | ; There are some builtint functions. | 15 | ; fun bar(): nil { |
10 | println("hello world") | 16 | ; foo() |
17 | ; } | ||
11 | 18 | ||
12 | ; Let/set. | 19 | ; ; There are some builtint functions. |
13 | let num = 1 | 20 | ; println("hello world") |
14 | set num = 2 | ||
15 | set num = 0 + num | ||
16 | 21 | ||
17 | ; Loops and conditionals. | 22 | ; ; Let/set. |
18 | if (num) 3 else 1 | 23 | ; let num = 1 |
19 | let val = if (2 + num == 4) num else num | 24 | ; set num = 2 |
20 | if (true) { | 25 | ; set num = 0 + num |
21 | let c = 1 | ||
22 | 1 + 1 + c | ||
23 | } | ||
24 | 26 | ||
25 | match (num) { | 27 | ; ; Loops and conditionals. |
26 | case 1 = 23 | 28 | ; if (num) 3 else 1 |
27 | case 2 = num | 29 | ; let val = if (2 + num == 4) num else num |
28 | else = num | 30 | ; if (true) { |
29 | } | 31 | ; let c = 1 |
32 | ; 1 + 1 + c | ||
33 | ; } | ||
30 | 34 | ||
31 | cond { | 35 | ; match (num) { |
32 | case 1 == 1 = 23 | 36 | ; case 1 = 23 |
33 | case 2 != 1 = num | 37 | ; case 2 = num |
34 | else = num | 38 | ; else = num |
35 | } | 39 | ; } |
36 | 40 | ||
37 | while (num == 1) num | 41 | ; cond { |
38 | while (true) { | 42 | ; case 1 == 1 = 23 |
39 | let c = 1 | 43 | ; case 2 != 1 = num |
40 | 1 + 1 + c | 44 | ; else = num |
41 | } | 45 | ; } |
42 | 46 | ||
43 | fun nested(): u32 { | 47 | ; while (num == 1) num |
44 | fun adder(a: u32, b: u32): u32 a + b | 48 | ; while (true) { |
45 | adder(1,2) | 49 | ; let c = 1 |
46 | } | 50 | ; 1 + 1 + c |
51 | ; } | ||
52 | |||
53 | ; fun nested(): u32 { | ||
54 | ; fun adder(a: u32, b: u32): u32 a + b | ||
55 | ; adder(1,2) | ||
56 | ; } | ||
47 | 57 | ||
48 | ; This should err. | 58 | ; This should err. |
49 | ; fun foo(): nil { | 59 | ; fun foo(): nil { |