Re: interface inference with delegates/functions

2025-02-05 Thread axricard via Digitalmars-d-learn
On Wednesday, 5 February 2025 at 01:20:07 UTC, Jonathan M Davis wrote: Note that it talks about the "initial inferred return type", whereas your function doesn't have an initial inferred return type, because it fails to compile when determining the return type. So, while the spec doesn't expand

Re: interface inference with delegates/functions

2025-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2025 5:53:02 AM MST axricard via Digitalmars-d-learn wrote: > 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(); >

interface inference with delegates/functions

2025-02-04 Thread axricard via Digitalmars-d-learn
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

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 15:46:18 UTC, Paul Backus wrote: On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: 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

Re: interface inference

2023-11-28 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: 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?** Known bug, first reported in 2009: https://issues

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 14:10:30 UTC, Dom DiSc wrote: On Tuesday, 28 November 2023 at 11:01:14 UTC, Antonio wrote: ```d I aOrB(bool check){ if(check) return new A(); else return new B(); } ``` **Is it the expected behaviour for ternary conditional?** Here the compiler know

Re: interface inference

2023-11-28 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 11:01:14 UTC, Antonio wrote: ```d I aOrB(bool check){ if(check) return new A(); else return new B(); } ``` **Is it the expected behaviour for ternary conditional?** Here the compiler knows what type to return (from the function signature). But the t

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: ```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 ); } ```

interface inference

2023-11-23 Thread Antonio via Digitalmars-d-learn
```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 conver