comp.lang.ada
 help / color / mirror / Atom feed
* Question about generic formal derived types
@ 1999-03-30  0:00 adam
  1999-03-30  0:00 ` Steve Quinlan
  1999-03-30  0:00 ` Stephen Leake
  0 siblings, 2 replies; 6+ messages in thread
From: adam @ 1999-03-30  0:00 UTC (permalink / raw)


In this program fragment:

-------------------------------------------------------------------------------
package Pack1 is
    type Root_Type is tagged record
        Field1 : Integer;
        Field2 : Boolean;
    end record;
end Pack1;

with Pack1;
generic
    type Formal_Type is new Pack1.Root_Type with private;
package Pack2 is
    type New_Type is new Formal_Type with record
        Field3 : Character;
    end record;
end Pack2;

with Pack1;
package Pack3 is
    type Root_Type_Extension is new Pack1.Root_Type with record
        Field3 : Float;
    end record;
end Pack3;

. . .

with Pack2;
with Pack3;
package body Pack4 is

    package Instantiation is new Pack2 (Pack3.Root_Type_Extension);

    procedure Inner is
        X : Character;
        Y : Instantiation.New_Type;
    begin
        X := Y.Field3;
    end Inner;

end Pack4;

-------------------------------------------------------------------------------

I can't believe that a record type can have two components of the same name,
but it appears that Instantiation.New_Type would have two components named
Field3.

When Y.Field3 is accessed, which Field3 is meant?

Which language rules in the RM govern this situation?

				-- thanks, Adam

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about generic formal derived types
  1999-03-30  0:00 Question about generic formal derived types adam
  1999-03-30  0:00 ` Steve Quinlan
@ 1999-03-30  0:00 ` Stephen Leake
  1999-03-30  0:00   ` adam
  1999-03-31  0:00   ` robert_dewar
  1 sibling, 2 replies; 6+ messages in thread
From: Stephen Leake @ 1999-03-30  0:00 UTC (permalink / raw)


adam@irvine.com writes:

After adding a spec for Pack4, running this thru ObjectAda 7.1.2 gives
the error:

adam.adb: Error: line 32 col 67 LRM:8.3(26), Illegal to override
       declaration in same region, Introducing new declaration anyway
       (In instance of generic Pack2 at adam.adb: line 13 col 9)

I believe that answers all your questions :).

-- Stephe

> In this program fragment:
> 
> -------------------------------------------------------------------------------
> package Pack1 is
>     type Root_Type is tagged record
>         Field1 : Integer;
>         Field2 : Boolean;
>     end record;
> end Pack1;
> 
> with Pack1;
> generic
>     type Formal_Type is new Pack1.Root_Type with private;
> package Pack2 is
>     type New_Type is new Formal_Type with record
>         Field3 : Character;
>     end record;
> end Pack2;
> 
> with Pack1;
> package Pack3 is
>     type Root_Type_Extension is new Pack1.Root_Type with record
>         Field3 : Float;
>     end record;
> end Pack3;
> 
> . . .
> 
> with Pack2;
> with Pack3;
> package body Pack4 is
> 
>     package Instantiation is new Pack2 (Pack3.Root_Type_Extension);
> 
>     procedure Inner is
>         X : Character;
>         Y : Instantiation.New_Type;
>     begin
>         X := Y.Field3;
>     end Inner;
> 
> end Pack4;
> 
> -------------------------------------------------------------------------------
> 
> I can't believe that a record type can have two components of the same name,
> but it appears that Instantiation.New_Type would have two components named
> Field3.
> 
> When Y.Field3 is accessed, which Field3 is meant?
> 
> Which language rules in the RM govern this situation?
> 
> 				-- thanks, Adam
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about generic formal derived types
  1999-03-30  0:00 Question about generic formal derived types adam
@ 1999-03-30  0:00 ` Steve Quinlan
  1999-03-30  0:00 ` Stephen Leake
  1 sibling, 0 replies; 6+ messages in thread
From: Steve Quinlan @ 1999-03-30  0:00 UTC (permalink / raw)


GNAT doesn't like it either.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about generic formal derived types
  1999-03-30  0:00 ` Stephen Leake
@ 1999-03-30  0:00   ` adam
  1999-03-31  0:00     ` Stephen Leake
  1999-03-31  0:00   ` robert_dewar
  1 sibling, 1 reply; 6+ messages in thread
From: adam @ 1999-03-30  0:00 UTC (permalink / raw)


In article <uemm6suip.fsf@gsfc.nasa.gov>,
  Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote:

>
> After adding a spec for Pack4, running this thru ObjectAda 7.1.2 gives
> the error:
>
> adam.adb: Error: line 32 col 67 LRM:8.3(26), Illegal to override
>        declaration in same region, Introducing new declaration anyway
>        (In instance of generic Pack2 at adam.adb: line 13 col 9)
>
> I believe that answers all your questions :).
>
> -- Stephe

I hope the smiley means you were kidding.  Certainly, just running it through
a compiler and seeing what the compiler says doesn't really answer any
questions, since the Ada language rules are not determined by what a specific
compiler says they are or aren't.  (This principle might not apply to other
languages. :-))  Besides, the error message doesn't say what "declaration"
it considers illegal, and the line number doesn't help because you had to add
some text to my fragment.

