Type-check token definitions#148
Merged
Merged
Conversation
SpaceManiac
approved these changes
Jun 18, 2026
SpaceManiac
left a comment
Contributor
There was a problem hiding this comment.
Seems like the right path
Replace the parse-only stubs for `token` with full type checking, mirroring
the existing `utxo` machinery:
- Add `Type::TokenAny` / `Type::TokenNamed`, parallel to Utxo, and thread them
through every exhaustive `Type` match.
- Expand `TypedTokenDef` into `{ name, parts, ty }` with `TypedTokenPart` and
`TypedTokenGlobal { indexed }`.
- `register_token` registers the named type as an opaque handle; the bare
`Token` annotation resolves to `TokenAny`.
- Register a built-in `Token` ABI (`attach(Utxo) -> ()`, `detach(Utxo) -> ()`)
so `impl Token` reuses `check_abi_impl`; reject a user-declared `abi Token`.
- `infer_token` validates structure (at least one `mint fn`, exactly one
`impl Token`) before inferring bodies, checks storage (carrying `indexed`),
rejects an explicit return type on `mint`, and validates impl conformance.
Storage is in scope for all token functions.
- Add `apply_token`, export the token name as a type, four new error codes
(E0052–E0055) with docs, and full language-server symbols/hover.
`Token` is now a reserved type name like `Utxo`; rename the `struct Token` in
the `struct_param.star` codegen fixture to avoid the collision.
Token codegen remains a stub and is left for a follow-up.
Signed-off-by: rvcas <x@rvcas.dev>
Signed-off-by: rvcas <x@rvcas.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #138 (parser support). Replaces the parse-only
tokenstubs with full type checking, mirroring the existingutxomachinery. Token codegen is intentionally left as a follow-up.Behavior
A
tokendefinition is now checked end to end:Rules enforced: at least one
mint fn, exactly oneimpl Token,mintmay not declare a return type, and theimpl Tokenblock must match the built-inattach(Utxo) -> ()/detach(Utxo) -> ()signatures. Additionalimpl <UserAbi>blocks are allowed.Changes
types.rs):Type::TokenAny+Type::TokenNamed, parallel to Utxo, threaded through every exhaustiveTypematch (apply, substitute, occurs/free-vars, env, exhaustiveness, docs, to-wasm handle lowering).typed_ast.rs):TypedTokenDef { name, parts, ty }withTypedTokenPart+TypedTokenGlobal { indexed }.infer.rs):register_token(opaque handle),Tokenannotation →TokenAny, a built-inTokenABI registered at construction soimpl Tokenreusescheck_abi_impl, a guard rejecting user-declaredabi Token, andinfer_token(structural pre-pass, storage scope, mint return-type rule, impl conformance) plusapply_tokenand type export.E0052–E0055with rendered messages and docs.document.rs): token symbols, hover, and type-annotation collection.Note
Tokenis now a reserved type name likeUtxo. Thestruct_param.starcodegen fixture happened to definestruct Token, so it was renamed tostruct Item(snapshot regenerated).Known parallels-to-utxo / deferred
check_abi_impldoes not enforce parameter arity (pre-existing utxo limitation).unifyarms (utxo has none either; token-typed values don't flow through unification yet).starstream-to-wasmremains a "not yet supported" stub.