Mercurial > octave
comparison libinterp/parse-tree/pt-idx.cc @ 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 | 796f54d4ddbf |
children | 396f60e0b984 |
comparison
equal
deleted
inserted
replaced
31071:f03902a39810 | 31072:277e31f0bb60 |
---|---|
364 bool is_var = tw.is_variable (m_expr); | 364 bool is_var = tw.is_variable (m_expr); |
365 | 365 |
366 std::string nm = id->name (); | 366 std::string nm = id->name (); |
367 | 367 |
368 if (is_var && is_word_list_cmd ()) | 368 if (is_var && is_word_list_cmd ()) |
369 error ("%s used as variable and later as function", nm.c_str ()); | 369 { |
370 bool maybe_binary_op = false; | |
371 if ((*p_args) && (*p_args)->length () > 0) | |
372 { | |
373 // check if first character of first argument might be (the | |
374 // start of) a binary operator | |
375 std::string ops = "+-*/\\.^|&"; | |
376 string_vector arg_list = (*p_args)->get_arg_names (); | |
377 if (! arg_list.isempty () | |
378 && (ops.find (arg_list(0)[1]) != std::string::npos)) | |
379 maybe_binary_op = true; | |
380 } | |
381 | |
382 std::string advice; | |
383 if (maybe_binary_op) | |
384 advice = "\nCheck whitespace around potential binary operator."; | |
385 | |
386 error ("variable \"%s\" used as function in command style expression%s", | |
387 nm.c_str (), advice.c_str ()); | |
388 } | |
370 | 389 |
371 if (! is_var) | 390 if (! is_var) |
372 { | 391 { |
373 octave_value_list first_args; | 392 octave_value_list first_args; |
374 | 393 |