Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ecmwf-ifs/loki into sbrm-fix-scalar…
Browse files Browse the repository at this point in the history
…-syntax-for-array-arguments
  • Loading branch information
rolfhm committed Nov 9, 2023
2 parents 64a959d + 874ac83 commit 0259596
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion loki/transform/transform_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ def _map_unbound_dims(var, val):
{v: v.clone(name=f'{member.name}_{v.name}') for v in duplicate_locals}
)
member.spec = shadow_mapper.visit(member.spec)
member.body = shadow_mapper.visit(member.body)

var_map = {}
duplicate_locals_names = {dl.name.lower() for dl in duplicate_locals}
for v in FindVariables(unique=False).visit(member.body):
if v.name.lower() in duplicate_locals_names:
var_map[v] = v.clone(name=f'{member.name}_{v.name}')
member.body = SubstituteExpressions(var_map).visit(member.body)

# Get local variable declarations and hoist them
decls = FindNodes(VariableDeclaration).visit(member.spec)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_transform_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,11 @@ def test_inline_member_routines_variable_shadowing(frontend):
fcode = """
subroutine outer()
real :: x = 3 ! 'x' is real in outer.
real :: tmp = 0
real :: y
y = 1.0
call inner(tmp, y=y)
x = x + tmp
call inner(y)
x = x + y
contains
subroutine inner(y)
Expand Down Expand Up @@ -515,7 +514,7 @@ def test_inline_member_routines_variable_shadowing(frontend):
# Check inner 'y' was substituted, not renamed!
assign = FindNodes(Assignment).visit(routine.body)
assert routine.variable_map['y'] == 'y'
assert assign[2].lhs == 'y' and assign[2].rhs == 'y + sum(x)'
assert assign[2].lhs == 'y' and assign[2].rhs == 'y + sum(inner_x)'


@pytest.mark.parametrize('frontend', available_frontends())
Expand Down

0 comments on commit 0259596

Please sign in to comment.