- Don't allow to chain let bindings like: let a = let b = 2.

- Give a proper warning when creating an incorrect let binding.
This commit is contained in:
Sander Spies 2020-02-03 10:53:44 +01:00
parent 87aa50f097
commit bf985797fb
3 changed files with 764 additions and 1033 deletions

View File

@ -0,0 +1,22 @@
open Cli_expect
let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/gitlab_111.religo" ; "main" ] ;
[%expect {|
ligo: : Parse error in file "gitlab_111.religo", line 28, characters 0-3, after "=" and before "let":
This is an incorrect let binding.
-
Examples of correct let bindings:
let a: int = 4;
let (a: int, b: int) = (1, 2);
let func = (a: int, b: int) => a + b;
{}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |} ] ;

View File

@ -418,13 +418,13 @@ unit:
(* Expressions *) (* Expressions *)
interactive_expr: interactive_expr:
expr EOF { $1 } expr_with_let_expr EOF { $1 }
expr: expr:
base_cond__open(expr) | switch_expr(base_cond) { $1 } base_cond__open(expr) | switch_expr(base_cond) { $1 }
base_cond__open(x): base_cond__open(x):
base_expr(x) | conditional(x) { $1 } base_expr(x) | conditional(expr_with_let_expr) { $1 }
base_cond: base_cond:
base_cond__open(base_cond) { $1 } base_cond__open(base_cond) { $1 }
@ -567,7 +567,7 @@ fun_expr:
in EFun {region; value=f} } in EFun {region; value=f} }
base_expr(right_expr): base_expr(right_expr):
let_expr(right_expr) | disj_expr_level | fun_expr { $1 } disj_expr_level | fun_expr { $1 }
conditional(right_expr): conditional(right_expr):
if_then_else(right_expr) | if_then(right_expr) { $1 } if_then_else(right_expr) | if_then(right_expr) { $1 }
@ -609,6 +609,7 @@ base_if_then_else:
closed_if: closed_if:
base_if_then_else__open(closed_if) base_if_then_else__open(closed_if)
| switch_expr(base_if_then_else) { $1 } | switch_expr(base_if_then_else) { $1 }
| let_expr(expr_with_let_expr) { $1 }
switch_expr(right_expr): switch_expr(right_expr):
"switch" switch_expr_ "{" cases(right_expr) "}" { "switch" switch_expr_ "{" cases(right_expr) "}" {
@ -896,8 +897,12 @@ update_record:
rbrace = $6} rbrace = $6}
in {region; value} } in {region; value} }
expr_with_let_expr:
expr { $1 }
| let_expr(expr_with_let_expr) { $1 }
sequence_or_record_in: sequence_or_record_in:
expr ";" sep_or_term_list(expr,";") { expr_with_let_expr ";" sep_or_term_list(expr_with_let_expr,";") {
let elts, _region = $3 in let elts, _region = $3 in
let s_elts = Utils.nsepseq_cons $1 $2 elts let s_elts = Utils.nsepseq_cons $1 $2 elts
in PaSequence {s_elts; s_terminator=None} in PaSequence {s_elts; s_terminator=None}
@ -907,7 +912,7 @@ sequence_or_record_in:
let r_elts = Utils.nsepseq_cons $1 $2 elts let r_elts = Utils.nsepseq_cons $1 $2 elts
in PaRecord {r_elts; r_terminator = None} in PaRecord {r_elts; r_terminator = None}
} }
| expr ";"? { PaSingleExpr $1 } | expr_with_let_expr ";"? { PaSingleExpr $1 }
sequence_or_record: sequence_or_record:
"{" sequence_or_record_in "}" { "{" sequence_or_record_in "}" {

File diff suppressed because it is too large Load Diff