Skip to content

Incorrect handling of nested preprocessor if/else blocks #404

Closed
@albertziegenhagel

Description

@albertziegenhagel

Describe the bug
Given a nested pre-processor block like this:

#if 0
#if 1
#define FOO 1
#endif
#endif

FOO is incorrectly defined to 1. fortls seems to only take the innermost #if into account and ignores that the outer #if statement evaluates to false.

To Reproduce
Given the example above is written to a file pp-nested-if.F90. Executing

python -m fortls --debug_filepath=pp-nested-if.F90 --debug_parser

gives

=== PreProc Pass ===

#if 0 !!! Conditional FALSE(1)
#if 1 !!! Conditional TRUE(2)
#define FOO 1 !!! Define statement(3)
#endif !!! Conditional TRUE/END(4)
#endif !!! Conditional FALSE/END(5)

=== Parsing Pass ===

which shows that the line #define FOO 1 is evaluated.

Expected behavior
FOO should not be defined.

Setup information (please complete the following information):

  • OS: Windows
  • Python Version 3.11
  • fortls Version 3.1.1.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions