351 – Recursive string template doesn't work if the terminating specialisation is given first

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 351 - Recursive string template doesn't work if the terminating specialisation is given first
Summary: Recursive string template doesn't work if the terminating specialisation is g...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks: 340
Show dependency tree / graph
Reported: 2006年09月16日 18:13 UTC by Stewart Gordon
Modified: 2014年02月15日 13:21 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Stewart Gordon 2006年09月16日 18:13:03 UTC
----------
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.
Comment 1 Thomas Kühne 2006年09月20日 14:20:52 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
-----BEGIN PGP SIGNATURE-----
iD8DBQFFEZkzLK5blCcjpWoRApT/AJ4uytg24UNRfmR6fO+mrVEx9eeF/ACfZ6+L
65qbqePX/9303yq/FqDmMMI=
=wuy3
-----END PGP SIGNATURE-----
Comment 2 Walter Bright 2006年10月10日 03:27:23 UTC
Fixed DMD 0.169


AltStyle によって変換されたページ (->オリジナル) /