www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8635] New: Allow postfix expressions for new

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635

           Summary: Allow postfix expressions for new
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2012-09-09 07:35:29 PDT ---
New expressions should have support for postfixes, eg. like so:

class C{
    int x;
    this(int x)
    {
        this.x = x;
    }
}
void main()
{
    assert(new C(2).x==2);
    assert(new C(3).x==3);
}

Necessary grammar changes:

UnaryExpression:
    ...
    ( Type ) . Identifier
-   NewExpression
    ...

PrimaryExpression:
    ...
    ImportExpression
+   NewExpression
    BasicType . Identifier
    ...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2012-09-09 07:50:29 PDT ---
This seems a nice idea.

See also:
https://github.com/D-Programming-Language/dmd/pull/1111

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com


--- Comment #2 from Jonathan M Davis <jmdavisProg gmx.com> 2012-09-09 16:45:01
PDT ---
It already works if you use parens:

assert((new C(2)).x == 2);

I don't know if making it work without parens is a good idea or not, since I
really don't know that the side effects of that would be.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #3 from bearophile_hugs eml.cc 2012-09-09 17:49:31 PDT ---
(In reply to comment #2)

 I don't know if making it work without parens is a good idea or not, since I
 really don't know that the side effects of that would be.

I agree. If the side effects are bad, this bug report will be closed and future similar ideas will be marked as duplicates of this :-) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #4 from timon.gehr gmx.ch 2012-09-09 18:08:59 PDT ---
There are no side effects. This just lifts a trivial restriction.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex lycus.org


--- Comment #5 from Alex Rønne Petersen <alex lycus.org> 2012-09-10 03:26:32
CEST ---
Also, it's how C# (and probably Java too) does it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #6 from Jonathan M Davis <jmdavisProg gmx.com> 2012-09-09 18:31:47
PDT ---
I have absolutely no problem with this as long as there are no side effects. I
just had figured that there was a valid reason why the parens were required.
It's often the case that something will seem like it should work and doesn't
but has a very good reason for why it doesn't, even if it looks fine at first
glance.

 Also, it's how C# (and probably Java too) does it.

Given D's increased complexity, it wouldn't surprise me at all if D couldn't do it when they could, but if it can, it definitely should as well. I think that it's the syntax that pretty much everyone tries at first - only to find that it doesn't work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #7 from timon.gehr gmx.ch 2012-09-09 18:40:01 PDT ---
(In reply to comment #6)
 I have absolutely no problem with this as long as there are no side effects. I
 just had figured that there was a valid reason why the parens were required.
 ...

Presumably it is just a C++ism that got carried over for no reason.
 Given D's increased complexity, 

The D grammar is not particularly complex. (it is still somewhat more complex than it would need to be though.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wfunction hotmail.com


--- Comment #8 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-12-08
15:10:55 PST ---
*** Issue 8116 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aziz.koeksal gmail.com


--- Comment #9 from yebblies <yebblies gmail.com> 2013-01-08 12:08:11 EST ---
*** Issue 8826 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
            Version|D2                          |D1 & D2


--- Comment #10 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-11
19:44:07 PST ---
Added D1 to mark Issue 2945 a duplicate.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benoit tionex.de


--- Comment #11 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-11
19:44:14 PST ---
*** Issue 2945 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com
            Version|D1 & D2                     |D2


--- Comment #12 from Walter Bright <bugzilla digitalmars.com> 2013-01-19
11:37:42 PST ---
D1 isn't going to get enhancements.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #13 from Walter Bright <bugzilla digitalmars.com> 2013-01-19
11:42:36 PST ---
This seems more of a "why do this" rather than "why not" ? Is C# doing it
really a compelling case?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #14 from bearophile_hugs eml.cc 2013-01-19 12:20:48 PST ---
(In reply to comment #13)
 Is C# doing it really a compelling case?

Generally C# is a well designed languages. But in this case it's not a matter of copying C#. In D I often have had to write: (new Foo()).bar() But that's not nice, because in D you are used to use UFCS: new Foo().bar() So it's not a big thing, but (unless it clashes with something else I am unaware of) it's a nice little improvement to have. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #15 from timon.gehr gmx.ch 2013-01-19 18:42:48 PST ---
(In reply to comment #13)
 This seems more of a "why do this" rather than "why not" ?

In my opinion it is exactly the other way round. The "why not" question people actually ask. Note that this has been requested independently at least 5 times, and it has come up a few times on D.learn as well IIRC. It lifts an arbitrary restriction and is very cheap. (Move a few lines of parser code somewhere else.)
 Is C# doing it really a compelling case?

No. But I do not think C# programmers ask "why do this". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #16 from bearophile_hugs eml.cc 2013-02-08 16:27:38 PST ---
An even better syntax is to allow new to act as a static method, that allows a
fully UFCS syntax:

class Foo {
    void bar() {}
}
Foo().new.bar();
Foo f = Foo.new;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com


--- Comment #17 from Denis Shelomovskij <verylonglogin.reg gmail.com>
2013-02-22 11:39:49 MSK ---
`c.new N().foo();` is already a valid syntex as Kenji Hara mentioned in pull
discussion so I don't see any reasons to not merge implementing pull as current
situation doesn't look consistent.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #18 from github-bugzilla puremagic.com 2013-06-08 19:57:41 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/405a549e87cce88e68367e7a3aeb358cfd38f41d
Fix issue 8635 - Allow postfix expressions for new

https://github.com/D-Programming-Language/dmd/commit/44fdd81dcd0086e551fd04c0ee9f109315755465
Merge pull request #1111 from tgehr/master

 Issue 8635 - Allow postfix expressions for new

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


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

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


--- Comment #19 from Kenji Hara <k.hara.pg gmail.com> 2013-06-08 23:57:50 PDT
---
Grammar fix:
https://github.com/D-Programming-Language/dlang.org/pull/337

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635



--- Comment #20 from github-bugzilla puremagic.com 2013-06-09 00:07:21 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/07c714eaa6bd6d4d811f77b3dfc870038cc61bb1
fix Issue 8635 - Allow postfix expressions for new

https://github.com/D-Programming-Language/dlang.org/commit/19227b73aac5bed6386e9ee4c12b470dc3911bad
Merge pull request #337 from 9rnsr/fix8635

Issue 8635 - Allow postfix expressions for new

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 09 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8635


Jacob Carlborg <doob me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob me.com


--- Comment #21 from Jacob Carlborg <doob me.com> 2013-06-09 11:13:10 PDT ---
This is a great change for DWT. new Foo().bar() is used a lot since it's ported
Java code.

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