Bug 9232 – Parsing error on some templated methods calls

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-28T04:20:00Z
Last change time
2015-06-17T21:03:37Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
dransic

Comments

Comment #0 by dransic — 2012-12-28T04:20:19Z
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)
Comment #1 by k.hara.pg — 2012-12-28T07:03:44Z
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
Comment #2 by dransic — 2012-12-28T07:41:13Z
> 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.
Comment #3 by k.hara.pg — 2012-12-28T22:50:58Z
(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
Comment #4 by dransic — 2012-12-30T14:53:56Z
(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.
Comment #5 by github-bugzilla — 2013-03-03T22:47:10Z
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
Comment #6 by github-bugzilla — 2013-03-03T23:38:35Z
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
Comment #7 by github-bugzilla — 2013-03-05T14:09:45Z
Comment #8 by github-bugzilla — 2015-03-29T07:39:09Z
Comment #9 by github-bugzilla — 2015-06-17T21:03:37Z