<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109609>109609</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] cannot parse a program where write statement is incorrectly positioned in contains section
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following invalid Fortran program.
```f90
write(*, *) 'OK'
contains
write(*, *) 'NG'
end
```
If you compile the above program with gfortran, the following error message is obtained. The message correctly points out an error in the program.
```console
$ gfortran test.f90
test.f90:3:16:
3 | write(*, *) 'NG'
| 1
Error: Unexpected WRITE statement in CONTAINS section at (1)
```
With flang-new, the following not-so-kind error message is obtained.
```console
$ flang-new test.f90
error: Could not parse test.f90
./test.f90:3:1: error: expected 'END'
write(*, *) 'NG'
^
./test.f90:3:1: in the context: END PROGRAM statement
write(*, *) 'NG'
^
./test.f90:1:1: in the context: main program
write(*, *) 'OK'
^
./test.f90:3:1: error: expected 'END PROGRAM'
write(*, *) 'NG'
^
./test.f90:3:1: in the context: END PROGRAM statement
write(*, *) 'NG'
^
./test.f90:1:1: in the context: main program
write(*, *) 'OK'
^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8ld-PozYQx_8a8zIKMiZAeOCB5sdpVTVbbbe6ZwMDuGfsyDbJ7X9fAQnZps1lV6ouikAYf_2d-eAZc2tFoxAzEv1Coo3He9dqk31bcGP0yXqFrt6ytVZWVGjAtQi1llKfhGpAqCOXooKdNs5wBQejG8M7n9ANoTmJ6fSvUzqNnIxwSNiKsJywNYy3FAhLnn8lLJnmlFo5LpR9oNh_mRWoqhvD6fGphjfdQ6m7g5A4hs4LfcRLmHASroWmnoIflv9ndmiMNtChtbxBEBZ0MUSGlQ-vLc4vSm0Mlk6-wUEL5Szo3gFXZ7lQ46p3yJRaWS3xPMqWczTg0Dp_Bjc_hXlIwjyISZifReMVACAEkqzhI8DGiTe_YHq1HYImYQ5_Kvx-wNJhBV9fnl63YB132KFyQ0rr5_1r_rT_AyyWTmgF3AFhq4Cw9D8_xdeBdC25ahYKT_9GrbRbWL34JlT1A-yP4M0GN_TwktRa97IazODAjcWbaT5hu1vQg2qWz0QIS7b7zZXnB6lH2x8bnffKUAH43Q0j2_0Gfn95_vKS_3b9AJ8yvesa3HftuJhr-aHZu9K9b_aQ5SXLzzL9v6H-TKafRDrve6_KwioNU-5hFiQsoXGarGKvzeKiqBmt6yDmabKsWR3iKkqDmIWUJrzmnsgYZUuaspBGYcxiv6pW0TKqY5osk1Ww4mRJseNC-lIeO1-bxhPW9pgFNI1p6kleoLTjScHYWG2EseHQMNkgWBR9Y8mSSmGdvS7hhJPj8TIpog2UXF2LkF_7cYsGJyzv240Fod43WSuGloPVQPlyWlwakdcbmbXOHezQIdmOsF0jXNsXfqk7wnZDUOfb4mD0X1g6wnZjkpaw3TnPY8b-DgAA__-gZA0E">