D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2940 - null is null cannot be evaluated at compile time
Summary: null is null cannot be evaluated at compile time
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-05-05 02:58 UTC by Don
Modified: 2014-04-18 09:12 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-05-05 02:58:55 UTC
static assert(null is null);
---
bug.d(1): Error: static assert  (null is null) is not evaluatable at compile t
ime

Whereas the code below compiles fine:
int main(){ 
   return (null is null);
}
---
This also applies to similar kinds of expressions, eg (null is typeid(int)).

The patch for this relies on my patch for 1524, otherwise you get an ICE with "null is typeid(int)".
Comment 1 Don 2009-05-05 03:01:44 UTC
PATCH in optimize.c, line 779, in IdentityExp::optimize(int result)
Just allow TOKnull as one of the parameters.

OLD:
    if (this->e1->isConst() && this->e2->isConst())
    {
	e = Identity(op, type, this->e1, this->e2);
    }
NEW:
    if ((this->e1->isConst() || this->e1->op == TOKnull) && (this->e2->isConst()|| this->e2->op == TOKnull))
    {
	e = Identity(op, type, this->e1, this->e2);
    }

Comment 2 Tomas Lindquist Olsen 2009-05-05 06:35:44 UTC
Does things break if NullExp::isConst() was just implemented? After all, null is constant...
Comment 3 Walter Bright 2009-09-03 13:25:00 UTC
Fixed dmd 1.047 and 2.032