λ1010: An option has either zero or one elements

A list pattern on an Option<T> tests for more elements than an option can contain.

Cause

A list pattern with two or more element patterns is applied to an Option<T>, for example option is [var a, var b].

Reason for rule

Option<T> supports list patterns so that [] matches None and [var value] matches Some. An option never contains more than one element, so any pattern with two or more elements can never match. Such a pattern is almost certainly a mistake and the branch it guards is dead code.

How to fix violations

Use [] to match None and [var value] (or [pattern]) to match Some.

Examples

Disallowed

static string Example(Option<string> option)
    => option is [var first, var second]
        ? first + second
        : "none";

Allowed

static string Example(Option<string> option)
    => option switch
    {
        [var value] => value,
        [] => "none",
    };

static bool IsFoo(Option<string> option)
    => option is ["foo"];