Skip to content
Snippets Groups Projects
Commit eaf9c44b authored by Rémi's avatar Rémi
Browse files

Merge branch 'er433/fix/unpack-typer' into 'dev'

Fix: check that Bytes.unpack's annotated type is an option

See merge request !1245
parents f958486d 674b0f37
No related branches found
No related tags found
2 merge requests!1561Draft: [LIGO-419] Fix religo grammar,!1245Fix: check that Bytes.unpack's annotated type is an option
Pipeline #350286914 passed with warnings
author: er433
merge_request: '1245'
title: 'Fix: check that Bytes.unpack''s annotated type is an option'
type: fixed
......@@ -2049,3 +2049,13 @@ let%expect_test _ =
{ parameter unit ;
storage int ;
code { CDR ; PUSH nat 2 ; PUSH nat 1 ; DIG 2 ; ADD ; ADD ; NIL operation ; PAIR } } |}]
(* wrong annotation in Bytes.unpack *)
let%expect_test _ =
run_ligo_bad [ "compile-expression" ; "--init-file" ; bad_contract "bad_annotation_unpack.mligo" ; "cameligo" ; "x" ] ;
[%expect {|
File "../../test/contracts/negative/bad_annotation_unpack.mligo", line 1, characters 9-42:
1 | let x = (Bytes.unpack (Bytes.pack "hello") : string)
Incorrect argument.
Expected an option, but got an argument of type "string". |}]
......@@ -209,9 +209,13 @@ let int ~raise loc : typer = typer_1 ~raise loc "INT" @@ fun t ->
let bytes_pack ~raise loc : typer = typer_1 ~raise loc "PACK" @@ fun _t ->
t_bytes ()
let bytes_unpack ~raise loc = typer_1_opt ~raise loc "UNPACK" @@ fun input output_opt ->
let bytes_unpack ~raise loc = typer_1_opt ~raise loc "UNPACK" @@ fun input tv_opt ->
let () = trace_option ~raise (expected_bytes loc input) @@ assert_t_bytes input in
trace_option ~raise (not_annotated loc) @@ output_opt
match tv_opt with
| None -> raise.raise (not_annotated loc)
| Some t ->
let t = trace_option ~raise (expected_option loc t) @@ get_t_option t in
t_option t
let hash256 ~raise loc = typer_1 ~raise loc "SHA256" @@ fun t ->
let () = trace_option ~raise (expected_bytes loc t) @@ assert_t_bytes t in
......
let x = (Bytes.unpack (Bytes.pack "hello") : string)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment