D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9232 - Parsing error on some templated methods calls
Summary: Parsing error on some templated methods calls
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-12-28 04:20 UTC by dransic
Modified: 2015-06-17 21:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description dransic 2012-12-28 04:20:19 UTC
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 Kenji Hara 2012-12-28 07:03:44 UTC
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 dransic 2012-12-28 07:41:13 UTC
> 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 Kenji Hara 2012-12-28 22:50:58 UTC
(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 dransic 2012-12-30 14:53:56 UTC
(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 github-bugzilla 2013-03-03 22:47:10 UTC
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 github-bugzilla 2013-03-03 23:38:35 UTC
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 8 github-bugzilla 2015-03-29 07:39:09 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/bd0385c5410eec129f40b16d109f4719f97c4b21
Move issue 9232 test case to compilable/testparse.d
Comment 9 github-bugzilla 2015-06-17 21:03:37 UTC
Commit pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/bd0385c5410eec129f40b16d109f4719f97c4b21
Move issue 9232 test case to compilable/testparse.d