Skip to content

Preprocessor variables not accounted for in diagnostics. #958

@kc9jud

Description

@kc9jud

Describe the bug
Preprocessor definitions do not seem to be applied to declarations correctly.

To Reproduce
A minimal example:

program mbwf2smwf
   implicit none
   character(LEN=MAX_PATHLENGTH) :: a, b='ffff  '
   a = TRIM(b)
end program mbwf2smwf

Within .fortls, we have:

{
  "pp_defs": {"MAX_PATHLENGTH": "256"}
}

Using VS Code, this gives an error squiggle under MAX_PATHLENGTH in the declaration, as well as error squiggles on a and b in a = TRIM(b):
image

It also gives an error when hovering:
image

Somehow, there are conflicting messages in the hover, where there is simultaneously no IMPLICIT type as well as the correctly deduced type CHARACTER(LEN=256):
image

Here is the output of adding --debug_log to the startup options for fortls. I have not been able to reproduce the messages from the command line.

REQUEST 4 textDocument/hover
SEND {"jsonrpc":"2.0","id":4,"result":{"contents":[{"language":"fortran90","value":"#define MAX_PATHLENGTH 256"}]}}
RECV {"jsonrpc":"2.0","id":5,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"range":{"start":{"line":2,"character":17},"end":{"line":2,"character":17}},"context":{"diagnostics":[{"range":{"start":{"line":2,"character":17},"end":{"line":2,"character":17}},"message":"Scalar INTEGER expression expected at (1)","severity":1}],"only":["quickfix"],"triggerKind":1}}}
REQUEST 5 textDocument/codeAction
SEND {"jsonrpc":"2.0","id":5,"result":null}
RECV {"jsonrpc":"2.0","id":6,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"position":{"line":3,"character":11}}}
REQUEST 6 textDocument/hover
SEND {"jsonrpc":"2.0","id":6,"result":{"contents":["TRIM(STRING) removes trailing blank characters of a string."]}}
RECV {"jsonrpc":"2.0","id":7,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"position":{"line":3,"character":13}}}
REQUEST 7 textDocument/hover
SEND {"jsonrpc":"2.0","id":7,"result":{"contents":[{"language":"fortran90","value":"CHARACTER(LEN=256)"}]}}
RECV {"jsonrpc":"2.0","id":8,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":13}},"context":{"diagnostics":[{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":13}},"message":"Symbol 'b' at (1) has no IMPLICIT type","severity":1}],"only":["quickfix"],"triggerKind":1}}}
REQUEST 8 textDocument/codeAction
SEND {"jsonrpc":"2.0","id":8,"result":null}
RECV {"jsonrpc":"2.0","id":9,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"position":{"line":3,"character":4}}}
REQUEST 9 textDocument/hover
SEND {"jsonrpc":"2.0","id":9,"result":{"contents":[{"language":"fortran90","value":"CHARACTER(LEN=256)"}]}}
RECV {"jsonrpc":"2.0","id":10,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"position":{"line":3,"character":3}}}
REQUEST 10 textDocument/hover
SEND {"jsonrpc":"2.0","id":10,"result":{"contents":[{"language":"fortran90","value":"CHARACTER(LEN=256)"}]}}
RECV {"jsonrpc":"2.0","id":11,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/pjfasano/Research/code/mfdn-transitions/src/mbwf2smwf.f90"},"range":{"start":{"line":3,"character":4},"end":{"line":3,"character":4}},"context":{"diagnostics":[{"range":{"start":{"line":3,"character":4},"end":{"line":3,"character":4}},"message":"Symbol 'a' at (1) has no IMPLICIT type","severity":1}],"only":["quickfix"],"triggerKind":1}}}
REQUEST 11 textDocument/codeAction
SEND {"jsonrpc":"2.0","id":11,"result":null}

Expected behavior
The erroneous warnings about missing types and missing integer constants should not appear.

Setup information (please complete the following information):

  • OS: Ubuntu 22.04
  • Python Version: 3.10.12
  • fortls Version: 2.13.0
  • Code editor used: VS Code
  • the Fortran extension for the code editor and its version: Modern Fortran v3.2.0

Configuration information (please complete the following information):

  • See above.
  • Defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions