title: Compiler Errors description: Complete reference for Chasm compiler error codes E001–E008 (sema) and E100–E103 (parse) with examples and fixes. keywords: ["chasm", "compiler", "errors", "diagnostics", "E001", "E002", "E003", "E005", "E006", "E007", "E008", "E100", "E101", "E102", "E103"]
Chasm's compiler produces structured diagnostics with a code, a source snippet, a caret pointing at the problem, and a help message. This page describes every error code, what causes it, and how to fix it.
E001, Undefined Variable
You used a name that isn't defined in the current scope.
def on_tick(dt :: float) do
@x = @x + speeed * dt # E001: `speeed` is not defined
enderror[E001]: undefined variable `speeed`
--> game.chasm:2:14
|
2 | @x = @x + speeed * dt
| ^^^^^^
= help: `speeed` is not defined in this scope
Common causes:
- Typo in a variable name (
speeedinstead ofspeed) - Using a variable before declaring it
- Referencing a parameter from the wrong function
- Accessing a module-level name without qualifying it (
Projectile.speedinstead ofspeedin a module that doesn't import it)
Fix: Declare the variable before use, or correct the spelling.
E002, Type Mismatch
The declared type and the inferred type of the value don't match.
speed :: float = 10 # E002: expected float, found interror[E002]: expected `float`, found `int`
--> game.chasm:1:17
|
1 | speed :: float = 10
| ^^
Common causes:
- Assigning an integer literal where a float is expected, use
10.0not10 - Passing the wrong type to a function that has a type annotation
Fix: Match the literal to the declared type. For floats, always include a decimal point: 10.0, 0.5, -3.14.
E003, Wrong Argument Count
You called a function with too many or too few arguments.
defp add(a :: int, b :: int) :: int do
return a + b
end
result = add(1, 2, 3) # E003: expected 2, got 3error[E003]: wrong argument count: expected 2, got 3
--> game.chasm:5:10
|
5 | result = add(1, 2, 3)
| ^^^
= help: function `add` is declared in this file
Fix: Count the parameters in the function definition and match the call site.
E005, Unknown Function
You called a function that isn't defined or imported.
def on_tick(dt :: float) do
draw_sprite(@x, @y) # E005: no function named `draw_sprite` is defined
enderror[E005]: no function named `draw_sprite` is defined
--> game.chasm:2:3
|
2 | draw_sprite(@x, @y)
| ^^^^^^^^^^^
= help: did you mean `draw_texture`?
Common causes:
- Calling an engine-specific function without the right
--engineflag - Typo in the function name
- Calling a function from a module without importing the module
- Calling a
defp(private) function from a different module
Fix:
- Check the spelling of the function name
- Run with
--engine raylibif it's a Raylib function - Add
import MyModuleif it's defined elsewhere - Note: private functions (
defp) are not callable from outside their module
E006, Return Type Mismatch
A function's return value doesn't match its declared return type.
defp clamp(v :: float, lo :: float, hi :: float) :: float do
if v < lo do return lo end
if v > hi do return hi end
return to_int(v) # E006: expected float, found int
enderror[E006]: return type mismatch in `clamp`: expected `float`, found `int`
--> game.chasm:4:10
|
4 | return to_int(v)
| ^^^^^^^^
= help: function `clamp` is declared to return `float`
Fix: Make sure every return path returns a value of the declared type. to_float converts an int to float.
E007, Undefined Struct Field
You accessed a field that doesn't exist on the struct.
defstruct Player do
x :: float = 0.0
y :: float = 0.0
end
p = Player{}
p.z # E007: Player has no field `z`error[E007]: `Player` has no field `z`
--> game.chasm:7:3
|
7 | p.z
| ^
= help: known fields of `Player`: x, y
Common causes:
- Typo in the field name
- Accessing a field you intended to add but forgot
- Using the wrong struct type
Fix: Check the struct definition for the correct field name. The help message lists all available fields.
E008, Lifetime Violation
You assigned a value with a shorter lifetime into an attribute with a longer lifetime.
@position :: persistent = Vec2{} # persistent attr
def on_tick(dt :: float) do
temp :: frame = Vec2{ x: 1.0, y: 2.0 }
@position = temp # E008: cannot store frame value in persistent attr
enderror[E008]: lifetime violation: cannot store a `frame` value in a `persistent` attribute
--> game.chasm:5:3
|
5 | @position = temp
| ^^^^^^^^^
= help: use `persist_copy(temp)` to promote the value to the persistent arena
Lifetime ordering (shortest to longest):
| Lifetime | Resets when |
|---|---|
frame | Every tick |
script | On hot-reload |
persistent | Never |
A frame value only lives for one tick. Storing it in a persistent attribute would leave a dangling pointer after the frame arena resets, E008 prevents this.
Fix: Use a promotion function to copy the value into the longer-lived arena:
| To store in | Use |
|---|---|
script attr | copy_to_script(value) |
persistent attr | persist_copy(value) |
@position :: persistent = Vec2{}
def on_tick(dt :: float) do
temp :: frame = Vec2{ x: 1.0, y: 2.0 }
@position = persist_copy(temp) # OK: copies into persistent arena
endParse Errors (E100–E103)
Parse errors are emitted before semantic analysis. Multiple parse errors can be reported in a single compile run.
E100, Unexpected Top-Level Token
A token that cannot start a definition or statement appeared at the top level.
def foo() do
return 1
end
end # E100: stray `end` at top levelerror[E100]: syntax error
--> game.chasm:4:1
|
4 | end
|
= unexpected token at top level: `end`
Common causes:
- Extra
endwith no matchingdo - Mismatched
if/while/defblocks leaving a danglingend
Fix: Remove the extra end or find the unclosed block it was meant to close.
E101, Missing do
A do keyword was expected after a function signature, if condition, while condition, or defstruct name, but a different token was found.
def on_tick(dt :: float) # missing `do`
@x = @x + 1
enderror[E101]: syntax error
--> game.chasm:1:25
|
1 | def on_tick(dt :: float)
|
= expected `do` after function signature for `on_tick`
Fix: Add do at the end of the function/if/while/defstruct header line.
E102, Missing end
An end keyword was expected to close a function body, if, while, or defstruct, but a different token was found.
def on_tick(dt :: float) do
@x = @x + 1
# missing `end`
def on_draw() do
enderror[E102]: syntax error
--> game.chasm:4:1
|
4 | def on_draw() do
|
= expected `end` to close function `on_tick`
Fix: Add the missing end to close the block.
E103, Unexpected Token in Expression
A token appeared where an expression was expected but could not start one.
x = * 5 # E103: `*` cannot start an expressionerror[E103]: syntax error
--> game.chasm:1:5
|
1 | x = * 5
|
= unexpected token in expression: `*`
Fix: Replace or remove the invalid token. Check for missing operands or typos.
Reading Diagnostics
Every Chasm diagnostic follows the same format:
error[EABC]: short message
--> filename.chasm:line:col
|
N | source line text
| ^^^^
= help: suggestion
- code, the error code (e.g.
E001) - arrow, the file, line, and column where the problem was found
- snippet, the source line
- caret,
^marks pointing at the relevant token - help, a concrete suggestion for fixing the issue
Chasm reports all errors it finds in a single pass rather than stopping at the first one, so you can fix multiple issues at once.