Diagnostics and semantic errors

Learning objective

  • Interpret diagnostics quickly and choose the right fix path.

Key syntax

Line 2, column 12: Incompatible return type: expected int but got string

Examples

  • Common diagnostics:
  • undeclared variable
  • unknown function or class
  • wrong argument count
  • incompatible assignment or return type
  • return outside function
  • cyclic import or missing symbol

Frequent diagnostics and quick fixes

  • Undeclared variable: 'x'

- Cause: variable not declared in current scope. - Fix: declare with let/const or reference the correct symbol.

  • Unknown function or class: 'Foo'

- Cause: missing import, typo, or wrong symbol name. - Fix: add import and verify exact identifier.

  • Incorrect number of arguments for 'fn': A != B

- Cause: call does not match function/method signature. - Fix: update call arguments or signature.

  • Cannot initialize 'x' of type list<T> with list<any>

- Cause: incompatible inferred list type. - Fix: use a typed declaration (let x: list<T> = []) or compatible values.

  • Cannot call member 'length' on type list<...>

- Cause: length() is not a Lucia list method. - Fix: use len(listValue).

  • Unexpected Token '=' near indexed write

- Cause in older compiler versions: indexed assignment target not enabled. - Current behavior: obj[i] = value; is supported.

Common mistakes

  • Applying quick fix without understanding root cause.
  • Ignoring file/module boundaries when errors come from imports.

Debug workflow

  • Read the first error first. Later diagnostics are often cascade effects.
  • Verify imports and symbol names before touching complex logic.
  • Reduce to a minimal reproducible snippet.
  • Re-run after each fix to confirm the true root cause is solved.

Suggested practice

  • Trigger 3 diagnostics intentionally and fix each with explanation.
  • declarations-let-const
  • functions-and-builtins
  • oop-and-modules