feat: Add Json as a built-in type with type checker support for json_parse/json_stringify#29
Merged
Merged
Conversation
…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
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.
Previously, json_parse and json_stringify were runtime-only builtins with
no type checker awareness, and using
Jsonas a type annotation resolvedto
Type::Named("Json", [])which failed to match concrete types.This adds:
Type::Jsonvariant to the type system as a dynamic JSON value typeJsonresolves correctly in type annotations viaresolve_type_exprjson_parsetyped as(Text) -> Jsonandjson_stringifyas(Json) -> TextText, List, Record, etc.) in both
types_compatibleandunifyhttps://claude.ai/code/session_01RDd7JqDDGMbFr6CsQKTQqg