Skip to content

Commit

Permalink
#2839: Raise error if ignore_directives=False but ignore_comments=True
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Jan 8, 2025
1 parent 9b8a0ba commit 5d3572d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/psyclone/psyir/frontend/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def __init__(self, free_form: bool = True, ignore_comments: bool = True,
if not self._parser:
self._parser = ParserFactory().create(std="f2008")
self._free_form = free_form
if ignore_comments and not ignore_directives:
raise ValueError(
"Setting ignore_directives to False will only have an effect if"
"ignore_comments is also set to False"
)
self._ignore_comments = ignore_comments
self._processor = Fparser2Reader(ignore_directives,
last_comments_as_codeblocks,
Expand Down
9 changes: 9 additions & 0 deletions src/psyclone/tests/psyir/frontend/fortran_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,12 @@ def test_fortran_psyir_from_file(fortran_reader, tmpdir_factory):
assert node.preceding_comment == "Comment on assignment"
else:
assert node.preceding_comment == ""

# Check that the following combination raises an error
with pytest.raises(ValueError) as err:
FortranReader(ignore_comments=True, ignore_directives=False)
msg = (
"Setting ignore_directives to False will only have an effect if"
"ignore_comments is also set to False"
)
assert msg in str(err.value)

0 comments on commit 5d3572d

Please sign in to comment.