Skip to content

feat: Add Json as a built-in type with type checker support for json_parse/json_stringify#29

Merged
jaimeam merged 4 commits into
mainfrom
claude/add-json-type-support-MO9NL
Feb 19, 2026
Merged

feat: Add Json as a built-in type with type checker support for json_parse/json_stringify#29
jaimeam merged 4 commits into
mainfrom
claude/add-json-type-support-MO9NL

Conversation

@jaimeam

@jaimeam jaimeam commented Feb 19, 2026

Copy link
Copy Markdown
Owner

Previously, json_parse and json_stringify were runtime-only builtins with
no type checker awareness, and using Json as a type annotation resolved
to Type::Named("Json", []) which failed to match concrete types.

This adds:

  • Type::Json variant to the type system as a dynamic JSON value type
  • Json resolves correctly in type annotations via resolve_type_expr
  • json_parse typed as (Text) -> Json and json_stringify as (Json) -> Text
  • Json is compatible with all JSON-representable types (Int, Float, Bool,
    Text, List, Record, etc.) in both types_compatible and unify
  • Field access on Json returns Json (for dynamic object property access)
  • Index access on Json returns Json (for dynamic array element access)
  • Unit tests covering all new behavior including error cases

https://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg

…parse/json_stringify

Previously, json_parse and json_stringify were runtime-only builtins with
no type checker awareness, and using `Json` as a type annotation resolved
to `Type::Named("Json", [])` which failed to match concrete types.

This adds:
- `Type::Json` variant to the type system as a dynamic JSON value type
- `Json` resolves correctly in type annotations via `resolve_type_expr`
- `json_parse` typed as `(Text) -> Json` and `json_stringify` as `(Json) -> Text`
- Json is compatible with all JSON-representable types (Int, Float, Bool,
  Text, List, Record, etc.) in both `types_compatible` and `unify`
- Field access on Json returns Json (for dynamic object property access)
- Index access on Json returns Json (for dynamic array element access)
- Unit tests covering all new behavior including error cases

https://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg
… sync

Retrospective from the Json type bug: json_parse/json_stringify were added
to the interpreter in v1.1 but never registered in the type checker. This
ADR documents the root cause, the 13 other builtins with the same gap, and
establishes a rule that both dispatch tables must stay in sync.

Adds a "Critical Invariant" section to CLAUDE.md so agents adding new
builtins know to update both the interpreter and type checker together.

https://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg
…pechecker sync test

Adds proper Type::Function signatures for every builtin that was missing
from the type checker (ADR-005 gap):

Regex (pure):
- regex_match(Text, Text) -> Option[Json]
- regex_find_all(Text, Text) -> List[Json]
- regex_replace(Text, Text, Text) -> Text
- regex_split(Text, Text) -> List[Text]
- regex_is_match(Text, Text) -> Bool

File I/O (effects: Fs):
- read_file(Text) -> Text
- write_file(Text, Text) -> Unit

HTTP (effects: Net):
- http_get(Text) -> Text
- http_post(Text, Text) -> Text

Random (effects: Rand):
- random_int(Int, Int) -> Int
- random_bool() -> Bool

Time (effects: Clock):
- current_time_millis() -> Int

Environment (effects: Env):
- get_env(Text) -> Option[Text]

Also adds test_interpreter_typechecker_builtin_sync — an automated test
that parses both source files, extracts builtin names from the interpreter
Call dispatch and the type checker Ident match, and asserts every
interpreter builtin has a type checker entry. This test will fail the
build if a new builtin is added to the interpreter without a corresponding
type signature, preventing the class of bug that caused the Json issue.

https://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg
The ADR was written before the 13 builtins were typed and the sync test
was added. Updates the gap table with correct signatures (regex_match
returns Option[Json], not List[Text]) and marks all as fixed. Replaces
the "future work" items that are now done with an "implemented safeguards"
section documenting what exists.

https://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg
@jaimeam jaimeam merged commit d7fd2c4 into main Feb 19, 2026
6 checks passed
@jaimeam jaimeam deleted the claude/add-json-type-support-MO9NL branch February 19, 2026 02:29
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.

2 participants