LFortran problem with derived type in data statement

Hi,

I’ve decided to test compilation of some of my new projects with LFortran alongside gfortran, because I think it would be great to eventually use the modules in jupyter notebooks (esp. the plotting library) and want to help improve it by identifying issues along the way. I didn’t see a similar topic/issue posted anywhere else for LFortran.

I ran into issues (syntax error: Token ',' is unexpected here, pointing at the first comma after the first 0 here) with a data statement if I use derived types. See MRE below:

program data_test

integer   :: i
type(col) :: colours

data (colours%rgb(i), i=1,3) /0, 0, 0/

type :: col
   integer :: rgb(3)
end type col

end program

In contrast, the following compiles fine with LFortran:

program data_test

integer :: i, rgb(3)
data (rgb(i), i=1,3) /0, 0, 0/

end program
1 Like

The error message may be a red herring (distraction). Try moving the definition of the type col to before the declaration of colours.

Hi. Thanks for the suggestion. However, it does not change anything if I do this here. (In the actual library, I define types in a separate module first and use it here, btw).

Great catch!

First make sure to compile with GFortran, here is the corrected code that compiles:

program data_test

integer   :: i

type :: col
   integer :: rgb(3)
end type col

type(col) :: colours

data (colours%rgb(i), i=1,3) /0, 0, 0/

end program

Then try LFortran:

$ lfortran a.f90
syntax error: Token ',' is unexpected here
  --> a.f90:11:32
   |
11 | data (colours%rgb(i), i=1,3) /0, 0, 0/
   |                                ^


Note: Please report unclear, confusing or incorrect messages as bugs at
https://github.com/lfortran/lfortran/issues.

That’s a bug in our parser. This is great, I haven’t seen a parser bug in a while, thanks for reporting it. I reported it at `syntax error: Token ',' is unexpected here`, for `/0, 0, 0/` · Issue #6936 · lfortran/lfortran · GitHub.

3 Likes