Skip to content

Add autofix suggestion for method calls mistaken as field access#42

Open
Wilfred wants to merge 1 commit intomainfrom
claude/autofix-list-len-method-qzm8E
Open

Add autofix suggestion for method calls mistaken as field access#42
Wilfred wants to merge 1 commit intomainfrom
claude/autofix-list-len-method-qzm8E

Conversation

@Wilfred
Copy link
Copy Markdown
Owner

@Wilfred Wilfred commented Feb 18, 2026

Summary

This PR adds an autofix suggestion when a user attempts to access a field that doesn't exist but matches a method name on the type. For example, accessing items.len will now suggest items.len() with an automatic fix.

Key Changes

  • Enhanced error diagnostics in type_checker.rs to detect when a field access name matches an available method on the type
  • When a mismatch is detected, the error message now includes a helpful suggestion: "Did you mean method_name()?"
  • Added an Autofix that automatically converts the field access to a method call (e.g., items.lenitems.len())
  • Applied this improvement to two error paths in the type checker (struct field access and general field access)
  • Added test case list_len_method.gdn demonstrating the autofix in action
  • Updated CHANGELOG.md to document the new feature

Implementation Details

  • The fix retrieves available methods from the type environment and checks if the accessed name matches any method
  • Only generates the suggestion and autofix when a matching method is found
  • The autofix includes both a description and the corrected code text for IDE integration

https://claude.ai/code/session_014eWiDph7M3enBMha1hczaQ

When a user writes `some_list.len` instead of `some_list.len()`, the
type checker now detects that the accessed name matches a method on
the receiver type and suggests adding parentheses. This applies to
all types with methods, not just List.

https://claude.ai/code/session_014eWiDph7M3enBMha1hczaQ
@Wilfred Wilfred force-pushed the claude/autofix-list-len-method-qzm8E branch from cf2eb8e to 21c2cde Compare March 23, 2026 08:04
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