Skip to content

Close non-last parameter types of function templates - #236

Merged
coord-e merged 1 commit into
mainfrom
claude/issue-235-fix-fzuahr
Aug 20, 2026
Merged

Close non-last parameter types of function templates#236
coord-e merged 1 commit into
mainfrom
claude/issue-235-fix-fzuahr

Conversation

@coord-e

@coord-e coord-e commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Fixes #235.

FunctionTemplateTypeBuilder::build gave a non-last parameter's type the scope of the parameters before it. Nothing in that type carries a template except an enum's type arguments, which TemplateTypeBuilder::build refines via build_refined, so for a parameter whose type contains a generic enum the scope leaked into the resulting type and left it open.

BasicBlockType::params holds the enclosing function's arguments, and analyze::basic_block instantiates each of them against the caller's variable through assert_closed. A generic enum in any parameter but the last one therefore aborted with unexpected variable as soon as the body had a block needing its own precondition:

fn get_or(o: Option<i64>, d: i64) -> i64 {
    match o { Some(x) => x, None => d }
}

This builds such a parameter without the scope. The last parameter's own type is already built that way inside build_refined — only its refinement is scoped — so the two paths now agree.

The alternative repair sketched in the issue (carrying the enum-argument templates through the basic-block parameter instead of calling assert_closed) is not taken here: the scope only ever reached enum type arguments, incidentally, and it never reached the last parameter's type at all, so dropping it is the smaller and more consistent change.

Testing

  • tests/ui/{pass,fail}/option_param_order.rs: the get_or shape above, with the fail file breaking only the None-case assertion. Both ICE (exit 101) on main and pass here.
  • All 13 rows of the issue's isolation table verify as safe, including the &self-method shape, and the three soundness spot-checks it lists are still rejected as Unsat.
  • cargo test: 326 UI tests, 2 doc-tests passing; cargo fmt --check clean.

Generated by Claude Code

`FunctionTemplateTypeBuilder::build` gave a non-last parameter's type the
scope of the parameters before it. Nothing in that type carries a template
except an enum's type arguments, which `TemplateTypeBuilder::build` refines
via `build_refined`; for a parameter whose type contains a generic enum the
scope therefore leaked into the resulting type and left it open.

`BasicBlockType::params` holds the enclosing function's arguments, and
`analyze::basic_block` instantiates each of them against the caller's
variable through `assert_closed`. A generic enum in any parameter but the
last one thus aborted with "unexpected variable" as soon as the body had a
block needing its own precondition.

Build such a parameter without the scope, as the last parameter's own type
is already built inside `build_refined`.

Fixes #235

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Closes generic-enum refinements in non-last function parameters, preventing assert_closed panics during branching analysis.

Changes:

  • Builds non-last parameter types without leaking the function-template scope.
  • Adds paired UI tests covering successful and unsatisfiable Option parameter cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/refine/template.rs Builds nested templates with an empty scope and converts the resulting closed type.
tests/ui/pass/option_param_order.rs Verifies correct branching with a non-last Option parameter.
tests/ui/fail/option_param_order.rs Confirms an invalid assertion remains rejected.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coord-e
coord-e merged commit 7e785f7 into main Aug 20, 2026
7 checks passed
@coord-e
coord-e deleted the claude/issue-235-fix-fzuahr branch August 20, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants