www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20527] New: std.json CTFE cannot read integer

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

          Issue ID: 20527
           Summary: std.json CTFE cannot read integer
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: schveiguy yahoo.com

std.json has a quirky implementation of integer parsing where it parses a ulong
for non-negative numbers, but then sets the tag to point at a long. This gives
CTFE fits because you are setting one member of a union, then reading a
different member.

Code to reproduce:

static assert(parseJSON(`{ "int": 2}`)["int"].integer == 2);

Error: reinterpretation through overlapped field integer is not allowed in CTFE

Easy to fix, set the correct union member.

--
Jan 23 2020