Elm Exactly
Results / elm /

UnsafePatternMixedNestedAliasesAsPatternCasesTest

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 `(( { x }, (h :: _) as list ) as all)` is rejected with an
UNSAFE PATTERN error.

A function's parameter patterns must match every value of their type. The record pattern
and the `as` aliases always match, but the nested cons pattern `h :: _` fails on the empty
list.

Results

elm-0.19.1

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

This pattern does not cover all possiblities:

17| mixed (( { x }, (h :: _) as list ) as all) =
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/UnsafePatternMixedNestedAliasesAsPatternCasesTest.elm

This pattern does not cover all possibilities:

17| mixed (( { x }, (h :: _) as list ) as all) =
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/UnsafePatternMixedNestedAliasesAsPatternCasesTest.elm

This pattern does not cover all possibilities:

17| mixed (( { x }, (h :: _) as list ) as all) =
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/UnsafePatternMixedNestedAliasesAsPatternCasesTest.elm

This pattern does not cover all possiblities:

17| mixed (( { x }, (h :: _) as list ) as all) =
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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/UnsafePatternMixedNestedAliasesAsPatternCasesTest] in its title.

Source

The -- CHECK: lines give the expected output.

module UnsafePatternMixedNestedAliasesAsPatternCasesTest exposing (..)
{-| A function parameter pattern `(( { x }, (h :: _) as list ) as all)` is rejected with an
UNSAFE PATTERN error.
A function's parameter patterns must match every value of their type. The record pattern
and the `as` aliases always match, but the nested cons pattern `h :: _` fails on the empty
list.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-exhaustiveness
-- COMPILE-ERROR: UNSAFE PATTERN, Mixed nested aliases (AsPatternCases)
-- CHECK: -- UNSAFE PATTERN -
mixed (( { x }, (h :: _) as list ) as all) =
all
testValue =
mixed ( { x = 1 }, [ 1, 2 ] )

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