[Issue 19420] [master] TypeTrait semantic fails for non static aggregate members

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 22 10:46:39 UTC 2018


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

--- Comment #3 from Basile B. <b2.temp at 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.

--


More information about the Digitalmars-d-bugs mailing list