Complete reference for all Axon compiler error codes. Each error includes its code, description, example code that triggers it, and how to fix it.
| Range | Category | Description |
|---|---|---|
| E0001–E0099 | Lexer / Parser | Syntax errors |
| E1001–E1099 | Name Resolution | Undefined or duplicate names |
| E2001–E2099 | Type Errors | Type mismatches and inference failures |
| E3001–E3099 | Shape Errors | Tensor shape mismatches |
| E4001–E4099 | Borrow Errors | Ownership and lifetime violations |
| W5001–W5010 | Lint Warnings | Style and best-practice warnings |
val x = 42$;
// ^ ERROR[E0001]: unexpected character `$`
Fix: Remove or replace the invalid character.
val s = "hello;
// ^ ERROR[E0002]: unterminated string literal
Fix: Close the string with a matching ".
/* this comment never ends
//^ ERROR[E0003]: unterminated block comment
Fix: Close with */. Nested comments require matching pairs.
fn foo( {
// ^ ERROR[E0010]: expected `)`, found `{`
Fix: Add the missing token.
val x = ;
// ^ ERROR[E0011]: expected expression, found `;`
Fix: Provide a value or expression.
val x: = 42;
// ^ ERROR[E0012]: expected type, found `=`
Fix: Provide a type annotation after :.
val x = 0xGG;
// ^ ERROR[E0020]: invalid hexadecimal literal
Fix: Use valid digits for the number base (0-9, a-f for hex).
val x = 1.2.3;
// ^ ERROR[E0021]: invalid float literal
val s = "\q";
// ^ ERROR[E0030]: unknown escape sequence `\q`
Fix: Use valid escapes: \\, \n, \t, \r, \", \0.
match x {
1 => println("one"),
1 => println("one again"), // ERROR[E0040]: duplicate match arm
}
match value {
1 + 2 => println("?"), // ERROR[E0050]: expected pattern, found expression
}
fn main() {
println("{}", unknown_var);
// ^ ERROR[E1001]: undefined variable `unknown_var`
}
Fix: Declare the variable before use or check for typos.
fn main() {
foo();
// ^ ERROR[E1002]: undefined function `foo`
}
val x: NonExistent = 42;
// ^ ERROR[E1003]: undefined type `NonExistent`
fn foo() {}
fn foo() {}
// ^ ERROR[E1010]: duplicate definition of `foo`
model Point { x: Int32, x: Int32 }
// ^ ERROR[E1011]: duplicate field `x`
use std.nonexistent.Module;
// ^ ERROR[E1020]: unresolved import `std.nonexistent`
mod inner {
fn secret() {}
}
inner.secret();
// ^ ERROR[E1030]: function `secret` is private
Fix: Add pub to the item or access it from within its module.
val x: Int32 = "hello";
// ERROR[E2001]: type mismatch — expected `Int32`, found `String`
val x = "hello" + 42;
// ERROR[E2002]: cannot apply `+` to `String` and `Int32`
fn foo(): Int32 {
"not an integer"
// ERROR[E2003]: return type mismatch — expected `Int32`, found `String`
}
model Point { x: Int32, y: Int32 }
val p = Point { x: 1 };
// ERROR[E2010]: missing field `y` in struct `Point`
model Point { x: Int32, y: Int32 }
val p = Point { x: 1, y: 2, z: 3 };
// ^ ERROR[E2011]: unknown field `z` on `Point`
fn print_it<T: Display>(x: T) {}
print_it(SomeStruct {});
// ERROR[E2020]: trait `Display` not implemented for `SomeStruct`
Fix: Implement the required trait for the type.
// When multiple trait impls provide the same method
value.shared_method();
// ERROR[E2021]: ambiguous method call — candidates from `TraitA` and `TraitB`
Fix: Use fully qualified syntax: TraitA.shared_method(&value).
val x = Vec.new();
// ERROR[E2030]: cannot infer type — add a type annotation
Fix: val x: Vec<Int32> = Vec.new();
val x = "hello" as Int32;
// ERROR[E2040]: cannot cast `String` to `Int32`
val a: Tensor<Float32, [3, 4]> = randn([3, 4]);
val b: Tensor<Float32, [5, 6]> = randn([5, 6]);
val c = a @ b;
// ERROR[E3001]: matmul shape mismatch — inner dimensions 4 ≠ 5
// note: left shape [3, 4], right shape [5, 6]
Fix: Ensure the inner dimensions match: [M, K] @ [K, N].
val t: Tensor<Float32, [2, 3]> = randn([2, 3]);
val r = t.reshape([2, 2]);
// ERROR[E3002]: cannot reshape [2, 3] (6 elements) to [2, 2] (4 elements)
Fix: Ensure the total number of elements is preserved.
val a: Tensor<Float32, [3, 4]> = randn([3, 4]);
val b: Tensor<Float32, [3, 5]> = randn([3, 5]);
val c = a + b;
// ERROR[E3003]: shapes [3, 4] and [3, 5] are not broadcast-compatible
val t: Tensor<Float32, [2, 3, 4]> = randn([2, 3, 4]);
val p = t.permute([0, 1, 5]);
// ERROR[E3010]: axis 5 out of range for tensor with 3 dimensions
// When static shape info is unavailable
// ERROR[E3020]: cannot verify shape statically — consider using `?` for dynamic dims
// note: runtime shape check will be inserted
val data = randn([100]);
val other = data;
println("{}", data);
// ERROR[E4001]: use of moved value `data`
// note: `data` was moved on line 2
Fix: Clone the value or restructure to avoid the move.
val s = "hello".to_string();
val t = s;
val r = &s;
// ERROR[E4002]: cannot borrow `s` — value has been moved
var v = vec![1, 2, 3];
val r1 = &v;
val r2 = &mut v;
// ERROR[E4003]: cannot borrow `v` as mutable — also borrowed as immutable
// note: immutable borrow of `v` occurs on line 2
Fix: Ensure immutable borrows end before taking a mutable borrow.
var data = randn([10]);
val a = &mut data;
val b = &mut data;
// ERROR[E4004]: cannot borrow `data` as mutable more than once
fn dangling(): &String {
val s = "hello".to_string();
&s
// ERROR[E4005]: `s` does not live long enough
// note: borrowed value only lives until end of function
}
Fix: Return an owned value instead of a reference.
val data = randn([10]);
scale(&mut data, 2.0);
// ERROR[E4006]: cannot borrow `data` as mutable — declared as immutable
// help: consider changing to `var data`
var t = randn([256]);
val cpu_ref = &t;
val gpu_t = t.to_gpu();
// ERROR[E4007]: cannot move `t` to GPU while borrowed on CPU
val x = 42;
// WARNING[W5001]: unused variable `x`
// help: prefix with underscore: `_x`
use std.math.sin;
// WARNING[W5002]: unused import `sin`
fn unused_function() {}
// WARNING[W5003]: function `unused_function` is never called
var x = 42;
println("{}", x);
// WARNING[W5004]: variable `x` declared as mutable but never mutated
val x = 1;
val x = 2;
// WARNING[W5005]: variable `x` shadows previous declaration
fn MyFunction() {}
// WARNING[W5006]: function `MyFunction` should use snake_case
// help: rename to `my_function`
val x: Int32 = 42;
// WARNING[W5007]: type annotation is redundant — inferred as `Int32`
pub fn public_api() {}
// WARNING[W5008]: public item `public_api` is missing documentation
error[E2001]: type mismatch — expected `Int32`, found `String`
--> src/main.axon:5:15
help: consider using `parse()` to convert the string
{
"error_code": "E2001",
"message": "type mismatch — expected `Int32`, found `String`",
"severity": "error",
"location": { "file": "src/main.axon", "line": 5, "column": 15 },
"suggestion": "consider using `parse()` to convert the string"
}- CLI Reference — compiler flags including
--error-format - Language Tour — learn correct syntax
- Ownership & Borrowing — understand E4xxx errors