Skip to content

Commit

Permalink
refactor: drop without error the AST preproc node
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikit committed Apr 28, 2024
1 parent e172229 commit fe1ec6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,9 +2076,9 @@ def replace_vars(line: str):
defs = {}
try:
return eval(replace_ops(replace_vars(replace_defined(text))))
except Exception as exc:
log.error("Error evaluating preprocessor IF statement: %s", exc)
raise ParserError(exc) from exc
# This needs to catch all possible exceptions thrown by eval()
except Exception:
return False

def expand_func_macro(def_name: str, def_value: tuple[str, str]):
def_args, sub = def_value
Expand Down
4 changes: 4 additions & 0 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def test_load_from_disk_exception():

def test_preprocess_missing_includes_exception():
preprocess_file(["#include 'nonexistent_file.f90'"])


def test_preprocess_eval_if_exception():
preprocess_file(["#if (1=and=1)", 'print*, "1==1"', "#endif"])

0 comments on commit fe1ec6b

Please sign in to comment.