www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23083] New: .tupleof on static array rvalue evaluates


          Issue ID: 23083
           Summary: .tupleof on static array rvalue evaluates expression
                    multiple times
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.100.0-rc.1, the following program causes an AssertError at runtime:

int global = 0;

int[2] f()
    return [123, 456];

void g(int a, int b) {}

void main()
    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.

May 03 2022