diff --git a/CHANGELOG.md b/CHANGELOG.md index 53589708..b5e580b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ Modifications by (in alphabetical order): * P. Vitt, University of Siegen, Germany * A. Voysey, UK Met Office +18/08/2026 PR #525 for #524. Fix Io_Implied_Do rejecting a minimal-length + io-implied-do such as "(i,i=1,n)" (off-by-one in the length guard). + 16/07/2026 PR #520 for #519. Fix truncation of a character length expression that contains a comma (e.g. the arguments to an intrinsic such as MAX) when the kind appears before the length in a char-selector. diff --git a/src/fparser/two/Fortran2003.py b/src/fparser/two/Fortran2003.py index ecc89765..cbf2aa1c 100644 --- a/src/fparser/two/Fortran2003.py +++ b/src/fparser/two/Fortran2003.py @@ -9329,7 +9329,9 @@ class Io_Implied_Do(Base): # R917 @staticmethod def match(string): - if len(string) <= 9 or string[0] != "(" or string[-1] != ")": + # The shortest possible io-implied-do, e.g. "(i,i=1,2)", is 9 + # characters long. + if len(string) < 9 or string[0] != "(" or string[-1] != ")": return line, repmap = string_replace_map(string[1:-1].strip()) i = line.rfind("=") diff --git a/src/fparser/two/tests/test_fortran2003.py b/src/fparser/two/tests/test_fortran2003.py index cfcefaa1..5ff35a6e 100644 --- a/src/fparser/two/tests/test_fortran2003.py +++ b/src/fparser/two/tests/test_fortran2003.py @@ -2228,6 +2228,11 @@ def test_io_implied_do(): # R917 assert isinstance(obj, tcls), repr(obj) assert str(obj) == "(a, i = 1, 2)" + # Minimal-length (9-character) io-implied-do. + obj = tcls("(i,i=1,2)") + assert isinstance(obj, tcls), repr(obj) + assert str(obj) == "(i, i = 1, 2)" + obj = tcls("((i+j,j=3,4,1), i=1,2)") assert isinstance(obj, tcls), repr(obj) assert str(obj) == "((i + j, j = 3, 4, 1), i = 1, 2)"