Saltar al contenido
TE100 · Tipos · error

Variable no definida

El nombre no está declarado en ningún ámbito envolvente. El compilador adjunta una sugerencia "¿quisiste decir?" cuando existe un nombre similar.

Why this fires

The name is not declared in any enclosing scope. The most common causes are:

  • A typo in the name (prnt instead of print).
  • A missing use for a module symbol.
  • A name only declared inside a sibling scope that has already ended.
  • The declaration is below the use site in top-level code (Zolo resolves top-level items eagerly, so this is rare — but it can happen with conditional use blocks).
fn main() {
    prnt("hello")
//  ^^^^ error: undefined variable `prnt` — did you mean `print`?
}

Fix it

1. Correct the spelling

The compiler attaches a Levenshtein "did you mean?" suggestion when a similar name exists nearby. Trust it for typos.

2. Import the symbol

If the name comes from another module:

use std::math::{sin, cos}

fn main() {
    print(sin(0.5))
}

3. Move the declaration

If the name was declared in an inner scope that already closed:

if condition {
    let x = compute()
}
print(x)   // x went out of scope at the `}` above

Lift the binding out:

let x = if condition { compute() } else { default_value() }
print(x)

See also

  • TE104 — no such method on a value (different lookup mechanism).
  • TE102 — struct field not found.

Buscar en Zolo

9 resultados

en