-
Notifications
You must be signed in to change notification settings - Fork 1
Type Checker
Riley Peel edited this page Jan 21, 2025
·
1 revision
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.
The type checker walks through the bound AST and performs assertions between certain types.
Here is a snippet from the type checker that checks BoundVariableDeclaration
s 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;
}