Elm Exactly
Results / elm /

UnsafePatternTripleNestedPatternsPatternArgCasesTest

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 function parameter pattern `( ( a, b ), { x, y }, h :: t )` is rejected with an UNSAFE
PATTERN error.

A function's parameter patterns must match every value of their type. The nested tuple and
the record pattern always match, but the cons pattern `h :: t` in the third position fails
on the empty list.

Results

elm-0.19.1

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

This pattern does not cover all possiblities:

17| complex ( ( a, b ), { x, y }, h :: t ) =
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Other possibilities include:

    ( ( _, _ ), _, [] )

I would have to crash if I saw one of those! So rather than pattern matching in
function arguments, put a `case` in the function body to account for all
possibilities.

Detected problems in 1 module.

elm-0.19.2

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

This pattern does not cover all possibilities:

17| complex ( ( a, b ), { x, y }, h :: t ) =
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Other possibilities include:

    ( ( _, _ ), _, [] )

I would have to crash if I saw one of those! So rather than pattern matching in
function arguments, put a `case` in the function body to account for all
possibilities.

Detected problems in 1 module.

elm-0.19.3

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

This pattern does not cover all possibilities:

17| complex ( ( a, b ), { x, y }, h :: t ) =
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Other possibilities include:

    ( ( _, _ ), _, [] )

I would have to crash if I saw one of those! So rather than pattern matching in
function arguments, put a `case` in the function body to account for all
possibilities.

Detected problems in 1 module.

lamdera-1.5.0

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

This pattern does not cover all possiblities:

17| complex ( ( a, b ), { x, y }, h :: t ) =
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Other possibilities include:

    ( ( _, _ ), _, [] )

I would have to crash if I saw one of those! So rather than pattern matching in
function arguments, put a `case` in the function body to account for all
possibilities.

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module UnsafePatternTripleNestedPatternsPatternArgCasesTest exposing (..)
{-| A function parameter pattern `( ( a, b ), { x, y }, h :: t )` is rejected with an UNSAFE
PATTERN error.
A function's parameter patterns must match every value of their type. The nested tuple and
the record pattern always match, but the cons pattern `h :: t` in the third position fails
on the empty list.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-exhaustiveness
-- COMPILE-ERROR: UNSAFE PATTERN, Triple nested patterns (PatternArgCases)
-- CHECK: -- UNSAFE PATTERN -
complex ( ( a, b ), { x, y }, h :: t ) =
a
testValue =
complex ( ( 1, "hello" ), { x = 3.14, y = 2 }, [ 3, 4 ] )

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