Re: [sv-bc] operators and data type compatibility rules

From: Steven Sharp <sharp_at_.....>
Date: Fri Sep 15 2006 - 17:17:25 PDT
>From: Gordon Vreugdenhil <gordonv@model.com>

>My view of the conditional operator for classes is that they
>should allow anything on either branch that is assignment compatible
>with the target.

You seem to be assuming that the result of the conditional operator
is being used immediately in an assignment.  This may not always be
the case. We need rules that define the result type of the conditional
operator for all cases.  Some examples:

  $typename(cond ? c : b)

We need to know the type of the conditional operator result in order
to determine the value of the system function.

  (cond ? c : b).my_method

The BNF appears to allow the prefix of a method call to be an expression.
Class C could have redefined my_method when it extended class B.  If
this is allowed, then there must be a type to which both c and b can
be converted, which must be used to determine what my_method is used.

One solution would be to require both expressions to have equivalent
types.  Then that is the type of the result.  This is the simplest, and
is what the LRM currently says.

Another solution would be to require one of the expressions to have a
type that is assignment compatible with the other.  Whichever one can
be assigned from the other (i.e. the base class) is the type of the
result.

Another solution would be to require that the types of the two expressions
have a common base class.  The closest common base class would be the
type of the result.  This is a superset of the previous solution.  It
could be surprising when the result type is different from either of
the two starting expressions.  The my_method that got used in the
second example above might be neither c.my_method nor b.my_method.

Steven Sharp
sharp@cadence.com
Received on Fri Sep 15 17:17:33 2006

This archive was generated by hypermail 2.1.8 : Fri Sep 15 2006 - 17:17:38 PDT