Thread overview
[Issue 1903] New: Template declaration (for mixin) can't be parsed
Mar 10, 2008
d-bugmail
Mar 10, 2008
d-bugmail
Mar 10, 2008
d-bugmail
Mar 10, 2008
downs
Mar 10, 2008
Russell Lewis
Mar 10, 2008
Robert Fraser
Mar 11, 2008
Bill Baxter
Nov 21, 2008
d-bugmail
March 10, 2008
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: bugzilla@digitalmars.com
        ReportedBy: webmaster@villagersonline.com


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


-- 

March 10, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1903





------- Comment #1 from webmaster@villagersonline.com  2008-03-10 13:35 -------
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 ')'


-- 

March 10, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1903





------- Comment #2 from shro8822@vandals.uidaho.edu  2008-03-10 13:37 -------
I don't think you can mixin statements, only decelerations.


-- 

March 10, 2008
d-bugmail@puremagic.com 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: bugzilla@digitalmars.com
>         ReportedBy: webmaster@villagersonline.com
> 
> 
> 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
March 10, 2008
downs wrote:
> d-bugmail@puremagic.com 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: bugzilla@digitalmars.com
>>         ReportedBy: webmaster@villagersonline.com
>>
>>
>> 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.
March 10, 2008
Russell Lewis wrote:
> downs wrote:
>> d-bugmail@puremagic.com 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: bugzilla@digitalmars.com
>>>         ReportedBy: webmaster@villagersonline.com
>>>
>>>
>>> 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.

Well, AST macros are a planned feature. In fact, there's already a macro.c in DMD2's front-end source code :-).
March 11, 2008
Robert Fraser wrote:

>> I refactored it to use string mixins.  It works now, but it's ugly.
> 
> Well, AST macros are a planned feature. In fact, there's already a macro.c in DMD2's front-end source code :-).

Had me excited there for a minute.  The macro.c currently in the source is for expansion of DDoc macros.

--bb
November 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1903


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #5 from smjg@iname.com  2008-11-20 20:06 -------
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.


--