Skip to content

Type Checker

Riley Peel edited this page Jan 21, 2025 · 1 revision

What it does

The type checker performs static analysis on the bound AST to make sure you don't do things like true + 69. It has a similar job to the resolver, but for the bound AST instead of the regular AST.

How it does it

The type checker walks through the bound AST and performs assertions between certain types.

Here is a snippet from the type checker that checks BoundVariableDeclarations and asserts that the initializer is the same type that the variable was annotated with.

public object? VisitBoundVariableDeclaration(BoundVariableDeclaration variableDeclaration)
{
    if (variableDeclaration.Initializer == null)
        return null;
        
    Check(variableDeclaration.Initializer);
    Assert(variableDeclaration.Initializer, variableDeclaration.Symbol.Type);
    return null;
}
Clone this wiki locally