Skip to content

Nested forall! crashes goto-cc with an invariant abort ("quantifier must not contain side effects") instead of a user-facing error #4902

Open

Description

@kasimte

I tried this code:

#[kani::proof]
fn nested_forall() {
    kani::assume(kani::forall!(|i in (0, 4)| kani::forall!(|j in (0, 4)| i + j < 10)));
    assert!(true);
}

using the following command line invocation:

kani nested_forall.rs -Z quantifiers

with Kani version: reproduces on 0.67.0 and 0.68.0 (latest release as of filing), macOS aarch64.

I expected to see this happen: either the nested quantifier verifies, or a "nested quantifiers are not supported" error.

Instead, this happened: goto-cc aborts (SIGABRT) with a C++ invariant violation:

--- begin invariant violation report ---
Invariant check failed
File: src/ansi-c/goto-conversion/goto_clean_expr.cpp:714 function: clean_expr
Condition: !has_subexpr(expr, ID_side_effect) || (code.operands()[0].id() == ID_side_effect
           && code.operands()[0].get_named_sub()[ID_statement].id() == ID_statement_expression)
Reason: quantifier must not contain side effects

(Backtrace: clean_expr from convert_expression; full trace on request.)

The inner forall! becomes a statement-expression inside the outer quantifier's body, which is what clean_expr rejects (ID_statement_expression). So Kani emits the nested form instead of flattening or rejecting it earlier.

The abort is during goto conversion, before any solver runs, so the backend doesn't matter. With #[kani::solver(z3)] a single forall! verifies but the nested pair still crashes, so this isn't a solver limitation.

Kani already catches some nested-quantifier cases: an indirect variant (a quantified loop invariant calling a contracted function, in a verify-rust-std build at 152c6a8) panics with Detected recursions in the usage of quantifiers. The direct lexical nesting above isn't caught.

Related

Happy to help with reproducers or testing.

Activity

  1. added
    Z-Contracts
    on Sep 28, 2026
  2. added this to the Contracts milestone on Sep 28, 2026
  3. added
    Z-Quantifiers
    on Sep 28, 2026
  4. added
    [C] Bug
    [F] Crash
    on Nov 6, 2026
  5. self-assigned this
    on Nov 6, 2026
  6. added theissue type on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Z-ContractsZ-Quantifiers[C] Bug[F] Crash

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions