digitalmars.D - static if AssignExpression
- =?UTF-8?B?THXDrXM=?= Marques (6/6) Feb 13 2019 `static if` is defined in the D grammar as `static if (
- H. S. Teoh (11/15) Feb 13 2019 It's either an oversight, or was probably chosen just for consistency
- rikki cattermole (3/17) Feb 13 2019 Ugh...
- bauss (10/16) Feb 13 2019 I would agree with that it makes no sense that it's an
`static if` is defined in the D grammar as `static if ( AssignExpression )`. What's the point of AssignExpression, instead of just a ConditionalExpression? In what situation can you even use `static if(x = y)?`, `static if(x += y)?`, etc?
Feb 13 2019
On Wed, Feb 13, 2019 at 04:45:39PM +0000, Luís Marques via Digitalmars-d wrote:`static if` is defined in the D grammar as `static if ( AssignExpression )`. What's the point of AssignExpression, instead of just a ConditionalExpression? In what situation can you even use `static if(x = y)?`, `static if(x += y)?`, etc?It's either an oversight, or was probably chosen just for consistency with the normal `if` condition (to make it simpler to implement in the compiler since we could just use the same code for parsing the condition). Though, in an extreme case, one could potentially have a user-defined that overloads += to return bool at compile-time. Probably an example of operator overload abuse, though. T -- I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller
Feb 13 2019
On 14/02/2019 6:33 AM, H. S. Teoh wrote:On Wed, Feb 13, 2019 at 04:45:39PM +0000, LuÃs Marques via Digitalmars-d wrote:Ugh... https://github.com/dlang/dmd/blob/master/src/dmd/parse.d#L2407`static if` is defined in the D grammar as `static if ( AssignExpression )`. What's the point of AssignExpression, instead of just a ConditionalExpression? In what situation can you even use `static if(x = y)?`, `static if(x += y)?`, etc?It's either an oversight, or was probably chosen just for consistency with the normal `if` condition (to make it simpler to implement in the compiler since we could just use the same code for parsing the condition). Though, in an extreme case, one could potentially have a user-defined that overloads += to return bool at compile-time. Probably an example of operator overload abuse, though.
Feb 13 2019
On Wednesday, 13 February 2019 at 16:45:39 UTC, LuÃs Marques wrote:`static if` is defined in the D grammar as `static if ( AssignExpression )`. What's the point of AssignExpression, instead of just a ConditionalExpression? In what situation can you even use `static if(x = y)?`, `static if(x += y)?`, etc?I would agree with that it makes no sense that it's an AssignExpression. It would've made more sense if the normal if statement was an AssignExpression, but even that isn't. I don't believe there are any situations where you'd end up with an AssignExpression as the condition for a static if statement. Either there is a magic reason for some compiler bug that it avoids OR it's a simple mistake.
Feb 13 2019