Bug 23083 – .tupleof on static array rvalue evaluates expression multiple times

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-03T13:39:29Z
Last change time
2022-05-04T16:32:57Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-05-03T13:39:29Z
As of DMD 2.100.0-rc.1, the following program causes an AssertError at runtime: --- int global = 0; int[2] f() { global++; return [123, 456]; } void g(int a, int b) {} void main() { g(f().tupleof); assert(global == 1); } --- The error is: --- [email protected](14): 2 != 1 --- This happens because the expression `f().tupleof` is erroneously expanded to `f()[0].tupleof, f()[1].tupleof`, which results in `f` being called twice instead of once.
Comment #1 by dlang-bot — 2022-05-03T14:50:12Z
@pbackus created dlang/dmd pull request #14068 "Fix Issue 23083 - .tupleof on static array rvalue evaluates expressio…" fixing this issue: - Fix Issue 23083 - .tupleof on static array rvalue evaluates expression multiple times https://github.com/dlang/dmd/pull/14068
Comment #2 by dlang-bot — 2022-05-04T16:32:57Z
dlang/dmd pull request #14068 "Fix Issue 23083 - .tupleof on static array rvalue evaluates expressio…" was merged into stable: - 76710fd0143f6b97c930be319f777af4bf1c29ca by Paul Backus: Fix Issue 23083 - .tupleof on static array rvalue evaluates expression multiple times https://github.com/dlang/dmd/pull/14068