!standard 6.1 (17) 01-10-16 AC95-00014/01 !class confirmation 01-10-16 !status received no action 01-10-10 !subject Visibility of parameter names !summary !appendix !topic visibility of parameter names !reference RM95-6.1(17) !from Dan Eilers 01-10-10 !keywords visibility parameter !discussion package pak is type name is new integer; procedure p (name: integer; y: name); -- legal reference to type name? function f (name: integer) return name; -- legal reference to type name? end pak; Is it legal in Ada95 to use the direct name of a subprogram formal parameter later in the subprogram_specification to refer to an earlier declaration with the same name? RM 95 6.1(17) says a formal parameter is an object directly visible within a subprogram_body, but it doesn't make clear whether such a parameter hides an earlier type definition referenced within the subprogram specification. Note: in Ada83, RM83-8.3(16) clearly made both declarations illegal. I believe GNAT rejects the first declaration, but accepts the second. **************************************************************** From: Gary Dismukes Sent: Wednesday, October 10, 2001 3:53 PM Dan Eilers wrote: > > package pak is > type name is new integer; > procedure p (name: integer; y: name); -- legal reference to type name? > function f (name: integer) return name; -- legal reference to type name? > end pak; > > > Is it legal in Ada95 to use the direct name of a subprogram formal parameter > later in the subprogram_specification to refer to an earlier declaration with > the same name? The type called 'name' is hidden from direct visibility within each of the above subprogram declarations, because the integer parameters are homographs of the type. This is a consequence of the rules in 8.3(21-22). So both of the above subprogram declarations are illegal. (As an aside, also note that there's a special legality rule given by 6.1(21) that makes it illegal to refer to a parameter within its containing formal_part, so it can't be given as a default in that context, but that's a different matter.) > RM 95 6.1(17) says a formal parameter is an object directly visible > within a subprogram_body, but it doesn't make clear whether such > a parameter hides an earlier type definition referenced within the > subprogram specification. Note: in Ada83, RM83-8.3(16) clearly made > both declarations illegal. Actually the rule in RM83-8.3(16) is talking strictly about the name of the subprogram and doesn't relate to the question of hiding by parameter names. ****************************************************************