UnsafePatternDestructFixedListPatternLetDestructCasesTest
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.
A `let` that destructures a list with the fixed-length pattern `[ a, b ] = [ 1, 2 ]` is rejected with an UNSAFE PATTERN error. A pattern in a `let` must match every value of its type, and `[ a, b ]` matches only lists of exactly two elements.
Results
elm-0.19.1
passOutput
Compiling ...-- UNSAFE PATTERN - src/UnsafePatternDestructFixedListPatternLetDestructCasesTest.elm
This pattern does not cover all possible values:
18| [ a, b ] =
^^^^^^^^
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
passOutput
Compiling ...-- UNSAFE PATTERN - src/UnsafePatternDestructFixedListPatternLetDestructCasesTest.elm
This pattern does not cover all possible values:
18| [ a, b ] =
^^^^^^^^
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
passOutput
Compiling ...-- UNSAFE PATTERN - src/UnsafePatternDestructFixedListPatternLetDestructCasesTest.elm
This pattern does not cover all possible values:
18| [ a, b ] =
^^^^^^^^
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
passOutput
Detected problems in 1 module.
-- UNSAFE PATTERN - src/UnsafePatternDestructFixedListPatternLetDestructCasesTest.elm
This pattern does not cover all possible values:
18| [ a, b ] =
^^^^^^^^
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/UnsafePatternDestructFixedListPatternLetDestructCasesTest] in its title.
Source
The -- CHECK: lines give the expected output.
module UnsafePatternDestructFixedListPatternLetDestructCasesTest exposing (..)
{-| A `let` that destructures a list with the fixed-length pattern `[ a, b ] = [ 1, 2 ]` is
rejected with an UNSAFE PATTERN error.
A pattern in a `let` must match every value of its type, and `[ a, b ]` matches only lists
of exactly two elements.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-exhaustiveness
-- COMPILE-ERROR: UNSAFE PATTERN, Destruct fixed list pattern (LetDestructCases)
-- CHECK: -- UNSAFE PATTERN -
testValue =
let
[ a, b ] =
[ 1, 2 ]
in
( a, b )
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_UnsafePatternDestructFixedListPatternLetDestructCasesTest, 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.