Thread overview
[Issue 9232] New: Parsing error on some templated methods calls
Dec 28, 2012
Nicolas Sicard
Dec 28, 2012
Kenji Hara
Dec 28, 2012
Nicolas Sicard
Dec 29, 2012
Kenji Hara
Dec 30, 2012
Nicolas Sicard
Mar 04, 2013
Walter Bright
December 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9232

           Summary: Parsing error on some templated methods calls
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dransic@gmail.com


--- Comment #0 from Nicolas Sicard <dransic@gmail.com> 2012-12-28 04:20:19 PST ---
I think this should compile:
---
struct Foo {
    void bar(T)() {}
    void baz() {}
}

void main() {
    Foo foo;
    (foo).bar!int();   // Error: found '!' when expecting ';' following
statement
    ((foo)).bar!int(); // OK
    foo.bar!int();     // OK
    (foo).baz();       // OK
}
---
(DMD 2.060 MacOSX)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9232


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-28 07:03:44 PST ---
This is an enhancement request against language syntax.

---

>  (foo).bar!int();   // Error: found '!' when expecting ';' following

In current, "(foo).bar" matches UnaryExpression "(Type) . identifier".
http://dlang.org/expression#UnaryExpression

("foo" is parsed as TypeIdentifier, and in semantic analysis phase, it will be finally analyzed as an expression.)

Then, the remaining portions "!int();" don't match anything in the grammar.

---

To allow it, we should add a case to UnaryExpression like follows:

UnaryExpression:
    & UnaryExpression
    ++ UnaryExpression
    -- UnaryExpression
    * UnaryExpression
    - UnaryExpression
    + UnaryExpression
    ! UnaryExpression
    ComplementExpression
    ( Type ) . Identifier
    ( Type ) . TemplateInstance       // new!
    NewExpression
    DeleteExpression
    CastExpression
    PowExpression

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9232



--- Comment #2 from Nicolas Sicard <dransic@gmail.com> 2012-12-28 07:41:13 PST ---
> In current, "(foo).bar" matches UnaryExpression "(Type) . identifier".
> http://dlang.org/expression#UnaryExpression

It should not since foo is not a type but an identifier.

(foo).bar!int should match "PrimaryExpression . TemplateInstance", where
PrimaryExpression matches "( Identifier )".

So this is a compiler bug IMO, and should not be classified as an enhancement request.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9232


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid
           Severity|enhancement                 |normal


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-28 22:50:58 PST ---
(In reply to comment #2)
> > In current, "(foo).bar" matches UnaryExpression "(Type) . identifier".
> > http://dlang.org/expression#UnaryExpression
> 
> It should not since foo is not a type but an identifier.
> 
> (foo).bar!int should match "PrimaryExpression . TemplateInstance", where
> PrimaryExpression matches "( Identifier )".
> 
> So this is a compiler bug IMO, and should not be classified as an enhancement request.

OK. I was convinced that it is a grammar bug, rather than an enhancement.

https://github.com/D-Programming-Language/dmd/pull/1422 https://github.com/D-Programming-Language/d-programming-language.org/pull/223

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9232



--- Comment #4 from Nicolas Sicard <dransic@gmail.com> 2012-12-30 14:53:56 PST ---
(In reply to comment #3)
> (In reply to comment #2)
> > > In current, "(foo).bar" matches UnaryExpression "(Type) . identifier".
> > > http://dlang.org/expression#UnaryExpression
> > 
> > It should not since foo is not a type but an identifier.
> > 
> > (foo).bar!int should match "PrimaryExpression . TemplateInstance", where
> > PrimaryExpression matches "( Identifier )".
> > 
> > So this is a compiler bug IMO, and should not be classified as an enhancement request.
> 
> OK. I was convinced that it is a grammar bug, rather than an enhancement.
> 
> https://github.com/D-Programming-Language/dmd/pull/1422 https://github.com/D-Programming-Language/d-programming-language.org/pull/223

It works fine with this pull request. And by studying it, I now understand how
it works.
Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9232



--- Comment #5 from github-bugzilla@puremagic.com 2013-03-03 22:47:10 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d9a04e70c65fbdc29e1b157381c86e28d39ba739 fix Issue 9232 - Parsing error on some templated methods calls

https://github.com/D-Programming-Language/dmd/commit/2d452f170a8f538ac4203195c2cd0e64a017691b Merge pull request #1422 from 9rnsr/fix9232

Issue 9232 - Parsing error on some templated methods calls

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9232


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9232



--- Comment #6 from github-bugzilla@puremagic.com 2013-03-03 23:38:35 PST ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/3fa9b9a7a15e24dab28aeff0f5bf0f4e9f18ce06 Merge pull request #1422 from 9rnsr/fix9232

Issue 9232 - Parsing error on some templated methods calls

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9232



--- Comment #7 from github-bugzilla@puremagic.com 2013-03-05 14:09:45 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/92a1b3a127ab9ecf32b0aebbd82f7e81965bb1ca fix Issue 9232 - Parsing error on some templated methods calls

https://github.com/D-Programming-Language/d-programming-language.org/commit/2596485da033b347f63606761d3fca296af93e9c Merge pull request #223 from 9rnsr/fix9232

Issue 9232 - Parsing error on some templated methods calls

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