# Confusing compiler message (Gnat 16.1.0) on new bracket syntax

**URL:** <https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990>\
**Category:** General\
**Tags:** gnat\
**Created:** [November 25, 2026, 11:22am UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990 "2026-11-25T11:22:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 25, 2026, 11:22am UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/1 "2026-11-25T11:22:02Z")

</div>

I had an array of enums and used the following

```ada
Data_Items [I].Tag := Data.FIFO_Tag'Enum_Val (Data_16.Tag);

```

when it should have been

```ada
Data_Items (I).Tag := Data.FIFO_Tag'Enum_Val (Data_16.Tag);

```

The bracket error compiler messages are usually very informative but a little embarrassingly in a moment of end of day brain fog I was stumped by the following error message.

error: missing “:=”

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 25, 2026, 12:20pm UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/2 "2026-11-25T12:20:02Z")

</div>

I remember C compilers having single message: “syntax error” for all occasions. After all the idea of having `[]` was to get C vibe. Success, I would say… 😀

---

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [November 25, 2026, 6:26pm UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/3 "2026-11-25T18:26:35Z")

</div>

This may be a consequence of the compiler being overly helpful and backfiring.

As I understand it, you can only used brackets for initialization of an array. The compiler sees an identifier and then a bracket, so rather than say the actual problem (unexpected symbol) it tries to guess that you meant to initialize an array – hence the bracket. After all, it’s almost certainly not looking beyond the bracket to the rest of the line and trying to parse that.

I would like gnat to provide more helpful error messages, but not by trying to guess what I mean. I’d rather it provide a little more detail. For example, “invalid prefix” could tell me what type it’s seeing.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 25, 2026, 8:37pm UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/4 "2026-11-25T20:37:33Z")

</div>

> [@cantanima](#):
>
> As I understand it, you can only used brackets for initialization of an array. The compiler sees an identifier and then a bracket, so rather than say the actual problem (unexpected symbol) it tries to guess that you meant to initialize an array – hence the bracket.

Yes, this how my Ada parser treats it, giving:

`';', ':' or ':=' is expected`

guessing:

- assignment
- named statement
- call

GNAT parser guesses only assignment as the most probable alternative, assuming that the following `[` begins an aggregate. It is quite clever, but goes in the wrong direction.

> [@cantanima](#):
>
> I would like gnat to provide more helpful error messages, but not by trying to guess what I mean. I’d rather it provide a little more detail. For example, “invalid prefix” could tell me what type it’s seeing.

That would mean a more permissive grammar that considers `[]` being a mistyped `()`, which would be _more_ guessing.

The problem here is not GNAT, which gives a quite thoughtful message (alas the thought is all wrong). The problem is Ada. The introduction of `[]` was not necessary. But **if** decided, **then** `[]` should have been allowed in all contexts where `()` are. For example, for user-defined indexing. Then the grammar considering `Data_Items [I]` a valid name would be reasonable and the compiler would not reject it straight away, but later during semantic analysis giving more information about types and operations considered.

---

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [November 26, 2026, 2:34am UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/5 "2026-11-26T02:34:57Z")

</div>

> That would mean a more permissive grammar that considers `[]` being a mistyped `()`, which would be _more_ guessing.

I think one of us misunderstands the other. When I referred to “invalid prefix” I wasn’t talking about `[]` syntax at all. I was referring to the phenomenon where the code has `A.B` and gnat says `invalid prefix for B` because the type of `A` does not have `B` as a method – or, in some cases, `A` is not even tagged. The compiler doesn’t have to guess either of these things; if it didn’t already know that, it wouldn’t report the error.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 26, 2026, 8:54am UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/6 "2026-11-26T08:54:36Z")

</div>

Yes, but that is just same. Prefix (ARM 4.1) can be of a component, dereference, indexing. These give us two “operations” dot (`.`) and left parenthesis (`(`) that separate it from the suffix. So if we wanted `Data_Items` considered a prefix in `Data_Items [I]`, then `[` must be added to the list, e.g. as indexing or maybe some weird component etc. Then the compiler could say “invalid prefix” having first recognized it as such.

---

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [November 26, 2026, 2:21pm UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/7 "2026-11-26T14:21:53Z")

</div>

What I’m not following is how this statement of mine:

> For example, “invalid prefix” could tell me what type it’s seeing.

…which, as I clarified, refers to this:

> the phenomenon where the code has `A.B` and gnat says `invalid prefix for B` because the type of `A` does not have `B` as a method – or, in some cases, `A` is not even tagged.

…implies this: (emphasis added)

> **That would mean** a more permissive grammar that considers `[]` being a mistyped `()`, which would be _more_ guessing.

You do add this: (emphasis added)

> So **if** we wanted `Data_Items` considered a prefix in `Data_Items [I]`, then `[` must be added to the list…

And I don’t dispute that, but that isn’t what I was suggesting at all.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 26, 2026, 3:20pm UTC](https://forum.ada-lang.io/t/confusing-compiler-message-gnat-16-1-0-on-new-bracket-syntax/4990/8 "2026-11-26T15:20:31Z")

</div>

It is **not** a prefix.
