November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #30 from Manu <turkeyman@gmail.com> 2012-11-27 04:53:31 PST ---
(In reply to comment #28)
> (In reply to comment #26)
> 
> > It's a shame we don't have a 'manifest' keyword of some sort, it would help avoid confusion. I guess 'enum' was used to cut back on having too many keywords in the language.
> 
> Isn't the whole problem that the compiler and/or linker isn't capable of stripping out symbols that are only used at compile time.

It's also one of the things that D got absolutely right!
I never questioned this design for a moment, it makes perfect sense to me, but
as of yesterday my concept of what an enum is has been thrown up in the air for
absolutely no good reason other than terminology used by the D developers.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #31 from Manu <turkeyman@gmail.com> 2012-11-27 05:37:31 PST ---
(In reply to comment #20)
> https://gist.github.com/4152297

I am seeing a few error cases:

enum j { k = 10 }

pragma(msg, isFunction!(j.k));
pragma(msg, isManifestConstant!(j.k));
pragma(msg, isPropertyFunction!(j.k));
pragma(msg, isVariable!(j.k));

These all throw errors.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #32 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-27 06:25:56 PST ---
(In reply to comment #29)
> As a side point, what do you call X in: enum E { X = 10 } ?
> 
> Consider:
>  enum E { X = 10 }
>  enum Y = 10;
> 
> E.X and Y are both identical as far as I can tell.

Run typeid() on them.

> And every place it appears, it is clearly defined as being some subset of enum.

Well it wouldn't be the first time the docs lie. :)

"enum Y = 10;" is a special case which the compiler checks for and then parses this as a manifest constant, it does not parse it as an enum. "Y" is not an enum value of any sort, Y is a VarDeclaration with storage class STCmanifest.

Here:
enum E { X = 10 }

X is an EnumMember.

Just to make this clear, these two are different:
enum { X = 10 }
enum Y = 10;

X is an enum value, whereas Y is a manifest constant and is not associated with enums at all in any way.

The issue here is that the "enum" keyword can be a lie. It can mean two things depending on the declaration.

It also seems that internally the idea of a manifest keyword was thought about,
there's a bunch of commented out lines like so:
//case TOKmanifest:   stc = STCmanifest;     goto Lstc;

I wonder who put that in and why it wasn't used..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #33 from Manu <turkeyman@gmail.com> 2012-11-27 06:43:36 PST ---
(In reply to comment #32)
> (In reply to comment #29)
> > As a side point, what do you call X in: enum E { X = 10 } ?
> > 
> > Consider:
> >  enum E { X = 10 }
> >  enum Y = 10;
> > 
> > E.X and Y are both identical as far as I can tell.
> 
> Run typeid() on them.
> 
> > And every place it appears, it is clearly defined as being some subset of enum.
> 
> Well it wouldn't be the first time the docs lie. :)
> 
> "enum Y = 10;" is a special case which the compiler checks for and then parses this as a manifest constant, it does not parse it as an enum. "Y" is not an enum value of any sort, Y is a VarDeclaration with storage class STCmanifest.
> 
> Here:
> enum E { X = 10 }
> 
> X is an EnumMember.
> 
> Just to make this clear, these two are different:
> enum { X = 10 }
> enum Y = 10;
> 
> X is an enum value, whereas Y is a manifest constant and is not associated with enums at all in any way.

That's not really how the doc describes it: "If there is only one member of an anonymous enum, the { } can be omitted:"

Either way, it's a perfectly reasonably way to visualise it as a user. As I said before, I couldn't care less about internal compiler terminology, it looks like an anonymous enum value, and the doc even says it's an anonymous enum value. It must be so.

The doc is correct as far as I'm concerned, it makes perfect sense, the language shouldn't be defined by implementation details of DMD.


> The issue here is that the "enum" keyword can be a lie. It can mean two things depending on the declaration.
> 
> It also seems that internally the idea of a manifest keyword was thought about,
> there's a bunch of commented out lines like so:
> //case TOKmanifest:   stc = STCmanifest;     goto Lstc;
> 
> I wonder who put that in and why it wasn't used..

I'll bet it was realised during implementation that it is actually syntactic sugar for an anonymous enum, and the enum keyword was completely appropriate :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #34 from Manu <turkeyman@gmail.com> 2012-11-27 06:45:04 PST ---
@Kenji:

I'm getting an error when using your new isFunction, here's the case:

struct S
{
    static string func(alias Class)()
    {
        foreach(m; __traits(allMembers, Class))
        {
            pragma(msg, m);
            static if( isFunction!( mixin( m ) ) )
                bool b = true;
        }
    }

    enum nothing = func!(typeof(this))();
    mixin(nothing);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #35 from Manu <turkeyman@gmail.com> 2012-11-27 06:54:34 PST ---
I've just this afternoon encountered another one that I can't work out a nice way to discover:

struct S
{
  static int x;
}

bool b = isStatic!(S.x); // <- I can't think of a nice clean way to prove this other than trying to assign to it, which is horrible.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065


Dmitry Olshansky <dmitry.olsh@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh@gmail.com


--- Comment #36 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2012-11-27 07:16:39 PST ---
(In reply to comment #35)
> I've just this afternoon encountered another one that I can't work out a nice way to discover:
> 
> struct S
> {
>   static int x;
> }
> 
> bool b = isStatic!(S.x); // <- I can't think of a nice clean way to prove this other than trying to assign to it, which is horrible.

Trying to take the address should do the trick. is(typeof(&S.x)) that is.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #37 from Kenji Hara <k.hara.pg@gmail.com> 2012-11-27 07:19:03 PST ---
(In reply to comment #31)
> (In reply to comment #20)
> > https://gist.github.com/4152297
> 
> I am seeing a few error cases:
> 
> enum j { k = 10 }
> 
> pragma(msg, isFunction!(j.k));
> pragma(msg, isManifestConstant!(j.k));
> pragma(msg, isPropertyFunction!(j.k));
> pragma(msg, isVariable!(j.k));
> 
> These all throw errors.

Fixed.

(In reply to comment #34)
> @Kenji:
> 
> I'm getting an error when using your new isFunction, here's the case:
> 
> struct S
> {
>     static string func(alias Class)()
>     {
>         foreach(m; __traits(allMembers, Class))
>         {
>             pragma(msg, m);
>             static if( isFunction!( mixin( m ) ) )
>                 bool b = true;
>         }
>     }
> 
>     enum nothing = func!(typeof(this))();
>     mixin(nothing);
> }

This is a compiler bug, not an issue of isFunction template. I filed new bug 9083.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #38 from Jacob Carlborg <doob@me.com> 2012-11-27 07:35:19 PST ---
(In reply to comment #36)

> Trying to take the address should do the trick. is(typeof(&S.x)) that is.

That won't work for methods, but that might not be the use case.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #39 from Manu <turkeyman@gmail.com> 2012-11-27 07:52:20 PST ---
(In reply to comment #36)
> Trying to take the address should do the trick. is(typeof(&S.x)) that is.

And if I have:
  S s;
  bool b = isStatic!(s.x);

That solution doesn't work if 's' is an instance.
I'm sick of writing really brittle code, I'm just saying that is another
important std.traits. There's no trivial way to do this for an _anything_ that
I can work out.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------