Skip to content

fix(hy-emit): a bare-error result is an error slot, not a value (#726) - #736

Open
airdropia wants to merge 2 commits into
limitlessprojects:mainfrom
airdropia:fix/try-bare-error
Open

airdropia wants to merge 2 commits into
limitlessprojects:mainfrom
airdropia:fix/try-bare-error

Conversation

@airdropia

Copy link
Copy Markdown
Contributor

What

fn step() error + step()? passes hyb check, then the emitted Go fails
go build:

func run() error {
    hyT0, hyErr1 := step()        // step returns ONE value
    if hyErr1 != nil { ... }
}
// out.go: error: assignment mismatch: 2 variables but step returns 1 value

Why it happened

The fn-shape collector (hy-emit/src/lib.rs) recorded (f.results.len(), err, ...) — a trailing error result counted as a value AND as the error slot.
fn step() error has exactly one Go result, so the ? hoister's (1, true)
reading produced hyT0, hyErr1 := step(), which Go rejects. run()? in
main hit the same shape.

The fix

The value count now excludes the trailing error slot:

let value_count = if err { f.results.len() - 1 } else { f.results.len() };

The hoister's (0, true) special case (already present in stmt.rs —
hyErrN := call with no value temp) now applies to bare-error user functions
the same way it already applied to rust-crate methods like
serde_json.value.set(...).

Files: compiler/crates/hy-emit/src/lib.rs (one line + comment).

Tests

New emitter test bare_error_fn_under_try_emits_zero_value_temps pins the
emitted shape: hyErr0 := step() and no hyT0, hyErr1 := step().

No local Go toolchain: CI (parse + emit tests + go build of examples) is the
oracle.

`fn step() error` has ONE Go result. The fn-shape collector counted the
trailing error as a value too, so `step()?` desugared to
`hyT0, hyErr1 := step()` and the emitted Go failed go build with an
assignment mismatch. The value count now excludes the trailing error slot.
Upstream added test_emit_t9_set_surface in the same integration test file;
kept it alongside the new bare-error regression test.
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.

1 participant