csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

Champion: target-typed conditional expression (VS 16.8, .NET 5)

Open gafter opened this issue 7 years ago • 8 comments

  • [X] Proposal added (https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/target-typed-conditional-expression.md)
  • [x] Discussed in LDM 2019-04-22
  • [X] Decision in LDM (Approved for C# 8)
  • [ ] Finalized (done, rejected, inactive)
  • [ ] Spec'ed

This was split from https://github.com/dotnet/csharplang/issues/2389 and is being treated as a separate feature

For a conditional expression c ? e1 : e2, when there is no common type for e1 and e2, we define a new conditional expression conversion that permits an implicit conversion from the conditional expression to any type T for which there is a conversion-from-expression from e1 to T and also from e2 to T. It is an error if a conditional expression neither has a common type between e1 and e2 nor is subject to a conditional expression conversion.

Relates to https://github.com/dotnet/csharplang/issues/2701 (target-typed new[])

gafter avatar Apr 22 '19 19:04 gafter

Could this also apply to the ?? operator as well?

YairHalberstadt avatar Apr 23 '19 10:04 YairHalberstadt

@YairHalberstadt This proposal is for the ?: operator only.

gafter avatar Apr 23 '19 21:04 gafter

@gafter I understand, but is there any reason not to do the equavelent for ??. I would find it extremely useful. Should I open a new proposal for it?

YairHalberstadt avatar Apr 23 '19 21:04 YairHalberstadt

I don’t know. I have not thought about doing something for ??. The main reason not to do something in general is the balance between limited resources and limited benefit.

gafter avatar Apr 24 '19 13:04 gafter

If I were to offer to implement it, would that make a difference?

YairHalberstadt avatar Apr 24 '19 13:04 YairHalberstadt

@YairHalberstadt Without a proposed specification, I have no idea. I think we'd want to review the proposed specification to decide if it were something we want or not.

gafter avatar Apr 25 '19 16:04 gafter

I have suggested a specification at #2473

YairHalberstadt avatar Apr 28 '19 16:04 YairHalberstadt

Would love to see this feature added!

ErikSchierboom avatar May 02 '19 08:05 ErikSchierboom