D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23083 - .tupleof on static array rvalue evaluates expression multiple times
Summary: .tupleof on static array rvalue evaluates expression multiple times
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-05-03 13:39 UTC by Paul Backus
Modified: 2022-05-04 16:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2022-05-03 13:39:29 UTC
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:

---
core.exception.AssertError@bug.d(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 Dlang Bot 2022-05-03 14:50:12 UTC
@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 Dlang Bot 2022-05-04 16:32:57 UTC
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