hirosystems / clarinet

Write, test and deploy high-quality smart contracts to the Stacks blockchain and Bitcoin.
https://hiro.so/clarinet
GNU General Public License v3.0
291 stars 130 forks source link

Having a "+" before a tuple key breaks the parser #536

Closed hugocaillard closed 1 year ago

hugocaillard commented 1 year ago

Code to reproduce

(define-public (hello-world)
  (if (is-eq block-height u1)
    (ok (print { + msg: "Hello world", tip: block-height, sender: tx-sender }))
    (err (print { msg: "Hello world", tip: block-height, sender: tx-sender }))
  )
)

Issue 1

It will result in the parser detecting many errors (see screenshot):

Screenshot 2022-09-14 at 20 51 19

Issue 2

With 2 +s, the parser will crash

(define-public (hello-world)
  (if (is-eq block-height u1)
    (ok (print { + msg: "Hello world", tip: block-height, sender: tx-sender }))
    ;; second "+"here
    (err (print { + msg: "Hello world", tip: block-height, sender: tx-sender }))
  )
)
Screenshot 2022-09-14 at 20 44 14

Stack trace:

browserServerMain.js:1 panicked at 'index out of bounds: the len is 860 but the index is 860', components/clarity-repl/src/repl/ast/parser/mod.rs:161:25

Stack:

Error
    at P.e.wbg.__wbg_new_693216e109162396 (https://hugoclrd.vscode-unpkg.net/hugoclrd/obscurity-lsp/0.1.35/extension/server/dist/browserServerMain.js:1:163415)
    at console_error_panic_hook::hook::hf8cb89282173fedb (wasm://wasm/0194b50a:wasm-function[2114]:0x354feb)
    at core::ops::function::Fn::call::h9e0390046b6368fe (wasm://wasm/0194b50a:wasm-function[5636]:0x3e3e01)
    at std::panicking::rust_panic_with_hook::h8888bbc201384d7b (wasm://wasm/0194b50a:wasm-function[3342]:0x3b5ccf)
    at std::panicking::begin_panic_handler::{{closure}}::hea311ea2bd92a293 (wasm://wasm/0194b50a:wasm-function[3817]:0x3cc7c8)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h7df6c1a4b8949645 (wasm://wasm/0194b50a:wasm-function[4864]:0x3e1204)
    at rust_begin_unwind (wasm://wasm/0194b50a:wasm-function[4500]:0x3dda8d)
    at core::panicking::panic_fmt::h18b15be283411c65 (wasm://wasm/0194b50a:wasm-function[4512]:0x3ddd60)
    at core::panicking::panic_bounds_check::h884af9d3b9389f93 (wasm://wasm/0194b50a:wasm-function[4069]:0x3d46c4)
    at clarity_repl::repl::ast::parser::Parser::parse_tuple::hc5e1ed8419e5e9f9 (wasm://wasm/0194b50a:wasm-function[205]:0x138c22)

Note

👉 It can be reproduced with clarinet check or the VSCode extension

obycode commented 1 year ago

I have a fix for this which will go into stacks-network/stacks-blockchain in the PR with some other parser v2 fixes.

saralab commented 1 year ago

PR on blockchain merged, closing this