Elm Exactly
Results / elm /

TypeMismatchSecondCasePatternTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:rule s-matchrule s-atpat-scon

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 `case` on a `String` whose second pattern is a `Char` literal is rejected with a TYPE MISMATCH.

The patterns are `"a"`, `'c'` and `_`; the second does not match the type of the scrutinee `"s"`.

Results

elm-0.19.1

pass
Output
Compiling ...-- TYPE MISMATCH --------------------- src/TypeMismatchSecondCasePatternTest.elm

The 2nd pattern in this `case` does not match the previous ones.

15|     case "s" of
16|         "a" ->
17|             1
18| 
19|>        'c' ->
20|             2
21| 
22|         _ ->
23|             3

The 2nd pattern is trying to match characters:

    Char

But all the previous patterns match:

    String

Note: A `case` expression can only handle one type of value, so you may want to
use <https://elm-lang.org/0.19.1/custom-types> to handle “mixing” types.

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- TYPE MISMATCH --------------------- src/TypeMismatchSecondCasePatternTest.elm

The 2nd pattern in this `case` does not match the previous ones.

15|     case "s" of
16|         "a" ->
17|             1
18| 
19|>        'c' ->
20|             2
21| 
22|         _ ->
23|             3

The 2nd pattern is trying to match characters:

    Char

But all the previous patterns match:

    String

Note: A `case` expression can only handle one type of value, so you may want to
use <https://elm-lang.org/0.19.2/custom-types> to handle “mixing” types.

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- TYPE MISMATCH --------------------- src/TypeMismatchSecondCasePatternTest.elm

The 2nd pattern in this `case` does not match the previous ones.

15|     case "s" of
16|         "a" ->
17|             1
18| 
19|>        'c' ->
20|             2
21| 
22|         _ ->
23|             3

The 2nd pattern is trying to match characters:

    Char

But all the previous patterns match:

    String

Note: A `case` expression can only handle one type of value, so you may want to
use <https://elm-lang.org/0.19.3/custom-types> to handle “mixing” types.

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- TYPE MISMATCH --------------------- src/TypeMismatchSecondCasePatternTest.elm

The 2nd pattern in this `case` does not match the previous ones.

15|     case "s" of
16|         "a" ->
17|             1
18| 
19|>        'c' ->
20|             2
21| 
22|         _ ->
23|             3

The 2nd pattern is trying to match characters:

    Char

But all the previous patterns match:

    String

Note: A `case` expression can only handle one type of value, so you may want to
use <https://elm-lang.org/0.19.3/custom-types> to handle “mixing” types.

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module TypeMismatchSecondCasePatternTest exposing (..)
{-| A `case` on a `String` whose second pattern is a `Char` literal is rejected with a TYPE MISMATCH.
The patterns are `"a"`, `'c'` and `_`; the second does not match the type of the scrutinee `"s"`.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, s-match, s-atpat-scon
-- COMPILE-ERROR: TYPE MISMATCH, second case pattern
-- CHECK: -- TYPE MISMATCH -
x =
case "s" of
"a" ->
1
'c' ->
2
_ ->
3

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_TypeMismatchSecondCasePatternTest, in StandardElmMech/Certs/). The kernel finds a core of the program's typing constraints that has no solution, so no derivation types it (core refutation, plan step 11) (Stat.not_legal_of_coreRefutes). It holds for every derivation, with no hypothesis about principality.