[flang] Misleading diagnostic order for coarray declaration: "expected entity declarations" precedes "expected '::'"
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Summary
When a type-declaration statement has an attribute list followed by a misplaced
token, flang emits two recovery diagnostics — `expected '::'` and
`expected entity declarations` — but reports `expected entity declarations`
first. With an attribute list present, the `::` separator is required by the
standard (F2018 R801 / C801), so `expected '::'` is the accurate, actionable
diagnostic and should be the leading message.
### Reproducer
```fortran
subroutine s1(a)
real, dimension (:)[10] :: a
end subroutine
```
(The `[10]` coarray codimension is misplaced within the `DIMENSION` attribute.)
### Actual output
```
error: expected entity declarations
real, dimension (:)[10] :: a
^
error: expected '::'
real, dimension (:)[10] :: a
^
```
Note how `expected entity declarations` is listed first.
### Expected output
`expected '::'` should be reported first, since after the attribute list the
standard requires the `::` separator before the entity-declaration list.
`expected entity declarations` is not valid at that position without a
preceding `::`, so it should not be the primary message.
### Notes
- The set of emitted errors is otherwise correct; only the ordering / primary
message is wrong.
- This affects every declaration of the form `, ... `.
- This re-ordering of errors is a regression caused by https://github.com/llvm/llvm-project/pull/215886
Assisted-by: Claude Opus 4.8
Contributor guide
Assessment
This issue has not been assessed yet.