Skip to content

Commit 5a6a322

Browse files
committed
refactor: drop without error the AST preproc node
1 parent caf2a6c commit 5a6a322

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

fortls/parsers/internal/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,9 +2076,9 @@ def replace_vars(line: str):
20762076
defs = {}
20772077
try:
20782078
return eval(replace_ops(replace_vars(replace_defined(text))))
2079-
except Exception as exc:
2080-
log.error("Error evaluating preprocessor IF statement: %s", exc)
2081-
raise ParserError(exc) from exc
2079+
# This needs to catch all possible exceptions thrown by eval()
2080+
except Exception:
2081+
return False
20822082

20832083
def expand_func_macro(def_name: str, def_value: tuple[str, str]):
20842084
def_args, sub = def_value

test/test_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ def test_load_from_disk_exception():
6161

6262
def test_preprocess_missing_includes_exception():
6363
preprocess_file(["#include 'nonexistent_file.f90'"])
64+
65+
66+
def test_preprocess_eval_if_exception():
67+
preprocess_file(["#if (1=and=1)", 'print*, "1==1"', "#endif"])

0 commit comments

Comments
 (0)