www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1903] New: Template declaration (for mixin) can't be parsed

reply d-bugmail puremagic.com writes:
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


-- 
Mar 10 2008
next sibling parent d-bugmail puremagic.com writes:
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 ')'


-- 
Mar 10 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
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.


-- 
Mar 10 2008
prev sibling next sibling parent reply downs <default_357-line yahoo.de> writes:
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
Mar 10 2008
parent reply Russell Lewis <webmaster villagersonline.com> writes:
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.
Mar 10 2008
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
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 :-).
Mar 10 2008
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
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
Mar 10 2008
prev sibling parent d-bugmail puremagic.com writes:
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.


-- 
Nov 20 2008