Skip to content

bug: Linter errors from include files reported in main file #931

Open
@albertziegenhagel

Description

@albertziegenhagel

Is there an existing issue for this?

  • I have searched the existing issues

Description

If a fortran file A includes another file B, and the file that is included (B) has a syntax error in it, the linter errors (I am using gfortran) are incorrectly reported to be in the file A.

As an example let file A be prog.f90 with

! Meaningless comment
! to make the error
! more visible
program prog
  implicit none
  include 'include.inc'

  print*, "Hello Include!"
end program prog

and file B is include.inc with

integers :: i

(note that there is a typo: integers instead of integer).

Here the linter error is reported in prog.f90 line 2, column 9 but in fact, it is in include.inc.

If I copy the gfortran command from the Modern Fortran output window to a terminal and invoke gfortran manually it reports

include.inc:2:8:

Error: Malformed type-spec at (1)

Screenshots

image

Expected Behaviour

That is actually not that easy to answer. One solution would be to report the errors in the include.inc file, but this could lead to problems when the file is included from multiple locations and each inclusion leads to different errors (as an example, one can fix the typo in the include.inc file above, but add -Wunused-variable to the linter arguments. In this case one will get a warning about an used variable i in the example. But if we would include the same file from another subroutine where i is used, this will not trigger a warning).

An alternative would be to show all warnings from the includes on the include 'include.inc' line in prog.f90, but this way one might get a lot of warnings/errors in that single line and it will be hard to figure out where exactly they originate from.

I am open for any other suggestions for solutions to that problem

Version of Modern Fortran

v3.4.2023062602

Version of Visual Studio Code

1.79.2

Platform and Architecture

Windows

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions