# LFortran problem with derived type in data statement

**URL:** <https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572>\
**Category:** LFortran\
**Created:** [April 9, 2025, 10:22am UTC](https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572 "2025-04-09T10:22:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 9, 2025, 10:22am UTC](https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572/1 "2025-04-09T10:22:54Z")

</div>

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](https://github.com/sebastian-mutz/fplt)) 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:

```auto
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:

```auto
program data_test

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

end program

```

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [April 9, 2025, 5:08pm UTC](https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572/2 "2025-04-09T17:08:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 9, 2025, 5:15pm UTC](https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572/3 "2025-04-09T17:15:12Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [April 9, 2025, 5:20pm UTC](https://fortran-lang.discourse.group/t/lfortran-problem-with-derived-type-in-data-statement/9572/4 "2025-04-09T17:20:26Z")

</div>

Great catch!

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

```fortran
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:

```console
$ 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](https://github.com/lfortran/lfortran/issues/6936).
