Thread overview
[Issue 19420] [master] TypeTrait semantic fails for non static aggregate members
Nov 22, 2018
Basile B.
Nov 22, 2018
Basile B.
Nov 22, 2018
Basile B.
Nov 22, 2018
RazvanN
Nov 26, 2018
RazvanN
November 22, 2018
https://issues.dlang.org/show_bug.cgi?id=19420

--- Comment #1 from Basile B. <b2.temp@gmx.com> ---
When i think to what AliasSeq does maybe that the semantic for TypeTrait should always create a tuple and let the aliasSemantic() do its job on this tuple, without adding any pre-processing...

--
November 22, 2018
https://issues.dlang.org/show_bug.cgi?id=19420

--- Comment #2 from Basile B. <b2.temp@gmx.com> ---
(In reply to Basile B. from comment #1)
> When i think to what AliasSeq does maybe that the semantic for TypeTrait should always create a tuple and let the aliasSemantic() do its job on this tuple, without adding any pre-processing...

This but only when within an AliasDeclaration. Not sure if this would work when the __trait expression is used in place of a type (cast, var decl, etc)...

--
November 22, 2018
https://issues.dlang.org/show_bug.cgi?id=19420

--- Comment #3 from Basile B. <b2.temp@gmx.com> ---
This works for fixing this bug but then type solving from a __traits() that's inside an alias is broken:


```
    override void visit(TypeTraits mtype)
    {
        import dmd.traits : semanticTraits;

        result = null;
        if (mtype.ty == Terror)
        {
            result = mtype;
            return;
        }
        if (mtype.exp.ident != Id.allMembers &&
            mtype.exp.ident != Id.derivedMembers &&
            mtype.exp.ident != Id.getMember &&
            mtype.exp.ident != Id.parent &&
            mtype.exp.ident != Id.getOverloads &&
            mtype.exp.ident != Id.getVirtualFunctions &&
            mtype.exp.ident != Id.getVirtualMethods &&
            mtype.exp.ident != Id.getAttributes &&
            mtype.exp.ident != Id.getUnitTests)
        {
            static immutable (const(char)*)[2] ctxt = ["as type", "in alias"];
            .error(mtype.loc, "trait `%s` is either invalid or not supported
%s",
                 mtype.exp.ident.toChars, ctxt[mtype.inAliasDeclaration]);
            result = mtype;
            mtype.ty = Terror;
            return;
        }
        if (Expression e = semanticTraits(mtype.exp, sc))
        {
            if (mtype.inAliasDeclaration)
            {
                Dsymbol aliased;
                if (TupleExp te = e.toTupleExp)
                {
                    aliased = new TupleDeclaration(mtype.loc,
                        Identifier.generateId("__aliastupmulti"),
cast(Objects*) te.exps);
                }
                else
                {
                    Objects* exps = new Objects(1);
                    (*exps)[0] = e;
                    TupleDeclaration td = new TupleDeclaration(mtype.loc,
                        Identifier.generateId("__aliastupsingle"), exps);
                    aliased = td;
                }
                AliasDeclaration ad = new AliasDeclaration(mtype.loc,
                    Identifier.generateId("__aliastup"), aliased);
                aliasSemantic(ad, sc);
                mtype.sym = ad.aliassym ? ad.aliassym.toAlias2() : null;
                result = ad.type ? ad.type : new TypeError();
            }
            else if (Type t = getType(e))
            {
                result = t.addMod(mtype.mod);
            }
            else result = new TypeError();
        }
        if (!mtype.inAliasDeclaration && !result)
        {
            if (!global.errors)
                .error(mtype.loc, "`%s` does not give a valid type",
mtype.toChars);
            result = mtype;
            mtype.ty = Terror;
        }
    }
```

so when __aliastupsingleN represents a type. At this point it's a put them in the right order game.

--
November 22, 2018
https://issues.dlang.org/show_bug.cgi?id=19420

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
PR : https://github.com/dlang/dmd/pull/8992

--
November 26, 2018
https://issues.dlang.org/show_bug.cgi?id=19420

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--