diff --git a/pkgs/racket-test-core/tests/racket/optimize.rktl b/pkgs/racket-test-core/tests/racket/optimize.rktl index 5cceb2ea3d..2fc0dc291a 100644 --- a/pkgs/racket-test-core/tests/racket/optimize.rktl +++ b/pkgs/racket-test-core/tests/racket/optimize.rktl @@ -3892,6 +3892,21 @@ '(error "oops")) (test-comp '(letrec-values ([(x y) (error "oops")]) 11) '(error "oops")) +(test-comp '(let-values (((y) (read)) (() (error "oops"))) 11) + '(let () (begin (read) (error "oops")))) +(test-comp '(let-values (((y) (read)) (() (error "oops"))) 11) + '(let () (begin (read) (error "oops")))) +(test-comp '(let-values ((() (error "oops")) ((x) 9)) 11) + '(error "oops")) +(test-comp '(let-values ((() (error "oops")) (() (values))) 11) + '(error "oops")) +(test-comp '(let-values (((y) (read)) (() (error "oops")) ((x) 9)) 11) + '(let () (begin (read) (error "oops")))) +(test-comp '(let-values (((y) (read)) (() (error "oops")) (() (values))) 11) + '(let () (begin (read) (error "oops")))) +(test-comp '(error "oops") + '(let () (begin (read) (error "oops"))) + #f) (test-comp '(with-continuation-mark 'x 'y diff --git a/racket/src/racket/src/optimize.c b/racket/src/racket/src/optimize.c index 6405bb0d05..6d0298aa2a 100644 --- a/racket/src/racket/src/optimize.c +++ b/racket/src/racket/src/optimize.c @@ -7523,6 +7523,14 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in naya2->value = scheme_false; naya2 = (Scheme_IR_Let_Value *)naya2->body; } + + if (!pre_body->count && !SCHEME_FALSEP(value)) { + /* Since `value` is not false, this clause must be the one + that is escaping. We'll end up dropping the remaining + clauses and the original body, but we need to keep the + erroring expression. */ + escape_body = value; + } } if (prev_body) @@ -8060,8 +8068,8 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in if (head->num_clauses) seq->array[1] = (Scheme_Object *)head; - else if (found_escapes) { - /* don't need the body, because some RHS escapes */ + else if (found_escapes && SCHEME_FALSEP(head->body)) { + /* don't need the `#f` for the body, because some RHS escapes */ new_body = ensure_noncm(rhs); } else seq->array[1] = head->body;