bugGNU Octave - Bugs: bug #58677, Error when using += operator

 
 

bug #58677: Error when using += operator

Submitted by:  Joaquín <joaran>
Submitted on:  Mon 29 Jun 2020 03:47:37 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Joaquin Open/Closed:  Open
Release:  6.0.90 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Wed 01 Jul 2020 10:19:28 PM UTC, comment #9: 

So, should this be marked as "Won't Fix" and closed?

Rik <rik5>
Project Administrator
Tue 30 Jun 2020 05:56:28 PM UTC, comment #8: 

If you change the "x += 5" assignment to be "x = x + 5" it will work as you expect.

The issue is that there is no ambiguity with "=" about whether the expression is an assignment or can be a "command".  So if the parser sees "x = ..." it tags X as a variable.  But, for compatibility with Matlab, we parse things like "IDENT += ..." as commands unless IDENT is previously known to be a variable.  In this case, because the script tb.m is parsed without knowledge of the context in which it will be executed, the parser doesn't recognize X as a variable.

In Rik's example from comment #7, the call to "whos" doesn't introduce X as a variable when the script is parsed ("whos" could be overloaded to be something other than the built-in "whos" function, so we can't expect the parser to assume that the arguments will name variables).  However, the "whos" function can look in the current stack frame at execution time to find the variable X.

I'm not sure what we can do to fix this issue unless we want to break compatibility with Matlab when parsing command-style function calls.

Note that this issue is also not limited to Octave's "OP=" style assignment operators.  The same issue can happen with scripts like this:

load x.mat  %% load a file that defines a variable "x"
x -option   %% error: x used as a variable and later as a function

John W. Eaton <jwe>
Project Administrator
Tue 30 Jun 2020 05:02:30 PM UTC, comment #7: 

Confirmed. 

I used Dmitri's simpler example, slightly modified, and uploaded as ta.m and tb.m.  tb.m is now

1;
whos x
fflush (stdout)
x += 5;

The resulting output shows that the Octave interpreter knows 'x' is a variable, but still gets the '+=' wrong.

octave:1> ta
Variables visible from the current scope:

variables in scope: top scope

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        x          10x1                         80  double

Total is 10 elements using 80 bytes

error: x used as variable and later as function
error: called from
    tb at line 4 column 1
    ta at line 3 column 1
ans = 0

I changed the version to 6.0.90.  It would be best to fix this before the 6.1 release assuming it is not too difficult.

(file #49399, file #49400)

Rik <rik5>
Project Administrator
Tue 30 Jun 2020 03:33:37 PM UTC, comment #6: 

Yes, this looks like a bug. A simplified test case:

cat ta.m
1;
x=[(1:10)]';
tb

cat tb.m
1;
x += ones(10,1);

With octave 5.2:
octave:1> ta
error: x(61,_): but x has size 10x1
error: called from
    tb at line 2 column 1
    ta at line 3 column 1

With octave 6.0.1 (hg id: 49f4d7814760 (stable))
octave:1> ta
error: x used as variable and later as function
error: called from
    tb at line 3 column 1
    ta at line 3 column 1

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Tue 30 Jun 2020 01:33:47 PM UTC, comment #5: 

comment #4:

> When I run this code I see:
>

> ignition
> error: p used as variable and later as function
> error: called from
>     momentumEqStaggered at line 33 column 1
>     ignition at line 164 column 5

>
>
> Dmitri.
> --
>


That's strange. It differs from the error appearing to me.  I for one don't have any p function, and neither I notice the line where Octave says p is used as a function.
Do you consider this could be a bug? Or do you think there's something wrong with this particular code?

Joaquín <joaran>
Mon 29 Jun 2020 09:32:06 PM UTC, comment #4: 

When I run this code I see:

ignition
error: p used as variable and later as function
error: called from
    momentumEqStaggered at line 33 column 1
    ignition at line 164 column 5

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 29 Jun 2020 05:42:32 PM UTC, comment #3: 

Running the file "ignition.m" instead of "ignit_Lucch.m" should represent the same error as reported.

Joaquín <joaran>
Mon 29 Jun 2020 05:26:25 PM UTC, comment #2: 

I'm still trying to upload the complete directory but I'm getting a seemingly well know error without a clear solution:

"No group chosen: nogroup "

Joaquín <joaran>
Mon 29 Jun 2020 03:54:34 PM UTC, comment #1: 

octave:1> ignit_Lucch
error: 'updtProp' undefined near line 69, column 69
error: called from
    ignit_Lucch at line 69 column 27

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 29 Jun 2020 03:47:37 PM UTC, original submission:  

I'm trying to add a vector to another vector by using the += operator. Octave somehow gets confused with the sizes and throws an error:

error: p(_,112): but p has size 80x1
error: called from
    momentumEqStaggered at line 33 column 1
    ignit_Lucch at line 223 column 5

As can be noticed, the error pops up in a file named "momentumEqStaggered.m", called from "ignit_Lucch.m".

Curious things are the following:

- Changing "p += pp" by "p = p + pp" solves the problem.

- The next line in the code is a similar operation, using +=, but this one works fine:

rho += pp.*M/8314./T;

- When defining the necessary vectors in "momentumEqStaggered.m" and calling directly to this script, the troubling line works just fine using the += operator!

I attach the two mentioned files in which the error shows, along with the file with the added vectors where the line is executed without an error.

Joaquín <joaran>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #49399:  ta.m added by rik5 (19B - text/x-matlab)
file #49400:  tb.m added by rik5 (52B - text/x-matlab)
file #49393:  TEquation.m added by joaran (2KiB - text/x-objcsrc)
file #49392:  ignition.m added by joaran (7KiB - text/x-objcsrc)
file #49391:  interpolate.m added by joaran (233B - text/x-objcsrc)
file #49390:  hFromT.m added by joaran (497B - text/x-objcsrc)
file #49389:  updtProp.m added by joaran (486B - text/x-objcsrc)
file #49386:  ignit_Lucch.m added by joaran (8KiB - text/x-objcsrc)
file #49387:  workingEquation.m added by joaran (1KiB - text/x-objcsrc)
file #49388:  momentumEqStaggered.m added by joaran (979B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by joaran (Submitted the item)
  • -email is unavailable- added by joaran
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-06-30 rik5 Attached File- => Added ta.m, #49399
        Attached File- => Added tb.m, #49400
        StatusNone => Confirmed
        Release5.2.0 => 6.0.90
    2020-06-29 joaran Attached File- => Added TEquation.m, #49393
    2020-06-29 joaran Attached File- => Added ignition.m, #49392
    2020-06-29 joaran Attached File- => Added interpolate.m, #49391
    2020-06-29 joaran Attached File- => Added hFromT.m, #49390
    2020-06-29 joaran Attached File- => Added updtProp.m, #49389
    2020-06-29 joaran Attached File- => Added ignit_Lucch.m, #49386
        Attached File- => Added workingEquation.m, #49387
        Attached File- => Added momentumEqStaggered.m, #49388
        Carbon-Copy- => Added joaquin.aranciaga@gmail.com

    Back to the top


    Powered by Savane 3.5