GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Ada: Fixes missing contract checks for calls to formal subprograms in instances

Ensures that preconditions on formal subprograms are checked when called within package instantiations.

This commit resolves an issue where preconditions on formal subprograms were not being checked during calls within package instantiations. The wrapper subprogram, designed to perform the check and invoke the actual subprogram, was being bypassed due to a homograph subprogram renaming. The fix removes the homographic subprogram renaming in sem_ch12.adb to ensure that calls resolve to the wrapper, enabling precondition checks when assertions are enabled.

In Details

Addresses a bug where contract checks were missing for calls to formal subprograms within package instantiations. The issue stemmed from a homographic subprogram renaming that caused calls to resolve to the actual subprogram instead of the wrapper. The fix involves removing the subprogram renaming in sem_ch12.adb (Build_Subprogram_Wrapper) to ensure calls resolve to the wrapper and trigger the precondition checks.

For Context

In Ada, contracts (preconditions and postconditions) specify conditions that must be true before and after a subprogram is executed. Formal subprograms are subprograms passed as parameters to other subprograms or generic units. Package instantiations create new packages from generic package templates. This commit fixes a bug where the preconditions on formal subprograms were not being checked when those subprograms were called from within a package created from a generic template. This ensures that the contracts are properly enforced, improving the reliability and correctness of the code.

Filed Under: adacompilerbugfixcontractsgenerics