Allow Access Types to be Constant
Is your capability/feature request related to a problem?
Currently, access types can only be variable. While this can make sense for most code, when using a generic type, this can become frustrating. eg.
package pkg is
generic (
type gen_t
);
procedure foo(a : gen_t);
end package;
If gen_t
is assigned to an access type, or a composite type containing an access type, there is a syntax error because a
is a constant parameter when it must be variable. The only workaround here is to maintain two copies of what is essentially the same package (or any other generic item) where one version is for non-access types and one version is for access types:
package pkg_scalar is
generic (
type gen_t
);
procedure foo(a : gen_t);
end package;
package pkg_access is
generic (
type gen_t
);
procedure foo(variable a : in gen_t);
end package;
Describe the solution you'd like
Allowing access types to also be constant. This would remove the need to maintain two versions of the same code (I have this problem currently with 2008 code). While it may allow some odd looking code, I dont think it would be language breaking or cause any issues. The new
operator should be reserved purely for procedural code, and this would prevent creating a constant access type to anything other than null
. This would then only allow useful constant objects of an access type in methods.
In addition, the access type cannot be de-referenced in a situation with a generic type as it would cause a syntax error, in the same way that attempting to index into a generic type.
This would work well with #40
Describe alternatives you've considered
Only current alternative is to maintain multiple near identical design units to cover usage separately for access and non-access types.