Skip to content

[1297] Add free-variables check rule - #1779

Merged
PinkMagicFly merged 1 commit into
MoganLab:mainfrom
saptadeep12:feat/gf-check-free-variables-v2
Nov 25, 2026
Merged

PinkMagicFly merged 1 commit into
MoganLab:mainfrom
saptadeep12:feat/gf-check-free-variables-v2

Conversation

@saptadeep12

Copy link
Copy Markdown
Contributor

What

Adds a free-variables rule to gf check that warns on unbound identifiers.

Why

Part of the gf check static-checker series. It catches typos and missing imports before runtime, using the analysis foundation from #1740.

How

  • New free-variables rule, split into small modules to stay within max-tree-depth, and registered in rules.scm and config.scm
  • Bindings are resolved from imports (only/except/rename/prefix), top-level defines, record types, and local forms (lambda, let family, named let, do, case-lambda, define* formals, let-values)
  • Quoted data is not analyzed
  • Indeterminate forms are skipped, to avoid false positives (macros, cond-expand, eval, include, unresolvable imports)
  • Keyword symbols and runtime globals such as read are skipped
  • Warnings only; exit status is unchanged
  • Config: "free-variables": {"enabled": true} in gf_check.json; supports excludes and --only free-variables

Testing

  • Tests for each binding form, unbound names, quoted data, skipped forms, enabled: false, excludes, and --only
  • Regression tests for define* formals, keyword symbols, read, and cdddr
  • Clean-cache plain bin/gf check passes, including max-tree-depth and max-file-lines
  • Goldcheck 199/199, R7RS 329/329, Goldfish 1537/1537
  • Repo-wide run: 0 warnings; a deliberate unbound name produced the expected warning
  • gf fmt verified per changed file (Windows; CI runs the full format check on Linux)

Reviewer notes

  • No excludes and no changes to existing rules' config
  • The rule favors missed warnings over false positives

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@da-liii da-liii changed the title Add free-variables check rule [1297] Add free-variables check rule Nov 25, 2026
@PinkMagicFly

Copy link
Copy Markdown
Contributor

Thank you for this PR, @saptadeep12! Adding a conservative, non-blocking free-variables check is a useful step toward catching typos and missing imports earlier. I appreciate the work you put into the scope analysis, import handling, and tests. I will help refine a few edge cases while keeping the rule warning-only, so we can improve it incrementally based on real-world results.

@PinkMagicFly
PinkMagicFly merged commit a2f9920 into MoganLab:main Nov 25, 2026
5 checks passed
@saptadeep12

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for merging @PinkMagicFly. Happy to help :)

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