# Bug or legit? Instantiation in body of preelaborable generic complains about non-static constant

**URL:** <https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742>\
**Category:** General\
**Created:** [January 23, 2025, 10:21pm UTC](https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742 "2025-01-23T22:21:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mosteo](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/mosteo/32/8_2.png) [@mosteo](https://forum.ada-lang.io/u/mosteo)\
**Post date:** [January 23, 2025, 10:21pm UTC](https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742/1 "2025-01-23T22:21:01Z")

</div>

So this is happening to me, here is a minimal example. Sadly, it requires both spec and body. Note that the library must be generic and the instantiation in the body for the error to be reported; otherwise everything works still being ` Preelaborate` (either non-generic lib or instance in spec).

This is with GNAT 10 to 14.

```ada
generic
package Bug with Preelaborate is
   
   type Any is tagged private;
   
   function Make return Any;
   
private
   
   type Any is tagged null record;

end Bug;

with Ada.Containers.Indefinite_Vectors;

package body Bug is
   
   function Make return Any is (null record);
   
   package Vectors is new Ada.Containers.Indefinite_Vectors
     (Positive, Any'Class);
   
end Bug;

```

The stream of errors at the instantiation point is:

```ada
bug.adb:7:04: error: instantiation error at a-coinve.ads:541
bug.adb:7:04: error: non-static constant in preelaborated unit
bug.adb:7:04: error: instantiation error at a-coinve.ads:541
bug.adb:7:04: error: "T_Check" is not a static constant (RM 4.9(5))
bug.adb:7:04: error: instantiation error at a-conhel.ads:88
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: non-static constant in preelaborated unit
bug.adb:7:04: error: instantiation error at a-conhel.ads:88
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: "T_Check" is not a static constant (RM 4.9(5))
bug.adb:7:04: error: instantiation error at a-conhel.ads:160
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: non-static constant in preelaborated unit
bug.adb:7:04: error: instantiation error at a-conhel.ads:160
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: "T_Check" is not a static constant (RM 4.9(5))
bug.adb:7:04: error: instantiation error at a-conhel.ads:166
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: non-static constant in preelaborated unit
bug.adb:7:04: error: instantiation error at a-conhel.ads:166
bug.adb:7:04: error: instantiation error at a-coinve.ads:407
bug.adb:7:04: error: "T_Check" is not a static constant (RM 4.9(5))
gprbuild: *** compilation phase failed

```

I look into the reported lines and indeed I see things that don’t seem to be static, but I don’t think this is intended; besides it working in the other cases I mentioned which doesn’t make sense to me.

So, legit or not?

---

<div class="post-metadata">

**Author:** ![OneWingedShark](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/onewingedshark/32/305_2.png) [@OneWingedShark](https://forum.ada-lang.io/u/OneWingedShark)\
**Post date:** [January 23, 2025, 11:08pm UTC](https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742/2 "2025-01-23T23:08:01Z")

</div>

Noting there looks wrong.  
Have you tried adding `Preelaborable_Initialization` to the `Any` type?

---

<div class="post-metadata">

**Author:** ![mosteo](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/mosteo/32/8_2.png) [@mosteo](https://forum.ada-lang.io/u/mosteo)\
**Post date:** [January 24, 2025, 10:05am UTC](https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742/3 "2025-01-24T10:05:37Z")

</div>

> [@OneWingedShark](#):
>
> Have you tried adding `Preelaborable_Initialization` to the `Any` type?

Yes, it made no difference.

---

<div class="post-metadata">

**Author:** ![JC001](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@JC001](https://forum.ada-lang.io/u/JC001)\
**Post date:** [January 25, 2025, 8:38am UTC](https://forum.ada-lang.io/t/bug-or-legit-instantiation-in-body-of-preelaborable-generic-complains-about-non-static-constant/1742/4 "2025-01-25T08:38:52Z")

</div>

`T_Check` is part of GNAT’s internal implementation of Ada.Containers.\* in general, so this must be a compiler error.
