Bug 1903 – Template declaration (for mixin) can't be parsed
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-03-10T13:30:00Z
Last change time
2015-06-09T01:14:37Z
Assigned to
bugzilla
Creator
webmaster
Comments
Comment #0 by webmaster — 2008-03-10T13:30:06Z
DMD 2.012 Linux
The following code doesn't work, and if I understand correctly, it should:
BEGIN CODE
void Foo(int a,int b) {}
template Bar(int x)
{
Foo(x,x);
}
void Baz()
{
mixin Bar!(1);
}
END CODE
Comment #1 by webmaster — 2008-03-10T13:35:14Z
I should have given more details on how it fails. It appears to fail on the , character in the template declaration:
test.d(4): found ',' when expecting ')'
test.d(4): semicolon expected, not 'x'
test.d(4): no identifier for declarator x
test.d(4): semicolon expected, not ')'
test.d(4): Declaration expected, not ')'
Comment #2 by shro8822 — 2008-03-10T13:37:12Z
I don't think you can mixin statements, only decelerations.
Comment #3 by default_357-line — 2008-03-10T16:45:25Z
[email protected] wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1903
>
> Summary: Template declaration (for mixin) can't be parsed
> Product: D
> Version: 2.012
> Platform: PC
> OS/Version: Linux
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: [email protected]
> ReportedBy: [email protected]
>
>
> DMD 2.012 Linux
>
> The following code doesn't work, and if I understand correctly, it should:
>
> BEGIN CODE
>
> void Foo(int a,int b) {}
> template Bar(int x)
> {
> Foo(x,x);
> }
> void Baz()
> {
> mixin Bar!(1);
> }
>
> END CODE
>
>
The problem is that a template basically constitutes a namespace, not a scope. :)
So you can only put stuff in a template that you could also put at the global module level.
--downs
Comment #4 by webmaster — 2008-03-10T17:15:22Z
downs wrote:
> [email protected] wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=1903
>>
>> Summary: Template declaration (for mixin) can't be parsed
>> Product: D
>> Version: 2.012
>> Platform: PC
>> OS/Version: Linux
>> Status: NEW
>> Severity: normal
>> Priority: P2
>> Component: DMD
>> AssignedTo: [email protected]
>> ReportedBy: [email protected]
>>
>>
>> DMD 2.012 Linux
>>
>> The following code doesn't work, and if I understand correctly, it should:
>>
>> BEGIN CODE
>>
>> void Foo(int a,int b) {}
>> template Bar(int x)
>> {
>> Foo(x,x);
>> }
>> void Baz()
>> {
>> mixin Bar!(1);
>> }
>>
>> END CODE
>>
>>
>
> The problem is that a template basically constitutes a namespace, not a scope. :)
>
> So you can only put stuff in a template that you could also put at the global module level.
>
> --downs
I refactored it to use string mixins. It works now, but it's ugly.
Comment #5 by smjg — 2008-11-20T20:06:32Z
Please don't blindly quote the entire message when replying. It's bad enough on any newsgroup, and when it clutters up Bugzilla, it's even worse.
A template by syntax contains declarations, not statements. So this isn't supposed to work.