generic
package pak1 is
end pak1;
generic
package pak1.pak2 is
end pak1.pak2;
with pak1.pak2;
generic
with package new_pak2 is new pak1.pak2; -- ERROR: illegal use of pak1
package pak5 is
end pak5;
$ gnatchop -w p; gnatmake -gnatVa pak5
splitting p into:
pak1.ads
pak1-pak2.ads
pak5.ads
gnatgcc -c -gnatVa pak5.ads
gnatgcc -c -gnatVa pak1.ads
gnatgcc -c -gnatVa pak1-pak2.ads
Compilation finished at Tue Apr 20 18:46:10
The error in the above program is kind of subtle, but relates to RM
12.1(11) (note 1): "Outside a generic unit a name that denotes the
generic_declaration denotes the generic unit."
Since pak5 is outside the generic unit pak1, pak1 refers
to the generic pak1, which must be instantiated before it
can be used to refer to child units such as pak1.pak2.
In this similar example:
generic
package pak1 is
end pak1;
generic
package pak1.pak2 is
end pak1.pak2;
with pak1.pak2;
generic
-- with package new_pak2 is new pak1.pak2;
package pak5 is
package new_pak2 is new pak1.pak2; --ERROR:
end pak5;
gnat correctly reports the error:
invalid prefix in selected component "pak1"
A legal version of the original example (which gnat correctly accepts)
would be:
generic
package pak1 is
end pak1;
generic
package pak1.pak2 is
end pak1.pak2;
with pak1.pak2;
generic
with package new_pak1 is new pak1;
with package new_pak2 is new new_pak1.pak2; --OK new_pak1 not pak1
package pak5 is
end pak5;