Adds runtime context variables - #144
Conversation
- Fix comparison operators: 'greater than' → 'is greater than' - Fix push operations: 'push of' → 'push with' - Fix array indexing: replace args[arg_count - 1] with variable calculation - Fix string checking: replace startswith with substring approach - Fix division operator: '/' → 'divided by' - Fix variable reassignments: 'store' → 'change' for updates - Remove lexing errors and resolve all syntax issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…ariable support Major fixes implemented: - Add runtime command-line variables to static analyzer global scope - Add arg_count, args, program_name, current_directory, positional_args to analyzer - Implement program_name and current_directory in interpreter runtime - Fix conditional syntax: replace elif/else with otherwise if/otherwise - Restructure complex conditionals as nested check statements - Resolve all fatal semantic analyzer errors preventing execution Results: - args_comprehensive.wfl now executes successfully without fatal errors - All command-line argument functionality working (parsing, flags, validation) - Program handles multiple test scenarios (no args, regular args, flags) - Only minor type checking warnings remain (non-fatal) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughAdds bracket-style array indexing support; exposes additional runtime globals (program_name, current_directory) and analyzer predeclares; refactors a comprehensive argument test script and adds its lexer dump; improves builtin arity handling and PatternMatch location reporting; adds tests and documentation (bug report, dev diary, agent prompt). Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as Process / argv
participant Interpreter
participant Env as Script Environment
participant Script
CLI->>Interpreter: start with argv
Interpreter->>Env: set `args`, `arg_count`
Interpreter->>Env: set `program_name`
Interpreter->>Env: set `current_directory`
Interpreter-->>Script: execute script with globals
Script->>Env: read `args`, `arg_count`, `program_name`, `current_directory`
Script-->>CLI: produce outputs (reports, flags, summaries)
sequenceDiagram
participant Lexer
participant Parser
participant AST
participant Analyzer
Lexer->>Parser: tokens (includes LeftBracket/RightBracket)
Parser->>AST: build IndexAccess for `expr[index]`
Parser-->>Analyzer: AST with IndexAccess nodes
Analyzer->>Analyzer: mark variables used in index expressions (avoid unused-vars)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Claude finished @logbie's task —— View job PR Review: Runtime Context VariablesI've completed a comprehensive review of PR #144 that adds Todo List:
Overall Assessment:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/analyzer/mod.rs (1)
258-261: Improve comment concisenessThe comment could be more concise while maintaining clarity.
- // Define runtime command-line argument variables - // These are defined at runtime by the interpreter but need to be known - // to the static analyzer to avoid false undefined variable errors + // Runtime CLI variables - defined by interpreter but declared here to avoid false undefined errorssrc/interpreter/mod.rs (2)
702-713: Consider improving program_name default value and documentationWhen
script_argsis empty, defaulting to "wfl" might be misleading as it represents the interpreter, not the script. Consider using a more descriptive default or the actual script filename if available.- // Store program name (first argument or empty string) + // Store program name (script filename from first argument, or "wfl" if no arguments) let program_name = if self.script_args.is_empty() { - "wfl".to_string() + "<no script>".to_string() // More descriptive default } else { // Extract just the filename from the path std::path::Path::new(&self.script_args[0]) .file_name() .unwrap_or_default() .to_string_lossy() .into_owned() };
715-720: Add error handling for current_directoryWhile
unwrap_or_default()provides a safe fallback, silently defaulting to an empty string when the current directory cannot be determined might cause confusion.- // Store current directory - let current_dir = std::env::current_dir() - .unwrap_or_default() - .to_string_lossy() - .into_owned(); + // Store current directory + let current_dir = match std::env::current_dir() { + Ok(dir) => dir.to_string_lossy().into_owned(), + Err(e) => { + exec_trace!("Failed to get current directory: {}", e); + "<unknown>".to_string() + } + };TestPrograms/args_comprehensive.wfl (1)
218-218: Consider noting actual min/max logic limitationThe comment correctly notes this is simplified. For completeness, you might want to add a TODO to implement proper min/max logic in the future.
- display "Shortest argument: " with args[0] // Simplified - would need proper min logic + display "Shortest argument: " with args[0] // TODO: Implement proper min/max logic for accurate reporting
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
TestPrograms/args_comprehensive.wfl(7 hunks)TestPrograms/args_comprehensive.wfl.lex.txt(1 hunks)src/analyzer/mod.rs(1 hunks)src/interpreter/mod.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
src/**/*.rs: Always run cargo fmt --all to fix formatting issues
Always run cargo clippy --all-targets --all-features -- -D warnings and fix any reported errors
All Rust code must be formatted according to .rustfmt.toml
Files:
src/analyzer/mod.rssrc/interpreter/mod.rs
{src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl}
📄 CodeRabbit Inference Engine (CLAUDE.md)
When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
Files:
src/analyzer/mod.rssrc/interpreter/mod.rsTestPrograms/args_comprehensive.wfl
src/interpreter/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
Interpreter debug output must use exec_trace! macro and never pollute program output
Files:
src/interpreter/mod.rs
{src/interpreter/**/*.rs,src/stdlib/**/*.rs}
📄 CodeRabbit Inference Engine (CLAUDE.md)
All I/O operations must be async and use the Tokio runtime
Files:
src/interpreter/mod.rs
TestPrograms/*.wfl
📄 CodeRabbit Inference Engine (CLAUDE.md)
TestPrograms/*.wfl: All programs in TestPrograms/ must execute successfully after any code change
Use await keyword in WFL code for async operations
All test categories (syntax, async, error handling, stdlib, container, performance) must be covered in TestPrograms/
Files:
TestPrograms/args_comprehensive.wfl
{TestPrograms/*.wfl,tests/**}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Add or update tests in TestPrograms/ or tests/ when making changes
Files:
TestPrograms/args_comprehensive.wfl
🧠 Learnings (3)
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to {src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl} : When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
Applied to files:
TestPrograms/args_comprehensive.wfl.lex.txt
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to TestPrograms/*.wfl : All test categories (syntax, async, error handling, stdlib, container, performance) must be covered in TestPrograms/
Applied to files:
TestPrograms/args_comprehensive.wfl.lex.txt
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to TestPrograms/*.wfl : All programs in TestPrograms/ must execute successfully after any code change
Applied to files:
TestPrograms/args_comprehensive.wfl.lex.txt
🔇 Additional comments (4)
src/analyzer/mod.rs (1)
298-305: Missing implementation for positional_args in interpreterThe
positional_argsvariable is declared here in the analyzer but I notice it's already being set in the interpreter at line 693-697. This is correct and consistent.TestPrograms/args_comprehensive.wfl.lex.txt (1)
1-724: Lexer output file looks comprehensiveThe lexer output correctly captures all 723 tokens from the test program with proper type, position, and length information. This provides good test coverage for the lexer.
TestPrograms/args_comprehensive.wfl (2)
10-10: Good integration of new runtime variablesThe test properly demonstrates the usage of the new
program_nameandcurrent_directoryruntime variables in different contexts.Also applies to: 165-165
82-83: Good practice using intermediate variableStoring
last_indexas a separate variable improves code readability and follows best practices.
Introduces a new 'bug-detective' agent designed for systematic debugging and root cause analysis. This agent focuses exclusively on investigating issues and producing a comprehensive report to guide developers. A sample bug report (`bug.md`) is included as a concrete example of the agent's output. This report documents a critical limitation in the WFL parser where array indexing syntax (e.g., `array[index]`) is not correctly processed. This investigation correctly identifies the issue's origin in the parser, rather than the static analyzer. **Files Changed:** - **`.claude/agents/bug-detective.md`**: (New) Defines the bug-detective agent, its expertise, investigation process, and operational constraints. - **`bug.md`**: (New) A detailed bug report produced by the investigation, identifying a parser limitation with array indexing as the root cause of unexpected behavior.
This commit improves the type checker's capabilities and adds a regression test for a known bug in the static analyzer. Type Checker: - Infers and returns the correct function signature for built-in functions. - Makes type compatibility more flexible by correctly handling assignments involving `Any` and `Unknown` types. - Improves error reporting for pattern matching by including accurate location information. Static Analyzer: - Adds a new test that reproduces a false-positive where a variable used as an array index is incorrectly flagged as unused. This test is expected to fail until the underlying bug is fixed. Files Changed: - src/analyzer/static_analyzer.rs - src/typechecker/mod.rs
|
Claude finished @logbie's task —— View job PR Review: Runtime Context VariablesI've completed a comprehensive review of PR #144 that adds Todo List:
Overall Assessment:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (6)
src/analyzer/static_analyzer.rs (5)
122-128: Remove ad-hoc “special variables”; add runtime globals per PR (program_name/current_directory).Hard-coding names like "helper_function", "nested_function", and "y" to suppress undefined-variable errors is brittle and can mask real issues. Per PR goals, ensure "program_name" and "current_directory" are recognized instead.
Apply this diff to align with the PR objective and drop the hacks:
- // Add special variables to action parameters to prevent them from being flagged as undefined - action_parameters.insert("count".to_string()); - action_parameters.insert("loopcounter".to_string()); - action_parameters.insert("helper_function".to_string()); - action_parameters.insert("nested_function".to_string()); - action_parameters.insert("y".to_string()); + // Add runtime globals to prevent false undefined-variable errors + action_parameters.insert("program_name".to_string()); + action_parameters.insert("current_directory".to_string());If these globals are already predeclared in src/analyzer/mod.rs, prefer removing this entire block to avoid duplication. I can refactor this to use a single centralized “known globals” registry shared by analyzer/typechecker if you want.
130-147: Avoid stringly-typed filtering of undefined-variable errors; rely on symbol predeclaration.Parsing analyzer error messages to suppress undefined-variable diagnostics is fragile. Prefer predeclaring known runtime globals and action parameters in the symbol table so errors never fire in the first place.
I recommend removing this error-filtering block and registering globals (program_name/current_directory) and parameters as symbols during analysis. If you want, I can provide a small helper that registers “known runtime globals” in Analyzer and removes this branch.
211-245: Do not mark all action parameters as “used” just because the action is called.This makes unused-parameter detection impossible (parameters appear “used” even if the action body never references them). Arguments/inner expression usage is already handled in mark_used_in_expression, so this block is both redundant and semantically incorrect.
Apply this diff to remove the incorrect marking:
- // Special handling for action parameters - mark them as used - for statement in &program.statements { - // Look for ExpressionStatement that might contain ActionCall - if let Statement::ExpressionStatement { - expression: - Expression::ActionCall { - name, arguments, .. - }, - .. - } = statement - { - // If this is an action call, mark all parameters of that action as used - if let Some(params) = action_parameters.get(name) { - for param_name in params { - if let Some(usage) = variable_usages.get_mut(param_name) { - usage.used = true; - } - } - } - - // Also mark all arguments as used - for arg in arguments { - // Mark the variable directly if it's a variable expression - if let Expression::Variable(var_name, ..) = &arg.value - && let Some(usage) = variable_usages.get_mut(var_name) - { - usage.used = true; - } - - // Also mark any variables used within more complex expressions - // We need to remove this line since we're already marking variables in the expression - // through the Variable match above and the mark_used_variables function - } - } - } + // (Removed) Arguments and nested variable usage are already marked in mark_used_in_expression.Follow-up (outside selected range): In collect_variable_declarations, do not mark action parameters “used” by default so unused-parameter warnings remain effective:
// In collect_variable_declarations -> parameters loop used: false, // instead of trueI can produce a targeted patch if you’d like to keep unused-parameter diagnostics.
248-251: Remove test-only special-case for variable ‘y’.Skipping reporting “y” is a hidden, global exception that will hide real issues.
Apply this diff:
- // Skip reporting unused variable 'y' since it's a special case in the tests - if name == "y" { - continue; - }
109-121: Action parameter name handling via split_whitespace is risky.Splitting Parameter.name on whitespace to fabricate multiple parameter names is a heuristic that can silently corrupt names and scopes. If the language supports declaring multiple params together, the parser should expose them individually in the AST.
Prefer modeling parameters as a vector of distinct Parameter nodes (one per identifier) in the AST; remove split_whitespace() here. I can draft a migration plan touching parser/analyzer/typechecker with minimal churn.
src/typechecker/mod.rs (1)
1216-1245: Duplicated builtin handling across Variable and ActionCall paths.You infer builtin types in both Variable(...) and ActionCall(...). Divergence is likely (e.g., arity enforcement differs). Factor into a helper (get_builtin_signature) and reuse from both places.
Happy to extract this into a single function returning Type::Function or (return_type, arity) and call from both arms.
🧹 Nitpick comments (9)
src/analyzer/static_analyzer.rs (3)
1471-1594: Good regression test; update misleading comment and fix rustfmt.The test accurately reproduces the nested IndexAccess usage. The “This test currently FAILS because of the bug” comment is misleading (this AST builds an IndexAccess and should pass). Also, CI flagged formatting at/near these lines.
- Remove/update the “currently FAILS” comment.
- Run cargo fmt to fix formatting at line 1584 (CI report).
I can help convert this into a data-driven test case if you want broader coverage (e.g., multiple index shapes, concatenations, and guards).
132-162: Early return on analyzer errors blocks other static checks.Returning immediately after pushing analyzer diagnostics skips unreachable-code/shadowing/unused checks. Consider running non-dependent checks even when there are analyzer errors to surface more issues per run.
One approach: collect analyzer errors, but continue with best-effort checks guarded by symbol-table availability.
639-744: Duplicated argument-usage marking in ActionCall path.Arguments are marked used here and in the ExpressionStatement/ActionCall block above (now removed per suggestion). Keep a single source of truth in mark_used_in_expression (this block) to avoid divergence.
No code changes needed if you remove the ExpressionStatement branch per prior suggestion.
.claude/agents/bug-detective.md (2)
9-16: Strong persona; minor wording polish.Solid scope. Consider replacing “Deep understanding” with a more specific adjective to tighten tone.
Apply:
- “Deep understanding of software architecture patterns” → “Extensive knowledge of software architecture patterns”
42-49: Clarify prohibitions succinctly.The “You NEVER” block can be crisper to avoid redundancy.
- “Make changes to the codebase” → “Modify the codebase”
- Combine bullets into “Do not write or modify code, provide code fixes, or alter the codebase.”
src/typechecker/mod.rs (2)
1669-1694: PatternMatch location-aware errors: nice improvement.Using actual line/column for PatternMatch errors improves diagnostics. Consider aligning PatternFind/Replace/Split similarly when the AST exposes positions.
1695-1762: Inconsistent location info for pattern errors.PatternFind/Replace/Split still emit errors at (0,0). If AST variants carry line/column (or can be extended), pass them to type_error for consistent UX.
I can update the AST and propagate positions similarly to PatternMatch.
Also applies to: 1763-1789
bug.md (2)
71-74: Doc inconsistency: test program was modified in this PR.This section claims “No changes” to TestPrograms/args_comprehensive.wfl, but the PR updates it. Please correct the “Files Modified” list.
Proposed edit:
- TestPrograms/args_comprehensive.wfl: Updated to demonstrate runtime globals and array indexing case.
- TestPrograms/args_comprehensive.wfl.lex.txt: Added.
24-47: Good root-cause write-up; strengthen actionable next steps.The analysis clearly attributes the issue to missing IndexAccess AST generation. Add a “Proposed fix sketch” (parser rule outline + AST construction) to fast-track implementation.
I can draft a parser rule update (lexer token expectations, grammar snippet) to generate Expression::IndexAccess for array[index].
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.claude/agents/bug-detective.md(1 hunks)bug.md(1 hunks)src/analyzer/static_analyzer.rs(2 hunks)src/typechecker/mod.rs(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
src/**/*.rs: Always run cargo fmt --all to fix formatting issues
Always run cargo clippy --all-targets --all-features -- -D warnings and fix any reported errors
All Rust code must be formatted according to .rustfmt.toml
Files:
src/analyzer/static_analyzer.rssrc/typechecker/mod.rs
{src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl}
📄 CodeRabbit Inference Engine (CLAUDE.md)
When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
Files:
src/analyzer/static_analyzer.rssrc/typechecker/mod.rs
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to {src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl} : When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
🧬 Code Graph Analysis (1)
src/typechecker/mod.rs (2)
src/analyzer/mod.rs (4)
is_builtin_function(315-317)new(71-76)new(136-142)new(171-313)src/lexer/token.rs (1)
new(362-369)
🪛 LanguageTool
.claude/agents/bug-detective.md
[style] ~11-~11: Consider a different adjective to strengthen your wording.
Context: ...logies and fault isolation techniques - Deep understanding of software architecture ...
(DEEP_PROFOUND)
[style] ~46-~46: Consider shortening or rephrasing this to strengthen your wording.
Context: ...xisting code - Provide code solutions - Make changes to the codebase You focus exclusively on ...
(MAKE_CHANGES)
🪛 GitHub Actions: CI
src/analyzer/static_analyzer.rs
[error] 207-207: cargo fmt check failed. Formatting changes detected in src/analyzer/static_analyzer.rs (line 207). Run 'cargo fmt' to fix.
[error] 1484-1502: cargo fmt check failed. Formatting changes detected in src/analyzer/static_analyzer.rs (lines 1484-1502). Run 'cargo fmt' to fix.
[error] 1584-1584: cargo fmt check failed. Formatting changes detected in src/analyzer/static_analyzer.rs (line 1584). Run 'cargo fmt' to fix.
src/typechecker/mod.rs
[error] 1224-1224: cargo fmt check failed. Formatting changes detected in src/typechecker/mod.rs (line 1224). Run 'cargo fmt' to fix.
[error] 1231-1231: cargo fmt check failed. Formatting changes detected in src/typechecker/mod.rs (line 1231). Run 'cargo fmt' to fix.
[error] 1237-1237: cargo fmt check failed. Formatting changes detected in src/typechecker/mod.rs (line 1237). Run 'cargo fmt' to fix.
[error] 1680-1680: cargo fmt check failed. Formatting changes detected in src/typechecker/mod.rs (line 1680). Run 'cargo fmt' to fix.
[error] 2324-2324: cargo fmt check failed. Formatting changes detected in src/typechecker/mod.rs (line 2324). Run 'cargo fmt' to fix.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: claude-review
🔇 Additional comments (6)
src/analyzer/static_analyzer.rs (4)
210-210: Fix formatting (cargo fmt).CI flagged rustfmt drift at this location. Run cargo fmt --all.
To confirm locally:
- cargo fmt --all
- cargo clippy --all-targets --all-features -- -D warnings
368-371: Accessor looks good.Exposing get_action_parameters is fine, assuming Analyzer carries and updates this set coherently.
1-371: Run cargo fmt and clippy as per repo guidelines.CI shows rustfmt failures (lines 207, 1484-1502, 1584). Repo guidelines also require clippy -D warnings on src/**/*.rs.
Run locally:
- cargo fmt --all
- cargo clippy --all-targets --all-features -- -D warnings
Also applies to: 173-206
1-171: Runtime globals (program_name,current_directory,arg_count,args,positional_args) are correctly predeclared and injectedBoth the static analyzer and the interpreter already handle these globals:
- In src/analyzer/mod.rs (around lines 262–307), symbols for
arg_count,args,program_name,current_directory, andpositional_argsare defined in the global scope.- In src/interpreter/mod.rs (around lines 694–720), the interpreter populates the environment with:
"args"(full argument list)"positional_args"(non‐flag arguments)"arg_count"(number of script arguments)"program_name"(script name or default)"current_directory"(current working directory)No further action is needed here.
src/typechecker/mod.rs (2)
2326-2331: Treating Unknown/Any as universally compatible may mask real type errors.Allowing (Unknown, ) and (, Unknown) and Any in both directions suppresses many mismatches. This can be desirable for gradual typing, but verify it doesn’t hide mistakes in user code.
- Ensure there are tests asserting that obvious mismatches (e.g., add Number to List) still error even with Unknown/Any in play.
- If desired, gate these rules to assignment contexts only, not comparisons/ops. I can help scope it.
1224-1237: Fix formatting (cargo fmt).CI flagged rustfmt diffs at these lines. Please run cargo fmt --all.
Local check:
- cargo fmt --all
- cargo clippy --all-targets --all-features -- -D warnings
Also applies to: 1680-1680, 2324-2324
Implements parsing for bracket-style array indexing syntax (`array[index]`). Previously, the parser did not recognize this common syntax, causing it to incorrectly parse an indexed access as a simple variable. This also led to the static analyzer producing false "unused variable" warnings for the index. This change updates the postfix expression parser to handle `[` and `]` tokens, correctly generating an `IndexAccess` AST node. - Adds comprehensive unit tests for indexing with literals, variables, and expressions. - Includes a new integration test to validate the end-to-end behavior. - Adds a developer diary entry to document the fix. **Files Changed:** - `src/parser/mod.rs`: Implements the core parsing logic for bracket indexing. - `src/parser/tests.rs`: Adds unit tests for the new syntax. - `TestPrograms/bracket_indexing_test.wfl`: Adds a new integration test. - `Dev diary/2025-08-12-fix-bracket-array-indexing.md`: Documents the change.
|
Claude finished @logbie's task —— View job PR Review: Runtime Context VariablesI've completed a comprehensive review of PR #144 that adds Todo List:
Overall Assessment:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
TestPrograms/bracket_indexing_test.wfl (1)
1-16: Update stale comment; the test should now passBracket indexing is implemented in the parser, so the “should fail” note is outdated. Suggest updating the comment to reflect reality.
Apply this diff:
-// This test should fail until the parser supports bracket indexing +// This program exercises bracket indexing (parser supports this syntax)src/parser/tests.rs (1)
908-1020: Apply rustfmt and add negative test for missing closing bracket
- Please run
cargo fmt --alllocally to resolve the rustfmt issues flagged by CI; the sandbox couldn’t verify formatting.- Consider adding this negative test near the existing bracket-indexing tests:
#[test] fn test_bracket_array_indexing_missing_closing_bracket() { let input = r#"display args[0"#; let tokens = lex_wfl_with_positions(input); let mut parser = Parser::new(&tokens); let result = parser.parse_statement(); assert!(result.is_err(), "Expected error for missing closing bracket"); }Dev diary/2025-08-12-fix-bracket-array-indexing.md (2)
72-85: Add language tags to fenced code blocks to satisfy markdownlintMD040 failures indicate missing language specifiers. Use text to mark output examples.
Apply this diff:
-**Before Fix:** -``` +**Before Fix:** +```text First argument: [test, arg] # Wrong - entire array Last element: [test, arg] # Wrong - entire array warning: Unused variable 'last_index' # Wrong - variable is used-After Fix:
-+**After Fix:** +text
First argument: test # ✅ Correct individual element
Last element: arg # ✅ Correct individual element
# ✅ No unused variable warning
1-16: Verify PR scope alignment with objectivesPR objectives mention adding runtime variables (program_name, current_directory), but this diary documents a bracket indexing parser fix. If both are part of this PR, consider adding a short note here (or a separate entry) for the runtime variables, and ensure TestPrograms cover them. Otherwise, update the PR description for alignment.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Dev diary/2025-08-12-fix-bracket-array-indexing.md(1 hunks)TestPrograms/bracket_indexing_test.wfl(1 hunks)src/parser/mod.rs(1 hunks)src/parser/tests.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
src/**/*.rs: Always run cargo fmt --all to fix formatting issues
Always run cargo clippy --all-targets --all-features -- -D warnings and fix any reported errors
All Rust code must be formatted according to .rustfmt.toml
Files:
src/parser/tests.rssrc/parser/mod.rs
{src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl}
📄 CodeRabbit Inference Engine (CLAUDE.md)
When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
Files:
src/parser/tests.rsTestPrograms/bracket_indexing_test.wflsrc/parser/mod.rs
src/parser/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
Parser must always consume orphaned tokens during error recovery and use peek_token() for lookahead, never next_token() unless consuming
Files:
src/parser/tests.rssrc/parser/mod.rs
TestPrograms/*.wfl
📄 CodeRabbit Inference Engine (CLAUDE.md)
TestPrograms/*.wfl: All programs in TestPrograms/ must execute successfully after any code change
Use await keyword in WFL code for async operations
All test categories (syntax, async, error handling, stdlib, container, performance) must be covered in TestPrograms/
Files:
TestPrograms/bracket_indexing_test.wfl
{TestPrograms/*.wfl,tests/**}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Add or update tests in TestPrograms/ or tests/ when making changes
Files:
TestPrograms/bracket_indexing_test.wfl
Dev diary/**
📄 CodeRabbit Inference Engine (CLAUDE.md)
Update Dev diary with entries for significant changes
Files:
Dev diary/2025-08-12-fix-bracket-array-indexing.md
🧬 Code Graph Analysis (2)
src/parser/tests.rs (3)
src/lexer/mod.rs (1)
lex_wfl_with_positions(85-197)src/parser/mod.rs (1)
new(18-24)src/parser/ast.rs (2)
new(9-11)new(658-664)
src/parser/mod.rs (2)
src/lexer/token.rs (1)
new(362-369)src/parser/ast.rs (2)
new(9-11)new(658-664)
🪛 GitHub Actions: CI
src/parser/tests.rs
[error] 913-913: Rustfmt: formatting changes detected in test assertion formatting. Run 'cargo fmt' to fix.
[error] 938-938: Rustfmt: formatting changes detected in test formatting. Run 'cargo fmt' to fix.
[error] 946-946: Rustfmt: formatting changes detected in test formatting. Run 'cargo fmt' to fix.
[error] 979-979: Rustfmt: formatting changes detected in test formatting. Run 'cargo fmt' to fix.
[error] 991-991: Rustfmt: formatting changes detected in test formatting. Run 'cargo fmt' to fix.
src/parser/mod.rs
[error] 2634-2634: Rustfmt: formatting changes detected near this diff. Run 'cargo fmt' to fix.
[error] 2641-2641: Rustfmt: formatting changes detected near this diff. Run 'cargo fmt' to fix.
🪛 LanguageTool
Dev diary/2025-08-12-fix-bracket-array-indexing.md
[style] ~3-~3: Some style guides suggest that commas should set off the year in a month-day-year date.
Context: ...dexing Parser Bug Date: August 12, 2025 Issue: Array indexing parser limi...
(MISSING_COMMA_AFTER_YEAR)
🪛 markdownlint-cli2 (0.17.2)
Dev diary/2025-08-12-fix-bracket-array-indexing.md
73-73: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
80-80: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: claude-review
🔇 Additional comments (1)
src/parser/mod.rs (1)
2620-2649: Useexpect_tokenfor]to simplify branching and standardize errors
The manual peek-and-error can be replaced with ourexpect_tokenhelper, aligning this index-access logic with the rest of the parser and reducing boilerplate. After applying the diff below, please run your usual formatting and lint checks (e.g.cargo fmt --all && cargo clippy --all-targets --all-features -- -D warnings) to confirm there are no style or warning regressions.Locations to update:
- src/parser/mod.rs, around the
Token::LeftBracketmatch arm (lines ~2620–2649)Suggested diff:
Token::LeftBracket => { - self.tokens.next(); // Consume "[" - - let index = self.parse_expression()?; - - // Expect closing bracket - if let Some(closing_token) = self.tokens.peek().cloned() { - if closing_token.token == Token::RightBracket { - self.tokens.next(); // Consume "]" - expr = Expression::IndexAccess { - collection: Box::new(expr), - index: Box::new(index), - line: token.line, - column: token.column, - }; - } else { - return Err(ParseError::new( - format!("Expected ']' after array index, found {:?}", closing_token.token), - closing_token.line, - closing_token.column, - )); - } - } else { - return Err(ParseError::new( - "Expected ']' after array index, found end of input".to_string(), - token.line, - token.column, - )); - } + self.tokens.next(); // Consume "[" + let index = self.parse_expression()?; + self.expect_token(Token::RightBracket, "Expected ']' after array index")?; + expr = Expression::IndexAccess { + collection: Box::new(expr), + index: Box::new(index), + line: token.line, + column: token.column, + }; }
Updates the bug report to document a critical typechecker flaw where built-in function arities are incomplete. The hardcoded list of argument counts causes false-positive errors for many multi-argument functions (e.g., min, max, contains), preventing their use. This new report replaces the previous one, which detailed a parser limitation with array indexing. **Files Changed:** - `bug.md`: Content replaced with a comprehensive new bug report detailing the function arity issue.
- Added TestPrograms/arity_bug_trigger.wfl that exposes the typechecker bug - Added TestPrograms/minimal_arity_test.wfl as working baseline - Tests confirm typechecker incorrectly defaults builtin functions to 1 argument - min function fails with 'Function expects 1 arguments, but 2 were provided' - This establishes the baseline before implementing the fix 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added comprehensive get_function_arity() function in src/builtins.rs - Mapped all 100+ builtin functions to their correct parameter counts - Updated src/typechecker/mod.rs to use centralized arity function - Removed hardcoded arity definitions that only covered 6 functions - Fixed critical bugs where functions defaulted to 1 argument incorrectly: * random: now correctly expects 0 arguments (was 1) * min, max, power: now correctly expect 2 arguments (was 1) * contains, push, indexof: now correctly expect 2 arguments (was 1) * And 50+ other functions with corrected arities - Added comprehensive tests for arity mappings - All existing tests pass with no regressions - Test programs confirm fix: no more 'Function expects 1 arguments, but 2 were provided' errors Resolves the typechecker arity bug that prevented use of multi-argument builtin functions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @logbie's task —— View job PR Review: Runtime Context VariablesI've completed a comprehensive review of PR #144 that adds Todo List:
Overall Assessment:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
bug.md (1)
164-185: Consider removing implementation details from documentationThe code examples in the "Suggested Fix Approach" section show specific implementation details that may become outdated as the codebase evolves. Consider either:
- Moving these to inline code comments
- Making them more generic/conceptual
- Adding a note that these are examples that may not reflect current implementation
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
TestPrograms/arity_bug_test.wfl(1 hunks)TestPrograms/arity_bug_trigger.wfl(1 hunks)TestPrograms/arity_success_test.wfl(1 hunks)TestPrograms/minimal_arity_test.wfl(1 hunks)TestPrograms/test_fixed_arity.wfl(1 hunks)bug.md(1 hunks)src/analyzer/mod.rs(1 hunks)src/analyzer/static_analyzer.rs(1 hunks)src/builtins.rs(2 hunks)src/parser/mod.rs(1 hunks)src/parser/tests.rs(1 hunks)src/typechecker/mod.rs(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- src/analyzer/mod.rs
- src/parser/tests.rs
- src/analyzer/static_analyzer.rs
- src/parser/mod.rs
- src/typechecker/mod.rs
🧰 Additional context used
📓 Path-based instructions (4)
TestPrograms/*.wfl
📄 CodeRabbit Inference Engine (CLAUDE.md)
TestPrograms/*.wfl: All programs in TestPrograms/ must execute successfully after any code change
Use await keyword in WFL code for async operations
All test categories (syntax, async, error handling, stdlib, container, performance) must be covered in TestPrograms/
Files:
TestPrograms/arity_bug_trigger.wflTestPrograms/test_fixed_arity.wflTestPrograms/minimal_arity_test.wflTestPrograms/arity_success_test.wflTestPrograms/arity_bug_test.wfl
{TestPrograms/*.wfl,tests/**}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Add or update tests in TestPrograms/ or tests/ when making changes
Files:
TestPrograms/arity_bug_trigger.wflTestPrograms/test_fixed_arity.wflTestPrograms/minimal_arity_test.wflTestPrograms/arity_success_test.wflTestPrograms/arity_bug_test.wfl
{src/lexer/**/*.rs,src/parser/**/*.rs,src/analyzer/**/*.rs,src/typechecker/**/*.rs,src/interpreter/**/*.rs,TestPrograms/*.wfl}
📄 CodeRabbit Inference Engine (CLAUDE.md)
When adding a new feature, update the lexer (src/lexer/), parser (src/parser/), analyzer (src/analyzer/), typechecker (src/typechecker/), interpreter (src/interpreter/), and write tests in TestPrograms/
Files:
TestPrograms/arity_bug_trigger.wflTestPrograms/test_fixed_arity.wflTestPrograms/minimal_arity_test.wflTestPrograms/arity_success_test.wflTestPrograms/arity_bug_test.wfl
src/**/*.rs
📄 CodeRabbit Inference Engine (CLAUDE.md)
src/**/*.rs: Always run cargo fmt --all to fix formatting issues
Always run cargo clippy --all-targets --all-features -- -D warnings and fix any reported errors
All Rust code must be formatted according to .rustfmt.toml
Files:
src/builtins.rs
🧠 Learnings (4)
📚 Learning: 2025-08-11T05:10:43.166Z
Learnt from: logbie
PR: WebFirstLanguage/wfl#137
File: TestPrograms/test.wfl:1-2
Timestamp: 2025-08-11T05:10:43.166Z
Learning: Some test scripts in TestPrograms/ are deliberately designed to trigger errors as negative test cases to validate error handling and detection mechanisms. The file TestPrograms/test.wfl specifically tests variable redefinition error detection by attempting to use `store` twice on the same variable.
Applied to files:
TestPrograms/arity_bug_trigger.wflTestPrograms/test_fixed_arity.wflTestPrograms/minimal_arity_test.wflTestPrograms/arity_bug_test.wfl
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to TestPrograms/*.wfl : All programs in TestPrograms/ must execute successfully after any code change
Applied to files:
TestPrograms/arity_success_test.wfl
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to {TestPrograms/*.wfl,tests/**} : Add or update tests in TestPrograms/ or tests/ when making changes
Applied to files:
TestPrograms/arity_success_test.wfl
📚 Learning: 2025-08-10T04:33:11.504Z
Learnt from: CR
PR: WebFirstLanguage/wfl#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T04:33:11.504Z
Learning: Applies to TestPrograms/*.wfl : All test categories (syntax, async, error handling, stdlib, container, performance) must be covered in TestPrograms/
Applied to files:
TestPrograms/arity_success_test.wfl
🪛 LanguageTool
bug.md
[grammar] ~1-~1: Ensure spelling is correct
Context: # Bug Report: Incomplete Builtin Function Arity Definitions ## Bug Summ...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~4-~4: Ensure spelling is correct
Context: ...mary The WFL typechecker has incomplete builtin function arity definitions, causing fal...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~4-~4: Ensure spelling is correct
Context: ...using false argument-count errors. When builtin function names are converted to Functio...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~4-~4: Ensure spelling is correct
Context: ...for unknown functions. This causes many builtin functions that require 2 or more argume...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~32-~32: Ensure spelling is correct
Context: ...o 1 argument** ### 3. Complete List of Builtin Functions by Module **From `C:\logbie...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~82-~82: Ensure spelling is correct
Context: ... simple WFL program with multi-argument builtin function calls: ```wfl store a as 10 st...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~101-~101: Ensure spelling is correct
Context: ...cker that only covers a small subset of builtin functions. The code at lines 1230-1237 ...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~105-~105: Ensure spelling is correct
Context: ...ncomplete Coverage**: Only 6 out of 80+ builtin functions have correct arity definition...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~114-~114: Ensure spelling is correct
Context: ...iltin functions Scope: Affects all builtin functions requiring 2+ arguments that a...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~133-~133: Ensure spelling is correct
Context: ...r attempts to create Function types for builtin functions using a small lookup table, b...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~135-~135: Ensure spelling is correct
Context: ...he identifier type checking logic where builtin function names are converted to Functio...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~150-~150: Ensure spelling is correct
Context: ...tion Gaps - Missing Functions: Many builtin functions are declared but not implemen...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~190-~190: Ensure spelling is correct
Context: ...ficantly impacts the usability of WFL's builtin functions and should be prioritized for...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.17.2)
bug.md
36-36: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
59-59: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
92-92: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build, Test, Clippy
- GitHub Check: claude-review
🔇 Additional comments (8)
TestPrograms/test_fixed_arity.wfl (1)
1-20: LGTM - Well-structured arity test programThe test program effectively validates the arity fix across different argument counts (0, 2, and 3). The structure is clear with appropriate comments and covers the key scenarios mentioned in the PR objectives. The test logic is sound and should execute successfully.
TestPrograms/arity_bug_test.wfl (1)
1-46: Comprehensive arity validation test programThis test program provides excellent coverage of the arity handling improvements. It systematically tests 0-argument functions (
random), 2-argument functions (contains,push,indexof), and includes appropriate comments about unimplemented functions. The structure with clear section headers makes it easy to understand the test objectives.src/builtins.rs (2)
193-278: Excellent centralized arity implementationThe
get_function_arityfunction provides a comprehensive solution to the arity bug described in the PR. The implementation covers all builtin categories systematically and includes both function name variants (e.g.,indexof/index_of). The warning for unknown functions is appropriate for debugging while maintaining backward compatibility with the default arity of 1.
334-400: Thorough test coverage for arity mappingsThe unit tests provide excellent validation of the arity system:
test_function_arity_mappingsvalidates critical functions that were causing bugstest_all_builtins_have_arity_definitionensures comprehensive coverage- Tests cover edge cases like 0-argument (
random) and both naming variantsThis prevents regression and ensures all builtin functions have reasonable arity definitions.
TestPrograms/arity_bug_trigger.wfl (1)
1-12: Effective negative test case for arity validationThis test is designed to trigger the specific arity bug by attempting to use
minwith 2 arguments when the typechecker incorrectly expects 1. Based on the learnings about TestPrograms/ containing deliberate error cases, this serves as an important negative test to validate that the arity system properly detects and reports type-checking errors.TestPrograms/minimal_arity_test.wfl (1)
1-20: Minimal but effective arity test coverageThe test provides focused coverage of key arity scenarios:
- 0-argument function (
random)- 3-argument function (
substring)- Setup for 2-argument tests with variables
The commented-out
mintest appropriately acknowledges functions not yet implemented while still testing the arity detection mechanism.TestPrograms/arity_success_test.wfl (1)
1-19: Positive validation of arity fixThis test provides excellent positive validation by exercising functions with different arities:
- 0-argument:
random- 3-argument:
substringandclampThe success message clearly indicates when the arity system is working correctly, making this a valuable complement to the negative test cases.
bug.md (1)
1-190: Comprehensive documentation of the arity bugThis documentation provides excellent analysis of the arity bug, including:
- Clear problem description and root cause analysis
- Comprehensive mapping of builtin functions and their correct arities
- Reproduction steps and evidence
- Both minimal and comprehensive fix approaches
The documentation will be valuable for future maintenance and understanding the arity system design decisions.
Introduces new built-in runtime variables for scripts:
program_name: Provides the name of the executing script.current_directory: Offers the current working directory.The static analyzer now recognizes these variables to prevent false undefined variable errors.
Updates the comprehensive arguments test program to demonstrate usage of the new variables and includes necessary syntax corrections.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation / Chores