Skip to content

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

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

hyperpolymath merged 1 commit into
mainfrom
fix/815-import-filter-v2

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

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

… name (#815)

`use Console;` made a parameter named `log` pull in a Console.log
import. Now program_free_names skips the fn's own parameters, and
resolve tracks local binders in scope.

When a local captures a qualified `Mod.f` call, resolve now gives a
clear error ("rename the local"). Before, the program linked wrong.
Full support for that case needs the qualifier carried through the
type checker and the backends.

Refs #815

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZjyGGiPhiEUxNGPwsr
@gitnotebooks

gitnotebooks Bot commented Nov 27, 2026

Copy link
Copy Markdown

@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-27T10:29:10.961107Z
We couldn’t complete this review. Comment @codex review to try again.
6ad4fbf PR opened
ℹ️ 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.

@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

    • Corrected handling of qualified imports when a local parameter or binding has the same name. These cases now produce a clear shadowing error instead of resolving ambiguously.
    • Module imports are no longer emitted unnecessarily when an imported function name is used only as a local parameter.
    • Qualified calls to imported functions continue to emit the required module import.
  • Tests

    • Added coverage for import generation and shadowing errors.

The change tracks local bindings while lowering qualified imported values and excludes function parameters from names used for import filtering. End-to-end tests cover import selection and shadowing errors.

Changes: Qualified Import Resolution

Layer / File(s) Summary
Scope-aware qualified path lowering
lib/resolve.ml
Lowering tracks bindings from parameters, patterns, and sequential block lets across nested expressions. It raises a parse error when a local binding shadows a qualified imported value.
Import filtering and end-to-end tests
lib/codegen.ml, test/test_e2e.ml
Function parameters no longer count as import-use names. Tests cover parameter-only imports, qualified calls retaining imports, and shadowing errors.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • Issue 815 — This change addresses the parameter-name import-filtering case. The issue also describes qualified-call support that remains incomplete.

Possibly related PRs

Suggested reviewers: metadatastician

Merge Risk: Minimal · up to 6ad4f

The change stops a function parameter from pulling in a same-named module function import. It also turns a qualified call captured by a local of the same name into a clear error instead of a wrong link. No concrete defect was found. Combining a same-named parameter with a qualified call is still unsupported and is left as follow-up work.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a function's own parameter no longer triggers a module function import (fix in codegen, issue #815). It matches the raw summary, which says program_free_names now excl…
Description check Passed The description relates directly to the changeset. It explains the replacement of PR #820, the parameter-name skip in program_free_names, the scope tracking in lower_qualified_value_paths, the new sha…
Linked Issues check Passed The only linked issue is #820. It is closed and marked as historical context only. Its acceptance criteria are not active requirements for this pull request. No active directly linked target remains, …
Out of Scope Changes check Passed All changed areas connect to the stated fix for the #815 parameter-shadowing problem. lib/codegen.ml: program_free_names skips a function's own parameter names, so a parameter named log under use Cons…
Full details: Title check

Explanation

The title names the main change: a function's own parameter no longer triggers a module function import (fix in codegen, issue #815). It matches the raw summary, which says program_free_names now excludes parameter names from import filtering. The title is specific and accurate, though the parameter-plus-qualified-call case remains unresolved, which the title does not need to cover.

Full details: Description check

Explanation

The description relates directly to the changeset. It explains the replacement of PR #820, the parameter-name skip in program_free_names, the scope tracking in lower_qualified_value_paths, the new shadowing error, and the three e2e tests. It also states a known remaining gap, which matches the scope of the changes.

Full details: Linked Issues check

Explanation

The only linked issue is #820. It is closed and marked as historical context only. Its acceptance criteria are not active requirements for this pull request. No active directly linked target remains, so no linked-issue coding requirements apply. The pull request uses "Refs #815" and describes a known remaining gap (issue test 2, same-named parameter plus qualified call, still does not compile). That gap is stated as follow-up work and is not a requirement of this pull request.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the stated fix for the #815 parameter-shadowing problem. lib/codegen.ml: program_free_names skips a function's own parameter names, so a parameter named log under use Console does not add a Console.log import. lib/resolve.ml: lower_qualified_value_paths tracks local binders in scope and reports a clear error when a local captures a qualified Mod.fn call. test/test_e2e.ml: three tests cover the parameter-only case, the qualified call case, and the capture error case, and they register in modmut561_tests. The PR description states that the conflict resolution only merges test sets. No unrelated change was identified from the summary. The resolve.ml change is large (+95/-65). The summary attributes this to scope tracking, but I did not read the hunks to confirm that no unrelated refactoring is included.

  • 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: 8db825c5-f2a5-4f4d-bade-89e9a2e4fe19
Commits

Reviewing files that changed from the base of the PR and between e94a5f9 and 6ad4fbf.

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: 5

  • GitHub Check: CodeRabbit
  • GitHub Check: lint
  • GitHub Check: bench-visibility
  • GitHub Check: build
  • GitHub Check: coverage-visibility

@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit ee211d3 into main Nov 27, 2026
18 checks passed
@hyperpolymath
hyperpolymath deleted the fix/815-import-filter-v2 branch November 27, 2026 10:38
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.

3 participants