Bug 10334 – ddoc should prefer simple syntax for template instantiations with one parameter
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-11T07:46:00Z
Last change time
2013-06-18T07:52:20Z
Keywords
ddoc, pull
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-06-11T07:46:42Z
-----
/** */
template templ(T...)
if (someConstraint!T)
{
}
-----
This currently emits:
> template templ(T...) if (someConstraint!(T))
But for readability purposes it can be:
> template templ(T...) if (someConstraint!T)
Comment #1 by andrej.mitrovich — 2013-06-11T09:07:31Z
This is a little bit complicated to implement. I have to take into account at least the following (where left is the input, right is the output), and these are also used for .di header generation so they must have valid D syntax:
Templ!() -> Templ!()
Templ!(T) -> Templ!T
Templ!T -> Templ!T
Templ!([1]) -> Templ!([1]) // cannot be Templ![1]
Templ!(Templ2!(T)) -> Templ!(Templ2(T) // cannot be Templ!Templ2!T
That last case is what I'm struggling with. How do I figure out whether an Object from 'tiargs' is a template instance in DMDFE?
Comment #5 by bearophile_hugs — 2013-06-17T18:01:01Z
This code:
template isBar(T) {
enum isBar = false;
}
template Foo(T) if (isBar!T) {
}
void main() {
alias F = Foo!int;
}
Gives (before this patch):
temp.d(7): Error: template instance Foo!(int) does not match template declaration Foo(T) if (isBar!(T))
isn't it better to use that ddoc logic to generate a simpler error message similar to:
temp.d(7): Error: template instance Foo!(int) does not match template declaration Foo(T) if (isBar!T)
Comment #6 by andrej.mitrovich — 2013-06-17T18:14:55Z
(In reply to comment #5)
> isn't it better to use that ddoc logic to generate a simpler error message
> similar to:
Yes, although the pull request didn't touch any ddoc code, it specifically targeted the internal Template "stringification" functions which are used by both ddoc and diagnostics.
I thought all diagnostics would be affected, but some slipped out (they weren't directly tested in the autotester, only ddoc output was tested).
I think the diagnostics can be improved. Could you file a separate bug for it?
Comment #7 by bearophile_hugs — 2013-06-17T18:55:03Z
(In reply to comment #6)
> I think the diagnostics can be improved. Could you file a separate bug for it?
I have compiled the compiler with this last change, and indeed there is no need to file a bug, the error message now is:
temp.d(7): Error: template instance Foo!int does not match template declaration Foo(T) if (isBar!T)
Comment #8 by andrej.mitrovich — 2013-06-17T18:56:13Z
(In reply to comment #7)
> (In reply to comment #6)
>
> > I think the diagnostics can be improved. Could you file a separate bug for it?
>
> I have compiled the compiler with this last change, and indeed there is no need
> to file a bug, the error message now is:
>
>
> temp.d(7): Error: template instance Foo!int does not match template declaration
> Foo(T) if (isBar!T)
Ah yes, my bad. I used the wrong version when testing it now.