www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23234] New: Delegate literal with inferred return value that

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 puremagic.com
          Reporter: default_357-line 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.

--
Jul 08 2022