Mercurial > octave
changeset 31072:277e31f0bb60 stable
Change wording of error message when using a variable as function (bug #62552).
* libinterp/parse-tree/pt-idx.cc (tree_index_expression::evaluate_n): Check
if first argument might have been intented as binary operator. Add a suggestion
to the error message in that case.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 04 Jun 2022 16:15:33 +0200 |
parents | f03902a39810 |
children | 396f60e0b984 2c8ab613e805 |
files | libinterp/parse-tree/pt-idx.cc |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-idx.cc Sun Jun 05 13:35:18 2022 +0200 +++ b/libinterp/parse-tree/pt-idx.cc Sat Jun 04 16:15:33 2022 +0200 @@ -366,7 +366,26 @@ std::string nm = id->name (); if (is_var && is_word_list_cmd ()) - error ("%s used as variable and later as function", nm.c_str ()); + { + bool maybe_binary_op = false; + if ((*p_args) && (*p_args)->length () > 0) + { + // check if first character of first argument might be (the + // start of) a binary operator + std::string ops = "+-*/\\.^|&"; + string_vector arg_list = (*p_args)->get_arg_names (); + if (! arg_list.isempty () + && (ops.find (arg_list(0)[1]) != std::string::npos)) + maybe_binary_op = true; + } + + std::string advice; + if (maybe_binary_op) + advice = "\nCheck whitespace around potential binary operator."; + + error ("variable \"%s\" used as function in command style expression%s", + nm.c_str (), advice.c_str ()); + } if (! is_var) {