aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-25 10:36:02 +0200
committerBad Diode <bd@badd10de.dev>2024-06-25 10:36:02 +0200
commitbcc40682a0d699e8c36df62975c12cdea491d167 (patch)
tree6511cdef1730d39bb81fceaf9839658654280f32 /tests
parent9eb5c9bfa3fcf8d7b03efd7d4def71e39ae3f799 (diff)
downloadbdl-bcc40682a0d699e8c36df62975c12cdea491d167.tar.gz
bdl-bcc40682a0d699e8c36df62975c12cdea491d167.zip
Add struct literals typechecking
Diffstat (limited to 'tests')
-rw-r--r--tests/semantics.bad52
-rw-r--r--tests/variables.bad53
2 files changed, 56 insertions, 49 deletions
diff --git a/tests/semantics.bad b/tests/semantics.bad
index 95e827b..60e47d1 100644
--- a/tests/semantics.bad
+++ b/tests/semantics.bad
@@ -1,27 +1,33 @@
1enum weekdays { 1struct vec {
2 mon = 1 2 x: f64
3 tue 3 y: f64
4 wed 4 z: f64
5 thu
6 fri
7 sat
8 sun
9} 5}
10let a = weekdays.tue 6let v = vec : { x = 1.0 }
11; let b = a 7; enum weekdays {
12 8; mon = 1
13struct item { 9; tue
14 id: int 10; wed
15 name: str 11; thu
16} 12; fri
17 13; sat
18; let a: item = item { 14; sun
19; id = 1 15; }
20; } 16; let a = weekdays.tue
21; let a: item = item ; this shouldn't work, or should it return the default val? 17; ; let b = a
22let c: item 18
23set c.id = 1 19; struct item {
24let d = c.id 20; id: int
21; name: str
22; }
23
24; ; let a: item = item {
25; ; id = 1
26; ; }
27; ; let a: item = item ; this shouldn't work, or should it return the default val?
28; let c: item
29; set c.id = 1
30; let d = c.id
25; set a.name = "hello" 31; set a.name = "hello"
26; let b = a.id 32; let b = a.id
27; let c = a.name 33; let c = a.name
diff --git a/tests/variables.bad b/tests/variables.bad
index 88e04d1..34293dc 100644
--- a/tests/variables.bad
+++ b/tests/variables.bad
@@ -11,10 +11,11 @@ set c = (1 + 2 - 3)
11 11
12; Struct definitions. 12; Struct definitions.
13struct vec { 13struct vec {
14 x: f32 14 x: f64
15 y: f32 15 y: f64
16 z: f32 16 z: f64
17} 17}
18let v = vec : { x = 2.0 y = 3.0 }
18 19
19; Default values are allowed, including const expressions. 20; Default values are allowed, including const expressions.
20struct person { 21struct person {
@@ -28,41 +29,41 @@ set player_a.name = "alex"
28set player_a.age = 32 29set player_a.age = 32
29let player_b = player_a 30let player_b = player_a
30 31
31; Anonymous structs can also be declared inline.
32let user: { id: u64 name: str }
33set user.id = 10
34set user.name = "haxor"
35
36; We can have anonymous struct fields. 32; We can have anonymous struct fields.
37struct entity { 33struct entity {
38 pos: vec 34 pos: vec
39 vel: vec 35 vel: vec
40 attr: { 36 ; TODO: ...
41 id: u64 37 ; attr: {
42 name: str 38 ; id: u64
43 } 39 ; name: str
40 ; }
44} 41}
45 42
46; Symbols followed by curly braces output struct literals. 43; Symbols followed by curly braces output struct literals.
47let particle = entity : { 44let particle = entity : {
48 ; Two ways of initializing inner fields. 45 ; Two ways of initializing inner fields.
49 pos = vec : { x = 1 y = 2 } 46 pos = vec : { x = 1.0 y = 2.0 }
50 attr.id = 1 47 ; TODO: Get rid of this, unnecessary complexity on the implementation, let's
51 attr.name = "particle" 48 ; just do the top option.
49 ; attr.id = 1
50 ; attr.name = "particle"
52 51
53 ; Missing initialization fields default to zero. 52 ; Missing initialization fields default to zero.
54 vel = vec : { y = -3 } 53 vel = vec : { y = -3.0 }
55} 54}
55; let particle = entity : {}
56; TODO: Now we can get rid of parenthesis on if/while statements
56 57
57; We can have static arrays and have indexed access. 58; ; We can have static arrays and have indexed access.
58let numbers: u32[0xff] 59; let numbers: u32[0xff]
59set numbers[0] = 32 60; set numbers[0] = 32
60set numbers[1] = 42 61; set numbers[1] = 42
61 62
62; Arrays are syntactic sugar for pointers (@). 63; ; Arrays are syntactic sugar for pointers (@).
63let ptr:@u32 = numbers 64; let ptr:@u32 = numbers
64set ptr[10] = 33 65; set ptr[10] = 33
65 66
66; Strings hold a .mem and .size fields with the number of bytes it holds. 67; ; Strings hold a .mem and .size fields with the number of bytes it holds.
67let hello: str = "hello world" 68; let hello: str = "hello world"
68set c[1] = 'a' ; "hallo world" 69; set c[1] = 'a' ; "hallo world"