is() syntax (Re: operator new(): struct v. class)

BCS ao at pathlink.com
Mon Aug 20 18:37:18 PDT 2007


Reply to Kirk,

> Bill Baxter wrote:
> 
>> And why do we even need is() to do basic type comparisons anyway?
>> What's ambiguous about
>> static if( MyType == OtherType ) {
>> ...
>> }
>> ?
>> I guess you could define a static opEquals, but A) that's useless
>> enough
>> that it could be outlawed B) it wouldn't take a type as an argument
>> so
>> it still wouldn't be ambiguous.
>> --bb
>> 
> It is ambiguous. Both sides of a comparison must be an expression, and
> types are not expressions. Allowing that would mean you couldn't
> determine whether 'MyType' is an expression or a type until after the
> syntactic pass. This would break some cardinal rules about the ease
> with which you can parse D code.
> 

Would it? The syntax could be defined as:

CompExp ::= TypeOrExp '==' TypeOrExp;

and then wait for the semantic pass to check what is actually used.





More information about the Digitalmars-d mailing list