Skip to content

Widen Proc_Decl (R1214) for Fortran 2008 initial-proc-target#502

Open
perazz wants to merge 3 commits intostfc:masterfrom
perazz:fix/proc-decl-initial-proc-target
Open

Widen Proc_Decl (R1214) for Fortran 2008 initial-proc-target#502
perazz wants to merge 3 commits intostfc:masterfrom
perazz:fix/proc-decl-initial-proc-target

Conversation

@perazz
Copy link
Copy Markdown

@perazz perazz commented Apr 21, 2026

Problem

Proc_Decl.match() in src/fparser/two/Fortran2003.py (R1214) hardcodes the right-hand side of => as Null_Init. That is correct for Fortran 2003 but too narrow for Fortran 2008: F2008 widened the R1214 rule
so the right-hand side can also be an initial-proc-target (R1216) (a procedure-name). Fortran2008/ has no override yet, so any declaration like

procedure(foo_cb), pointer, nopass :: eval => dummy_output

raises FortranSyntaxError under std='f2008', even though gfortran -std=f2008 compiles and runs it without complaint.

Standard reference

From §12.4.3.6 of the Fortran 2008 standard (ISO/IEC 1539-1:2010), publicly available as J3 working document
10-007r1:

R1214  proc-decl           is procedure-entity-name [ => proc-pointer-init ]
R1216  proc-pointer-init   is null-init
                           or initial-proc-target
R1217  initial-proc-target is procedure-name
C1219 (R1214) If => appears in proc-decl, the procedure entity shall
              have the POINTER attribute.

F2003 R1214 was procedure-entity-name [ => null-init ] - same rule number, narrower body. C1219 is unchanged between standards.

Change

  • New class Proc_Decl in src/fparser/two/Fortran2008/proc_decl_r1214.py, subclassing
    Fortran2003.Proc_Decl. match() calls the F2003 match first (which handles null-init), and on failure falls back to BinaryOpBase.match(Procedure_Entity_Name, "=>", Name, string) for the F2008 initial-proc-target branch. The RHS is matched as a bare Name, consistent with how fparser treats other name-bearing rules
    (a stricter implementation would introduce a dedicated Initial_Proc_Target class enforcing C1220; this is a deliberate minimal-viable choice and can be tightened later without changing the tree shape).
  • Registration in src/fparser/two/Fortran2008/__init__.py alongside the existing R12xx entries.
  • CHANGELOG.md entry under the current unreleased section, summarising the widening and citing J3/10-007r1 §12.4.3.6.

Tests

New module
src/fparser/two/tests/fortran2008/test_proc_decl_r1214.py with 12 cases covering:

  • the F2003 null-init branch (regression guard),
  • the F2008 initial-proc-target branch (parametrised over several names),
  • malformed inputs raising NoMatchError,
  • end-to-end module parse for both branches under std='f2008',
  • explicit FortranSyntaxError check confirming the widened form is still rejected under std='f2003' (the F2003 grammar is unchanged).

perazz added 2 commits April 21, 2026 22:52
The Fortran 2003 rule R1214 only accepts null-init on the right-hand
side of `=>`:

    R1214  proc-decl is procedure-entity-name [ => null-init ]

Fortran 2008 keeps the rule number but widens the body so that
proc-pointer-init can be either null-init or an initial-proc-target
(a procedure-name):

    R1214  proc-decl           is procedure-entity-name
                                  [ => proc-pointer-init ]
    R1216  proc-pointer-init   is null-init
                               or initial-proc-target
    R1217  initial-proc-target is procedure-name

(J3/10-007r1 §12.4.3.6; C1219 unchanged - `=>` requires the POINTER
attribute.)

Without an override, declarations such as

    procedure(cb), pointer, nopass :: eval => dummy

raise FortranSyntaxError under std='f2008' even though gfortran
-std=f2008 accepts them.

Add an F2008 Proc_Decl class in Fortran2008/proc_decl_r1214.py that
subclasses the F2003 Proc_Decl and extends its match() to fall back
to an initial-proc-target (matched as a Name) when the null-init
branch fails. Register the new class in Fortran2008/__init__.py and
add a test module covering null-init regression, initial-proc-target
parsing (both the rule in isolation and inside a full module), and
an explicit check that the same initial-proc-target form is still
rejected under std='f2003'.
Replace the PR #XXX placeholder for the R1214 widening with the
real PR number (stfc#502) now that the PR has been opened against
stfc/fparser:master.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.22%. Comparing base (a197a85) to head (4e3df50).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #502      +/-   ##
==========================================
+ Coverage   92.21%   92.22%   +0.01%     
==========================================
  Files          87       88       +1     
  Lines       13832    13853      +21     
==========================================
+ Hits        12755    12776      +21     
  Misses       1077     1077              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Adds a dedicated test exercising the if not string: return None
guard in the F2008 Proc_Decl.match method, which was previously
uncovered and blocked PR coverage checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant