# HG changeset patch # User Markus Mützel # Date 1654352133 -7200 # Node ID 277e31f0bb602a9a91c0bd6946a75eda2564170c # Parent f03902a398104b0592c3248f154c416babfd7fc7 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 f03902a39810 -r 277e31f0bb60 libinterp/parse-tree/pt-idx.cc --- 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) {