Thread overview
[Issue 1308] New: Recursive alias declaration, Error: forward reference to foo
Jul 02, 2007
d-bugmail
Sep 28, 2007
d-bugmail
Sep 28, 2007
BCS
July 02, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1308

           Summary: Recursive alias declaration, Error: forward reference to
                    foo
           Product: D
           Version: 1.017
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: onlystupidspamhere@yahoo.se


Code:

Version 1:

  template r(alias S, T...) {
    static if (T.length)
        alias r!(r, T[1..$]) r;
    else
        alias int r;
  }

  alias r!(r, Object) foo;

Version 2:

  template f() {}

  template r(alias S, T...) {
    static if (T.length)
        alias r!(r, T[1..$]) r;
    else
        alias f r;
  }

  alias r!(f, Object) foo;

Compiler output:

aliasbug.d(3): alias aliasbug.r!(r,Object).r recursive alias declaration
aliasbug.d(3): Error: forward reference to 'r!(r,T[1 .. __dollar])'
aliasbug.d(3): template instance r!(int) does not match any template
declaration
aliasbug.d(8): template instance aliasbug.r!(r,Object) error instantiating

----

I'm not sure if the first one should work (it's a minimal case that triggers the error msg), but the latter one should. It's derived from a compile time map template.


-- 

September 28, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1308





------- Comment #1 from onlystupidspamhere@yahoo.se  2007-09-27 19:12 -------
The original was a bit messy so here's a bit shorter one:

  template r(alias S, T...) {
    static if (T.length)
      alias r!(r) r;
    else
      alias float r;
  }

  alias r!(r, r) foo;

---

I expect it to work this way:

1. "alias r!(r, r) foo" calls r!(r, r)
2. static if is true so "template r!(r, r)" calls r!(r)
3. static if is now false so "template r!(r)" returns float.
4. r!(r, r) returns r!(r) = float.
5. foo becomes an alias of r!(r, r) = r!(r) = float.

---

The "template instance r!(int) does not match any template declaration" doesn't
make any sense. There's no instantion of r!(int) happening anywhere.


-- 

September 28, 2007
Reply to d-bugmail@puremagic.com,

> http://d.puremagic.com/issues/show_bug.cgi?id=1308
> 
> ------- Comment #1 from onlystupidspamhere@yahoo.se  2007-09-27 19:12
> ------- The original was a bit messy so here's a bit shorter one:
> 
> template r(alias S, T...) {
> static if (T.length)
> alias r!(r) r;
> else
> alias float r;
> }
> alias r!(r, r) foo;
> 
> ---
> 
> I expect it to work this way:
> 
> 1. "alias r!(r, r) foo" calls r!(r, r)
> 2. static if is true so "template r!(r, r)" calls r!(r)
> 3. static if is now false so "template r!(r)" returns float.
> 4. r!(r, r) returns r!(r) = float.
> 5. foo becomes an alias of r!(r, r) = r!(r) = float.
> ---
> 
> The "template instance r!(int) does not match any template
> declaration" doesn't make any sense. There's no instantion of r!(int)
> happening anywhere.
> 

int is the default that DMD uses when it don't known what to make of somthing. If it were up to me I'd have an unknown_type to server for this.