stacks-network / clarity-wasm

`clar2wasm` is a compiler for generating WebAssembly from Clarity.
GNU General Public License v3.0
12 stars 12 forks source link

Wrong evaluation order for tuples #393

Closed Acaccia closed 4 months ago

Acaccia commented 5 months ago

The evaluation order of tuples in a compiled clarity code evaluates the tuple fields in the lexicographical order of the keys, while it is evaluated in order of definition in the interpreter.

Here is an example:

#[test]
fn tuple_check_evaluation_order() {
    let snippet = r#"
        (define-data-var foo int 1)
        {
            b: (var-set foo 2),
            a: (var-get foo)
        }
    "#;

    let expected = Value::from(
        TupleData::from_data(vec![
            (ClarityName::from("b"), Value::Bool(true)),
            (ClarityName::from("a"), Value::Int(2)),
        ])
        .unwrap(),
    );

    crosscheck(snippet, Ok(Some(expected)));
}

This snippet has two different answers: