Elm Exactly
Results / elm /

MissingPatternsAMissingListLengthTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:restriction core-exhaustiveness

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
A `case` on a list that covers only the empty and one-element lists is rejected with a MISSING PATTERNS error.

`firstOrZero` matches `[]` and `[ x ]` but has no branch for lists of two or more
elements, so the match is not exhaustive.

Results

elm-0.19.1

pass
Output
Compiling ...-- MISSING PATTERNS -------------- src/MissingPatternsAMissingListLengthTest.elm

This `case` does not have branches for all possibilities:

16|>    case xs of
17|>        [] ->
18|>            0
19|>
20|>        [ x ] ->
21|>            x

Missing possibilities include:

    _ :: _ :: _

I would have to crash if I saw one of those. Add branches for them!

Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read <https://elm-lang.org/0.19.1/missing-patterns> for more
guidance on this workflow.

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- MISSING PATTERNS -------------- src/MissingPatternsAMissingListLengthTest.elm

This `case` does not have branches for all possibilities:

16|>    case xs of
17|>        [] ->
18|>            0
19|>
20|>        [ x ] ->
21|>            x

Missing possibilities include:

    _ :: _ :: _

I would have to crash if I saw one of those. Add branches for them!

Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read <https://elm-lang.org/0.19.2/missing-patterns> for more
guidance on this workflow.

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- MISSING PATTERNS -------------- src/MissingPatternsAMissingListLengthTest.elm

This `case` does not have branches for all possibilities:

16|>    case xs of
17|>        [] ->
18|>            0
19|>
20|>        [ x ] ->
21|>            x

Missing possibilities include:

    _ :: _ :: _

I would have to crash if I saw one of those. Add branches for them!

Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read <https://elm-lang.org/0.19.3/missing-patterns> for more
guidance on this workflow.

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- MISSING PATTERNS -------------- src/MissingPatternsAMissingListLengthTest.elm

This `case` does not have branches for all possibilities:

16|>    case xs of
17|>        [] ->
18|>            0
19|>
20|>        [ x ] ->
21|>            x

Missing possibilities include:

    _ :: _ :: _

I would have to crash if I saw one of those. Add branches for them!

Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read <https://elm-lang.org/0.19.3/missing-patterns> for more
guidance on this workflow.

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/MissingPatternsAMissingListLengthTest] in its title.

Source

The -- CHECK: lines give the expected output.

module MissingPatternsAMissingListLengthTest exposing (..)
{-| A `case` on a list that covers only the empty and one-element lists is rejected with a MISSING PATTERNS error.
`firstOrZero` matches `[]` and `[ x ]` but has no branch for lists of two or more
elements, so the match is not exhaustive.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-exhaustiveness
-- COMPILE-ERROR: MISSING PATTERNS, a missing list length
-- CHECK: -- MISSING PATTERNS -
firstOrZero xs =
case xs of
[] ->
0
[ x ] ->
x
testValue =
firstOrZero [ 1 ]

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_MissingPatternsAMissingListLengthTest, in StandardElmMech/Certs/). The program breaks a further restriction (Chapter 9) in every derivation (Stat.not_legal_of_furtherFailB). It holds for every derivation, with no hypothesis about principality.