TypeMismatchThirdCaseBranchTest
Tags:elm19-compile-errorelm-spec
Checks, in A Standard Definition of Elm?:rule s-match
Not translated into Lean for the mechanisation of the book: see why.
A `case` whose third branch returns a number while the first two return `String`s is rejected with a TYPE MISMATCH. Every branch of a `case` must produce the same type; the branches return `"a"`, `"b"` and `2`.
Results
elm-0.19.1
passOutput
Compiling ...-- TYPE MISMATCH ----------------------- src/TypeMismatchThirdCaseBranchTest.elm
The 3rd branch of this `case` does not match all the previous branches:
15| case 1 of
16| 1 ->
17| "a"
18|
19| 2 ->
20| "b"
21|
22| _ ->
23| 2
^
The 3rd branch is a number of type:
number
But all the previous branches result in:
String
Hint: All branches in a `case` must produce the same type of values. This way,
no matter which branch we take, the result is always a consistent shape. Read
<https://elm-lang.org/0.19.1/custom-types> to learn how to “mix” types.
Hint: Try using String.fromInt to convert it to a string?
Detected problems in 1 module.
elm-0.19.2
passOutput
Compiling ...-- TYPE MISMATCH ----------------------- src/TypeMismatchThirdCaseBranchTest.elm
The 3rd branch of this `case` does not match all the previous branches:
15| case 1 of
16| 1 ->
17| "a"
18|
19| 2 ->
20| "b"
21|
22| _ ->
23| 2
^
The 3rd branch is a number of type:
number
But all the previous branches result in:
String
Hint: All branches in a `case` must produce the same type of values. This way,
no matter which branch we take, the result is always a consistent shape. Read
<https://elm-lang.org/0.19.2/custom-types> to learn how to “mix” types.
Hint: Try using String.fromInt to convert it to a string?
Detected problems in 1 module.
elm-0.19.3
passOutput
Compiling ...-- TYPE MISMATCH ----------------------- src/TypeMismatchThirdCaseBranchTest.elm
The 3rd branch of this `case` does not match all the previous branches:
15| case 1 of
16| 1 ->
17| "a"
18|
19| 2 ->
20| "b"
21|
22| _ ->
23| 2
^
The 3rd branch is a number of type:
number
But all the previous branches result in:
String
Hint: All branches in a `case` must produce the same type of values. This way,
no matter which branch we take, the result is always a consistent shape. Read
<https://elm-lang.org/0.19.3/custom-types> to learn how to “mix” types.
Hint: Try using String.fromInt to convert it to a string?
Detected problems in 1 module.
lamdera-1.5.0
passOutput
Detected problems in 1 module.
-- TYPE MISMATCH ----------------------- src/TypeMismatchThirdCaseBranchTest.elm
The 3rd branch of this `case` does not match all the previous branches:
15| case 1 of
16| 1 ->
17| "a"
18|
19| 2 ->
20| "b"
21|
22| _ ->
23| 2
^
The 3rd branch is a number of type:
number
But all the previous branches result in:
String
Hint: All branches in a `case` must produce the same type of values. This way,
no matter which branch we take, the result is always a consistent shape. Read
<https://elm-lang.org/0.19.3/custom-types> to learn how to “mix” types.
Hint: Try using String.fromInt to convert it to a string?
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/TypeMismatchThirdCaseBranchTest] in its title.
Source
The -- CHECK: lines give the expected output.
module TypeMismatchThirdCaseBranchTest exposing (..)
{-| A `case` whose third branch returns a number while the first two return `String`s is rejected with a TYPE MISMATCH.
Every branch of a `case` must produce the same type; the branches return `"a"`, `"b"` and `2`.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, s-match
-- COMPILE-ERROR: TYPE MISMATCH, third case branch
-- CHECK: -- TYPE MISMATCH -
x =
case 1 of
1 ->
"a"
2 ->
"b"
_ ->
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_TypeMismatchThirdCaseBranchTest, 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.