diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-21 23:40:03 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-21 23:40:03 +0200 |
commit | 8931a6f22b9586c62082c525ec8b6de62c7de5d5 (patch) | |
tree | 8ab44ee3619893ae8f8acc195f9ac890710918cd /tests | |
parent | 835f4d9f23f55a973d76ae9384b7b9d75da5472b (diff) | |
download | bdl-8931a6f22b9586c62082c525ec8b6de62c7de5d5.tar.gz bdl-8931a6f22b9586c62082c525ec8b6de62c7de5d5.zip |
Start implementing the typechecker
Diffstat (limited to 'tests')
-rw-r--r-- | tests/semantics.bad | 120 |
1 files changed, 67 insertions, 53 deletions
diff --git a/tests/semantics.bad b/tests/semantics.bad index d050426..c331ebc 100644 --- a/tests/semantics.bad +++ b/tests/semantics.bad | |||
@@ -1,66 +1,80 @@ | |||
1 | fun nested(): u32 { | 1 | let a:u16 = (1 + 2 * 2) / 2 |
2 | fun adder(a: u32, b: u32): u32 a + b | 2 | ; enum test { |
3 | if (1 + 1) { | 3 | ; a = 1 |
4 | { | 4 | ; b |
5 | let b = 32 | 5 | ; } |
6 | } | 6 | ; ; Resolve struct accessors. |
7 | } | 7 | ; struct my_struct { |
8 | adder(1,2) | 8 | ; field_a: int |
9 | } | 9 | ; field_b: int |
10 | ; } | ||
10 | 11 | ||
11 | enum field { | 12 | ; let a:my_struct |
12 | a | 13 | ; set a.field_a = 1 |
13 | b | ||
14 | } | ||
15 | 14 | ||
16 | struct vec { | 15 | ; fun nested(): u32 { |
17 | a: int | 16 | ; fun adder(a: u32, b: u32): u32 a + b |
18 | b: int | 17 | ; if (1 + 1) { |
19 | } | 18 | ; { |
19 | ; let b = 32 | ||
20 | ; } | ||
21 | ; } | ||
22 | ; adder(1,2) | ||
23 | ; } | ||
20 | 24 | ||
21 | fun foo(): nil { | 25 | ; enum field { |
22 | bar() | 26 | ; a |
23 | } | 27 | ; b |
28 | ; } | ||
24 | 29 | ||
25 | fun bar(): nil { | 30 | ; struct vec { |
26 | foo() | 31 | ; a: int |
27 | } | 32 | ; b: int |
33 | ; } | ||
28 | 34 | ||
29 | ; There are some builtint functions. | 35 | ; fun foo(): nil { |
30 | println("hello world") | 36 | ; bar() |
37 | ; } | ||
31 | 38 | ||
32 | ; Let/set. | 39 | ; fun bar(): nil { |
33 | let num = 1 | 40 | ; foo() |
34 | set num = 2 | 41 | ; } |
35 | set num = 0 + num | 42 | |
43 | ; ; There are some builtint functions. | ||
44 | ; println("hello world") | ||
45 | |||
46 | ; ; Let/set. | ||
47 | ; let num = 1 | ||
48 | ; set num = 2 | ||
49 | ; set num = 0 + num | ||
36 | 50 | ||
37 | ; Loops and conditionals. | 51 | ; ; Loops and conditionals. |
38 | if (num) 3 else 1 | 52 | ; if (num) 3 else 1 |
39 | let val = if (2 + num == 4) num else num | 53 | ; let val = if (2 + num == 4) num else num |
40 | if (true) { | 54 | ; if (true) { |
41 | let c = 1 | 55 | ; let c = 1 |
42 | 1 + 1 + c | 56 | ; 1 + 1 + c |
43 | } | 57 | ; } |
44 | 58 | ||
45 | fun testmatches(): nil { | 59 | ; fun testmatches(): nil { |
46 | match (num) { | 60 | ; match (num) { |
47 | case 1 = 23 | 61 | ; case 1 = 23 |
48 | case 2 = num | 62 | ; case 2 = num |
49 | else = num | 63 | ; else = num |
50 | } | 64 | ; } |
51 | 65 | ||
52 | cond { | 66 | ; cond { |
53 | case 1 == 1 = 23 | 67 | ; case 1 == 1 = 23 |
54 | case 2 != 1 = num | 68 | ; case 2 != 1 = num |
55 | else = num | 69 | ; else = num |
56 | } | 70 | ; } |
57 | } | 71 | ; } |
58 | 72 | ||
59 | while (num == 1) num | 73 | ; while (num == 1) num |
60 | while (true) { | 74 | ; while (true) { |
61 | let c = 1 | 75 | ; let c = 1 |
62 | 1 + 1 + c | 76 | ; 1 + 1 + c |
63 | } | 77 | ; } |
64 | 78 | ||
65 | ; This should err. | 79 | ; This should err. |
66 | ; fun foo(): nil { | 80 | ; fun foo(): nil { |