* Discriminant ans tagged type ?! @ 2008-03-18 15:22 Tony 2008-03-18 15:54 ` Adam Beneschan 2008-03-18 18:40 ` Robert A Duff 0 siblings, 2 replies; 9+ messages in thread From: Tony @ 2008-03-18 15:22 UTC (permalink / raw) I just do not understand why the following code compiles with the Aonix compiler and not with the Gnat GPL 2007? package A_Pkg is type A (L : Natural) is tagged null record; end A_Pkg; package A_Pkg.B_Pkg is type B is new A with record T : String(1..L); end record; end A_Pkg.B_Pkg; with A_Pkg.B_Pkg; procedure Strange is begin null; end Strange; => RM95 3.7 (18) ?? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-18 15:22 Discriminant ans tagged type ?! Tony @ 2008-03-18 15:54 ` Adam Beneschan 2008-03-18 19:54 ` Adam Beneschan 2008-03-18 18:40 ` Robert A Duff 1 sibling, 1 reply; 9+ messages in thread From: Adam Beneschan @ 2008-03-18 15:54 UTC (permalink / raw) On Mar 18, 8:22 am, Tony <truand.t...@gmail.com> wrote: > I just do not understand why the following code compiles with the Aonix > compiler and not with the Gnat GPL 2007? Because one of the compilers has a bug. Or did you want a *helpful* answer??? :) :) :) > > package A_Pkg is > type A (L : Natural) is tagged null record; > end A_Pkg; > > package A_Pkg.B_Pkg is > type B is new A with record > T : String(1..L); > end record; > end A_Pkg.B_Pkg; > > with A_Pkg.B_Pkg; > procedure Strange is > begin > null; > end Strange; > > => RM95 3.7 (18) ?? Yes, B inherits the discriminant L, but this doesn't make L *visible*. In order to use L by itself, as you did in the definition of the component T, L has to be directly visible. The rules for this are in 8.1 and 8.2, and aren't easy to understand. The applicable rules here are that: The declaration of L (when the discriminant is first declared) is visible up to the end of the declarative region immediately enclosing it, which is the definition of the type A. But this declarative region does *not* encompass the declarations of any type extensions. (Also, the fact that B "inherits" L is not equivalent to there being an implicit declaration of L; unlike inherited subprograms, inherited discriminants aren't implicitly declared.) Thus, L is not directly visible within the declaration of B. However, I tried changing the declaration of T as follows: T : String (1 .. B.L); and GNAT accepted it. (I haven't done enough testing to make sure GNAT handles it correctly in other ways, though.) Here, B refers to the "current instance" of the type (8.6(17)), and 3.7(18) means that all instances of the type will have a component L that is inherited from A, so this should be legal unless there are some other rules that I've missed (and that GNAT also missed). Hope this helps, -- Adam ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-18 15:54 ` Adam Beneschan @ 2008-03-18 19:54 ` Adam Beneschan 2008-03-21 8:18 ` Tony 0 siblings, 1 reply; 9+ messages in thread From: Adam Beneschan @ 2008-03-18 19:54 UTC (permalink / raw) On Mar 18, 8:54 am, Adam Beneschan <a...@irvine.com> wrote: > However, I tried changing the declaration of T as follows: > > T : String (1 .. B.L); > > and GNAT accepted it. (I haven't done enough testing to make sure > GNAT handles it correctly in other ways, though.) Here, B refers to > the "current instance" of the type (8.6(17)), and 3.7(18) means that > all instances of the type will have a component L that is inherited > from A, so this should be legal unless there are some other rules that > I've missed (and that GNAT also missed). Never mind. After reading Bob's post, I got pointed to 3.8(10-12), which disallows references to inherited discriminants in a type extension. So I guess GNAT (or at least the version I'm using, which is probably not the latest) is wrong to accept this. Sorry. -- Adam ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-18 19:54 ` Adam Beneschan @ 2008-03-21 8:18 ` Tony 2008-03-21 15:25 ` Adam Beneschan 0 siblings, 1 reply; 9+ messages in thread From: Tony @ 2008-03-21 8:18 UTC (permalink / raw) On 18 mar, 20:54, Adam Beneschan <a...@irvine.com> wrote: > On Mar 18, 8:54 am, Adam Beneschan <a...@irvine.com> wrote: > > > However, I tried changing the declaration of T as follows: > > > T : String (1 .. B.L); > > > and GNAT accepted it. (I haven't done enough testing to make sure > > GNAT handles it correctly in other ways, though.) Here, B refers to > > the "current instance" of the type (8.6(17)), and 3.7(18) means that > > all instances of the type will have a component L that is inherited > > from A, so this should be legal unless there are some other rules that > > I've missed (and that GNAT also missed). > > Never mind. After reading Bob's post, I got pointed to 3.8(10-12), > which disallows references to inherited discriminants in a type > extension. So I guess GNAT (or at least the version I'm using, which > is probably not the latest) is wrong to accept this. Sorry. > > -- Adam -- I tried Bob's answer with the Aonix compiler: ERROR : LRM:3.8(12), A discriminant used in a constraint may only appear alone as a direct_name. I'm lost...;-) Is my first code correct? I guess yes... Tony ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-21 8:18 ` Tony @ 2008-03-21 15:25 ` Adam Beneschan 2008-03-21 16:46 ` Simon Wright 2008-03-22 9:05 ` Tony 0 siblings, 2 replies; 9+ messages in thread From: Adam Beneschan @ 2008-03-21 15:25 UTC (permalink / raw) On Mar 21, 1:18 am, Tony <truand.t...@gmail.com> wrote: > On 18 mar, 20:54, Adam Beneschan <a...@irvine.com> wrote: > > > > > On Mar 18, 8:54 am, Adam Beneschan <a...@irvine.com> wrote: > > > > However, I tried changing the declaration of T as follows: > > > > T : String (1 .. B.L); -- NO, THIS IS WRONG, I SCREWED UP > > > > and GNAT accepted it. (I haven't done enough testing to make sure > > > GNAT handles it correctly in other ways, though.) Here, B refers to > > > the "current instance" of the type (8.6(17)), and 3.7(18) means that > > > all instances of the type will have a component L that is inherited > > > from A, so this should be legal unless there are some other rules that > > > I've missed (and that GNAT also missed). > > > Never mind. After reading Bob's post, I got pointed to 3.8(10-12), > > which disallows references to inherited discriminants in a type > > extension. So I guess GNAT (or at least the version I'm using, which > > is probably not the latest) is wrong to accept this. Sorry. > > > -- Adam > > -- > I tried Bob's answer with the Aonix compiler: > ERROR : LRM:3.8(12), A discriminant used in a constraint may only > appear alone as a direct_name. > I'm lost...;-) 3.8(12) is one of the rules I overlooked (thanks, Tuck). Perhaps you tried Bob's answer together with my incorrect suggestion to use string(1..B.L), which violates that rule; when you use a discriminant in a constraint, the discriminant can't be an "expanded name" or part of a larger expression, and I think B.L is an expanded name here. My apologies for misleading you. This should work: type B (L : Natural) is new A(L) with record T : String (1 .. L); end record; Everything I said earlier about visibility wouldn't apply here, because redeclaring the discriminant L makes it visible inside the record declaration of B. This would work too: type B (Ell : Natural) is new A(L) with record T : String (1 .. Ell); end record; It's the new discriminant that can be used in the declaration, not the one inherited from A. > Is my first code correct? I guess yes... Still no. The compiler may accept it, but that just means the compiler has a bug. I hope I've got everything straight now. -- Adam ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-21 15:25 ` Adam Beneschan @ 2008-03-21 16:46 ` Simon Wright 2008-03-22 9:05 ` Tony 1 sibling, 0 replies; 9+ messages in thread From: Simon Wright @ 2008-03-21 16:46 UTC (permalink / raw) Adam Beneschan <adam@irvine.com> writes: > type B (Ell : Natural) is new A(L) with record A(L => Ell) > T : String (1 .. Ell); > end record; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-21 15:25 ` Adam Beneschan 2008-03-21 16:46 ` Simon Wright @ 2008-03-22 9:05 ` Tony 2008-04-04 15:40 ` Tom Grosman 1 sibling, 1 reply; 9+ messages in thread From: Tony @ 2008-03-22 9:05 UTC (permalink / raw) On 21 mar, 16:25, Adam Beneschan <a...@irvine.com> wrote: > On Mar 21, 1:18 am, Tony <truand.t...@gmail.com> wrote: > > > > > On 18 mar, 20:54, Adam Beneschan <a...@irvine.com> wrote: > > > > On Mar 18, 8:54 am, Adam Beneschan <a...@irvine.com> wrote: > > > > > However, I tried changing the declaration of T as follows: > > > > > T : String (1 .. B.L); -- NO, THIS IS WRONG, I SCREWED UP > > > > > and GNAT accepted it. (I haven't done enough testing to make sure > > > > GNAT handles it correctly in other ways, though.) Here, B refers to > > > > the "current instance" of the type (8.6(17)), and 3.7(18) means that > > > > all instances of the type will have a component L that is inherited > > > > from A, so this should be legal unless there are some other rules that > > > > I've missed (and that GNAT also missed). > > > > Never mind. After reading Bob's post, I got pointed to 3.8(10-12), > > > which disallows references to inherited discriminants in a type > > > extension. So I guess GNAT (or at least the version I'm using, which > > > is probably not the latest) is wrong to accept this. Sorry. > > > > -- Adam > > > -- > > I tried Bob's answer with the Aonix compiler: > > ERROR : LRM:3.8(12), A discriminant used in a constraint may only > > appear alone as a direct_name. > > I'm lost...;-) > > 3.8(12) is one of the rules I overlooked (thanks, Tuck). Perhaps you > tried Bob's answer together with my incorrect suggestion to use > string(1..B.L), which violates that rule; when you use a discriminant > in a constraint, the discriminant can't be an "expanded name" or part > of a larger expression, and I think B.L is an expanded name here. My > apologies for misleading you. > > This should work: > > type B (L : Natural) is new A(L) with record > T : String (1 .. L); > end record; > > Everything I said earlier about visibility wouldn't apply here, > because redeclaring the discriminant L makes it visible inside the > record declaration of B. This would work too: > > type B (Ell : Natural) is new A(L) with record > T : String (1 .. Ell); > end record; > > It's the new discriminant that can be used in the declaration, not the > one inherited from A. > > > Is my first code correct? I guess yes... > > Still no. The compiler may accept it, but that just means the > compiler has a bug. > > I hope I've got everything straight now. > > -- Adam -- You are right !! , it works :-) Thanks for all. Tony. -- ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-22 9:05 ` Tony @ 2008-04-04 15:40 ` Tom Grosman 0 siblings, 0 replies; 9+ messages in thread From: Tom Grosman @ 2008-04-04 15:40 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2871 bytes --] "Tony" <truand.tony@gmail.com> a �crit dans le message de news: cc37c7dc-d89b-4f4a-82e3-24941300efb5@k13g2000hse.googlegroups.com... > On 21 mar, 16:25, Adam Beneschan <a...@irvine.com> wrote: >> On Mar 21, 1:18 am, Tony <truand.t...@gmail.com> wrote: >> >> >> >> > On 18 mar, 20:54, Adam Beneschan <a...@irvine.com> wrote: >> >> > > On Mar 18, 8:54 am, Adam Beneschan <a...@irvine.com> wrote: >> >> > > > However, I tried changing the declaration of T as follows: >> >> > > > T : String (1 .. B.L); -- NO, THIS IS WRONG, I SCREWED UP >> >> > > > and GNAT accepted it. (I haven't done enough testing to make sure >> > > > GNAT handles it correctly in other ways, though.) Here, B refers >> > > > to >> > > > the "current instance" of the type (8.6(17)), and 3.7(18) means >> > > > that >> > > > all instances of the type will have a component L that is inherited >> > > > from A, so this should be legal unless there are some other rules >> > > > that >> > > > I've missed (and that GNAT also missed). >> >> > > Never mind. After reading Bob's post, I got pointed to 3.8(10-12), >> > > which disallows references to inherited discriminants in a type >> > > extension. So I guess GNAT (or at least the version I'm using, which >> > > is probably not the latest) is wrong to accept this. Sorry. >> >> > > -- Adam >> >> > -- >> > I tried Bob's answer with the Aonix compiler: >> > ERROR : LRM:3.8(12), A discriminant used in a constraint may only >> > appear alone as a direct_name. >> > I'm lost...;-) >> >> 3.8(12) is one of the rules I overlooked (thanks, Tuck). Perhaps you >> tried Bob's answer together with my incorrect suggestion to use >> string(1..B.L), which violates that rule; when you use a discriminant >> in a constraint, the discriminant can't be an "expanded name" or part >> of a larger expression, and I think B.L is an expanded name here. My >> apologies for misleading you. >> >> This should work: >> >> type B (L : Natural) is new A(L) with record >> T : String (1 .. L); >> end record; >> >> Everything I said earlier about visibility wouldn't apply here, >> because redeclaring the discriminant L makes it visible inside the >> record declaration of B. This would work too: >> >> type B (Ell : Natural) is new A(L) with record >> T : String (1 .. Ell); >> end record; >> >> It's the new discriminant that can be used in the declaration, not the >> one inherited from A. >> >> > Is my first code correct? I guess yes... >> >> Still no. The compiler may accept it, but that just means the >> compiler has a bug. >> >> I hope I've got everything straight now. >> >> -- Adam > -- > You are right !! , it works :-) > Thanks for all. > Tony. > -- Tony, Thanks for bringing this problem to our attention. Tom Grosman, Aonix ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Discriminant ans tagged type ?! 2008-03-18 15:22 Discriminant ans tagged type ?! Tony 2008-03-18 15:54 ` Adam Beneschan @ 2008-03-18 18:40 ` Robert A Duff 1 sibling, 0 replies; 9+ messages in thread From: Robert A Duff @ 2008-03-18 18:40 UTC (permalink / raw) Tony <truand.tony@gmail.com> writes: > I just do not understand why the following code compiles with the Aonix > compiler and not with the Gnat GPL 2007? > > package A_Pkg is > type A (L : Natural) is tagged null record; > end A_Pkg; > > package A_Pkg.B_Pkg is > type B is new A with record > T : String(1..L); > end record; > end A_Pkg.B_Pkg; > > with A_Pkg.B_Pkg; > procedure Strange is > begin > null; > end Strange; > > => RM95 3.7 (18) ?? There's 3.9.1(8), which is a NOTE. If you want to do the above, you can say: type B (L : Natural) is new A(L) with ... - Bob ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-04-04 15:40 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-03-18 15:22 Discriminant ans tagged type ?! Tony 2008-03-18 15:54 ` Adam Beneschan 2008-03-18 19:54 ` Adam Beneschan 2008-03-21 8:18 ` Tony 2008-03-21 15:25 ` Adam Beneschan 2008-03-21 16:46 ` Simon Wright 2008-03-22 9:05 ` Tony 2008-04-04 15:40 ` Tom Grosman 2008-03-18 18:40 ` Robert A Duff
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox