import std.json;
JSONValue foo()
{
JSONValue v;
v.integer = 1;
return v;
}
void main(string[] args)
{
enum v1 = foo(); // 2.064.2 OK -> 2.065a NG
auto v2 = foo(); // OK
}
Comment #1 by andrej.mitrovich — 2013-11-12T07:59:57Z
What exactly is the problem? There's an exception thrown:
std\json.d(765): Error: Uncaught CTFE exception std.json.JSONException("JSONValue is not an integer")
test.d(6): thrown from here
test.d(12): called from here: foo()
Comment #2 by zan77137 — 2013-11-12T09:48:10Z
Quite honestly, the behavior that this code makes the compilation error by the exception in CTFE is a destructive change, but thinks that I can permit it.
The big problem is that even if every other methods, union (JSONValue.Store) cannot be initialized.
The reason why the code mentioned above was OK in the past is a thing by the bugs of the compilers. (SeeAlso: Issue11427
This problem is settled by supporting union formally in CTFE.
Comment #3 by k.hara.pg — 2013-11-13T07:13:55Z
(In reply to comment #2)
> This problem is settled by supporting union formally in CTFE.
For that, I posted a compiler enhancement issue 11510.
Comment #4 by andrej.mitrovich — 2013-11-15T10:24:30Z
(In reply to comment #2)
> The reason why the code mentioned above was OK in the past is a thing by the
> bugs of the compilers. (SeeAlso: Issue11427
std.json was refactored a while ago and it might be the cause of this regression. But I still don't understand what the problem is with this code *right now*. Can anyone try to explain what SHOO meant in plain English?
Comment #5 by k.hara.pg — 2013-11-16T02:41:13Z
(In reply to comment #4)
> (In reply to comment #2)
> > The reason why the code mentioned above was OK in the past is a thing by the
> > bugs of the compilers. (SeeAlso: Issue11427
>
> std.json was refactored a while ago and it might be the cause of this
> regression. But I still don't understand what the problem is with this code
> *right now*. Can anyone try to explain what SHOO meant in plain English?
I separately filed the true std.json regression as issue 11527.
After fixing the bug, the OP case will print following errors.
C:\dmd2\src\phobos\std\json.d(181): Error: Unions with overlapping fields are not yet supported in CTFE
C:\dmd2\src\phobos\std\json.d(103): called from here: this.assign(v)
test.d(6): called from here: v.integer(1L)
test.d(12): called from here: foo()
The error is caused by issue 11510, and could be fixed by my compiler enhancement fix.
I change this to dmd issue.
Comment #6 by john.loughran.colvin — 2013-11-16T04:50:11Z
(In reply to comment #5)
> (In reply to comment #4)
> > (In reply to comment #2)
> > > The reason why the code mentioned above was OK in the past is a thing by the
> > > bugs of the compilers. (SeeAlso: Issue11427
> >
> > std.json was refactored a while ago and it might be the cause of this
> > regression. But I still don't understand what the problem is with this code
> > *right now*. Can anyone try to explain what SHOO meant in plain English?
>
> I separately filed the true std.json regression as issue 11527.
I would argue that is not necessarily a bug. See my comments in issue 11527 and https://github.com/D-Programming-Language/phobos/pull/1693https://d.puremagic.com/issues/show_bug.cgi?id=11510 is the real problem here, as you rightly point out.