Wednesday, August 23, 2006

 

Equality of expanded objects

David Hollenberg noticed that EiffelStudio 5.7 is accepting the following code fragment. Although the compiler emits two VWEQ warnings, the fragment compiles and runs (printing "False" twice):
local
   a: INTEGER
   b: BOOLEAN
do
   print (3 = True)
   print (a = b)
end
David asked (on the EiffelStudio Developers mailing list):
Is this really allowed by ECMA-367 or does the compiler have a problem? If ECMA-367 allows this, should it?
Bertrand Meyer replied:
This is permitted by the ECMA language definition. The matter was discussed at length in the committee over several meetings; the deciding point was that it's not quite realistic to enforce the earlier rule that the type of either of the arguments should conform to the other. This prevents comparing objects of types C and D, both of which conform to both of A and B, but not to each other. Then variables of these types can actually be attached to the same object.
The definition of x = y for reference semantics (see 8.21.3 in the standard) is that x and y are attached to the same object. For expanded semantics as in your example, it's that they are attached to equal objects, where equal objects must have both the same type and the same value.
In the end it was felt that one should be able to ask a question, without first asking the question of whether one may ask the question.
I must admit that I did a double-take at the above sentence: isn't that what static typing is all about?

Bertrand continues:
There could have been a special rule for the expanded case -- since we know in advance that there is no conformance and that the result will always be False -- but this seemed to complicate the rules too much.
As a general rule I am wary of relying on warnings but this seems to be a valid use for them: an indication by the compiler that things are not necessarily wrong but that the construction is unusual and needs to be checked.

Comments:
In SmartEiffel, the signature is is_equal(other: ANY).
 
INTEGER = BOOLEAN is now just a warning.

The end of static typing.

And if the committee was in doubt, why not make it a setting? 100% of all Eiffel programmer will turn it on, believe me.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?