Elm Exactly
Results / elm /

TypeExprUnitAppliedTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:figure core-grammar-types

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

Issue: elm/error-message-catalog#188

The type annotation `foo : () String Float` is rejected, and not as a TYPE MISMATCH.

<https://github.com/elm/error-message-catalog/issues/188>

The annotation places the unit type `()` before `String` and `Float` with no separator. The
test accepts any error heading except TYPE MISMATCH, which would compare the body
`( "foo", 3.2 )` against the malformed annotation.

A Standard Definition of Elm?, Figure 7 (the grammar of type expressions): a type construction
applies a type constructor to its arguments, and `()` is not a type constructor, so `() String
Float` is not a type expression; a compiler that reports a TYPE MISMATCH has read it as one.
<https://elm-test-suite.netlify.app/standard/figures/core-grammar-types>

Results

elm-0.19.1

pass
Output
Compiling ...-- EXPECTING DEFINITION ------------------------ src/TypeExprUnitAppliedTest.elm

I just saw the type annotation for `foo` so I was expecting to see its
definition here:

25| foo : () String Float
             ^
Type annotations always appear directly above the relevant definition, without
anything else in between. (Not even doc comments!)

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- EXPECTING DEFINITION ------------------------ src/TypeExprUnitAppliedTest.elm

I just saw the type annotation for `foo` so I was expecting to see its
definition here:

25| foo : () String Float
             ^
Type annotations always appear directly above the relevant definition, without
anything else in between. (Not even doc comments!)

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- EXPECTING DEFINITION ------------------------ src/TypeExprUnitAppliedTest.elm

I just saw the type annotation for `foo` so I was expecting to see its
definition here:

25| foo : () String Float
             ^
Type annotations always appear directly above the relevant definition, without
anything else in between. (Not even doc comments!)

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- EXPECTING DEFINITION ------------------------ src/TypeExprUnitAppliedTest.elm

I just saw the type annotation for `foo` so I was expecting to see its
definition here:

25| foo : () String Float
             ^
Type annotations always appear directly above the relevant definition, without
anything else in between. (Not even doc comments!)

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module TypeExprUnitAppliedTest exposing (..)
{-| The type annotation `foo : () String Float` is rejected, and not as a TYPE MISMATCH.
<https://github.com/elm/error-message-catalog/issues/188>
The annotation places the unit type `()` before `String` and `Float` with no separator. The
test accepts any error heading except TYPE MISMATCH, which would compare the body
`( "foo", 3.2 )` against the malformed annotation.
A Standard Definition of Elm?, Figure 7 (the grammar of type expressions): a type construction
applies a type constructor to its arguments, and `()` is not a type constructor, so `() String
Float` is not a type expression; a compiler that reports a TYPE MISMATCH has read it as one.
<https://elm-test-suite.netlify.app/standard/figures/core-grammar-types>
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, fig:core-grammar-types
-- COMPILE-ERROR: a type annotation that does not parse
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: TYPE MISMATCH
foo : () String Float
foo =
( "foo", 3.2 )

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Static semantics: expected to be rejected, and eco's parser rejects it too. See the Lean mechanisation for which tests are in Lean, and why.