typeof(typename) fails silently

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Sep 19 04:58:11 PDT 2008


Sean Kelly wrote:
> == Quote from Sean Kelly (sean at invisibleduck.org)'s article
>> Jarrett Billingsley wrote:
>>> On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean at invisibleduck.org> wrote:
>>>> Code like the following:
>>>>
>>>>
>>>> static if(is(typeof(int))) { pragma(msg, "hi"); }
>>>>
>>>> used to work just fine (ie. it used to print "hi") even though typeof was
>>>> being used to evaluate a type.  Now apparently the same tests fail, but they
>>>> do so silently.  If typeof isn't supposed to be used to evaluate types,
>>>> could we _please_ get a compile error about this?  I've just discovered that
>>>> a bunch of Tango code silently stopped working when this change was
>>>> implemented and it would have been great if the build had simply failed on
>>>> what is now apparently an illegal operation.
>>>>
>>> Oh but Sean, anything illegal inside an is() expression doesn't give an error!
>> Technically untrue.  An 'is' expression must contain a type.  ie. you
>> can't do this:
>>      is(5)
>> That aside, the contents of an 'is' expression must still be valid D
>> code, and typeof(int) is clearly no longer valid D code.  All I'm asking
>> is to be told that my code is invalid.
> 
> Darnit, I take it back.  I suppose it's possible that the symbol passed to typeof
> within an 'is' expression might be a type and it might be a value.  The 'is'
> expression is just doing what it's supposed to.  What a pain :-)
> 
> 
> Sean

Could be a type, could be a value... and could be neither, like a 
non-existent symbol/reference. Super Happy Fun Time! Like Jarrett 
mentioned, there are lots of semantic errors that evaluate to false, 
whereas it would probably be much better if they generated an error.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D


More information about the Digitalmars-d-bugs mailing list