Skip to content

feat: type annotations 📚#131

Draft
timfennis wants to merge 13 commits intomasterfrom
feature/type-annotations
Draft

feat: type annotations 📚#131
timfennis wants to merge 13 commits intomasterfrom
feature/type-annotations

Conversation

@timfennis
Copy link
Copy Markdown
Owner

No description provided.

timfennis and others added 13 commits March 24, 2026 15:02
Co-authored-by: Claude <noreply@anthropic.com>
The lexer greedily tokenises `>>`, `>=`, and `>>=` as single tokens,
which breaks nested generic type annotations like `List<List<Int>>`.
The parser now splits these compound tokens when closing angle brackets
in type parameter lists.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Introduces TypeBinding enum (Inferred/Annotated) to track whether a
variable was declared with an explicit type annotation. Annotated
bindings refuse type widening on reassignment, emitting a type mismatch
error instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extends the annotated binding check to OpAssignment (+=, /=, etc.).
Also fixes a bug where destructured `let v, n = 100, 100` incorrectly
marked sub-bindings as annotated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds `named_parameter` parser for function param lists, separate from
`named_binding` (used by `let` destructuring). Params now accept
optional type annotations (e.g. `fn foo(x: Int)`). Also adds
`TypeSignature::from_annotated_bindings` constructor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Parse `-> Type` return type annotations on function declarations
- Analyser validates inferred return type against annotation
- Parameter type annotations now feed into analysis (no longer ignored)
- Register Int-specific overloads for +, -, *, % with fast i64 path
- Register Float-specific overloads for +, -, *, /, %
- Widen container element type on index op-assignment (e.g. x[0] /= 3)
- Add StaticType::with_element_type helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…holders 🔄

When pre-registering a recursive function, use the declared return type
annotation instead of Any so that recursive calls resolve correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Introduce FunctionParameter to unify parameter representation in the
AST, replacing TypeSignature on FunctionDeclaration. Move inferred
return types to an AnalysisResult side table so the LSP can distinguish
annotated vs inferred return types. Walk parameter lvalues in the
visitor so parameter type hints are emitted.

Also compute the LUB of return types across all overload candidates in
dynamic bindings, improving type inference for overloaded functions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant