Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Else_Stmt and Return_Stmt compare equal #400

Open
reuterbal opened this issue Apr 12, 2023 · 2 comments
Open

Else_Stmt and Return_Stmt compare equal #400

reuterbal opened this issue Apr 12, 2023 · 2 comments
Assignees

Comments

@reuterbal
Copy link
Collaborator

I have just run into an odd situation where the following would occur:

Python 3.8.8 (default, Feb 24 2021, 16:52:30)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fparser.two import Fortran2003
>>> Fortran2003.Else_Stmt('ELSE') == Fortran2003.Return_Stmt('RETURN')
True

I have not dug any deeper into this but it seems unexpected. In my particular case this occurs with an If_Construct that looks something like this:

IF (N == 0) THEN
  VAL = Z0
  RETURN
ELSE
  VAL = Z1
  RETURN
ENDIF

From an earlier search I would have the Else_Stmt node already available and do something like if_construct_node.children.index(else_stmt_node), which I would expect to yield 3 but instead returns 2.

@arporter
Copy link
Member

I think this is related to #174. Certainly, the incorrect/unexpected behaviour of index is down to that.

@arporter
Copy link
Member

I can reproduce this:

>>> elsenode = Fortran2003.Else_Stmt("else")
>>> rnode = Fortran2003.Return_Stmt("return")
>>> rnode == elsenode
True

From my investigation in #174, it seems that self.items is used to compare two instances of Base and, in this case:

>>> rnode.items
(None,)
>>> elsenode.items
(None,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants