Files
rexlang/examples/basics/errors.dino
T
Your NameandClaude Sonnet 5.5 eaf9567a36 Dino compiler: language, formatter, language server, docs, editor support
Compiler in Rust (lexer, parser, checker, C codegen), maps, chars,
dino fmt, dino lsp (diagnostics, formatting, outline, definition,
hover, completion, signature help), docs, examples, VS Code/Vim files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 23:46:12 +01:00

49 lines
902 B
Plaintext

func parse_digit(c: string): (int, error) {
if c == "0" { return 0, nil }
if c == "1" { return 1, nil }
if c == "2" { return 2, nil }
return error("not a digit: {c}")
}
func add_digits(a: string, b: string): (int, error) {
var x = parse_digit(a)?
var y = parse_digit(b)?
return x + y, nil
}
func check(n: int): error {
if n < 0 {
return error("negative: {n}")
}
return nil
}
func run(): error {
check(5)?
print("5 is fine")
check(-3)?
print("never printed")
return nil
}
func main(): error {
var sum, err = add_digits("1", "2")
if err != nil {
print("unexpected:", err)
} else {
print("sum =", sum)
}
var _, bad = add_digits("1", "x")
if bad != nil {
print("failed:", bad)
}
var ok: error = nil
print("ok is", ok)
run()?
print("not reached")
return nil
}