Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
405 stars 131 forks source link

FORD 7.0.1: AttributeError: 'FortranSubmodule' object has no attribute 'deplist' #577

Closed jeffhole closed 10 months ago

jeffhole commented 10 months ago

I am running FORD 7.0.1 and getting the following error and backtrace:

Parsing files ━━━━━━━━━━━━━━━━━━━━━ 100% 465/465 0:00:00 0:00:07 src/core/Utilities/LAPACK_eig.f90 Correlating information from different parts of your project...Traceback (most recent call last): File "/home/jeffhole/.local/bin/ford", line 8, in sys.exit(run()) File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/init.py", line 491, in run main(proj_data, proj_docs) File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/init.py", line 419, in main project.correlate() File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/fortran_project.py", line 315, in correlate deplist = { File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/fortran_project.py", line 316, in module: set(module.deplist) AttributeError: 'FortranSubmodule' object has no attribute 'deplist'

jeffhole commented 10 months ago

Searching the issues for "deplist", I came across this discussion in #475. I think the issue I am having is that I am using fypp, which uses the "$" character for template variable expansion. All the files that with this fypp syntax have a unique extension, so I'll experiment with "exclude" in the project file.

jeffhole commented 10 months ago

Fantastic, I can specify a unique preprocessor in the project file metadata section (thanks, devs!)

fpp_extensions: fpp 
preprocess: true
preprocessor: fypp -I include/

Now I'm getting:

  Correlating information from different parts of your project...Traceback (most recent call last):
  File "/home/jeffhole/.local/bin/ford", line 8, in <module>
    sys.exit(run())
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/__init__.py", line 491, in run
    main(proj_data, proj_docs)
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/__init__.py", line 419, in main
    project.correlate()
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/fortran_project.py", line 336, in correlate
    container.correlate(self)
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/sourceform.py", line 1296, in correlate
    entity.correlate(project)
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/sourceform.py", line 1261, in correlate
    item = self._find_chain_item(call)
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/sourceform.py", line 1491, in _find_chain_item
    return get_label_item(context, call_chain[-1])
  File "/home/jeffhole/.local/lib/python3.9/site-packages/ford/sourceform.py", line 1453, in get_label_item
    labels[extend_type.name.lower()] = extend_type
AttributeError: 'str' object has no attribute 'name'
ZedThree commented 10 months ago

AttributeError: 'FortranSubmodule' object has no attribute 'deplist'

Oh dear, that's not really a very helpful error message! It looks like it happens a long time after parsing, so it would be much nicer if we could catch this earlier on.

Glad you found the custom preprocessor option though!

AttributeError: 'str' object has no attribute 'name'

Would you be able to make a minimal example that shows this bug please? It looks like we're not correctly parsing a call to a type-bound procedure, but it's quite tricky to reproduce without some example source code!

jeffhole commented 10 months ago

Absolutely! I will narrow down the problem to reproduce the bug.

It's interesting, the bug appears when ford is run on only a part of the project, but when run on the whole thing, it works.

More to follow.

jeffhole commented 10 months ago

AttributeError: 'FortranSubmodule' object has no attribute 'deplist'

For this error, I was able to reproduce it with a project with one file containing a submodule. FortranSubmodule-has-no-attr-deplist.zip

! file: module_a.f90
module module_A
end module

Though unlikely to happen in practice (who would make a submodule w/o a module?), it could be that submodules are kept in a separate directory from the modules. When I'm testing FORD out, I like to process a subset of the entire project, so if I wasn't paying attention and had a submodule w/o a parent module, this could bite me. One thing I really appreciate about FORD is it doesn't mind if things are left undefined (e.g. types/modules that are excluded from FORD's src_dir).

AttributeError: 'str' object has no attribute 'name'

I'm digging into this next.

jeffhole commented 10 months ago

I was able to reproduce the error message:

AttributeError: 'str' object has no attribute 'name'

problem-2.zip

I don't know if this is the same bug as before, but I can see this same error when running FORD on a small subset of my project base. In fact, the source files in problem-2.zip are severe distillations of the code base until the problem was as small as possible. Even though the provided Fortran files will not compile, the interesting thing is that the original files, which are fully defined still produced the bug. In the original code base, the "BaseClass" is defined elsewhere in a module stored in a different directory. If I include a file "BaseClassHeader.f90" containing module "BaseClassHeader" defining a bare bones BaseClass, the above example in problem-2.zip will successfully be processed by FORD:

! file: BaseClassHeader.f90
module BaseClassHeader
    implicit none
    type, abstract :: BaseClass
    end type
end module
ZedThree commented 10 months ago

It looks like both of these issues come from Ford not being able to find entities it expects to be available, such as the parent module of a submodule, or the base class of a derived type.

At the very least, Ford should give a more helpful error message if it can't continue

ZedThree commented 10 months ago

@jeffhole Should be fixed (and give more helpful warnings!) in #580

jeffhole commented 10 months ago

@jeffhole Should be fixed (and give more helpful warnings!) in #580

Thanks @ZedThree!