Published
Exhaustive enum matches in Jik v0.1.0-alpha.21
Jik v0.1.0-alpha.21 is now available. Its main addition is match support for enums. Enum matches are exhaustive, so every member must be handled exactly once.
Match every enum member
match previously worked only with variants. It can now be used with enums as well. Every possible enum value must be covered. If a case is missing, or a member is handled more than once, the compiler reports an error. This makes changes to an enum safer: adding a member points directly to every match that needs updating.
enum State:
STARTING
RUNNING
STOPPED
end
func label(state: State) -> String:
match state:
case State.STARTING:
return "starting"
case State.RUNNING:
return "running"
case State.STOPPED:
return "stopped"
end
end
Like variant matches, enum cases are qualified with their enum type, such as State.RUNNING.
Other improvements
- Error propagation now works correctly for calls used in assignments.
argparseparsers can now include a description.- Vector literals accept a missing newline correctly, and binary-operation type errors are clearer.
- The standard library has more robust exception handling, including fixes to
io.read_fileandio.write_file.
Release: Jik v0.1.0-alpha.21 Docs: Enumerations