Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with nested call to try! function #573

Open
csgui opened this issue Nov 26, 2024 · 1 comment
Open

Issue with nested call to try! function #573

csgui opened this issue Nov 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@csgui
Copy link
Collaborator

csgui commented Nov 26, 2024

A test like below should be possible when nesting a call for try! function.

#[test]
fn stx_transfer_issue() {
        crosscheck(
            "(begin (try! (stx-transfer? u7000000000000 tx-sender 'ST1B5DE8HTXE283QJQV7FCY0VVF29S4W06JEWKF3E))
(try! (stx-transfer? u7000000000000 tx-sender 'STGHNHX1ZCXQWG7N0AQ7PRBCQ34SZARHW7WS1X3A))
(try! (stx-transfer? u7000000000000 tx-sender 'ST1VJ1SYFXYPWZ9VZF30QNEKXZ5GWXGC9HKGGCG2E))
(try! (stx-transfer? u7000000000000 tx-sender 'STCDSX3RBA18YGEKV5QJKPB25S8JCJ7WCCQYVDBZ))
(try! (stx-transfer? u7000000000000 tx-sender 'ST1ZJFBB7H5G0NN2KNMQREFHPSKJMWNEXRG0FYXWM))
(try! (stx-transfer? u7000000000000 tx-sender 'ST35TDDM0PH4K26DW8NNRTN0RY9JVFQZGFQEFQPJ7))
(try! (stx-transfer? u7000000000000 tx-sender 'ST2DJGD3XCFVW6TBST7WH7XVQKNV4T0YN317KXR63))
(try! (stx-transfer? u7000000000000 tx-sender 'ST2AKMX184WNA6ZMG7X43S2FXAARCQ4X138HHS0MJ))
(try! (stx-transfer? u7000000000000 tx-sender 'ST2JHQQH8BXH76WGZ8887WDRB90PTQDW4ETWS44XV))
(try! (stx-transfer? u7000000000000 tx-sender 'ST3CJSAGRTR40WRABA4YKK51FNEK8X0ERK4Q210V5)) (ok true))",
            evaluate("(ok true)"),
        )
    }

current error:

    Invalid input WebAssembly code at offset 3896: type mismatch: expected i32, found i64)))
interpreted: Err(ShortReturn(ExpectedValue(Response(ResponseData { committed: false, data: UInt(1) }))))
  left: Err(Wasm(UnableToLoadModule(WebAssembly translation error

Caused by:
    Invalid input WebAssembly code at offset 3896: type mismatch: expected i32, found i64)))
 right: Err(ShortReturn(ExpectedValue(Response(ResponseData { committed: false, data: UInt(1) }))))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@github-project-automation github-project-automation bot moved this to Status: 🆕 New in Stacks Core Eng Nov 26, 2024
@csgui csgui added the bug Something isn't working label Nov 26, 2024
@Acaccia
Copy link
Collaborator

Acaccia commented Nov 26, 2024

Seems like the issue is with the handling of ShortReturnType errors.
With the compiler, this code works:

(define-private (foo) (if false (ok true) (err u1)))
            
(define-private (foobar) (begin 
    (try! (foo)) 
    (ok true)
))

(foobar)

but if we move the begin out of the function, it should return a ShortReturnType error, but it fails because the expected type is (response bool NoType), but the value stored is (response bool uint).

(define-private (foo) (if false (ok true) (err u1)))
            
(begin
    (try! (foo)) 
    (ok true)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Status: 🆕 New
Development

No branches or pull requests

2 participants