Skip to content

Test plan for "target-typed conditional" #43186

@jcouv

Description

@jcouv

Championed issue: dotnet/csharplang#2460

  • Trial VS insertion succeeds
  • LangVersion [See TargetTypedConditionalOperatorTests.TestLanguageVersion and SemanticErrorTests.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_*]
  • 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(); where A -> B, A -> C, B -> C, is consistent across language versions [TestUserDefinedConversionChain]
  • Constant conversions
    • short x = true ? 1 : 2 continues to work in old language versions
    • short x = flag ? 1 : 2 requires new language version to work
    • short x = flag ? 1 << 16 : 1 always fails
    • short x = true ? 1 : 1 << 16 continues to work in old and new language versions
      • similar scenarios but with conditional expressions as constant patterns: case true ? 1 : int.MaxValue:
    • 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();

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions