software-mansion / protostar

Protostar is a toolchain for developing and testing Starknet contracts
https://docs.swmansion.com/protostar/
MIT License
248 stars 48 forks source link

`loop` bug #2071

Open piotmag769 opened 1 year ago

piotmag769 commented 1 year ago

It bugs when compiling from sierra to casm. Protostar 0.13.0, Cairo 1.1.0, minimal reproducible example:

use array::ArrayTrait;

#[test]
fn essa() {
   let mut calldata = ArrayTrait::new();
   calldata.append(1);
   loop {
        match calldata.pop_front() {
            Option::Some(call) => {},
            Option::None(_) => {
                break ();
            }
        };
    };
   assert(1 == 1, '');
}

Console output:

Collected 1 suite, and 1 test case (3.03)
  0%|                                                                      [0/1]
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: UnrecognizedToken { token: (1238, Token(13, "["), 1239), expected: ["\"(\"", "\")\"", "\",\"", "\":\"", "\"::\"", "\";\"", "\"<\"", "\"=\"", "\">\"", "\"@\"", "\"with_info\""] }', crates/cairo-lang-protostar/src/lib.rs:39:73
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[UNEXPECTED_EXCEPTION] tests/test_hello_starknet.cairo
Traceback (most recent call last):
  File "protostar/cairo/bindings/cairo_bindings.py", line 142, in handle_bindings_errors
  File "protostar/cairo/bindings/cairo_bindings.py", line 132, in compile_protostar_sierra_to_casm
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: UnrecognizedToken { token: (1238, Token(13, "["), 1239), expected: ["\"(\"", "\")\"", "\",\"", "\":\"", "\"::\"", "\";\"", "\"<\"", "\"=\"", "\">\"", "\"@\"", "\"with_info\""] }

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "protostar/cairo_testing/cairo1_test_runner.py", line 222, in suite_exception_handling
  File "protostar/cairo_testing/cairo1_test_runner.py", line 199, in run_test_suite
  File "protostar/cairo/bindings/cairo_bindings.py", line 136, in compile_protostar_sierra_to_casm
  File "contextlib.py", line 137, in __exit__
  File "protostar/cairo/bindings/cairo_bindings.py", line 148, in handle_bindings_errors
protostar.cairo.bindings.cairo_bindings_exception.CairoBindingException: A unexpected type of error occurred in binding compile_protostar_sierra_to_casm: called `Result::unwrap()` on an `Err` value: UnrecognizedToken { token: (1238, Token(13, "["), 1239), expected: ["\"(\"", "\")\"", "\",\"", "\":\"", "\"::\"", "\";\"", "\"<\"", "\"=\"", "\">\"", "\"@\"", "\"with_info\""] }

Unexpected Protostar error. Report it here:
https://github.com/software-mansion/protostar/issues

A unexpected type of error occurred in binding compile_protostar_sierra_to_casm: called `Result::unwrap()` on an `Err` value: UnrecognizedToken { token: (1238, Token(13, "["), 1239), expected: ["\"(\"", "\")\"", "\",\"", "\":\"", "\"::\"", "\";\"", "\"<\"", "\"=\"", "\">\"", "\"@\"", "\"with_info\""] }
abulenok commented 1 year ago

It seems that this bug is about adding a loop This should be enough to reproduce it

#[test]
fn please_dont_fail() {
    loop {
        break ();
    };
    assert(1 == 1, '');
}