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

Improve the accuracy of Function_Call_Or_Allocator_Level

The Ada compiler's `Function_Call_Or_Allocator_Level` now correctly determines the accessibility level for object declarations, mirroring `Accessibility_Level`.

This update rectifies an inaccuracy in the Function_Call_Or_Allocator_Level function within the Ada compiler. Previously, for object declarations, it returned the static scope depth, deviating from its parent function Accessibility_Level which uses the dynamic scope. The change ensures consistency by recursing on the defining identifier for object declarations and simplifies related expander code by calling Accessibility_Level more directly.

In Details

This commit refines the handling of accessibility levels in the Ada front-end, specifically concerning Function_Call_Or_Allocator_Level and Accessibility_Level. The core issue was a discrepancy in how these functions computed accessibility for object declarations. The fix in accessibility.adb by recursing on the defining identifier for N_Object_Declaration ensures consistent dynamic scope evaluation. The secondary changes in exp_ch3.adb and exp_ch5.adb are cleanups that leverage the improved Accessibility_Level by removing redundant, manual accessibility computations within the…

For Context

In programming, 'accessibility levels' determine where in your code you can refer to a variable or data structure. Think of it like a set of nested boxes: you can always see things in your current box or any boxes immediately containing it, but not necessarily things in adjacent boxes or boxes far away. The Ada compiler has functions like Accessibility_Level and Function_Call_Or_Allocator_Level that calculate these 'depths' or 'levels' to enforce these rules. This commit corrects a subtle mistake where one of these functions was sometimes looking at the wrong 'box' (static scope instead of dynamic scope) when dealing with newly declared variables. The fix ensures these calculations are consistently accurate, which helps prevent bugs where your program might try to access data that no longer exists or isn't supposed to be visible.

Filed Under: adacompilersemanticsaccessibility