Reference / Common Errors & Solutions

Common Errors & Solutions

Compile-Time Errors

Implicit Narrowing

let x = 1;          // i64
let y: i32 = x;     // 错误:i64 不能塞进 i32

Fix: literals can be annotated as i32 directly; variables need an explicit conversion or switching to i64.

Number as a Boolean Condition

if (x) { }   // 错误:x 是数字不是 bool

Fix: write if (x != 0).

Nested Function Definitions

fn outer() {
    fn inner() {}   // 错误:不允许嵌套
}

Fix: all functions are top-level definitions.

Repeating a Variable Name

let x = 1;
let x = 2;   // 错误:当前作用域重复声明

Runtime Pitfalls

Vec Out-of-Bounds Access

Native Vec has no bounds checking; get(-1) / set(i, v) (i ≥ len) is undefined behavior and may segfault (0xC0000005).

Fix: check the index range yourself before accessing.

Deep Recursion Stack Overflow

50,000 levels of recursion will overflow the stack (0xC00000FD), losing buffered output.

Fix: recursive functions must have a termination condition to avoid infinite recursion.

Forgetting str_free

Runtime-allocated strings (int_to_str / substr / variable concatenation) leak if not freed.

match Wildcard Branches

When a match branch contains a wildcard _ or a binding pattern and is not in the last position, make sure no further instructions are generated after that branch (to avoid invalid LLVM IR crashes).

Miscellaneous

Aero 文档 · 基于 Aero 1.2.0 文档整理 · MIT
SereinTeam
Compile errors: look at line/column firstformat: line 3 col 5 [stage] message
Generic functions can't be #[export]write concrete types in exported functions
Python binding errors after upgrading Pythonv1 locks the ABI, needs recompilation
Stale debug build cacheafter changing the compiler, delete src/.aero-cache/*.exe and build again