mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 08:54:25 +00:00
enums and match (in the compiler written in Finch)
enum Color { Red, Green, Blue } enum Status { Ok = 200, NotFound = 404 }
Color.Red, Color(n) (checked), int(c), == and != only, printed by name, usable as
map keys and struct fields, with methods (fn Color.next()).
match value { Red, Green -> ... Blue -> ... else -> ... } as a statement, or as an
expression that gives a value. Works on enums, whole numbers, chars, text and bools;
a match on an enum has to handle every variant or end with else, and says which are
missing. A bare variant name (Red) is enough inside a match on an enum.
Only the self-hosted compiler has them; tests/new holds their tests, tests/run stays what
the C++ compiler also runs. boot.sh: 31 passed.
This commit is contained in:
parent
a5ba4bc8f0
commit
609ceffe58
15 changed files with 576 additions and 18 deletions
14
tests/new/enums.out
Normal file
14
tests/new/enums.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Green Blue 2 418
|
||||
true false
|
||||
red blue false true
|
||||
fine odd
|
||||
Pixel(color: Blue, x: 3)
|
||||
[Red, Blue] 2
|
||||
a red one
|
||||
something else
|
||||
NotFound Ok
|
||||
medium
|
||||
2
|
||||
two!
|
||||
5 {Red: 2, Blue: 5}
|
||||
Green!
|
||||
Loading…
Reference in a new issue