dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Wrong types in create-temporary rewrites (CommaExp) wrt. `alias this`

Open TurkeyMan opened this issue 9 months ago • 4 comments

It is alleged that this is a frontend issue that breaks LDC: https://github.com/ldc-developers/ldc/issues/4882

TurkeyMan avatar Mar 17 '25 16:03 TurkeyMan

Test case from https://github.com/ldc-developers/ldc/issues/4246#issuecomment-1308175222:

struct Result(Type) {
    Type get() {  assert(0); }

    alias get this;

    this(ref Result) {}
}

float dotProduct() {
    Result!float got;
    return got;
}

The got in return got; is rewritten to: (float __copytmp2 = got.get(); __copytmp2). The type of the overall CommaExp is Result!float (instead of float), and so is the 2nd nested expression's (__copytmp2).

Additionally, the temporary isn't required - it's a trivial float. Result!float is no POD because of the copy ctor, I guess that tricks the frontend into thinking it has to create a float temporary (because it's using the wrong Result!float type, not float).

kinke avatar Mar 17 '25 16:03 kinke

This is constantly creating ICE in LDC; someone needs to fix this...

TurkeyMan avatar Oct 08 '25 05:10 TurkeyMan

So, is this fixed now? Does DMD need to take any action? I thought it was said the problem was a DMD bug, but it seems they fixed it in LDC?

TurkeyMan avatar Oct 26 '25 22:10 TurkeyMan

Just because the DMD codegenerator doesn't hick up on the wrong AST types doesn't mean this is an LDC issue.

kinke avatar Oct 31 '25 14:10 kinke