ScopingNode._refine_copy() uses replace_symbols_using to ensure that Symbols referred to in a sub-tree are updated. However, since replace_symbols_using only uses symbol names, this won't get the correct symbol if the PSyIR happens to have symbols shadowed in nested scopes. In practise, this isn't often a problem but it is easy to imagine a situation where it will break, e.g.:
subroutine test
integer :: a
integer :: b = 1
if condition then
! PSyIR declares a shadowed, locally-scoped a'
a' = 1
if condition2 then
! PSyIR declares a shadowed, locally-scoped b'
b' = 2
a = a' + b'
Here, the final assignment will end up being a' = a' + b' and thus the semantics of the code are changed. (Note that Fortran code is only used to illustrate the problem - it's not possible to create such a situation directly from actual Fortran because it doesn't support nested scopes*.)
apart from ASSOCIATE constructs and the PSyIR doesn't support those yet.
ScopingNode._refine_copy()
usesreplace_symbols_using
to ensure that Symbols referred to in a sub-tree are updated. However, sincereplace_symbols_using
only uses symbol names, this won't get the correct symbol if the PSyIR happens to have symbols shadowed in nested scopes. In practise, this isn't often a problem but it is easy to imagine a situation where it will break, e.g.:Here, the final assignment will end up being
a' = a' + b'
and thus the semantics of the code are changed. (Note that Fortran code is only used to illustrate the problem - it's not possible to create such a situation directly from actual Fortran because it doesn't support nested scopes*.)