Skip to content

fix(codegen): do not import a module fn for a parameter with the same name (#815) - #820

Merged
hyperpolymath merged 0 commit into
mainfrom
fix/815-import-filter
Nov 27, 2026
Merged

hyperpolymath merged 0 commit into
mainfrom
fix/815-import-filter

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Refs #815

Summary

  • program_free_names (lib/codegen.ml) now skips a fn's own parameter names. A parameter named log under use Console; no longer adds a Console.log import.
  • lower_qualified_value_paths (lib/resolve.ml) tracks the local binders in scope: let, lambda, match, handler, for and fn params.
  • When a local captures a qualified Mod.f call, resolve gives a clear error: "Mod.fn is shadowed by a local fn in scope; rename the local". Before, that program linked wrong.

Gap that remains

Issue test 2 (same param plus a qualified call: import kept and links) now gives the clear error. It does not compile yet. Full support needs the qualifier carried through the type checker and the backends (size L). This PR uses "Refs", not "Closes".

Tests

  • 3 new e2e tests: param only (no import), qualified call (import kept), capture (error).
  • Suites: e2e 660, WASM 47, Bun-ESM 41, native Bun 8. All pass.

Generated by Claude Code

@gitnotebooks

gitnotebooks Bot commented Nov 27, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Qualified calls through imported modules now resolve correctly when local names are in scope. If a local name shadows the qualified field, compilation reports a clear error instead of rewriting the call.
    • Function parameters are no longer incorrectly treated as free names, helping ensure generated output reflects the program’s actual name usage.
    • Import handling now distinguishes between calls to imported functions and names supplied by function parameters, including Console.log calls.

Resolver lowering now tracks local bindings when handling imported qualified paths. Code generation excludes function parameters from free-name collection. End-to-end tests cover parameter-only, explicit qualified, and shadowed qualified calls.

Changes: Imported qualifier handling

Layer / File(s) Summary
Scope-aware qualified path lowering
lib/resolve.ml
Resolver lowering carries imported qualifiers and bound local names through expressions, statements, patterns, and function bodies. It raises a parse error when a qualified path's field name is locally bound.
Free-name collection and import tests
lib/codegen.ml, test/test_e2e.ml
program_free_names filters function parameters from body names. End-to-end tests check parameter-only imports, explicit qualified calls, and errors for locally shadowed qualified calls.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • Issue 815: The PR covers the parameter-only case and reports an error for the qualified-call case. The issue's case where Mod.f(..) retains its import and links remains unimplemented.

Suggested reviewers: metadatastician

Merge Risk: Minimal · up to fbf1f

A function parameter named log no longer pulls in an unneeded Console.log import under use Console;. A qualified call captured by a local of the same name now fails with a clear rename error instead of linking to the wrong function. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a function parameter with the same name as an imported module function no longer triggers an import under codegen. It matches the raw summary (program_free_names skips…
Description check Passed The description relates directly to the changeset. It describes the program_free_names change in lib/codegen.ml, the local-binder tracking in lower_qualified_value_paths in lib/resolve.ml, the new sha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a function parameter with the same name as an imported module function no longer triggers an import under codegen. It matches the raw summary (program_free_names skips parameter names) and the PR objectives. It also carries the issue reference #815, which is acceptable.

Full details: Description check

Explanation

The description relates directly to the changeset. It describes the program_free_names change in lib/codegen.ml, the local-binder tracking in lower_qualified_value_paths in lib/resolve.ml, the new shadowing error, the three new e2e tests, and the remaining gap for the qualified-call case.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 4f6533b7-9d0a-4647-9bc8-5d9c708e6b05
Commits

Reviewing files that changed from the base of the PR and between bb595b9 and fbf1f7a.

Files selected for processing: 3

  • lib/codegen.ml
  • lib/resolve.ml
  • test/test_e2e.ml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: semgrep-cloud-platform/scan
Additional comments: 2

lib/resolve.ml: 1

1045-1045: Data Integrity & Integration

The reviewer's premise that pattern_binders omits record-punning binders is contradicted. For PatRecord fields with no sub-pattern, the helper returns the field name. The guard therefore sees a shorthand-bound log and applies the same refusal as for a parameter. No capture path is established.

lib/codegen.ml: 1

4046-4046: Functional Correctness

The concern about enclosing parameters in a lambda does not hold. lower_qualified_value_paths extends the enclosing binder set when it enters a lambda, so log stays bound inside || { Console.log("x"); 0 }. The lowering then rejects the qualified call with the shadowing error instead of flattening it to a bare log call. The codegen filter at lib/codegen.ml:4046 therefore does not expose the lambda to the claimed capture.

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 27, 2026 01:07
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-27T01:07:38.101237Z
We couldn’t complete this review. Comment @codex review to try again.
5e2f5e9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@hyperpolymath
hyperpolymath force-pushed the fix/815-import-filter branch 3 times, most recently from e1d9f76 to fbf1f7a Compare November 27, 2026 02:06
@hyperpolymath
hyperpolymath merged commit e94a5f9 into main Nov 27, 2026
1 of 12 checks passed
@hyperpolymath
hyperpolymath deleted the fix/815-import-filter branch November 27, 2026 02:16
@sonarqubecloud

Copy link
Copy Markdown

hyperpolymath added a commit that referenced this pull request Nov 27, 2026
… name (#815) (#824)

Refs #815

Replaces #820. A push error of mine put main's tip on the #820 branch,
so GitHub closed #820 as "merged" with no change. This PR has the same
change, rebased on main (after #823). The only new work is the conflict
in test/test_e2e.ml: both PRs add tests to `modmut561_tests`, and this
PR keeps both sets.

## Summary
- `program_free_names` (lib/codegen.ml) now skips a fn's own parameter
names. A parameter named `log` under `use Console;` no longer adds a
`Console.log` import.
- `lower_qualified_value_paths` (lib/resolve.ml) tracks the local
binders in scope: let, lambda, match, handler, for and fn params.
- When a local captures a qualified `Mod.f` call, resolve gives a clear
error: "`Mod.fn` is shadowed by a local `fn` in scope; rename the
local". Before, that program linked wrong.

## Gap that remains
Issue test 2 (same param plus a qualified call: import kept and links)
now gives the clear error. It does not compile yet. Full support needs
the qualifier carried through the type checker and the backends (size
L). This PR uses "Refs", not "Closes".

## Tests
- 3 new e2e tests: param only (no import), qualified call (import kept),
capture (error).
- `dune runtest` main suite: 662 tests pass (659 on main plus these 3).

---
_Generated by [Claude Code](https://claude.ai/code)_

Co-authored-by: Claude <noreply@anthropic.com>
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