Bug 1566 – Nested template issue

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-10-10T06:05:00Z
Last change time
2014-02-20T17:30:59Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
pop.atry

Comments

Comment #0 by pop.atry — 2007-10-10T06:05:56Z
template T(int n) { template T(char c) { alias long T; } } int main() { alias T!(3) T3; static assert(is(long == T3!('b'))); // OK static assert(is(long == T!(3)!('b'))); // error return 0; }
Comment #1 by smjg — 2007-11-08T06:49:55Z
Please post the error messages when filing bugs. And assign keywords as appropriate. DMD 1.023 Windows: bz1566.d(10): found '!' when expecting ')' bz1566.d(10): found ')' when expecting ';'
Comment #2 by verylonglogin.reg — 2014-01-05T00:26:30Z
This is by design and should be closed as INVALID or converted to an enhancement.
Comment #3 by smjg — 2014-01-05T06:35:44Z
Explain please.
Comment #4 by verylonglogin.reg — 2014-01-05T07:38:04Z
(In reply to comment #3) > Explain please. It's a bug iff there is a language documentation allowing such syntax or dmd behaviour partially allowing it. If I don't miss something multiple `!` is considered harmful as `A!B!C` may be considered as `A` instantiated with `B!C` or `A!B` instantiated with `C`. Also requirement to always have parantheses in such case may be added but IMO it doesn't look like a worthwhile language complication as it isn't generally needed.
Comment #5 by smjg — 2014-01-05T08:10:46Z
Oh yes. The grammar is http://dlang.org/template.html TemplateInstance: TemplateIdentifier TemplateArguments TemplateArguments: !( ) !( TemplateArgumentList ) ! TemplateSingleArgument TemplateIdentifier: Identifier And so T!(3)!('b') isn't parseable as a TemplateInstance. As such, the compiler is behaving according to spec. However, there's a problem: (T!(3)) is equally not an Identifier, so going by this spec we can't even write (T!(3))!('b'). This seems overly restrictive. But the error message is confusing, and liable to make the user think the compiler is playing up. We should explicitly detect an attempt to do this, and deliver a clearer error message. As such, I'm changing this to diagnostic.
Comment #6 by k.hara.pg — 2014-02-18T21:47:08Z
*** Issue 12195 has been marked as a duplicate of this issue. ***
Comment #7 by k.hara.pg — 2014-02-18T22:01:08Z
Comment #8 by github-bugzilla — 2014-02-20T16:49:24Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f5222493c1d34443a556e2bef65b8f0326d4b9f8 fix Issue 1566 - Nested template issue https://github.com/D-Programming-Language/dmd/commit/765e123d97f5943474e4c8c8db12062d6c87b885 Merge pull request #3283 from 9rnsr/fix1566 [diagnostic] Issue 1566 - Nested template issue