StandardA98TypeBeforeAliasStringMismatchTest
Tags:elm19-compile-errorelm-spec
Checks, in A Standard Definition of Elm?:rule sm-topdec-typesrule sm-topdec-seqrule sm-datbind
Not translated into Lean for the mechanisation of the book: see why.
A custom type declared before a local alias spelt like an imported type uses the local alias. The module declares `type T = T String` and then `type alias String = Int`, and applies `String.length` to the field of a `T`. A Standard Definition of Elm?, ruling A98: the module's type declarations are elaborated together, so `T`'s argument is the local `String`, which is `Int`, and `String.length` cannot take it. Reading the declarations in order would make the argument the imported `String`, and the program would be accepted. <https://elm-test-suite.netlify.app/standard/rules/sm-topdec-types> Elm 0.19.1, 0.19.2 and 0.19.3 reject the program with TYPE MISMATCH.
Results
elm-0.19.1
passOutput
Compiling ...-- TYPE MISMATCH ---------- src/StandardA98TypeBeforeAliasStringMismatchTest.elm
The 1st argument to `length` is not what I expect:
34| String.length s
^
This `s` value is a:
StandardA98TypeBeforeAliasStringMismatchTest.String
But `length` needs the 1st argument to be:
String.String
Detected problems in 1 module.
elm-0.19.2
passOutput
Compiling ...-- TYPE MISMATCH ---------- src/StandardA98TypeBeforeAliasStringMismatchTest.elm
The 1st argument to `length` is not what I expect:
34| String.length s
^
This `s` value is a:
StandardA98TypeBeforeAliasStringMismatchTest.String
But `length` needs the 1st argument to be:
String.String
Detected problems in 1 module.
elm-0.19.3
passOutput
Compiling ...-- TYPE MISMATCH ---------- src/StandardA98TypeBeforeAliasStringMismatchTest.elm
The 1st argument to `length` is not what I expect:
34| String.length s
^
This `s` value is a:
StandardA98TypeBeforeAliasStringMismatchTest.String
But `length` needs the 1st argument to be:
String.String
Detected problems in 1 module.
lamdera-1.5.0
passOutput
Detected problems in 1 module.
-- TYPE MISMATCH ---------- src/StandardA98TypeBeforeAliasStringMismatchTest.elm
The 1st argument to `length` is not what I expect:
34| String.length s
^
This `s` value is a:
StandardA98TypeBeforeAliasStringMismatchTest.String
But `length` needs the 1st argument to be:
String.String
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/StandardA98TypeBeforeAliasStringMismatchTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StandardA98TypeBeforeAliasStringMismatchTest exposing (main)
{-| A custom type declared before a local alias spelt like an imported type uses the local alias.
The module declares `type T = T String` and then `type alias String = Int`, and applies
`String.length` to the field of a `T`. A Standard Definition of Elm?, ruling A98: the module's type
declarations are elaborated together, so `T`'s argument is the local `String`, which is `Int`, and
`String.length` cannot take it. Reading the declarations in order would make the argument the
imported `String`, and the program would be accepted.
<https://elm-test-suite.netlify.app/standard/rules/sm-topdec-types>
Elm 0.19.1, 0.19.2 and 0.19.3 reject the program with TYPE MISMATCH.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, sm-topdec-types, sm-topdec-seq, sm-datbind
-- COMPILE-ERROR: TYPE MISMATCH, the field of T is the local String
-- CHECK: -- TYPE MISMATCH -
import Html exposing (text)
type T
= T String
type alias String =
Int
len : T -> Int
len (T s) =
String.length s
main =
text (Debug.toString (len (T 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_StandardA98TypeBeforeAliasStringMismatchTest, 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.