# HG changeset patch # User Markus Mützel # Date 1654352133 -7200 # Sat Jun 04 16:15:33 2022 +0200 # Branch stable # Node ID d59b7186b041c77ce7949d3ae2b96502641d9843 # Parent d33af4594440e67ef1f35e9919f2f4bd824701a5 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. diff -r d33af4594440 -r d59b7186b041 libinterp/parse-tree/pt-idx.cc --- a/libinterp/parse-tree/pt-idx.cc Sat Jun 04 00:07:58 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) {