RedundantPatternABranchAfterAWildcardTest
Tags:elm19-compile-errorelm-spec
Checks, in A Standard Definition of Elm?:restriction core-irredundancy
Not translated into Lean for the mechanisation of the book: see why.
A `case` branch placed after a wildcard branch is rejected with a REDUNDANT PATTERN error. In `name`, the `_` branch comes first and matches every value, so the following `0` branch can never be reached.
Results
elm-0.19.1
passOutput
Compiling ...-- REDUNDANT PATTERN --------- src/RedundantPatternABranchAfterAWildcardTest.elm The 2nd pattern is redundant: 16| case n of 17| _ -> 18| "any" 19| 20|> 0 -> 21| "zero" Any value with this shape will be handled by a previous pattern, so it should be removed. Detected problems in 1 module.
elm-0.19.2
passOutput
Compiling ...-- REDUNDANT PATTERN --------- src/RedundantPatternABranchAfterAWildcardTest.elm The 2nd pattern is redundant: 16| case n of 17| _ -> 18| "any" 19| 20|> 0 -> 21| "zero" Any value with this shape will be handled by a previous pattern, so it should be removed. Detected problems in 1 module.
elm-0.19.3
passOutput
Compiling ...-- REDUNDANT PATTERN --------- src/RedundantPatternABranchAfterAWildcardTest.elm The 2nd pattern is redundant: 16| case n of 17| _ -> 18| "any" 19| 20|> 0 -> 21| "zero" Any value with this shape will be handled by a previous pattern, so it should be removed. Detected problems in 1 module.
lamdera-1.5.0
passOutput
Detected problems in 1 module. -- REDUNDANT PATTERN --------- src/RedundantPatternABranchAfterAWildcardTest.elm The 2nd pattern is redundant: 16| case n of 17| _ -> 18| "any" 19| 20|> 0 -> 21| "zero" Any value with this shape will be handled by a previous pattern, so it should be removed.
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/RedundantPatternABranchAfterAWildcardTest] in its title.
Source
The -- CHECK: lines give the expected output.
module RedundantPatternABranchAfterAWildcardTest exposing (..)
{-| A `case` branch placed after a wildcard branch is rejected with a REDUNDANT PATTERN error.
In `name`, the `_` branch comes first and matches every value, so the following `0`
branch can never be reached.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-irredundancy
-- COMPILE-ERROR: REDUNDANT PATTERN, a branch after a wildcard
-- CHECK: -- REDUNDANT PATTERN -
name n =
case n of
_ ->
"any"
0 ->
"zero"
testValue =
name 0
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_RedundantPatternABranchAfterAWildcardTest, 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.