[Issue 23234] New: Delegate literal with inferred return value that requires following alias-this uses class cast instead.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 8 11:41:02 UTC 2022


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

          Issue ID: 23234
           Summary: Delegate literal with inferred return value that
                    requires following alias-this uses class cast instead.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider the following code:

class Bar
{
}

class Foo
{
    Bar get() { return new Bar; }
    alias get this;
}

void main() {
    auto foo = new Foo;
    void test(Bar delegate() dg) {
        assert(dg() !is null);
    }
    test({ return foo; });
}

-vcg-ast reveals that the delegate is compiled to `return cast(Bar) foo`,
rather than `return foo.get`.

`test(delegate Bar() { return foo; })` works.

--


More information about the Digitalmars-d-bugs mailing list