interface inference
Antonio
antoniocabreraperez at gmail.com
Thu Nov 23 19:17:20 UTC 2023
```d
interface I {
bool check();
}
class A : I {
bool check() =>true;
}
class B : I {
bool check() =>false;
}
I aOrB(bool check) => check ? new A() : new B();
void main()
{
assert( aOrB(true).check );
}
```
Compiler error:
```d
x.d(11): Error: cannot implicitly convert expression `check ? new
A : new B` of type `object.Object` to `x.I`
```
Basically, the ternary conditional ```?:``` result type is not
inferred even if the type returned by the two possibilities are
the same.
**Is it a bug or the expected behaviour?**
More information about the Digitalmars-d-learn
mailing list