crosslang/golang-lean/GolangLean/Error.lean
Maximus Gorog fd3d42ae33 Add 'golang-lean/' from commit 'f5f17019224c6a6c319387214ceb8e29d09251c6'
git-subtree-dir: golang-lean
git-subtree-mainline: 6487c7046f
git-subtree-split: f5f1701922
2026-05-12 02:59:14 -06:00

27 lines
1.2 KiB
Text

namespace GolangLean
/-- Runtime / static errors produced anywhere in the Go toolchain. -/
inductive GoError where
| scan (msg : String) (line col : Nat) -- lexical
| parse (msg : String) (line col : Nat) -- syntactic
| typeErr (msg : String) -- static type-check
| runtime (msg : String) -- panic / runtime
| nilDeref -- nil-pointer dereference
| indexOOB (i n : Int) -- index out of range
| divByZero
| notImpl (what : String) -- placeholder for stubs
deriving Repr, Inhabited
def GoError.toString : GoError → String
| .scan m l c => s!"scan error: {m} ({l}:{c})"
| .parse m l c => s!"parse error: {m} ({l}:{c})"
| .typeErr m => s!"type error: {m}"
| .runtime m => s!"runtime error: {m}"
| .nilDeref => "runtime error: nil pointer dereference"
| .indexOOB i n => s!"runtime error: index out of range [{i}] with length {n}"
| .divByZero => "runtime error: integer divide by zero"
| .notImpl what => s!"not implemented: {what}"
instance : ToString GoError := ⟨GoError.toString⟩
end GolangLean