I did look at 8.3(26), but it's taken me a while to figure out whether it
applies to the two components with the same name, and I'm still not sure.
8.3(26) refers to a homograph being declared in the same declarative region,
but the definition of "declarative region" in 8.1(1-11) doesn't give any
indication that component names in a type extension belong to the same
declarative region.  I had to stumble across 3.4(14) to find out that the
components of a parent type are considered to be implicit declarations in the
declarative region of the derived type.  (From what I can find, it appears
that 3.4(14) and 8.3(26) taken together are the way we know that a component
in a type extension can't have the same name as a component of the parent
type, in contrast to 3.8(9) which says, probably redundantly, that two
components of a record type can't have the same name.)	Anyway, figuring out
how this applies to a generic isn't trivial.  8.3(26) doesn't seem to help
since the name being defined twice is neither a dispatching operation nor an
overloadable declaration.  12.3(11) seems to be the key here, saying that
Legality Rules (of which 8.3(26) is one) are enforced at the time of
instantiation for the visible part of an instance.  But then we have to deal
with 12.3(18), which seems like it might imply that one declaration of Field3
might override the other, since (according to 3.4(14)) the component
declarations inherited from a parent type are *implicit* declarations in the
declarative region of the derived type.  Then there's 12.3(11.v) in the AARM,
which seems like it might clarify things, assuming I'm interpreting it
correctly, which I'm not sure about.

So after reading everything, it looks like the intent is to make this
instantiation illegal because of the name conflict, although it seems to be
the only way I can think of that a generic instantiation can be illegal for
this reason.  This last makes me skeptical that this was what the language
designers intended, which is why I'm hoping for an "official" answer from
someone in the know (i.e. a human someone, not a compiler someone).

				-- Adam

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about generic formal derived types
  1999-03-30  0:00 ` Stephen Leake
  1999-03-30  0:00   ` adam
@ 1999-03-31  0:00   ` robert_dewar
  1 sibling, 0 replies; 6+ messages in thread
From: robert_dewar @ 1999-03-31  0:00 UTC (permalink / raw)


In article <uemm6suip.fsf@gsfc.nasa.gov>,
  Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote:
> adam@irvine.com writes:
>
> After adding a spec for Pack4, running this thru
> ObjectAda 7.1.2 gives
> the error:
>
> adam.adb: Error: line 32 col 67 LRM:8.3(26), Illegal to
>           override declaration in same region,
>           Introducing new declaration anyway
>           (In instance of generic Pack2 at
>           adam.adb: line 13 col 9)


GNAT says

pack4.adb:6:05: instantiation error at pack2.ads:7
pack4.adb:6:05: "Field3" conflicts with declaration at
                pack3.ads:5

which seems clear enough (even if it does not send you
scurrying to the RM to answer all your questions :-)


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about generic formal derived types
  1999-03-30  0:00   ` adam
@ 1999-03-31  0:00     ` Stephen Leake
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 1999-03-31  0:00 UTC (permalink / raw)


adam@irvine.com writes:

> In article <uemm6suip.fsf@gsfc.nasa.gov>,
>   Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote:
> 
> >
> > After adding a spec for Pack4, running this thru ObjectAda 7.1.2 gives
> > the error:
> >
> > adam.adb: Error: line 32 col 67 LRM:8.3(26), Illegal to override
> >        declaration in same region, Introducing new declaration anyway
> >        (In instance of generic Pack2 at adam.adb: line 13 col 9)
> >
> > I believe that answers all your questions :).
> >
> > -- Stephe
> 
> I hope the smiley means you were kidding.  Certainly, just running it through
> a compiler and seeing what the compiler says doesn't really answer any
> questions, since the Ada language rules are not determined by what a specific
> compiler says they are or aren't.  (This principle might not apply to other
> languages. :-))  Besides, the error message doesn't say what "declaration"
> it considers illegal, and the line number doesn't help because you had to add
> some text to my fragment.

Hmm, I wasn't kidding, although I didn't spend much time on it. I'd
have spent more time if you had posted fully compilable code, and said
what error your compiler gave. Since you didn't, I assumed you had no
compiler, and simply provided the answer a compiler gives. I used
ObjectAda, because it gives LRM references.

I don't intend this as criticism, just as a suggestion on how to
phrase future posts to more likely elicit the response you really
want.

> <snip rummaging thru LRM>
> 
> So after reading everything, it looks like the intent is to make this
> instantiation illegal because of the name conflict, although it seems to be
> the only way I can think of that a generic instantiation can be illegal for
> this reason.  This last makes me skeptical that this was what the language
> designers intended, which is why I'm hoping for an "official" answer from
> someone in the know (i.e. a human someone, not a compiler someone).

Well, I'm not in a position to say anything authoritative. But my
approach to understanding this would be "this would make no sense if
it were legal, so how can I charitably read the LRM to make it
illegal". Depending on why you want to know what the LRM says, this
might be enough (it's enough for me :). If you're writing a compiler,
you need more detail.

-- Stephe




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-03-31  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-30  0:00 Question about generic formal derived types adam
1999-03-30  0:00 ` Steve Quinlan
1999-03-30  0:00 ` Stephen Leake
1999-03-30  0:00   ` adam
1999-03-31  0:00     ` Stephen Leake
1999-03-31  0:00   ` robert_dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox