fpm icon indicating copy to clipboard operation
fpm copied to clipboard

Program without program-statement misclassification during parsing

Open ivan-pi opened this issue 1 year ago • 3 comments

Description

fpm doesn't classify correctly the source type of program units without a program-statement, such as:

print *, "Hello World"
end

or

print *, "Hello World"
end program

which are allowed according to the standard.

Currently, parse_f_source will return FPM_UNIT_SUBPROGRAM (=4)` for these two cases.

Expected Behaviour

The expected source unit type should be FPM_UNIT_PROGRAM (=1).

Version of fpm

0.8.1, alpha

Platform and Architecture

MacOS (Intel)

Additional Information

The culprit is the parsing logic, which relies on detecting the program statement at front:

https://github.com/fortran-lang/fpm/blob/da6d1bf89a241cd87d640b889ab1e570e8be5f35/src/fpm_source_parsing.f90#L335-L355

Instead it should probably rely on the end program statement which is mandatory per the standard. (J3/24-007, 14.1)

ivan-pi avatar Sep 22 '24 23:09 ivan-pi

I suppose that from the build perspective, a program unit is not very different to an external procedure.

ivan-pi avatar Sep 22 '24 23:09 ivan-pi

Apparently, @urbanjost already knew about this long time ago: https://github.com/fortran-lang/fpm/issues/820#issuecomment-1373028685

ivan-pi avatar Mar 07 '25 22:03 ivan-pi

This is a duplicate of https://github.com/fortran-lang/fpm/issues/637.

ivan-pi avatar Mar 14 '25 15:03 ivan-pi