www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21428] New: Appending to keys of an empty associative array

https://issues.dlang.org/show_bug.cgi?id=21428

          Issue ID: 21428
           Summary: Appending to keys of an empty associative array
                    "cannot be interpreted at compile time"
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: CTFE, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

import std.algorithm;

auto foo() {
    bool[string] p;
    return p.keys ~ "bar";
}

enum a = foo;

void main() {
}

onlineapp.d(7): Error: keys(p) ~ ["bar"] cannot be interpreted at compile time
onlineapp.d(10):        called from here: foo()

Compiles if the array is not empty or p.keys are appended to indirectly.

--
Nov 26 2020