-
Notifications
You must be signed in to change notification settings - Fork 0
Fix type inference for RHS forms in included files (issue #553) #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Include Type Inference: Remaining RHS Forms (Issue #553) | ||
|
|
||
| **Date:** 2026-07-03 | ||
|
|
||
| ## What Changed | ||
|
|
||
| Issue #553 (follow-on to #551/#552) reported that four right-hand-side forms | ||
| still aborted with a fatal `Could not infer type for variable 'v'` when they | ||
| appeared inside an `include from` file: | ||
|
|
||
| ```wfl | ||
| store v as parts[0] # list index | ||
| store v as rec["k"] # object index (parse_json result) | ||
| store v as a is equal to b # comparison result | ||
| store v as length of a # length of (already fixed by #552's builtin table) | ||
| ``` | ||
|
|
||
| Investigating end to end showed the failures were not include-specific at all. | ||
| The same forms failed inference in the **main file** too — but `main.rs` | ||
| reports type errors as non-fatal warnings and keeps running, while the include | ||
| pipeline turned the first type error into a fatal `RuntimeError`. That | ||
| asymmetry is what made includes look uniquely broken. | ||
|
|
||
| ### Root causes and fixes | ||
|
|
||
| 1. **The type checker had no scope for action bodies** | ||
| (`src/typechecker/mod.rs`). The analyzer creates a child scope for each | ||
| action body during analysis and then discards it, so when the type checker | ||
| later walked the AST, neither parameters nor body-local variables resolved | ||
| to any symbol. `store parts as string_split of a and "-"` inferred | ||
| `List<Text>` but had nowhere to record it, so `parts[0]` on the next line | ||
| inferred `Unknown`. The `ActionDefinition` branch now pushes a scope, | ||
| defines parameter symbols (declared type, or `Unknown` when untyped), and | ||
| the `VariableDeclaration` branch defines body-local symbols with their | ||
| inferred types so later statements can see them. | ||
|
|
||
| 2. **Comparisons with `Unknown` operands inferred `Unknown`.** A comparison | ||
| yields a Boolean no matter what the operand types turn out to be; only | ||
| arithmetic results depend on the operand types. `BinaryOperation` inference | ||
| now returns `Boolean` for `Equals`/`NotEquals`/ordered comparisons/ | ||
| `And`/`Or`/`Contains` even when an operand is `Unknown` or `Any`. | ||
|
|
||
| 3. **Indexing an `Any` collection was a type error.** `parse_json` results | ||
| are typed `Any` (the shape is only known at runtime), but `IndexAccess` | ||
| had no `Any` arm and fell through to `Cannot index into Any`. Indexing | ||
| `Any` now yields `Any`, and `Unknown`/`Any` index values are tolerated | ||
| for list and text indexing. | ||
|
|
||
| 4. **Include type errors are now non-fatal warnings** | ||
| (`src/interpreter/mod.rs`). `include from` executes in the parent scope — | ||
| the code is semantically part of the main program — so its type-check | ||
| findings are now reported exactly like the main file's: printed as | ||
| `Type checking warnings in included file '...'` and execution continues. | ||
| This closes the class of bug behind #551/#553 rather than the four | ||
| instances: any future inference gap degrades to a warning instead of a | ||
| show-stopping abort. Parse and semantic errors in included files remain | ||
| fatal. | ||
|
|
||
| 5. **Bonus: false `ANALYZE-UNUSED` fix** (`src/analyzer/static_analyzer.rs`). | ||
| The issue's own repro flagged `Unused variable 'parts'` after | ||
| `store v as parts[0]` inside an action: `mark_used_variables` had no | ||
| `VariableDeclaration` arm, so right-hand sides of `store` statements inside | ||
| action/loop bodies never counted as uses. Added the arm. | ||
|
|
||
| ### No new syntax | ||
|
|
||
| No new syntax was needed, so nothing was added to the language surface. The | ||
| change is purely semantic and aligns with the WFL foundation principles of | ||
| clear and actionable error reporting (principle 4) and type safety with | ||
| inference where practical (principle 5): inference now understands the | ||
| bread-and-butter forms, and what it cannot infer degrades to a readable | ||
| warning instead of a fatal abort. | ||
|
|
||
| ## Tests | ||
|
|
||
| `tests/docs_parser_and_include_fixes_test.rs` gained regression tests: each | ||
| of the four RHS forms inside an included action called from a main program, | ||
| main-file inference guards for list-index and comparison results, and a guard | ||
| that a genuinely uninferable store (`a plus b` on untyped parameters) in an | ||
| included file runs to completion instead of aborting. | ||
|
|
||
| ## Docs | ||
|
|
||
| - `Docs/04-advanced-features/modules.md`: documented include type-check | ||
| behavior (warnings, not fatal). | ||
| - `Docs/reference/error-codes.md`: refreshed the "Could not infer type" | ||
| entry. |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.