Skip to main content

Module infer

Module infer 

Source
Expand description

Gradual type inference (Playbook §3.3–§3.6 + §5): a single forward, bottom-up, bidirectional walk over a lowered Body. No unification variables — types flow forward from annotations, literals, and the engine API (rust-analyzer’s structure, Pyright’s gradual semantics).

The walk memoizes every expression’s Ty in InferenceResult::expr_ty (the source of hover + inlay), does flow-scoped is/as narrowing over the lexical guarded sub-tree, and raises the §5 type diagnostics. The load-bearing invariant: a Variant/Unknown/Error receiver is uninformative — it never fires UNSAFE_*, never cascades — so cross-file code (which lands on Unknown via the seam) produces zero false diagnostics.

Structs§

Binding
A typed local binding — the unit hover + inlay hints read for var/param/for names.
FileInference
The full single-file inference: the item tree, every inferred unit, and the merged §5 diagnostics. The whole-file entry point the IDE layer consumes.
InferenceResult
The result of inferring one body.
Unit
One inferred unit of a file: a function body or a class field’s initializer, with its lowered Body and InferenceResult (kept so position-based features — hover, inlay, member completion — can map a cursor back through the source map).

Enums§

BindingKind
What kind of binding a Binding describes.

Constants§

CYCLIC_INHERITANCE
A genuine extends cycle: a file’s base chain transitively returns to itself (A extends B, B extends A). Illegal in Godot (gdscript_analyzer.cpp raises it). Only the extends inheritance chain cycles — a preload/load cycle is legal at runtime and is NOT reported.
INFERENCE_ON_VARIANT
:= / inferred binding from a statically-Variant value.
INTEGER_DIVISION
int / int.
INVALID_NODE_PATH
A $Path/%Unique/get_node("…") whose literal path is genuinely absent in the owning scene (only raised when the script attaches to exactly one scene — never on an ../absolute path or a path that descends into an instanced sub-scene we don’t see).
NARROWING_CONVERSION
float stored into an int slot.
SHADOWED_GLOBAL_IDENTIFIER
A declared class_name that shadows another global identifier — a duplicate user class_name, an engine/native class, a builtin/utility, a global enum/const, or a *-autoload singleton. Godot’s gdscript_analyzer.cpp raises this (as an error) so the global namespace stays unique.
TYPE_MISMATCH
Incompatible hard types (our umbrella for the engine’s push_error).
UNSAFE_CALL_ARGUMENT
An argument whose static type needs an unsafe implicit cast (Variant / a downcast) into the resolved parameter type — Godot’s per-argument value-prop warning.
UNSAFE_METHOD_ACCESS
A method missing on a statically-known base.
UNSAFE_PROPERTY_ACCESS
A property missing on a statically-known base.

Functions§

analyze_file
Infer an entire file: lower its item tree, then infer every function body and every class-field initializer against a shared ClassScope. The single entry point for the IDE features (Playbook §6 — a pure (api, parsed file) -> result function).
infer
Infer a lowered body (its tail initializer expression and/or its statement block). return_ty is the function’s declared return type (Variant if none / for an initializer body).
infer_func
Convenience: recover a function node from its AstPtr, lower its body, resolve its declared return type, and infer it.