Skip to content

fix(move-compiler): prevent panic on assert! with wrong arg count#25471

Open
lau90eth wants to merge 2 commits intoMystenLabs:mainfrom
lau90eth:fix-assert-panic-25459
Open

fix(move-compiler): prevent panic on assert! with wrong arg count#25471
lau90eth wants to merge 2 commits intoMystenLabs:mainfrom
lau90eth:fix-assert-panic-25459

Conversation

@lau90eth
Copy link

Fixes #25459

Problem

The Move compiler would panic with called Result::unwrap() on an Err value when assert! was called with more than 2 arguments.

Root Cause

In hlir/translate.rs, the code used .unwrap() when converting the argument list to a fixed-size array [TI; 2]:

E::ExpList(arg_list) => arg_list.try_into().unwrap(),

When assert! received 3+ arguments, try_into() failed and unwrap() caused a compiler panic.
Solution
Replaced .unwrap() with proper error handling using match:
E::ExpList(arg_list) => match arg_list.try_into() {
    Ok(arr) => arr,
    Err(_) => {
        context
            .env
            .add_diag(ice!((eloc, "assert! expects 1 or 2 arguments, but got a different number")));
        return error_exp(eloc);
    }
},

Changes
Fixed 2 locations in hlir/translate.rs (lines 905 and 943)
Added test case bad_assert_args to prevent regression
Testing
assert!(true, 0, 1) now produces a graceful error instead of panic
Valid cases (assert!(true) and assert!(true, 0)) continue to work

@vercel
Copy link

vercel bot commented Feb 14, 2026

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

Project Deployment Actions Updated (UTC)
multisig-toolkit Error Error Feb 14, 2026 8:50pm
sui-docs Error Error Feb 14, 2026 8:50pm
sui-kiosk Error Error Feb 14, 2026 8:50pm

Request Review

ebmifa and others added 2 commits February 14, 2026 21:48
Fixes MystenLabs#25459

The compiler would panic with 'called Result::unwrap() on an Err value'
when assert! was called with more than 2 arguments. This happened in
hlir/translate.rs when trying to convert the argument list to a fixed-size
array of 2 elements.

Now it gracefully handles the error and reports a proper diagnostic message
instead of crashing.

Test case added: bad_assert_args
@vercel
Copy link

vercel bot commented Feb 14, 2026

Deployment failed with the following error:

Invalid vercel.json file provided

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.

Compiler panic in HLIR pass: unwrap() on assert! with wrong number of arguments

2 participants