www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - typeof(typename) fails silently

reply Sean Kelly <sean invisibleduck.org> writes:
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.


Sean
Sep 15 2008
next sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean 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.


 Sean

Oh but Sean, anything illegal inside an is() expression doesn't give an error! FUN.
Sep 15 2008
next sibling parent BCS <ao pathlink.com> writes:
Reply to Jarrett,

 On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean 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.
 
 Sean
 

an error! FUN.

That includes things like import("file") can't find the file Real fun!
Sep 15 2008
prev sibling parent reply Sean Kelly <sean invisibleduck.org> writes:
Jarrett Billingsley wrote:
 On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean 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. Sean
Sep 15 2008
parent reply Sean Kelly <sean invisibleduck.org> writes:
== Quote from Sean Kelly (sean invisibleduck.org)'s article
 Jarrett Billingsley wrote:
 On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean 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!

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
Sep 15 2008
next sibling parent reply Sean Kelly <sean invisibleduck.org> writes:
Jarrett Billingsley wrote:
 On Mon, Sep 15, 2008 at 9:00 PM, Sean Kelly <sean invisibleduck.org> wrote:
 == Quote from Sean Kelly (sean invisibleduck.org)'s article

 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.

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 :-)

Conversation Update kicked in halfway through my construction of just such an example ;) (if you want to get _real_ technical: that's a syntactically invalid is() expression, and should give an error. However the _contents_ of the is() expression may be syntactically valid, but _semantic_ errors simply cause it to evaluate to false (except in a few, buggy cases). And as you've realized, something like typeof(A) may only be semantically invalid, meaning that according to the semantics of is(), should make it evaluate false and not give an error.)

I'm of two minds on this. The is expression already requires whatever it contains to be a type or there will be a compile-time error, but with the change to typeof we no longer have a bullet-proof way of ensuring that something is a type. So either we use is(T) and hope T is a type or use is(typeof(T)) and hope T is not a type (because if T is a type then the condition will silently fail). Neither is ideal, for obvious reasons. Sean
Sep 15 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Sean,


 I'm of two minds on this.  The is expression already requires whatever
 it contains to be a type or there will be a compile-time error, but
 with the change to typeof we no longer have a bullet-proof way of
 ensuring that something is a type.  So either we use is(T) and hope T
 is a type or use is(typeof(T)) and hope T is not a type (because if T
 is a type then the condition will silently fail).  Neither is ideal,
 for obvious reasons.
 

is(T) || is(typeof(T)) ??
Sep 16 2008
parent Sean Kelly <sean invisibleduck.org> writes:
BCS wrote:
 Reply to Sean,
 
 
 I'm of two minds on this.  The is expression already requires whatever
 it contains to be a type or there will be a compile-time error, but
 with the change to typeof we no longer have a bullet-proof way of
 ensuring that something is a type.  So either we use is(T) and hope T
 is a type or use is(typeof(T)) and hope T is not a type (because if T
 is a type then the condition will silently fail).  Neither is ideal,
 for obvious reasons.

is(T) || is(typeof(T))

Technically, the tests would have to be reversed, but yeah, that would work. It's just annoying :-) Sean
Sep 16 2008
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Tue, 16 Sep 2008 22:43:08 +0400, BCS <ao pathlink.com> wrote:

 Reply to Sean,


 I'm of two minds on this.  The is expression already requires whatever
 it contains to be a type or there will be a compile-time error, but
 with the change to typeof we no longer have a bullet-proof way of
 ensuring that something is a type.  So either we use is(T) and hope T
 is a type or use is(typeof(T)) and hope T is not a type (because if T
 is a type then the condition will silently fail).  Neither is ideal,
 for obvious reasons.

is(T) || is(typeof(T)) ??

template isType(T) { const bool isType = true; } template isType(alias T) { const bool isType = false; } Stdout(isType!(int)); Stdout(isType!(5)); ??
Sep 16 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Sep 16, 2008 at 6:17 PM, Denis Koroskin <2korden gmail.com> wrote:
 On Tue, 16 Sep 2008 22:43:08 +0400, BCS <ao pathlink.com> wrote:

 Reply to Sean,


 I'm of two minds on this.  The is expression already requires whatever
 it contains to be a type or there will be a compile-time error, but
 with the change to typeof we no longer have a bullet-proof way of
 ensuring that something is a type.  So either we use is(T) and hope T
 is a type or use is(typeof(T)) and hope T is not a type (because if T
 is a type then the condition will silently fail).  Neither is ideal,
 for obvious reasons.

is(T) || is(typeof(T)) ??

template isType(T) { const bool isType = true; } template isType(alias T) { const bool isType = false; } Stdout(isType!(int)); Stdout(isType!(5)); ??

D2 only.
Sep 16 2008
prev sibling parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Sean Kelly wrote:
 == Quote from Sean Kelly (sean invisibleduck.org)'s article
 Jarrett Billingsley wrote:
 On Mon, Sep 15, 2008 at 7:08 PM, Sean Kelly <sean 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.


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
Sep 19 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Mon, Sep 15, 2008 at 9:00 PM, Sean Kelly <sean invisibleduck.org> wrote:
 == Quote from Sean Kelly (sean invisibleduck.org)'s article

 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 :-)

Conversation Update kicked in halfway through my construction of just such an example ;) (if you want to get _real_ technical: that's a syntactically invalid is() expression, and should give an error. However the _contents_ of the is() expression may be syntactically valid, but _semantic_ errors simply cause it to evaluate to false (except in a few, buggy cases). And as you've realized, something like typeof(A) may only be semantically invalid, meaning that according to the semantics of is(), should make it evaluate false and not give an error.)
Sep 15 2008