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. ***