pub struct ExpressionChecker<'a, 'ctx> { /* private fields */ }Expand description
Expression type checker that operates on the shared context.
This is a stateless checker that borrows the context mutably. All type inference for expressions goes through this checker.
Implementations§
Source§impl<'a, 'ctx> ExpressionChecker<'a, 'ctx>
impl<'a, 'ctx> ExpressionChecker<'a, 'ctx>
Sourcepub const fn new(ctx: &'a mut CheckerContext<'ctx>) -> Self
pub const fn new(ctx: &'a mut CheckerContext<'ctx>) -> Self
Create a new expression checker with a mutable context reference.
Sourcepub fn check(&mut self, idx: NodeIndex) -> TypeId
pub fn check(&mut self, idx: NodeIndex) -> TypeId
Check an expression and return its type.
This is the main entry point for expression type checking. It handles caching and dispatches to specific expression handlers.
Sourcepub fn check_with_context(
&mut self,
idx: NodeIndex,
context_type: Option<TypeId>,
) -> TypeId
pub fn check_with_context( &mut self, idx: NodeIndex, context_type: Option<TypeId>, ) -> TypeId
Check an expression with a contextual type hint.
Contextual types enable downward inference where the expected type influences the inferred type. For example:
const x: string = expr-expris checked with contextstringconst f: (x: number) => void = (x) => {}-xis inferred asnumber
§Caching Behavior
When context_type is Some, the cache is bypassed to avoid
incorrect results. The same expression can have different types
depending on the context, so caching by NodeIndex alone is unsound.
Sourcepub fn compute_type_uncached(&mut self, idx: NodeIndex) -> TypeId
pub fn compute_type_uncached(&mut self, idx: NodeIndex) -> TypeId
Compute the type of an expression without caching.
This is called by CheckerState::compute_type_of_node to get an initial
type for expressions. Returns TypeId::DELEGATE if the expression needs
full CheckerState context for proper type resolution.
Simple expressions that don’t need contextual typing or symbol resolution
are handled directly here. Complex expressions delegate to CheckerState.
Sourcepub const fn context(&self) -> &CheckerContext<'ctx>
pub const fn context(&self) -> &CheckerContext<'ctx>
Get the context reference (for read-only access).