Elm Exactly
Results / elm /

UnsafePatternAllDestructPatternsEdgeCaseCasesTest

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 `let` that destructures a list with `(h :: t) = [ 4, 5 ]` is rejected with an UNSAFE
PATTERN error.

A pattern in a `let` must match every value of its type. The same `let` also destructures a
tuple, a record and an `as` alias, which always match; the cons pattern does not, because
it fails on the empty list.

Results

elm-0.19.1

pass
Output
Compiling ...-- UNSAFE PATTERN ---- src/UnsafePatternAllDestructPatternsEdgeCaseCasesTest.elm

This pattern does not cover all possible values:

25|         (h :: t) =
             ^^^^^^
Other possibilities include:

    []

I would have to crash if I saw one of those! You can use `let` to deconstruct
values only if there is ONE possiblity. Switch to a `case` expression to account
for all possibilities.

Hint: Are you calling a function that definitely returns values with a very
specific shape? Try making the return type of that function more specific!

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- UNSAFE PATTERN ---- src/UnsafePatternAllDestructPatternsEdgeCaseCasesTest.elm

This pattern does not cover all possible values:

25|         (h :: t) =
             ^^^^^^
Other possibilities include:

    []

I would have to crash if I saw one of those! You can use `let` to deconstruct
values only if there is ONE possibility. Switch to a `case` expression to
account for all possibilities.

Hint: Are you calling a function that definitely returns values with a very
specific shape? Try making the return type of that function more specific!

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- UNSAFE PATTERN ---- src/UnsafePatternAllDestructPatternsEdgeCaseCasesTest.elm

This pattern does not cover all possible values:

25|         (h :: t) =
             ^^^^^^
Other possibilities include:

    []

I would have to crash if I saw one of those! You can use `let` to deconstruct
values only if there is ONE possibility. Switch to a `case` expression to
account for all possibilities.

Hint: Are you calling a function that definitely returns values with a very
specific shape? Try making the return type of that function more specific!

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- UNSAFE PATTERN ---- src/UnsafePatternAllDestructPatternsEdgeCaseCasesTest.elm

This pattern does not cover all possible values:

25|         (h :: t) =
             ^^^^^^
Other possibilities include:

    []

I would have to crash if I saw one of those! You can use `let` to deconstruct
values only if there is ONE possiblity. Switch to a `case` expression to account
for all possibilities.

Hint: Are you calling a function that definitely returns values with a very
specific shape? Try making the return type of that function more specific!

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module UnsafePatternAllDestructPatternsEdgeCaseCasesTest exposing (..)
{-| A `let` that destructures a list with `(h :: t) = [ 4, 5 ]` is rejected with an UNSAFE
PATTERN error.
A pattern in a `let` must match every value of its type. The same `let` also destructures a
tuple, a record and an `as` alias, which always match; the cons pattern does not, because
it fails on the empty list.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-exhaustiveness
-- COMPILE-ERROR: UNSAFE PATTERN, All destruct patterns (EdgeCaseCases)
-- CHECK: -- UNSAFE PATTERN -
testValue =
let
( a, b ) =
( 1, 2 )
{ x } =
{ x = 3 }
(h :: t) =
[ 4, 5 ]
(v as w) =
6
in
[ a, x, h, v ]

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_UnsafePatternAllDestructPatternsEdgeCaseCasesTest, 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.