Thread overview
[Issue 351] New: Recursive string template doesn't work if the terminating specialisation is given first
Sep 16, 2006
d-bugmail
Sep 20, 2006
Thomas Kuehne
Oct 10, 2006
d-bugmail
September 16, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=351

           Summary: Recursive string template doesn't work if the
                    terminating specialisation is given first
           Product: D
           Version: 0.166
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: smjg@iname.com
OtherBugsDependingO 340
             nThis:


----------
import std.stdio;

template Reverse(char[] s: "") {
    const char[] Reverse = "";
}

template Reverse(char[] s) {
    const char[] Reverse = Reverse!(s[1..$]) ~ s[0];
}

void main() {
    writefln(Reverse!("Recursive string template"));
}
----------
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string slice [1
.. 0] is out of bounds
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string slice [1
.. 0] is out of bounds
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): void has no
value
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): incompatible
types for ((Reverse!(""[1..0])) ~ (cast(int)(""[0]))): 'void' and 'int'
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): Can only
concatenate arrays, not (void ~ int)
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): cannot
implicitly convert expression (Reverse!(""[1..0]) ~ cast(int)(""[0])) of type
int to char[]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
instance string_template1.Reverse!("") error instantiating
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
instance string_template1.Reverse!("e") error instantiating
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
is out of bounds [0 .. 0]
D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
instance string_template1.Reverse!("te") error instantiating
[and so on....]
----------

If the two definitions of template Reverse are swapped, then the code compiles and runs correctly.


-- 

September 20, 2006
d-bugmail@puremagic.com schrieb am 2006-09-16:
> http://d.puremagic.com/issues/show_bug.cgi?id=351

> ----------
> import std.stdio;
>
> template Reverse(char[] s: "") {
>     const char[] Reverse = "";
> }
>
> template Reverse(char[] s) {
>     const char[] Reverse = Reverse!(s[1..$]) ~ s[0];
> }
>
> void main() {
>     writefln(Reverse!("Recursive string template"));
> }
> ----------
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string slice [1
> .. 0] is out of bounds
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string slice [1
> .. 0] is out of bounds
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): void has no
> value
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): incompatible
> types for ((Reverse!(""[1..0])) ~ (cast(int)(""[0]))): 'void' and 'int'
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): Can only
> concatenate arrays, not (void ~ int)
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): cannot
> implicitly convert expression (Reverse!(""[1..0]) ~ cast(int)(""[0])) of type
> int to char[]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
> instance string_template1.Reverse!("") error instantiating
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
> instance string_template1.Reverse!("e") error instantiating
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): string index 0
> is out of bounds [0 .. 0]
> D:\My Documents\Programming\D\Tests\bugs\string_template1.d(8): template
> instance string_template1.Reverse!("te") error instantiating
> [and so on....]
> ----------
>
> If the two definitions of template Reverse are swapped, then the code compiles and runs correctly.

Added to DStress as http://dstress.kuehne.cn/compile/t/template_44_A.d http://dstress.kuehne.cn/compile/t/template_44_B.d

Thomas


October 10, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=351


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla@digitalmars.com  2006-10-10 03:27 -------
Fixed DMD 0.169


--