Bug 2955 – Compiler rejects chained <>=

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2009-05-09T09:33:00Z
Last change time
2014-04-18T09:12:06Z
Keywords
diagnostic
Assigned to
nobody
Creator
lijat.me

Comments

Comment #0 by lijat.me — 2009-05-09T09:33:11Z
The following code void main(){ double a,b,c; assert(a <>= b <>= c); } gets this response from the compiler johang@klaffhorn:~$ dmd test.d test.d(4): found '<>=' when expecting ')' test.d(4): found 'c' when expecting ';' following 'statement' test.d(4): found ')' instead of statement johang@klaffhorn:~$ if parenthesis are added the problem disappear. If this is not valid code the a more helpful error message would be nice.
Comment #1 by jarrett.billingsley — 2009-05-09T10:31:56Z
This is by design. Comparison operators cannot be chained like this. C accepts such foolishness as "a < b < c" even though it doesn't do what you'd expect (i.e. it doesn't evaluate to "a < b && b < c"). D changed all comparison operators to have the same precedence so that this kind of code would not be accepted, and for possible future expansion in which chained comparisons really would be converted into multiple clauses.
Comment #2 by lijat.me — 2009-05-09T20:05:53Z
In that case I think that a better error message would be needed. The current one left me confused about if it was a compiler bug or by design.
Comment #3 by jarrett.billingsley — 2009-05-09T20:46:58Z
Fair enough :)
Comment #4 by andrei — 2011-01-08T16:17:12Z
I think we're good as we are.