www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - DMD 0.132: Bizarre template interaction with aliases and dependent

reply Burton Radons <burton-radons smocky.com> writes:
This code fails compilation with the error message "f.d(10): this for 
data needs to be type B not type B *".  It's valid code and should work.

     struct A (uint D)
     {
         alias B! (D - 1) b;
     }

     struct B (uint D)
     {
         uint [D] data;

         uint foo () { return data [0]; }
     }

     alias B! (3) b3;
     alias B! (4) b4;

The error goes away if the "alias B! (3) b3;" line is removed, the 
"alias B! (D - 1) b;" line is removed or changed to "alias B! (3) b;", 
or the "uint foo () { return data [0]; }" line is changed to "uint foo 
() { return this.data [0]; }".

Another variant that works is to change the "alias B! (3) b3;" line to 
"alias B! (4) b4;" and to change the "alias B! (D - 1) b;" line to 
"alias B! (D) b;".  So it seems to be an interaction between constant 
folding and aliasing.
Sep 25 2005
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Sun, 25 Sep 2005 12:49:23 -0700, Burton Radons  
<burton-radons smocky.com> wrote:
 This code fails compilation with the error message "f.d(10): this for  
 data needs to be type B not type B *".  It's valid code and should work.

      struct A (uint D)
      {
          alias B! (D - 1) b;
      }

      struct B (uint D)
      {
          uint [D] data;

          uint foo () { return data [0]; }
      }

      alias B! (3) b3;
      alias B! (4) b4;

 The error goes away if the "alias B! (3) b3;" line is removed, the  
 "alias B! (D - 1) b;" line is removed or changed to "alias B! (3) b;",  
 or the "uint foo () { return data [0]; }" line is changed to "uint foo  
 () { return this.data [0]; }".

 Another variant that works is to change the "alias B! (3) b3;" line to  
 "alias B! (4) b4;" and to change the "alias B! (D - 1) b;" line to  
 "alias B! (D) b;".  So it seems to be an interaction between constant  
 folding and aliasing.
I tried it with 0.133 on Windows... C:\Library\D\src\temp>dmd Digital Mars D Compiler v0.133 Copyright (c) 1999-2005 by Digital Mars written by Walter Bright .. C:\Library\D\src\temp>dmd bug8.d C:\Library\D\dmd\bin\..\..\dm\bin\link.exe bug8,,,user32+kernel32/noi; <compiles fine> When run my version outputs 0 twice (expected), full source below. [bug8.d] import std.stdio; struct A (uint D) { alias B! (D - 1) b; } struct B (uint D) { uint [D] data; uint foo () { return data [0]; } } alias B! (3) b3; alias B! (4) b4; void main() { b3 a; b4 b; writefln(a.foo()); writefln(b.foo()); } Regan
Sep 25 2005
parent Burton Radons <burton-radons smocky.com> writes:
Regan Heath wrote:
 On Sun, 25 Sep 2005 12:49:23 -0700, Burton Radons  
 <burton-radons smocky.com> wrote:
 
 This code fails compilation with the error message "f.d(10): this for  
 data needs to be type B not type B *".  It's valid code and should work.

      struct A (uint D)
      {
          alias B! (D - 1) b;
      }

      struct B (uint D)
      {
          uint [D] data;

          uint foo () { return data [0]; }
      }

      alias B! (3) b3;
      alias B! (4) b4;

 The error goes away if the "alias B! (3) b3;" line is removed, the  
 "alias B! (D - 1) b;" line is removed or changed to "alias B! (3) 
 b;",  or the "uint foo () { return data [0]; }" line is changed to 
 "uint foo  () { return this.data [0]; }".

 Another variant that works is to change the "alias B! (3) b3;" line 
 to  "alias B! (4) b4;" and to change the "alias B! (D - 1) b;" line 
 to  "alias B! (D) b;".  So it seems to be an interaction between 
 constant  folding and aliasing.
I tried it with 0.133 on Windows... C:\Library\D\src\temp>dmd Digital Mars D Compiler v0.133 Copyright (c) 1999-2005 by Digital Mars written by Walter Bright .. C:\Library\D\src\temp>dmd bug8.d C:\Library\D\dmd\bin\..\..\dm\bin\link.exe bug8,,,user32+kernel32/noi; <compiles fine> When run my version outputs 0 twice (expected), full source below.
Confirmed fixed on Linux in 0.133.
Sep 26 2005
prev sibling parent reply Burton Radons <burton-radons smocky.com> writes:
Burton Radons wrote:
 This code fails compilation with the error message "f.d(10): this for 
 data needs to be type B not type B *".  It's valid code and should work.
 
     struct A (uint D)
     {
         alias B! (D - 1) b;
     }
 
     struct B (uint D)
     {
         uint [D] data;
 
         uint foo () { return data [0]; }
     }
 
     alias B! (3) b3;
     alias B! (4) b4;
 
 The error goes away if the "alias B! (3) b3;" line is removed, the 
 "alias B! (D - 1) b;" line is removed or changed to "alias B! (3) b;", 
 or the "uint foo () { return data [0]; }" line is changed to "uint foo 
 () { return this.data [0]; }".
 
 Another variant that works is to change the "alias B! (3) b3;" line to 
 "alias B! (4) b4;" and to change the "alias B! (D - 1) b;" line to 
 "alias B! (D) b;".  So it seems to be an interaction between constant 
 folding and aliasing.
Whoops, scratch that. The problem is NOT fixed in 0.133 (I tested a fixed copy by mistake), AND I posted the wrong example. It should instead be: struct A (uint D) { alias B! (D - 1) b; } struct B (uint D) { uint [D] data; uint foo () { return data [0]; } } alias B! (3) b3; alias A! (4) a4; One little letter at the end.
Sep 26 2005
parent =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Burton Radons schrieb:

 Whoops, scratch that.  The problem is NOT fixed in 0.133 (I tested a
 fixed copy by mistake), AND I posted the wrong example.  It should
 instead be:
 
     struct A (uint D)
     {
         alias B! (D - 1) b;
     }
 
     struct B (uint D)
     {
         uint [D] data;
 
         uint foo () { return data [0]; }
     }
 
     alias B! (3) b3;
     alias A! (4) a4;
 
 One little letter at the end.
Added to DStress as http://dstress.kuehne.cn/run/t/template_class_10_A.d http://dstress.kuehne.cn/run/t/template_class_10_B.d http://dstress.kuehne.cn/run/t/template_class_10_C.d http://dstress.kuehne.cn/run/t/template_class_10_D.d http://dstress.kuehne.cn/run/t/template_class_10_E.d http://dstress.kuehne.cn/run/t/template_struct_03_A.d http://dstress.kuehne.cn/run/t/template_struct_03_B.d http://dstress.kuehne.cn/run/t/template_struct_03_C.d http://dstress.kuehne.cn/run/t/template_struct_03_D.d http://dstress.kuehne.cn/run/t/template_struct_03_E.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDOGgX3w+/yD4P9tIRArnTAKCEmuPiHFj2Ij3y68wTvozz2bGEuACeICRe eAj1yJRnUsujL+alq64Zfl0= =ql3Z -----END PGP SIGNATURE-----
Sep 26 2005