Common Errors
This page lists common errors you may encounter when writing Luma programs and how to fix them.
Compilation errors
“declared and not used”
app.luma:5:2: declared and not used: xCause: You declared a variable but never used it. Luma (via Go) does not allow unused variables.
Fix: Either use the variable or remove the declaration.
“undefined: name”
app.luma:3:5: undefined: usernameCause: You’re referencing a variable or function that hasn’t been declared.
Fix: Check for typos in the name, or make sure the variable is declared before it’s used.
“unknown field in struct literal”
unknown field "email" in struct literal Person; valid fields are: name, ageCause: You’re trying to set a field that doesn’t exist on the struct.
Fix: Check the struct definition for the correct field names.
“duplicate field in struct literal”
duplicate field "name" in struct literal PersonCause: You’re setting the same field twice in a struct constructor.
Fix: Remove the duplicate field assignment.
Import errors
“no exported symbols found”
import "helpers": no exported symbols found. Make sure declarations are marked `pub`Cause: The imported file exists but has no pub fn or pub declarations.
Fix: Mark the functions you want to export with pub:
// helpers.luma
pub fn greet(name: str) -> str {
return "Hello, ${name}"
}“module has no namespace-exposable exports”
Cause: The imported module was found but contains no public functions or variables that can be accessed through a namespace.
Fix: Add pub to the functions and variables you want to export.
Impl errors
“impl method must have ‘self’ as first param”
Cause: Methods inside an impl block must take self as their first parameter.
Fix:
impl Person {
fn greet(self) -> str {
return "Hi, I'm ${self.name}"
}
}Walk errors
“walk requires one or two loop variables”
Cause: You passed zero or more than two parameters to .walk().
Fix: Use one parameter (value only) or two parameters (index and value):
// One parameter
items.walk(item) -> print(item)
// Two parameters
items.walk(i, item) -> print("${i}: ${item}")“set walk requires exactly one loop variable”
Cause: Sets don’t have indices, so .walk() on a set only accepts one parameter.
Fix:
names: {str} = {"Alice", "Bob"}
names.walk(name) -> print(name)“file.walk() requires exactly one parameter”
Cause: File walk iterates over lines and only accepts one parameter (the line variable).
Fix:
file("data.txt").walk(line) -> {
print(line)
}Type errors
“cannot use X as type Y”
Cause: You’re assigning a value of the wrong type to a variable.
Fix: Make sure the types match. Use type conversion if needed:
s: str = "42"
n: int = s.to_int(0) // convert string to int with defaultMixing int and float
If you get unexpected results from arithmetic, remember that int / int produces an int (truncated). Use float when you need decimal results:
result: float = 7 / 2 // 3.5 (coerced because result is float)Runtime errors
Nil pointer dereference
Cause: You used an optional value that was nil without checking first.
Fix: Always check optionals before using them:
x: ?int = "abc".to_int()
if x != nil {
print(x)
}Or use a default value:
x: int = "abc".to_int(0) // defaults to 0File not found
Cause: You tried to read a file that doesn’t exist with a non-optional return type.
Fix: Either check existence first or use an optional return:
// Check first
if file("data.txt").exists() {
content: str = file("data.txt").read()
}
// Or use optional
content: ?str = file("data.txt").read()