Should the non-negative assumption apply to the used Property or both?
The current behavior is shown below. I think we should have an error for both lines.
interface IIndexable
{
int this[int i] { get; }
}
interface ICountableViaCount
{
int Count { get; }
}
interface ICountableViaLength
{
int Length { get; }
}
class X
{
public static void Test5<T>(T t) where T : IIndexable, ICountableViaLength, ICountableViaCount
{
_ = t is { Length: -1 }; // error CS8518: An expression of type 'T' can never match the provided pattern.
_ = t is { Count: -1 }; // should Count benefit from the assumption when it is not the preferred property?
}
}
Should we assume that Length and Count have the same value?
Another related question is whether we should assume Length and Count to have the same value? For example: case { Length: > 0 }: case { Count: 0 }: case { Count: var unreachable }:.
Should we assume non-null slice when we expect a non-zero slice?
Should we consider null or { Length: not 4 } => 0, [_, .. [_, _], _] => 0 exhaustive in a nullable context?
It is possible for a type to claim Length=4 but return a null slice, but that would violate our assumption that lengths and elements are consistent between outer and nested lists.
Options:
- this switch is not exhaustive: this is simpler, safer, but goes slightly against our "well-behaved collection" assumption
- this switch is exhaustive assuming a well-behaved collection: not sure we want to modify our DAG/codegen for this
- reject this slice method because it returns a nullable type: this seems odd, as we generally don't want nullability to affect semantics
FYI @alrz @333fred
Relates to proposal #3435
Relates to test plan dotnet/roslyn#51289
Should the non-negative assumption apply to the used Property or both?
The current behavior is shown below. I think we should have an error for both lines.
Should we assume that Length and Count have the same value?
Another related question is whether we should assume
LengthandCountto have the same value? For example:case { Length: > 0 }: case { Count: 0 }: case { Count: var unreachable }:.Should we assume non-null slice when we expect a non-zero slice?
Should we consider
null or { Length: not 4 } => 0, [_, .. [_, _], _] => 0exhaustive in a nullable context?It is possible for a type to claim
Length=4but return a null slice, but that would violate our assumption that lengths and elements are consistent between outer and nested lists.Options:
FYI @alrz @333fred
Relates to proposal #3435
Relates to test plan dotnet/roslyn#51289