[Issue 19786] alias to __traits(getMember) wrongfully always binds to this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 4 15:14:58 UTC 2019


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

--- Comment #5 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Basile-z from comment #4)
> I wont fix the issue since it's assigned but just a few words to clarify the
> problem:
> 
> 1. The wrong symbol is return because of a call to `getDsymbolWithoutExp()`
> (https://github.com/dlang/dmd/blob/93b4b99b0b024d238b223e73804c1d0c01ee42ec/
> src/dmd/typesem.d#L1637)
> 
> 2. After this call, a type is returned from the `TraitExp`, always, even
> when the `TraitsExp` doesn't represent a `Type`. That's because `getType()`
> returns the type of the expression when the expression itself doesn't
> represents/wraps a `Type`.
> 
> The fix would consist into detecting the invalid stuff beforehand
>
Fixing this specific case is trivial, but fixing the general case is more
complicated because there are a lot of corner cases (expressions that might or
might no be convertible to symbols/types).
> ---
> if (Expression e = semanticTraits(mtype.exp, sc))
> {
>     if (TupleExp te = e.toTupleExp)
>         mtype.sym = new TupleDeclaration(mtype.loc,
>             Identifier.generateId("__aliastup"), cast(Objects*) te.exps);
>     else if (Dsymbol ds = getDsymbol(e))
>         mtype.sym = ds;
> 
>     // detect invalid cases such as 19786 here at worst
> 
>     // if you reach this point with smthg like issue 19786 it's too late
>     else if (Dsymbol ds = getDsymbolWithoutExpCtx(e))
>         mtype.sym = ds;
> 
>     // if you reach this point with an invalid case it's too late
>     else if (Type t = getType(e))
>         result = t.addMod(mtype.mod);
> }
> ---
> 
> Note in reaction to previous comment, `rhs` is not an expression, it's a
> `VarDeclaration`, so a symbol.

`rhs.x` is an expression, a DotVarExp. x is the var declaration that is
returned and the this is implicitly added by the compiler in both cases.

--


More information about the Digitalmars-d-bugs mailing list