-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
Milestone
Description
Championed issue: dotnet/csharplang#2460
- Trial VS insertion succeeds
- LangVersion [See
TargetTypedConditionalOperatorTests.TestLanguageVersionandSemanticErrorTests.CS0172ERR_AmbigQM] - target-typing to a nullable reference type [
TestNullableReferenceType_*] - target-typed 'ref' conditional (expect an error) [I don't know how to test this. Any attempt runs afoul of other language violations.]
- SemanticModel
- shows an appropriate ConvertedType in GetTypeInfo [Most tests in
TargetTypedConditionalOperatorTests] - ClassifyConversion(Expression, Type) [
TestClassifyConversion_*]
- shows an appropriate ConvertedType in GetTypeInfo [Most tests in
- IOperation shows conversion appropriately [Tests show no conversion in the trees, as intended, like other conversion-from-expression cases. See, for example,
ThrowFlow_32_Regular8] - With user-defined conversions
-
C c = flag ? new A() : new B();whereA -> B,A -> C,B -> C, is consistent across language versions [TestUserDefinedConversionChain]
-
- Constant conversions
-
short x = true ? 1 : 2continues to work in old language versions -
short x = flag ? 1 : 2requires new language version to work -
short x = flag ? 1 << 16 : 1always fails -
short x = true ? 1 : 1 << 16continues to work in old and new language versions- similar scenarios but with conditional expressions as constant patterns:
case true ? 1 : int.MaxValue:
- similar scenarios but with conditional expressions as constant patterns:
-
SomeEnum e = b ? 0 : 0;works in new language version (but works in any language version when 'b' is constant)
-
- Overload resolution
-
M(b ? 1 : 2) // calls M(long), not M(short) -
M(true ? 1 : 2) // calls M(short), not M(long) -
M(true ? 1 : 1 << 16) // calls M(short), not M(long)
-
- Lambdas
Action a = b ? () => { } : () => { } - Method group conversions
Action a = b ? M1 : M2 - Iterators
IEnumerable<short> M1() { yield return b ? 1 : 2; } - Default literal
Widget x = b ? default : default; - Pointers
void* ptr = b ? (int*)x : (long*)y; - Function pointers, particularly variance in returns+parameters
- Expression trees
- dynamic conversions
-
FormattableString formattable = flag ? $"a" : $"b"- also try with IFormattable?
- composition of tuples and conditional expressions
- throw expressions
-
object obj = b ? throw new Exception : throw new Exception(); -
object obj = b ? default : throw new Exception();
-
Reactions are currently unavailable