* Dispatching Example @ 2001-09-03 15:16 Ed Colbert 2001-09-04 10:55 ` Jacob Sparre Andersen 2001-09-04 21:30 ` Tucker Taft 0 siblings, 2 replies; 7+ messages in thread From: Ed Colbert @ 2001-09-03 15:16 UTC (permalink / raw) Hi All, Below is a simplified example from Richard Riehle's & my course on Ada. GNAT v3.13p says that the call Is_Item is an mbiguous expression, and ObjectAda v 7.2 says the statement is illegal based on LRM 5.2(6). Both Richard and I thought that the expression is tag indeterminate, LRM 3.9.2(6), and would static resolved, LRM 3.9.2(19). Are Richard and I missing something or are both compilers wrong? package Dispatching_Examples is type T1 is tagged private; function Is_Item return T1; type T2 is new T1 with private; function Is_Item return T2; private -- full definition of T1 and T2 type T1 is tagged null record; type T2 is new T1 with null record; end Dispatching_Examples; with Dispatching_Examples; use Dispatching_Examples; procedure Dispatching_Examples_Driver is A, B : T1; -- simple variables Q, R : T2; -- simple variables C : T1'Class := A; -- class-wide variable D : T2'Class := R ; -- class-wide variable begin C := Is_Item ; -- static resolution? end Dispatching_Examples_Driver; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-03 15:16 Dispatching Example Ed Colbert @ 2001-09-04 10:55 ` Jacob Sparre Andersen 2001-09-04 21:30 ` Tucker Taft 1 sibling, 0 replies; 7+ messages in thread From: Jacob Sparre Andersen @ 2001-09-04 10:55 UTC (permalink / raw) Ed: > with Dispatching_Examples; > use Dispatching_Examples; > procedure Dispatching_Examples_Driver is > A, B : T1; -- simple variables > Q, R : T2; -- simple variables > C : T1'Class := A; -- class-wide variable > D : T2'Class := R ; -- class-wide variable > begin > C := Is_Item ; -- static resolution? Since both: C := T2'Class (Q); and C := T1'Class (B); are legal, the compiler can not possibly figure out which of the two "Is_Item" functions you refer to. If you want the compiler to do a static resolution, you have to specify which type the class-wide variable should be treated as having: T1 (C) := Is_Item; > end Dispatching_Examples_Driver; Jacob -- "Then, after a second or so, nothing continued to happen." ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-03 15:16 Dispatching Example Ed Colbert 2001-09-04 10:55 ` Jacob Sparre Andersen @ 2001-09-04 21:30 ` Tucker Taft 2001-09-04 22:18 ` Pat Rogers 2001-09-10 0:50 ` Ed Colbert 1 sibling, 2 replies; 7+ messages in thread From: Tucker Taft @ 2001-09-04 21:30 UTC (permalink / raw) Ed Colbert wrote: > > Hi All, > > Below is a simplified example from Richard Riehle's & my course on Ada. > GNAT v3.13p says that the call Is_Item is an mbiguous expression, and > ObjectAda v 7.2 says the statement is illegal based on LRM 5.2(6). Both > Richard and I thought that the expression is tag indeterminate, LRM > 3.9.2(6), and would static resolved, LRM 3.9.2(19). Are Richard and I > missing something or are both compilers wrong? The call on Is_Item is ambiguous, even though one of the possible interpretations (the one returning type T1) violates 5.2(6). This is one of those cases where the overload resolution rules are less picky than the legality rules, which can be a bit confusing. ObjectAda is not being very helpful by telling you that one of the interpretations is illegal, without first telling you that the expression is considered ambiguous by the overloading rules. In any case, if only the Is_Item that returned type T1 were directly visible, the expression would not be ambiguous, and the call would be legal. It would involve a "dispatching on result" where the tag of "C" would determine which body of Is_Item were called. In general the overload resolution and legality rules relating to classwide assignment are confusing at best. We tried other rules, but they had worse problems, so I suppose the current rules are the best of a set of unpleasant alternatives. ObjectAda's error message was unfortunately only adding to the confusion. -Tucker Taft stt@avercom.net > > package Dispatching_Examples > is > type T1 is tagged private; > function Is_Item return T1; > > type T2 is new T1 with private; > function Is_Item return T2; > > private > -- full definition of T1 and T2 > type T1 is tagged null record; > type T2 is new T1 with null record; > end Dispatching_Examples; > > with Dispatching_Examples; > use Dispatching_Examples; > procedure Dispatching_Examples_Driver is > A, B : T1; -- simple variables > Q, R : T2; -- simple variables > C : T1'Class := A; -- class-wide variable > D : T2'Class := R ; -- class-wide variable > begin > C := Is_Item ; -- static resolution? > end Dispatching_Examples_Driver; -- -Tucker Taft stt@avercom.net http://www.avercom.net Chief Technology Officer, AverCom Corporation (A Titan Company) Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar: http://www.averstar.com/~stt) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-04 21:30 ` Tucker Taft @ 2001-09-04 22:18 ` Pat Rogers 2001-09-05 16:02 ` Tucker Taft 2001-09-10 0:50 ` Ed Colbert 1 sibling, 1 reply; 7+ messages in thread From: Pat Rogers @ 2001-09-04 22:18 UTC (permalink / raw) Yet AARM 3.9.2{19a} sez: "Ramification: This includes the cases of a tag-indeterminate procedure call, and a tag-indeterminate function_call that is used to initialize a class-wide formal parameter or class-wide object. " Hence I would have thought (and indeed, have taught) that: C : T1'Class := Is_Item; is a call to the function returning a value of type T1. "Tucker Taft" <stt@avercom.net> wrote in message news:3B9547D9.BE2CC282@avercom.net... > Ed Colbert wrote: > > > > Hi All, > > > > Below is a simplified example from Richard Riehle's & my course on Ada. > > GNAT v3.13p says that the call Is_Item is an mbiguous expression, and > > ObjectAda v 7.2 says the statement is illegal based on LRM 5.2(6). Both > > Richard and I thought that the expression is tag indeterminate, LRM > > 3.9.2(6), and would static resolved, LRM 3.9.2(19). Are Richard and I > > missing something or are both compilers wrong? > > The call on Is_Item is ambiguous, even though one of the > possible interpretations (the one returning type T1) violates > 5.2(6). This is one of those cases where the overload > resolution rules are less picky than the legality rules, > which can be a bit confusing. > > ObjectAda is not being very helpful by telling you that one > of the interpretations is illegal, without first telling > you that the expression is considered ambiguous by the > overloading rules. > > In any case, if only the Is_Item that returned type T1 were > directly visible, the expression would not be ambiguous, and > the call would be legal. It would involve a "dispatching > on result" where the tag of "C" would determine which body > of Is_Item were called. > > In general the overload resolution and legality rules relating > to classwide assignment are confusing at best. We tried other > rules, but they had worse problems, so I suppose the current > rules are the best of a set of unpleasant alternatives. > ObjectAda's error message was unfortunately only adding to > the confusion. > > -Tucker Taft stt@avercom.net > > > > package Dispatching_Examples > > is > > type T1 is tagged private; > > function Is_Item return T1; > > > > type T2 is new T1 with private; > > function Is_Item return T2; > > > > private > > -- full definition of T1 and T2 > > type T1 is tagged null record; > > type T2 is new T1 with null record; > > end Dispatching_Examples; > > > > with Dispatching_Examples; > > use Dispatching_Examples; > > procedure Dispatching_Examples_Driver is > > A, B : T1; -- simple variables > > Q, R : T2; -- simple variables > > C : T1'Class := A; -- class-wide variable > > D : T2'Class := R ; -- class-wide variable > > begin > > C := Is_Item ; -- static resolution? > > end Dispatching_Examples_Driver; > > -- > -Tucker Taft stt@avercom.net http://www.avercom.net > Chief Technology Officer, AverCom Corporation (A Titan Company) > Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar: > http://www.averstar.com/~stt) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-04 22:18 ` Pat Rogers @ 2001-09-05 16:02 ` Tucker Taft 2001-09-05 21:19 ` Florian Weimer 0 siblings, 1 reply; 7+ messages in thread From: Tucker Taft @ 2001-09-05 16:02 UTC (permalink / raw) Pat Rogers wrote: > > Yet AARM 3.9.2{19a} sez: > > "Ramification: This includes the cases of a tag-indeterminate procedure > call, and a tag-indeterminate function_call that is used to initialize a > class-wide formal parameter or class-wide object. " > > Hence I would have thought (and indeed, have taught) that: > > C : T1'Class := Is_Item; > > is a call to the function returning a value of type T1. This is still ambiguous, because either interpretation of Is_Item would be allowed by the overload resolution rules. However, presuming you only have one of them visible, then you are correct that 3.9.2(19) applies, and it would be a statically bound call rather than dynamically bound. However, I believe the original question related to an assignment statement rather than an initialization. With an assignment statement, the LHS already has a value, and hence a tag, and the implementation uses that tag to control the dispatch. In an initialization, the LHS doesn't have a tag yet, so the tag is statically determined by the "compile-time" return type of Is_Item. -Tucker Taft stt@avercom.net > > "Tucker Taft" <stt@avercom.net> wrote in message > news:3B9547D9.BE2CC282@avercom.net... > > Ed Colbert wrote: > > > > > > Hi All, > > > > > > Below is a simplified example from Richard Riehle's & my course on Ada. > > > GNAT v3.13p says that the call Is_Item is an mbiguous expression, and > > > ObjectAda v 7.2 says the statement is illegal based on LRM 5.2(6). Both > > > Richard and I thought that the expression is tag indeterminate, LRM > > > 3.9.2(6), and would static resolved, LRM 3.9.2(19). Are Richard and I > > > missing something or are both compilers wrong? > > > > The call on Is_Item is ambiguous, even though one of the > > possible interpretations (the one returning type T1) violates > > 5.2(6). This is one of those cases where the overload > > resolution rules are less picky than the legality rules, > > which can be a bit confusing. > > > > ObjectAda is not being very helpful by telling you that one > > of the interpretations is illegal, without first telling > > you that the expression is considered ambiguous by the > > overloading rules. > > > > In any case, if only the Is_Item that returned type T1 were > > directly visible, the expression would not be ambiguous, and > > the call would be legal. It would involve a "dispatching > > on result" where the tag of "C" would determine which body > > of Is_Item were called. > > > > In general the overload resolution and legality rules relating > > to classwide assignment are confusing at best. We tried other > > rules, but they had worse problems, so I suppose the current > > rules are the best of a set of unpleasant alternatives. > > ObjectAda's error message was unfortunately only adding to > > the confusion. > > > > -Tucker Taft stt@avercom.net > > > > > > package Dispatching_Examples > > > is > > > type T1 is tagged private; > > > function Is_Item return T1; > > > > > > type T2 is new T1 with private; > > > function Is_Item return T2; > > > > > > private > > > -- full definition of T1 and T2 > > > type T1 is tagged null record; > > > type T2 is new T1 with null record; > > > end Dispatching_Examples; > > > > > > with Dispatching_Examples; > > > use Dispatching_Examples; > > > procedure Dispatching_Examples_Driver is > > > A, B : T1; -- simple variables > > > Q, R : T2; -- simple variables > > > C : T1'Class := A; -- class-wide variable > > > D : T2'Class := R ; -- class-wide variable > > > begin > > > C := Is_Item ; -- static resolution? > > > end Dispatching_Examples_Driver; > > > > -- > > -Tucker Taft stt@avercom.net http://www.avercom.net > > Chief Technology Officer, AverCom Corporation (A Titan Company) > > Bedford, MA USA (AverCom was formerly the Commercial Division of > AverStar: > > http://www.averstar.com/~stt) -- -Tucker Taft stt@avercom.net http://www.avercom.net Chief Technology Officer, AverCom Corporation (A Titan Company) Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar: http://www.averstar.com/~stt) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-05 16:02 ` Tucker Taft @ 2001-09-05 21:19 ` Florian Weimer 0 siblings, 0 replies; 7+ messages in thread From: Florian Weimer @ 2001-09-05 21:19 UTC (permalink / raw) Tucker Taft <stt@avercom.net> writes: > However, I believe the original question related to an > assignment statement rather than an initialization. > With an assignment statement, the LHS already has a value, > and hence a tag, and the implementation uses that tag > to control the dispatch. In an initialization, the LHS > doesn't have a tag yet, so the tag is statically determined > by the "compile-time" return type of Is_Item. Hmm, the whole discussion reminds me of the Ada reference in the famous 'Real Programmers Don't Use Pascal' paper. ;-) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Dispatching Example 2001-09-04 21:30 ` Tucker Taft 2001-09-04 22:18 ` Pat Rogers @ 2001-09-10 0:50 ` Ed Colbert 1 sibling, 0 replies; 7+ messages in thread From: Ed Colbert @ 2001-09-10 0:50 UTC (permalink / raw) Hi Tucker, "Tucker Taft" <stt@avercom.net> wrote in message news:3B9547D9.BE2CC282@avercom.net... > Ed Colbert wrote: > > > > Hi All, > > > > Below is a simplified example from Richard Riehle's & my course on Ada. > > GNAT v3.13p says that the call Is_Item is an mbiguous expression, and > > ObjectAda v 7.2 says the statement is illegal based on LRM 5.2(6). Both > > Richard and I thought that the expression is tag indeterminate, LRM > > 3.9.2(6), and would static resolved, LRM 3.9.2(19). Are Richard and I > > missing something or are both compilers wrong? > > The call on Is_Item is ambiguous, even though one of the > possible interpretations (the one returning type T1) violates > 5.2(6). This is one of those cases where the overload > resolution rules are less picky than the legality rules, > which can be a bit confusing. > > ObjectAda is not being very helpful by telling you that one > of the interpretations is illegal, without first telling > you that the expression is considered ambiguous by the > overloading rules. > Why is the expression ambiguous? Isn't the tag of C, which in this case is compile time determinable, used to resolve the call to Is_Item per 5.2(9)? I suppose it could be ambiguous if the expression is evaluated first as allowed by 5.2(7); but then when would 5.2(8-10) apply? > In any case, if only the Is_Item that returned type T1 were > directly visible, the expression would not be ambiguous, and > the call would be legal. It would involve a "dispatching > on result" where the tag of "C" would determine which body > of Is_Item were called. > > In general the overload resolution and legality rules relating > to classwide assignment are confusing at best. We tried other > rules, but they had worse problems, so I suppose the current > rules are the best of a set of unpleasant alternatives. > ObjectAda's error message was unfortunately only adding to > the confusion. > Clearly, there's something that's confusing Richard & I. > > > > package Dispatching_Examples > > is > > type T1 is tagged private; > > function Is_Item return T1; > > > > type T2 is new T1 with private; > > function Is_Item return T2; > > > > private > > -- full definition of T1 and T2 > > type T1 is tagged null record; > > type T2 is new T1 with null record; > > end Dispatching_Examples; > > > > with Dispatching_Examples; > > use Dispatching_Examples; > > procedure Dispatching_Examples_Driver is > > A, B : T1; -- simple variables > > Q, R : T2; -- simple variables > > C : T1'Class := A; -- class-wide variable > > D : T2'Class := R ; -- class-wide variable > > begin > > C := Is_Item ; -- static resolution? > > end Dispatching_Examples_Driver; > > -- > -Tucker Taft stt@avercom.net http://www.avercom.net > Chief Technology Officer, AverCom Corporation (A Titan Company) > Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar: > http://www.averstar.com/~stt) > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-09-10 0:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-09-03 15:16 Dispatching Example Ed Colbert 2001-09-04 10:55 ` Jacob Sparre Andersen 2001-09-04 21:30 ` Tucker Taft 2001-09-04 22:18 ` Pat Rogers 2001-09-05 16:02 ` Tucker Taft 2001-09-05 21:19 ` Florian Weimer 2001-09-10 0:50 ` Ed Colbert
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox