Bug 22200 – it is not specified that `$` yields a rvalue

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-11T08:26:38Z
Last change time
2021-08-19T10:56:08Z
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2021-08-11T08:26:38Z
I was curious to see if the following ``` void main() { int[] a; a[++$ - 1] = 0; } ``` worked. It is not > /tmp/temp_7F0644F44CF0.d:8:9: Error: cannot modify operator `$` but given the specifications > the spec is "Within the [ ] of a static or a dynamic array, the symbol $ represents the length of the array." it was not clear that this will fail.
Comment #1 by razvan.nitu1305 — 2021-08-19T10:45:09Z
You do have the 5th definition from [1] which specifies what an lvalue is. Rvalues are defined as "if it's not an lvalue, then it's an rvalue". `$` does not appear in the list of lvalues, therefore, I would say that the spec is accurate. [1] https://dlang.org/spec/expression.html
Comment #2 by b2.temp — 2021-08-19T10:56:08Z
okay.