Thread overview
[Issue 11504] New: [CTFE] JSONValue cannot make in CTFE
Nov 12, 2013
SHOO
Nov 12, 2013
Andrej Mitrovic
Nov 12, 2013
SHOO
Nov 13, 2013
Kenji Hara
Nov 15, 2013
Andrej Mitrovic
Nov 16, 2013
Kenji Hara
Nov 16, 2013
John Colvin
Nov 22, 2013
Kenji Hara
November 12, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504

           Summary: [CTFE] JSONValue cannot make in CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: zan77137@nifty.com


--- Comment #0 from SHOO <zan77137@nifty.com> 2013-11-12 07:49:56 PST ---
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
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 12, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-11-12 07:59:57 PST ---
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()

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 12, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504



--- Comment #2 from SHOO <zan77137@nifty.com> 2013-11-12 09:48:10 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |11510


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2013-11-13 07:13:55 PST ---
(In reply to comment #2)
> This problem is settled by supporting union formally in CTFE.

For that, I posted a compiler enhancement issue 11510.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 15, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-11-15 10:24:30 PST ---
(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?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 16, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE
          Component|Phobos                      |DMD


--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2013-11-16 02:41:13 PST ---
(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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 16, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504


John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com


--- Comment #6 from John Colvin <john.loughran.colvin@gmail.com> 2013-11-16 12:50:11 GMT ---
(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/1693

https://d.puremagic.com/issues/show_bug.cgi?id=11510 is the real problem here, as you rightly point out.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11504


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2013-11-22 02:35:37 PST ---
Issue 10527 has been fixed. So add a link to pull request.

https://github.com/D-Programming-Language/dmd/pull/2757

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------