www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why is this?

reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
I have weird thing:

template E(F){
    enum E {
        K = F(1)
    }
}

struct S(F = float, alias e_ = E!double.K) {}
S!float x; // Error: E!double.K is used as a type

alias T = E!double.K;
struct S2(F = float, alias e_ = T) {}
S2!float y; // alias makes it okay...

struct S3(F = float, alias e_ = (E!double.K)) {}
S3!float z; // just putting parens make it okay as well... wat!?


This can't be right... right?

No problem if E is not a template.
Sep 05 2016
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 06/09/2016 6:07 PM, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
typeof(E!double.K)
 S!float x; // Error: E!double.K is used as a type

 alias T = E!double.K;
 struct S2(F = float, alias e_ = T) {}
 S2!float y; // alias makes it okay...

 struct S3(F = float, alias e_ = (E!double.K)) {}
 S3!float z; // just putting parens make it okay as well... wat!?


 This can't be right... right?

 No problem if E is not a template.
Sep 05 2016
parent reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 6 September 2016 at 16:10, rikki cattermole via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On 06/09/2016 6:07 PM, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
typeof(E!double.K)
== double ?? Not sure what you're saying.
Sep 05 2016
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 06/09/2016 6:23 PM, Manu via Digitalmars-d wrote:
 On 6 September 2016 at 16:10, rikki cattermole via Digitalmars-d
 <digitalmars-d puremagic.com> wrote:
 On 06/09/2016 6:07 PM, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
typeof(E!double.K)
== double ?? Not sure what you're saying.
Basically your code only it is using typeof to get the type after all K is a value and alias is for types. template E(F){ enum E { K = F(1) } } struct S(F = float, alias e_ = typeof(E!double.K)) { pragma(msg, e_); // E pragma(msg, E!double.K); // 1.0 pragma(msg, typeof({return E!double.K;}())); // E } S!float x; But yes little weird.
Sep 05 2016
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 06/09/2016 6:42 PM, rikki cattermole wrote:
 On 06/09/2016 6:23 PM, Manu via Digitalmars-d wrote:
 On 6 September 2016 at 16:10, rikki cattermole via Digitalmars-d
 <digitalmars-d puremagic.com> wrote:
 On 06/09/2016 6:07 PM, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
typeof(E!double.K)
== double ?? Not sure what you're saying.
Basically your code only it is using typeof to get the type after all K is a value and alias is for types. template E(F){ enum E { K = F(1) } } struct S(F = float, alias e_ = typeof(E!double.K)) { pragma(msg, e_); // E pragma(msg, E!double.K); // 1.0 pragma(msg, typeof({return E!double.K;}())); // E } S!float x; But yes little weird.
*sigh* I'm not thinking right that alias is template argument alias not alias of types. template E(F){ enum E { K = F(1) } } struct S(F = float, V=E!double, V e_ = V.K) { pragma(msg, e_); // E pragma(msg, E!double.K); // 1.0 pragma(msg, typeof({return E!double.K;}())); // E } S!float x;
Sep 05 2016
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 06.09.2016 08:07, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
 S!float x; // Error: E!double.K is used as a type

 alias T = E!double.K;
 struct S2(F = float, alias e_ = T) {}
 S2!float y; // alias makes it okay...

 struct S3(F = float, alias e_ = (E!double.K)) {}
 S3!float z; // just putting parens make it okay as well... wat!?


 This can't be right... right?

 No problem if E is not a template.
Bug.
Sep 06 2016
parent Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 6 September 2016 at 21:28, Timon Gehr via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On 06.09.2016 08:07, Manu via Digitalmars-d wrote:
 I have weird thing:

 template E(F){
     enum E {
         K = F(1)
     }
 }

 struct S(F = float, alias e_ = E!double.K) {}
 S!float x; // Error: E!double.K is used as a type

 alias T = E!double.K;
 struct S2(F = float, alias e_ = T) {}
 S2!float y; // alias makes it okay...

 struct S3(F = float, alias e_ = (E!double.K)) {}
 S3!float z; // just putting parens make it okay as well... wat!?


 This can't be right... right?

 No problem if E is not a template.
Bug.
https://issues.dlang.org/show_bug.cgi?id=16472
Sep 06 2016