stfc/fparser

fparser not detecting interfaces as symbols provided by a module

hiker opened this issue · 2 comments

hiker commented

A simple generic interface like:

module dummy_mod
  interface dummy_code
   module procedure dummy_code_1, dummy_code_2
  end interface
...

will not be handled properly. If dummy_code is used by a module that is parsed by fparser, fparser will report:

fparser.common.utils.AnalyzeError: entity name 'dummy_code' is not in module 'dummy_mod'

A simple fix appears to be:

git diff one/block_statements.py
diff --git a/src/fparser/one/block_statements.py b/src/fparser/one/block_statements.py
index 125073b..70b9c57 100644
--- a/src/fparser/one/block_statements.py
+++ b/src/fparser/one/block_statements.py
@@ -701,6 +701,8 @@ class Interface(
                 p.update_attributes(self.a.attributes)
             else:
                 parent_interface[self.name] = self
+            parent_module_provides = self.parent.a.module_provides
+            parent_module_provides[self.name] = self
             return
 
     def topyf(self, tab=""):

This adds the name of the interface to the module_provides attribute of the module (with the interface as value of the dictionary). This seems to work for my LFRic test and the fparser tests. ATM I do get:

FAILED common/tests/test_readfortran.py::test_f2py_directive_f77[False]

though that is apparently unrelated (I get the same with the unmodified fparser). I might need to update my fparser.
edit: Update to current master of fparser did not fix that error.

I cant' judge if this fix is even remotely correct ;) But am happy to provide a PR (with some comments and a test) if someone confirms that it makes sense.

Since this appears to be fparser one (your git diff above is for one/block_statements.py) I propose we leave this as fparser1 is deprecated and will shortly be dropped by PSyclone (once the new metadata handling is put to use). Does that work or is this problem limiting existing PSyclone functionality?

hiker commented

Fair enough. I only get a warning, and I thought my module management had a problem :) I'll just close this again, I didn't really notice the 'one' 🤦