bugGNU Octave - Bugs: bug #51988, syntax error on command syntax in...

 
 

bug #51988: syntax error on command syntax in script file when command is shadowed by a variable

Submitter:  None
Submitted:  Sun 10 Sep 2017 10:48:27 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 28 Mar 2024 05:35:08 PM UTC, comment #9: 

thanks for the follow up.  closing report as fixed.

Nicholas Jankowski <nrjank>
Group Member
Thu 28 Mar 2024 04:55:12 PM UTC, comment #8: 

I saved the following to a file:

axis = 5
try
axis equal
end
try
axis "equal"
end
clear axis
axis equal
axis "equal"


Trying to execute it results in the following error:

>> test_clear_fcn_name

error: axis: invalid use of symbol as both variable and command near line 3, column 0 in file D:\repo\Octave\octave-2\.build\test_clear_fcn_
name.m
>>


When I execute these commands one after the other at the octave prompt, the function `axis` is working correctly again after `clear axis`. The same when I copy and paste these commands at the octave prompt.

I'd say that error message is specific enough and this report can be closed.

Markus Mützel <mmuetzel>
Group administrator
Thu 28 Mar 2024 04:22:41 PM UTC, comment #7: 

Explore the quotation part of it.  That is,

axis = 5;
axis equal
axis "equal"
clear axis
axis equal
axis "equal"

If the sequence makes sense, then close.  I suppose the same could be achieve with

clear "all"

in your example.

Out of curiosity, you could try the following example to see if there is any way out of the situation:

clear = 1;
clear all
clear clear
clear("all")

That sort of thing.

Dan Sebald <sebald>
Thu 28 Mar 2024 02:27:33 PM UTC, comment #6: 

I guess what i meant was comment #1 works now, and if that case covers the comment #0 problem, then i think this is good. if there's something additional to test to see if the comment #0 problem persists, I'm not sure what else should be tested.

Nicholas Jankowski <nrjank>
Group Member
Thu 28 Mar 2024 08:23:46 AM UTC, comment #5: 

I don't have v9.1 built, but I do recall a lot of changes on the shadowing of variables a number of years ago.  I can only imagine that improvements were made.  If you want a more concrete assessment, JWE could say if it's been fixed.

I think the the point of comment #0 is that

> axis equal


failed because earlier in the poster's code there happened to be a variable named "axis", but then that variable went out of scope (was deleted) by the time

> axis equal


was entered.  That failed.  (This kind of issue is what JWE was working on at the time.)  But, then oddly

> axis "equal"


worked.

Dan Sebald <sebald>
Wed 27 Mar 2024 07:07:58 PM UTC, comment #4: 

can anyone confirm if this bug is still active in v9.1?  I cannot recreate the comment #1 example and i couldn't quite follow the comment #0 description to attempt another test from that.

regarding the comment #1 example, if foo is a function I always get 'normal' behavior.  If I make it a script, I get the error
"error: variable "exist" used as function in command style expression"  which i believe is a fairly recent behavior change (octave 8 maybe?).    (it seems the output from `type foo` has changed since comment #1 was written? as it doesn't show any function/endfunction lines, but says foo.m is a function not a script)

script:

>> type foo
foo is the script defined from: C:\Users\nicholas.jankowski\Desktop\workingfiles\temp\foo.m

  exist x


>> clear all
>> exist = 1
exist = 1
>> foo
error: variable "exist" used as function in command style expression
error: called from
    foo at line 1 column 3



>> type foo
foo is the function defined from: C:\Users\nicholas.jankowski\Desktop\workingfiles\temp\foo.m

function foo ()
  exist x
endfunction



>> clear all
>> exist = 1
exist = 1
>> foo
ans = 0



unless someone has a different example of concern, i think this bug report can be closed.

Nicholas Jankowski <nrjank>
Group Member
Sun 10 Sep 2017 11:48:14 PM UTC, comment #3: 

This is not really the same issue as bug #46852. That issue is about a clear "out of bounds" message when indexing a variable that shadows a function. This issue is about an unclear "syntax error" message when a variable shadows a function that is called specifically using command syntax without parentheses.

Mike Miller <mtmiller>
Group Member
Sun 10 Sep 2017 11:42:32 PM UTC, comment #2: 

This issue or something similar has been discussed previously, e.g.,

https://savannah.gnu.org/bugs/?46852

Look through that to see if it is the same issue.  Perhaps any changes in the message were after 4.2.1.  There's a changeset here

http://hg.savannah.gnu.org/hgweb/octave/rev/dcbd2ceadff1

where language "shadows" was introduced.

As you pointed out, it is very easy to not be aware that a function has been over-written by some choice of variable name.  As such, it's not immediately obvious what has happened.

Dan Sebald <sebald>
Sun 10 Sep 2017 11:31:47 PM UTC, comment #1: 

Thanks for your bug report. I can confirm this, it looks like a slightly different manifestation of bug #48031.


>> type foo
foo is the user-defined function defined from: /tmp/foo.m

exist x

>> clear all
>> exist = 1;
>> foo
parse error near line 1 of file /tmp/foo.m

  syntax error

>>> exist x
          ^


Mike Miller <mtmiller>
Group Member
Sun 10 Sep 2017 10:48:27 PM UTC, original submission:  

The statement "axis equal;" kept triggering a parse error in a script foo.m but it was restricted to that specific file foo.m and no others. After much hair-pulling, including searching for invisible Unicode characters, it turned out that there had been a previous variable named axis, long since cleared by the time "axis equal" was called with its graphics meaning.

In foo.m, the variable axis was renamed and the problem stopped. But when most variables are cleared and then invoked, Octave either invokes a function or script by that name or gives a "reference to cleared variable" error. A bald "parse error" is triggered only by certain two-word commands like "hold on" and "axis equal" and "format compact" -- it appears that the interpreter gets confused with the use of a command that used to be a variable for those multi-word forms alone. However calling axis "equal" with the argument in quotes does work  even without patentheses -- cleared variables stay cleared and the interpreter does not error out.

If this behavior must remain the way it is, please consider changing the parse error to "Parse error (was this command used earlier as a variable?)".

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by sebald (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-28 nrjank StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2024-03-27 nrjank StatusConfirmed Need Info
    2017-09-10 mtmiller SummaryInterpreter error with multiword commands previously used as variables syntax error on command syntax in script file when command is shadowed by a variable
    2017-09-10 mtmiller StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code