Basically the same question than https://forum.dlang.org/post/aoltazzfmnztsyatf...@forum.dlang.org but with functions/delegates and inferred return types:

``` D
interface I {
        bool check();
}
class A : I {
        bool check() =>true;
}
class B : I {
        bool check() =>false;
}

void main()
{
    I myI = () {
        final switch("A")
        {
        case "A": return new A();
        case "B": return new B();
        }
    }();
}
```

This won't compile, because return type "Return type of `A` inferred here.".

My understanding from the spec (https://dlang.org/spec/expression.html#lambda-return-type) is that it should pick `I` as return type, because it is different from the initial return type (`A`) and a `A` implicitly converts to `I`.

Is it an expected behavior ?

Reply via email to