Repository navigation
Description
The smallest .hy program that demonstrates it
package main
fn step() error {
return nil
}
fn run() error {
step()?
return nil
}
fn main() {
run()?
fmt.println("ok")
}Commit: main @ 91222f3e6042def689713806f7e66f1875689f8a. hyb built from that commit (cargo build -p hyb, rust 1.99.0; banner build pins: go1.26.9 / rust 1.99.0). Go 1.26.9, linux/amd64.
$ hyb check try_bare_error_call.hy
try_bare_error_call.hy: OK (0 diagnostics)
$ hyb build try_bare_error_call.hy -o try_bare_error_call
emitted try_bare_error_call.go
go build failed:
# command-line-arguments
out/try_bare_error_call.go:14:18: assignment mismatch: 2 variables but step returns 1 value
out/try_bare_error_call.go:24:19: assignment mismatch: 2 variables but run returns 1 value
What the checker should say
Nothing. The program is valid and should print ok.
- SPEC-LANGUAGE E1 (line 972): "Functions signal failure by returning
erroras the final result:(string, error),(total int, err error), or bareerror." - E3 (line 985) / E4 (line 1009):
?applies to an error-returning call inside a function whose results end inerror, or inmain. A statementstep()?on anerror-only function is the simplest legal use. It is the Hybrid spelling ofif err := step(); err != nil { return err }.
What it actually said
OK (0 diagnostics), and then the emitted Go does not compile:
func run() error {
hyT0, hyErr1 := step() // step returns one value
if hyErr1 != nil {
return hyErr1
}
hyT0 // also: `hyT0` evaluated but not used
return nil
}main gets the same broken pair inside its E6 wrapper.
The same happens for methods: fn (s *store) save() error + s.save()? emits hyT0, hyErr1 := s.save().
Cause: hy-emit has a dedicated zero-result path for this exact shape (Stmt::Expr → zero_try, and hoist_one_try emits hyErrN := call when call_results(..) == Some((0, true)), compiler/crates/hy-emit/src/stmt.rs around lines 24 and 766). But for user functions call_results reads fn_shapes, which lib.rs (around line 626) fills with f.results.len(). That count includes the trailing error, so fn step() error is recorded as (1, true) and never matches (0, true). The rust-descriptor and curated-method sources use the "non-error results" count, so only user-declared functions and methods hit this. User methods are not in fn_shapes at all (call_results returns None), so they fall through to the two-name form too.
Claimed severity
P2: claim-precision bug (accepted value should have been unproven)
(Accepted-but-unbuildable on a core E1/E3 pattern: any helper fn validate(...) error called with ?. Proposed tier: Medium.)
Anything else
- Not a duplicate of [soundness]
?is never checked against its operand — on option/int/closure-local calls accepted with 0 diagnostics and emits non-compiling Go (E4/T20 unimplemented) #155 / PRs fix(hy-check): implement the E4 / T20 / E3b rules for the try operator #166 fix: resolve hy-check:?operator never validated against operand or enclosing scope (E4, T20, E3b) + closure error scoping in hy-emit (#155) #469. Those are about?on calls that do not returnerror(option/int results, closures with no error result), which should be rejected. This program is valid. The bug is in lowering a legal?. - Suggested fix: store
results.len() - (err as usize)infn_shapes(and check the otherfn_shapesreaders that use the count), and give user methods acall_resultsentry frommethod_decls. Add a corpus ACCEPT program withstep()?on a bare-errorfn and method.
Activity
isHeSatoshi commentedon Oct 19, 2026
Opened #791 with both halves of the fix, since your root-cause read was exactly right and the repro was unambiguous.
Confirming your diagnosis and adding one thing it did not mention: user methods needed a second registry, not just a corrected count. call_results resolves a descriptor member through \lookup_member, but a user struct is not in \SHAPES, so \s.save()?\ found no entry at all rather than a wrong one. I added \method_results\ keyed (receiver struct, method), filled from \ile.fns()\ — a method is a \Decl::Fn\ with a receiver, so it was already in that iterator and only needed the receiver's struct name to become findable. It joins through the existing \�ar_struct\ registry.
Also worth recording: the fixture has to be an ACCEPT, not a REJECT. \hyb check\ reported 0 diagnostics both before and after, so a reject fixture would have been the wrong shape and would have passed for the wrong reason. The real assertion lives at the emitter level (\hy-emit/tests/bare_error_try_lowering.rs, 7 tests) because the corpus harness cannot see a lowering bug behind a clean check — which is exactly how this survived.
Verified on main @ aa4a9d9: all 4 bare-\error\ shapes (free fn, fn with args, user method, in \main) ACCEPT+FAIL before and ACCEPT+BUILD after; the two-result forms still build, with a test pinning that the value token is NOT collapsed for a call that genuinely has one. Corpus 113 -> 114, 114/114 agreement, differential 76/76 reject and 36/38 accept (baseline).
emitter(try): a bare-`error` call under `?` lowers to a one-name assi…
emitter(try): a bare-`error` call under `?` lowers to a one-name assi…
fix(hy-emit): avoid allocating value temp on bare error try lowering (f…
fix(hy-emit): avoid allocating value temp on bare error try lowering (f…
airdropia commentedon Oct 29, 2026
PR #2246 opened: fix(hy-emit): a bare-error result is an error slot, not a value. CI pending.
fix(hy-emit): a bare-error result is an error slot, not a value (limi…
airdropia commentedon Oct 29, 2026
PR #2246 rebased onto current main (1f0ff97), now MERGEABLE. The conflict was in hy-emit tests.rs — the test was re-added cleanly without touching main's newer defer tests.
fix(hy-emit): a bare-error result is an error slot, not a value (limi…
fix(hy-emit): avoid allocating value temp on bare error try lowering (f…
Merge PR limitlessprojects#2246: fix(hy-emit): a bare-error result is…
Merge PR #2405: f()? on a name-bound closure knows its result count (f…