Skip to content

Fix MATLAB in-out parameter semantics when input and output share a name#217

Open
nallana wants to merge 1 commit intomainfrom
codex/linear-mention-rm-40-fix-matlab-in-out-parameter-semantics
Open

Fix MATLAB in-out parameter semantics when input and output share a name#217
nallana wants to merge 1 commit intomainfrom
codex/linear-mention-rm-40-fix-matlab-in-out-parameter-semantics

Conversation

@nallana
Copy link
Copy Markdown
Contributor

@nallana nallana commented Mar 23, 2026

Motivation

  • Function lowering currently defines outputs after parameters in the same scope which overwrites parameter bindings when an output shares an input name, breaking MATLAB in-out semantics.
  • This causes body references to resolve to the output slot instead of the incoming argument, producing incorrect runtime behavior for common authoring patterns.

Description

  • Preserve the parameter binding when an output name matches an existing parameter by adding fn lookup_current_scope(&self, name: &str) -> Option<VarId> and reusing that VarId instead of defining a new one during AstStmt::Function lowering in crates/runmat-hir/src/lib.rs.
  • Added a HIR-level regression test function_output_reuses_param_binding_when_names_match in crates/runmat-hir/tests/coverage.rs that asserts the output reuses the parameter VarId and that body references resolve to the shared binding.
  • Added runtime regression tests shared_input_output_name_behaves_like_in_out_parameter and shared_input_output_name_preserves_input_value_for_other_outputs in crates/runmat-ignition/tests/functions.rs to verify single-output and multi-output shared-name behaviors at execution time.
  • Updated lowering behavior so subsequent remapping and VM frame creation see a single VarId for shared input/output names, restoring MATLAB-compatible semantics.

Testing

  • Ran cargo test -p runmat-hir function_output_reuses_param_binding_when_names_match -- --nocapture, which passed.
  • Ran cargo test -p runmat-ignition shared_input_output_name -- --nocapture, which passed both added runtime tests.
  • Ran cargo fmt --all to format changes.

Codex Task


Note

Medium Risk
Changes core function-lowering symbol binding semantics, which can affect variable resolution across many functions; scope is small and covered by new HIR and runtime regression tests.

Overview
Fixes MATLAB in/out parameter semantics during HIR lowering by reusing the existing parameter VarId when a function output name matches an already-defined binding in the current function scope (via new lookup_current_scope).

Adds regression coverage at both the HIR level (verifying shared param/output IDs and body variable resolution) and runtime level in runmat-ignition (verifying single- and multi-output shared-name behavior).

Written by Cursor Bugbot for commit aa92e53. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
runmat Ready Ready Preview, Comment, Open in v0 Mar 23, 2026 10:39pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix MATLAB in-out parameter semantics when input and output share a name

1 participant