Re: if (int bar = .. bug or some thing

2017-10-31 Thread codephantom via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 04:27:27 UTC, Joel wrote: Ok, thanks guys. why not throw in some UFCS too...just because you can ;-) import std.stdio; void main() { int foo; if (foo.bar != 0) // would be nice if I could do: (int foo.bar != 0) { throw new

Re: if (int bar = .. bug or some thing

2017-10-30 Thread Joel via Digitalmars-d-learn
Ok, thanks guys.

Re: if (int bar = .. bug or some thing

2017-10-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 04:08:12 UTC, Joel wrote: if (int bar = foo() != 0) { Not a bug, but I do think it is an iffy design. That is more like: int bar; if(bar = (foo() != 0)) so the foo != 0 is evaluated first, which ends up being boolean true or false, then THAT

Re: if (int bar = .. bug or some thing

2017-10-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 31, 2017 04:08:12 Joel via Digitalmars-d-learn wrote: > The following code assert fails (bar == 1, not -10!). I've wasted > a bit of time because of this happening. > > void main() { > if (int bar = foo() != 0) { > assert(bar == -10); > } > } > > auto foo() { >

if (int bar = .. bug or some thing

2017-10-30 Thread Joel via Digitalmars-d-learn
The following code assert fails (bar == 1, not -10!). I've wasted a bit of time because of this happening. void main() { if (int bar = foo() != 0) { assert(bar == -10); } } auto foo() { return -10; }