diff options
| author | gingerBill <bill@gingerbill.org> | 2019-12-27 16:55:32 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-12-27 16:55:32 +0000 |
| commit | 5ec8dd166a9baab230c235e9f24684197efb5a86 (patch) | |
| tree | 526a7aed6ce337c5077a48e924b4eaafe7d96b33 /examples | |
| parent | 80a32a8182545b71f184e2889414e01ed27cc9da (diff) | |
Add #partial tag for enumerated arrays to prevent common errors using non-contiguous enumerations
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index a11a0a387..12d2eaf55 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -1845,11 +1845,9 @@ constant_literal_expressions :: proc() { FOO_ARRAY_DEFAULTS :: [3]Foo{{}, {}, {}}; fmt.println(FOO_ARRAY_DEFAULTS[2].x); - - fmt.println("-------"); - Baz :: enum{A=5, B, C, D=9}; + Baz :: enum{A=5, B, C, D}; ENUM_ARRAY_CONST :: [Baz]int{.A .. .C = 1, .D = 16}; fmt.println(ENUM_ARRAY_CONST[.A]); @@ -1859,6 +1857,18 @@ constant_literal_expressions :: proc() { fmt.println("-------"); + Partial_Baz :: enum{A=5, B, C, D=16}; + #assert(len(Partial_Baz) < len(#partial [Partial_Baz]int)); + PARTIAL_ENUM_ARRAY_CONST :: #partial [Partial_Baz]int{.A .. .C = 1, .D = 16}; + + fmt.println(PARTIAL_ENUM_ARRAY_CONST[.A]); + fmt.println(PARTIAL_ENUM_ARRAY_CONST[.B]); + fmt.println(PARTIAL_ENUM_ARRAY_CONST[.C]); + fmt.println(PARTIAL_ENUM_ARRAY_CONST[.D]); + + fmt.println("-------"); + + STRING_CONST :: "Hellope!"; fmt.println(STRING_CONST[0]); |