From 6beccd09a8f020b12f1cf8736ee8ea651cca0f9a Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Sun, 2 Feb 2020 18:08:16 +0100 Subject: [PATCH] Wrong function arguments error message. --- src/bin/expect_tests/syntax_error_tests.ml | 19 +++++++++++++++++++ src/passes/1-parser/reasonligo.ml | 9 ++++++++- .../negative/error_function_arguments.religo | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/negative/error_function_arguments.religo diff --git a/src/bin/expect_tests/syntax_error_tests.ml b/src/bin/expect_tests/syntax_error_tests.ml index bf835d78b..0d29a80d1 100644 --- a/src/bin/expect_tests/syntax_error_tests.ml +++ b/src/bin/expect_tests/syntax_error_tests.ml @@ -15,3 +15,22 @@ let%expect_test _ = * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new * Check the changelog by running 'ligo changelog' |} ] ; + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_arguments.ligo" ; "main" ] ; + [%expect {| + ligo: in file "basic.religo", line 1, characters 14-27. : It looks like you are defining a function, however we do not + understand the parameters declaration. + Examples of valid functions: + let x = (a: string, b: int) : int => 3; + let tuple = ((a, b): (int, int)) => a + b; + let x = (a: string) : string => "Hello, " ++ a; + {"location":"in file \"basic.religo\", line 1, characters 14-27"} + + + 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' |} ] ; + diff --git a/src/passes/1-parser/reasonligo.ml b/src/passes/1-parser/reasonligo.ml index 17091363b..5254018e8 100644 --- a/src/passes/1-parser/reasonligo.ml +++ b/src/passes/1-parser/reasonligo.ml @@ -55,7 +55,14 @@ module Errors = let wrong_function_arguments (expr: AST.expr) = let title () = "" in - let message () = "Wrong function arguments.\n" in + let message () = "It looks like you are defining a function, \ + however we do not\n\ + understand the parameters declaration.\n\ + Examples of valid functions:\n\ + let x = (a: string, b: int) : int => 3;\n\ + let tuple = ((a, b): (int, int)) => a + b; \n\ + let x = (a: string) : string => \"Hello, \" ++ a;\n" + in let expression_loc = AST.expr_to_region expr in let data = [ ("location", diff --git a/src/test/contracts/negative/error_function_arguments.religo b/src/test/contracts/negative/error_function_arguments.religo new file mode 100644 index 000000000..b80d7f002 --- /dev/null +++ b/src/test/contracts/negative/error_function_arguments.religo @@ -0,0 +1,2 @@ +let div = (a, b : nat * nat) : option (nat) => + if (b == 0n) { None; } else { Some (a/b); } \ No newline at end of file