From 44613f6102ba8c4d7a526e81291f94e39e284de5 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Sat, 2 Nov 2024 05:37:48 +0000 Subject: [PATCH] Expression: Fix scoping of intrinsic procedures in scope removal --- loki/transformations/sanitise.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/loki/transformations/sanitise.py b/loki/transformations/sanitise.py index b745b7e4e..df418a811 100644 --- a/loki/transformations/sanitise.py +++ b/loki/transformations/sanitise.py @@ -141,7 +141,17 @@ def map_array(self, expr, *args, **kwargs): map_variable_symbol = map_scalar map_deferred_type_symbol = map_scalar - map_procedure_symbol = map_scalar + + def map_procedure_symbol(self, expr, *args, **kwargs): + new = self.map_scalar(expr, *args, **kwargs) + # Ensure we re-scope intrinsic procedure symbols + # (which are by default scoped to the closest scope, + # but do not actually have a parent if they happen + # to be created under an associate). + # TODO: Try create on Subroutine, not Associate? + if expr.type.dtype.is_intrinsic: + new = new.clone(scope=new.scope.parent) + return new class ResolveAssociatesTransformer(Transformer):