From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,c52c30d32b866eae X-Google-Attributes: gidfac41,public X-Google-Thread: 1108a1,c52c30d32b866eae X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,2ea02452876a15e1 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Real OO Date: 1996/05/02 Message-ID: #1/1 X-Deja-AN: 152638944 references: organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.eiffel,comp.lang.ada,comp.object Date: 1996-05-02T00:00:00+00:00 List-Id: In article donh@syd.csa.com.au (Don Harrison) writes: > Also, is it legal to write: > V : Vehicle'Class; > ... > T := Truck(V); > without supplying an aggregate containing the missing attributes? > If both of these are legal, both may result in inconsistent > objects being assigned. > Neither is possible in Eiffel. Don, you keep assuming that, just because the models are different, there must be some gaping holes in the Ada 95 rules. There aren't, or at least there aren't any known violations of the obvious OO principles in any of the Ada tagged type rules. If there are any, I assure they are way out at the edges and will be fixed in the standard as found. Now to the specific case above. The declaration is illegal, but only because it must have an initial value: V: Vehicle'Class := Some_Truck; ...but this really doesn't affect your question. What happens in your example is called a view conversion rather than a value conversion. But when you track it down there is a rule 4.6(42) which applies to both which says: "The tag of the result is the tag of the operand. If the operand type is class-wide, a check is made that the tag of the operand identifies a (specific) type that is covered by or descended from the target type." In other words, if the Value of V is not a truck, or a of a type descended from Truck, you get an exception at run-time. In most cases the compiler will either optimize the check away or print a warning that an error will occur, but there are some cases where the check must be done at run-time. The practice in the Ada standard in such cases is to always require an exception, which allows different compilers to different degrees of checking at compile time without worrying whether this case requires a warning or is an error. Before you ask why Ada allows this, think about this "slightly" different version: V : Truck'Class := Some_Semi; ... T := Truck(V); This results in a value for T which doesn't have the additional information in objects of type Semi, but that is all right, it is now a Truck. Notice that no run-time checks are required. Whatever the value of V, it is convertable to a Truck. If you later wanted to do: Some_other_Semi := Semi(T); ...it wouldn't work. This is a case that is dectected at compile time. Instead you need to write: Some_other_Semi := Semi'(T with ...); ...and provide the missing components, if there are none, you write: Some_other_Semi := Semi'(T with null); So as everyone has been trying to tell Don all along, the Ada model is a generalization of the Eiffel model, and this results in more cases that require run-time checks. But if you don't like those checks, don't write that code! This especially applies to the multiple dispatch cases. (Jon's example omitted.) If you do write such code, Ada doesn't require that any set of actual parameters makes sense, all it does is to insure that something is done with them, even if it is an explicit nothing. Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is... -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...