Egg diagnostics (v2)
Every diagnostic has a stable code. Tools and AI agents should match on the
code, not the message text. eggc check FILE --json prints one JSON object
per line. file is the file the error is in, which may be one the
program imports:
{"file":"a.egg","line":4,"col":11,"code":"E110","message":"local variable 'unused' is never used"}
| Code | Stage | Meaning | Typical fix |
|---|---|---|---|
| E001 | lexer | unexpected character; 0x or 0b without hex or binary digits after it (0xfg, 0b102); a malformed character literal ('', 'ab', 'é' of several bytes, '\u{e9}', an unknown escape, no closing '); in a string, an unknown escape, \x without two hex digits, or \u{N} that is malformed, a surrogate or above 10ffff |
remove it; a character literal holds one byte ('a', '\n', '\xff'): use a string for more; in a string, correct the escape: two hex digits for a byte (\xff), a code point in braces (\u{e9}) |
| E002 | parser | syntax error (also: chained comparison a < b < c; &, \| and ^ mixed without parentheses, a \| b & c; && or \|\| for and or or; an if with a value without else, or with a block as a branch) |
follow spec/grammar.ebnf |
| E003 | parser, checker | integer literal does not fit its type (or is above u64’s maximum), or a float literal is infinite in its type (1e400, 1e39 as f32) or rounds to zero though it is not zero (1e-400); a literal shift amount below 0 or not below the shifted type’s width (x << 8 for a u8 x) |
use a smaller literal or a wider type; for one that rounds to zero, a larger literal, 0.0, or f64 instead of f32 |
| E101 | checker | undefined variable | declare it with const or var |
| E102 | checker | undefined function, or calling a variable | define the function |
| E103 | checker | type mismatch (also: the branches of an if with a value having different types, or no value such as void; comparing structs, arrays or unions; an array where a slice is expected; an inout slice parameter given &x instead of &x[lo..hi]; two integer types in one operation; negating an unsigned value; a generic function used as a value; a function whose parameter modes differ from the function type expected) |
make both sides the same type with @as; no implicit conversions; give both branches of an if one type (two slices, or a slice and text, can be one) |
| E104 | checker | wrong number of arguments | match the function’s parameter list |
| E105 | checker | assigning to, or passing as inout, a const, a by-value parameter, or an element of a read-only slice or str; reassigning an inout slice parameter itself; lending a mutable slice (&x[lo..hi]) of a const, a plain parameter, a read-only slice or a str |
declare it with var, or make the parameter inout (inout xs: []T for a slice, passed as &x[lo..hi]); str elements are always read-only, so copy them into a var array |
| E106 | checker | duplicate definition (function, type, import, field, member, method) or shadowing; a type named like a built-in one (Buf, i64, …) |
rename one of them |
| E107 | checker | non-void function can reach its end without returning | add a return on every path |
| E108 | checker | unknown type, void or type where a value type is needed, [_]T outside a literal; ?T of a !U |
use a value type; write !?T for a result that may be null |
| E109 | checker | missing or invalid main (returns something else, or takes a parameter that is not a capability value, or one twice) |
fn main(io: Io) void, fn main() i64 or fn main(io: Io, a: Allocator) !void |
| E110 | checker | local variable is never used | remove it |
| E111 | checker | var is never changed (assigned, or passed as inout), or an inout r = &p borrow never changes what it borrows |
declare it with const |
| E112 | checker | unknown builtin (also: @print, removed in v2) |
see core.md section 15; print with io.print(x) |
| E113 | checker | a non-void value or an error is ignored (also: a defer whose expression is not void; _ = with a void value, an error union, or an owned value, which would never be freed) |
use the value, or drop a non-void, non-error value with _ = e; handle an error with try or catch; a void call stands on its own; end an owned value with a.free or its own sink method |
| E114 | — | reserved for the workflow profile | |
| E115 | checker | a type cannot be inferred (.member with no known type, @splat without an array type, const e = error.X, null without a pointer type) |
write the type: Color.red, var a: [4]i64 = ..., !i64 |
| E116 | checker | a borrow (const r = &s) of a slice or str, which already views its data; a slice ([]T, ?[]T, ![]T) used outside a parameter, an argument, a for, a function’s result or a local const or inout of a part of a variable or of a call that lends one (a var slice, a view of a temporary or through a pointer, a field, an element), or returned by an extern fn |
pass a[lo..hi] directly, or name it with const s = x[lo..hi] or inout s = &x[lo..hi]; slices exist only as parameters, local slices and results |
| E117 | checker | a place passed as inout, or an owned value moved into a call (a sink parameter), also appears in another argument of the same call; a bound of a slice x[lo..hi] changes x (b[i][0..grow(a, &b)]); an operand of a call, of io.print or of a text comparison borrows (slices, or borrows a buffer) what another operand changes through an inout argument or inout self of a nested call (f(b[0..], grow(a, &b))), or moves into a sink parameter or sink self of one (f(b, eat(a, b))) (places are compared by field: &v.data and v.len do not clash); an argument that takes a slice of a method’s inout self or moves an owned value out of it; the value of @replace mentions the place’s variable (any part of it: @replace(&v.data, v.len) too) |
copy the values you need into locals first (const n = @len(b)); a slice cannot be stored, so copy its elements or pass the indices instead |
| E118 | checker | try outside a function returning !T, or try/catch on a value that is not !T, orelse on one that is not ?T, or a value fallback for !void; a block after orelse, or after a catch on a !T other than !void, that does not leave on every path (it has no value to give); try, or a catch/orelse that leaves (return/break/continue, or a block that may), inside defer; errdefer in a function that does not return !T |
return !T, or handle the error with catch; end the block with return, break or continue, or give a value by calling a function (catch |e| f(e)); use defer |
| E119 | checker | a struct contains itself by value; a type alias defined in terms of itself | hold an index into an array instead; give the alias a type to end at |
| E120 | checker | struct { ... } outside a type function, or a type function whose body is not return struct { ... } |
declare the type with const Name = struct { ... } |
| E121 | checker | & outside an inout argument or a local borrow (in a file without allow unsafe, where it would take an address), a borrow that is a var or of something that is not a variable’s place (const r = &make()), or an inout argument without & |
write f(&x) exactly where the parameter is inout (f(&x[lo..hi]) for an inout xs: []T); borrow with const r = &x.f or inout r = &x.f |
| E122 | checker | no such field, method or member (also: reading a union’s member without switch) |
check the name; use switch for unions |
| E123 | checker | a struct or union literal with a missing, unknown or repeated field | name every field once; a union literal names one member |
| E124 | checker | an array literal with the wrong number of elements, or a zero-length array | match the length in [N]T |
| E125 | checker | a comptime argument that is not a type, or a type stored in a variable | pass a type such as i64 |
| E126 | checker | break or continue outside a loop |
move it into a loop |
| E127 | checker | a switch that is not over an enum, a union or an anyerror, misses members, repeats one, has an unreachable or misplaced else, or captures a payload that is not there; a switch on an error without an else, or with .name arms (an error arm is error.Name) |
handle each member once, or end with else |
| E128 | checker | a uses line names an unknown capability, or one twice |
the capabilities are alloc, args, fs, io, net and thread (the clock and random bytes are std/time and std/rand, not capabilities) |
| E129 | loader, checker | an import that is not a top-level const m = @import("file.egg") or a module-name import such as @import("std/name") or a package name, a file that cannot be found, a path that is not valid UTF-8 (a \xNN byte), a file import that leaves its module’s root (the root file’s directory, the library’s for std, a package’s own), an unknown module name (neither std nor a package given with --pkg), or a module used as a value |
import an existing .egg file under the module’s root, relative to the importing one, or a module by name ("std/math", a package’s "http"), giving packages with --pkg NAME=DIR (clutch add NAME); name something in it: m.f(...) |
| E130 | capabilities | a function uses a capability (directly, or through a call) that its file does not declare | add uses io / uses args / uses fs / uses net / uses thread / uses alloc to that file, or move the code to a file that declares it |
| E131 | checker | a pointer operation (p.*, @ptrAdd, @ptrCast, @intFromPtr, @ptrFromInt, @strPtr, @bufPtr, @sliceFromPtr), an extern fn, a link or a.str_from_c in a file without allow unsafe; or allow with anything but unsafe. (&x outside an inout argument in such a file stays E121.) |
add allow unsafe at the top of the file, or keep the unsafe operation in a module that has it |
| E132 | checker | an invalid extern fn: a name that is a C keyword, main, declared by the C headers the generated code includes (functions, macros, types), reserved in C (_X, __x), or starts with a generated prefix; a parameter that is not an integer, float, bool, pointer to a C type, function type or extern struct, or is a function type with inout or sink parameters or with parameters or a result that are none of those, or a result that is none of those and not void; an inout parameter; or two declarations of one C function with different types |
rename it, pass pointers instead of str or slices, declare the structs C sees as extern struct |
| E133 | checker | an owned value (a Buf(T), an owned struct, or a struct, union or array holding one) as a pointer’s target; a !T or ?T of one as a field, element, local or parameter, compared with null, or wrapped in another optional (??Buf(u8)); borrowing from a temporary one or from an if with a value (@len(make(a)), make_list(a).len, or passing it to a plain parameter, count(make(a))), or switching on a temporary one; or @forget of a temporary |
unwrap !T with try/catch and ?T with orelse or if (x) \|v\| { ... }; store a temporary in a variable; borrow each variable in its own branch of an if statement |
| E134 | ownership | paths that join disagree on whether a buffer (or a buffer field, v.data) was moved (after if, an if with a value, switch, select, catch, and/or), or a loop iteration (or a break/continue, or a loop condition) changes whether one from outside the loop is owned |
move or free it on every path, or on none; free and reassign it within the same iteration |
| E135 | ownership | a buffer, a buffer field of a struct, or an owned struct not yet ended, still owned where its owner goes away (end of its block, return, break/continue, a try that returns an error), a variable or field that owns one assigned another, or an inout parameter that does not own all its buffers (and, for an owned struct, the struct itself) when the function returns, a Thread not joined or detached, or a channel end not closed; or one moved into a struct or array literal or a sink argument before a later try in the same literal or call (or a catch/orelse there that leaves) |
for a literal or call: compute the parts that may fail into locals first (with errdefer for the owned ones); a.free(v) / a.free(v.data), return it or pass it on; defer a.free(v) / errdefer a.free(v) right after making it; for an owned struct, its ending method (defer db.close()); t.join() or t.detach() for a Thread, close() for a channel end, receiving all a Receiver holds first |
| E136 | ownership | a variable used after its buffer or owned struct was moved (passed, assigned, returned, freed or forgotten), also by a defer that runs after the move; a struct used whole while one of its buffer fields is moved; a field read or assigned after the whole struct was moved |
use it before moving it, or give it a new buffer first (v.data = ..., or v = ... after moving all of v) |
| E137 | ownership | a buffer moved, reassigned, or passed as inout to a function that may move, reassign or resize it (directly or through the functions it calls; an Allocator method, such as a.push(&b, x), always counts as one that does) inside a for loop over it (or over a field of it, or over a struct holding it); an element swapped (@replace, @take, &xs[i]) inside a for loop over xs when its elements own buffers |
if the elements own no buffers, change only them (b[i] = v); otherwise collect changes and apply them after the loop, or loop over an index with while |
| E138 | checker | a link whose library name is not letters, digits and _ . + - (or not valid UTF-8, from a \xNN byte), or starts with ., + or - |
write the name the C compiler takes after -l: link "m" for -lm |
| E139 | ownership | moving an owned value out of an element of an array or buffer (xs[i], xs[i].data), assigning over one, or moving a for loop variable that borrows an owned element, or moving or @forgetting a local borrow (const r = &p or inout r = &p) or a part of it, or a switch capture that borrows the payload of a union that cannot be moved here (a plain parameter, an element), or moving an owned value out of a Shared(T) with s.get(); s.get(i) or s.set(i, v) on a MultiArrayList(T) whose T owns memory |
s.copy(a) for a value of one’s own; for a MultiArrayList: borrow a field with s.items(.f)[i], swap one in a writable column with @replace, or put a whole element in with s.replace(i, v), which returns the old one; for a capture: declare the parameter sink, or take the element out with @replace(&xs[i], v) and switch on that; a.free(@replace(&xs[i], v)) to put a new value in, @take(&xs[i]) to take a buffer out (leaving .empty) |
| E140 | checker | the fill value of a.alloc, a.resize or @splat owns buffers or is (or holds) an owned struct, so it would be copied into every element |
fill with Buf(T).empty (or a literal made of .empty buffers) and put values in with @replace; for owned structs use a Buf: start from .empty and a.push each one, or write an array literal, which moves each element in ([_]Db{ d1, d2 }) |
| E141 | checker | an owned struct without a deinit (but a Shared(T) or an Atomic, which a.free closes), or a value holding one, freed with a.free or used as an element of an array or a Buf |
give it a deinit; or end it with its own API (such as close) and keep it in a local or a struct field |
| E142 | checker | building an owned struct (Db{ ... }) or ending one with @forget outside the file that declares it |
get one from, and end it with, the functions of its file |
| E143 | checker | an owned struct’s deinit that is not fn deinit(sink self: T) void or fn deinit(sink self: T, a: Allocator) void |
a.free can pass it only the value and an Allocator; end it some other way in a method of another name |
| E144 | ownership | moving, freeing, returning, assigning or @forgetting a plain parameter of an owned type, or any part of it: it is only borrowed |
declare it sink x: T to take it over, or copy out the plain values you need |
| E145 | checker | a sink parameter whose type owns nothing (not a buffer, an owned struct or a value holding one; in a generic instance it is allowed) |
remove sink: a plain parameter reads it |
| E146 | checker | a @compileError("...") that is checked: anywhere outside a comptime if branch that is not chosen (typically a generic function instantiated with a type it does not support), or one whose argument is not a single string literal |
call the function with a type it supports, as the message says; put @compileError only in a branch that should never be chosen, and give it one string literal |
| E148 | checker | a function given to threads.spawn that would borrow (an inout, slice or plain owned parameter) or returns a value |
take owned values by sink, and report results another way |
| E149 | ownership | moving, assigning, resizing, passing as inout or writing an element of a variable, or lending it as a writable slice or borrow, while a local slice or borrow of it is used later; reading it in any way while a writable local slice or borrow of it is used later |
use the slice or borrow first, or copy what it views |
| E150 | checker | a top-level value constant (const NAME = value, not a type, alias or import) whose value is not known when compiling (a call, a variable, float or text arithmetic), divides or takes a remainder by zero, shifts by less than 0 or more than 63, or overflows i64 (or takes a u64 or usize literal above i64 as an operand of a binary operator or of ~) in its integer arithmetic, or uses wrapping arithmetic (+% -% *%); or has a type other than a number, bool, str or an enum, or is defined in terms of itself |
use a literal, another constant, or integer arithmetic on those; compute anything else in a function |
| E151 | checker | a function returns a slice its signature does not lend: of a parameter not named after from (without from, one the default rule does not pick), or of memory that ends with the call (a local, a sink or inout parameter, an array inside a parameter or loop variable, a temporary) |
return a view of what a plain parameter points to; with from, name every parameter the result views there (from replaces the default rule) |
| E152 | checker | from on a function whose result is not a slice, or naming something that is not a plain parameter able to hold the result’s elements (not a parameter, an inout, sink or comptime one, or one of a type such as i64) |
name the plain parameters the result views, or remove from |
| E153 | checker | a select arm that is not a Receiver(T) or a tx.send(v); a receiving arm without \|v\| whose values are owned; an owned value sent from something other than a variable or a field; try (or orelse/catch that leaves) in an arm’s head; more than one timeout or closed arm; no arm that receives or sends; only receiving arms but no closed arm, or a closed arm beside a sending one, where it could never run |
receive from a Receiver or send with tx.send(v) on a Sender; give each owned value a name, send owned values from a variable, compute what may fail before the select; keep one timeout and one closed arm; add closed => { ... } to a select that only receives, and remove it beside a sending arm |
| E154 | checker | a field of an extern struct that is not a C type: an integer, float, bool, pointer to a C type, function type whose parameters and result are C types, array of a C type, or extern struct (not str, a slice, Buf, ?T, !T, an enum, a union or a plain struct) |
hold C types only: declare a nested struct as extern struct too, and pass text as a *u8 |
| E155 | checker | a Shared(T), or a ConcurrentMap(K, V)’s V, that is or holds an owned struct, a channel’s end, a file or socket, or a pointer |
share the plain data instead (buffers, structs and unions of them) |
| E157 | checker | a map key (std/map’s HashMap(K, V), ConcurrentMap(K, V), @hash) of a type that cannot be hashed: a float (NaN is not equal to itself), a pointer, a handle or an open file, an optional or error union, a str inside another key, or a struct, array or union holding one; and, for now, a ConcurrentMap key other than text or an integer |
key by @floatBits(x), by an id or a name; make text inside a key a Buf(u8) |
| E156 | checker | a MultiArrayList(T) whose T is not a struct (an integer, a union, an owned struct, …) or has no fields |
use a struct with at least one field; its fields may own memory |
Runtime panics (the program aborts with egg panic: <message>):
| Message | Cause |
|---|---|
| integer overflow | + - *, unary -, or / whose result does not fit its integer type |
| division by zero | / or % with a zero divisor |
| index out of bounds | a[i] with i < 0 or i >= @len(a) |
| slice out of bounds | a[lo..hi] unless 0 <= lo <= hi <= @len(a) |
| shift out of range | x << n or x >> n with n < 0 or n not below the bit width of x’s type |
| integer cast out of range | @as(T, x) where x does not fit T |
| float cast out of range | @as(T, x) from a float to an integer type T, where x truncated does not fit T, or x is nan or infinite |
| null pointer dereference | p.* where p is null |
| negative buffer length | a.alloc(n, v) or a.resize(&b, n, v) with n < 0 |
| out of memory | an Allocator could not get memory from the system, a concatenated string’s length does not fit in i64, or a buffer’s size in bytes does not fit in usize |
A main returning !void that returns an error prints error: Name to standard error and exits with status 1.