www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20275] New: Tuple created in template in with() includes

https://issues.dlang.org/show_bug.cgi?id=20275

          Issue ID: 20275
           Summary: Tuple created in template in with() includes
                    with-symbol
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider this code:

enum E { A }

alias AliasSeq(T...) = T;
alias EnumMembers(T) = AliasSeq!(__traits(allMembers, T));

void main()
{
    pragma(msg, EnumMembers!E.stringof);
    with (S())
    {
        pragma(msg, EnumMembers!E.stringof);
        auto members = [EnumMembers!E];
    }
}

struct S
{
    alias EnumMembers = .EnumMembers;
}

run.dlang.io: https://run.dlang.io/is/VwW2Zw

When run, it is seen that the `EnumMembers` aliased in the struct references
the with-symbol:

tuple("A")
(*__withSym).tuple("A")
onlineapp.d(12): Error: expression has no value

This is despite the fact that none of the members of the tuple reference the
struct, are looked up in the struct, or have anything to do with the struct.
Also the tuple isn't formed in the lexical context of the with() statement. As
a result, the attempt to form an array of enum members fails with a cryptic
error.

--
Oct 07 2019