v6 Parsing: type annotations and signatures

  • Build recursive Type trees and aligned parameter annotations.
  • Enforce function signature syntax while keeping optional local annotations.
  • Separate malformed type syntax from incompatible initializer semantics.
1 / 6

Readiness

  • Parse v5 modules and postfix expressions.
  • Understand recursive array/map/function type shapes.
2 / 6

Worked reconstruction

Parse this type annotation:

let transform: fn(array<number>, bool) -> map<string,number>;
Type node Children
function Params[0]=array, Params[1]=bool; Return=map
array Elem=number
map Key=string; Value=number

Store the complete tree in Stmt.TypeAnn. For a function declaration, keep ParamTypes aligned by index with Params and store ReturnType separately. fn f(x:array<number>)->number { return x[0]; } has one parameter, not the three type-name tokens array/number/number as separate parameters.

3 / 6

Diagnose before implementing

A type parser stops map<string,array<number>> after reading string, and a function parser appends types in a separate unordered map. Which two representation invariants are broken?

4 / 6

Independent transfer

Draw the Type tree for fn(fn(number)->bool)->array<string>. Then make one unknown type, one missing arrow, and one valid annotation with an incompatible initializer; classify parse versus semantic failure.

5 / 6

Carry forward

Carry complete Type trees into analysis. Do not erase them during parsing or treat a missing required signature as an inference request.

6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen