fortran-language-server icon indicating copy to clipboard operation
fortran-language-server copied to clipboard

Comment in middle of if statement creates "unexpected end of scope" error

Open jrwrigh opened this issue 5 years ago • 2 comments

If I have the following if statement:

       if ((longVariableX .neq. longVariableY) .and. ! ensure X != Y
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

I get an error for it's respective subroutine saying there's an "Unexpected end of scope" error.

Removing the first comment eliminates the error. ie:

       if ((longVariableX .neq. longVariableY) .and.
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

will not cause an error.

jrwrigh avatar Jan 25 '20 01:01 jrwrigh

Thanks for the report. However, I think this is technically invalid? As far as I know, trailing line comments are only allowed in free-form Fortran.

There is an "intersection" style that places ampersands at the start and end of files as below, but other than that I don't think this is technically allowed.

       if ((longVariableX .neq. longVariableY) .and.  & ! ensure X != Y
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

I can certainly add support for trailing line comments in fixed-form code, but I prefer to limit extensions like that to widely supported ones. Do you know if most compliers (ie. GNU, Intel, Cray, etc.) support this style without complaining?

hansec avatar Mar 31 '20 21:03 hansec

trailing line comments are only allowed in free-form Fortran.

Does this only support fixed-form? My code base is a weird mix of "interpreted as free-form but written in fixed-form (sort of)" so being able to do both would be quite nice.

Do you know if most compliers (ie. GNU, Intel, Cray, etc.) support this style without complaining?

The offending code has been compiled on several dozen HPC machines, so I'd imagine that it would work with all of them. That said, I can only vouch for Intel and GNU compilers.

jrwrigh avatar Apr 01 '20 14:04 jrwrigh