Elm Exactly
Results / elm /

CompilerIssue2057CallSiteChangesInferredTypeTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule s-dec-grouprule s-valbind-varrule sm-topdec-value

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/compiler#2057

Two annotated callers of a function with unannotated mutually recursive let functions are wrongly rejected.

<https://github.com/elm/compiler/issues/2057>

`sortWith` contains the unannotated mutually recursive `f` and `g`, and `sort` and `sortBy` call it
at their own type variables. Each function is well-typed on its own. Elm 0.19.1 rejects the
program ("This `sortWith` call produces: List asd / But the type annotation on `sortBy` says it
should be: List x"), unifying the rigid variables of different functions. It should compile.

Results

elm-0.19.1

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

Something is off with the body of the `sortBy` definition:

38|     sortWith cmp list
        ^^^^^^^^^^^^^^^^^
This `sortWith` call produces:

    List asd

But the type annotation on `sortBy` says it should be:

    List x

Hint: Your type annotation uses `asd` and `x` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.1/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 2nd argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                     ^^^^
This `list` value is a:

    List x

But `sortWith` needs the 2nd argument to be:

    List asd

Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.1/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 1st argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                 ^^^
This `cmp` value is a:

    x -> x -> Order

But `sortWith` needs the 1st argument to be:

    asd -> asd -> Order

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.1/type-annotations> for more advice!

Detected problems in 1 module.

elm-0.19.2

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

Something is off with the body of the `sortBy` definition:

38|     sortWith cmp list
        ^^^^^^^^^^^^^^^^^
This `sortWith` call produces:

    List asd

But the type annotation on `sortBy` says it should be:

    List x

Hint: Your type annotation uses `asd` and `x` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.2/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 2nd argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                     ^^^^
This `list` value is a:

    List x

But `sortWith` needs the 2nd argument to be:

    List asd

Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.2/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 1st argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                 ^^^
This `cmp` value is a:

    x -> x -> Order

But `sortWith` needs the 1st argument to be:

    asd -> asd -> Order

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.2/type-annotations> for more advice!

Detected problems in 1 module.

elm-0.19.3

fail
compile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

Something is off with the body of the `sortBy` definition:

38|     sortWith cmp list
        ^^^^^^^^^^^^^^^^^
This `sortWith` call produces:

    List asd

But the type annotation on `sortBy` says it should be:

    List x

Hint: Your type annotation uses `asd` and `x` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 2nd argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                     ^^^^
This `list` value is a:

    List x

But `sortWith` needs the 2nd argument to be:

    List asd

Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 1st argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                 ^^^
This `cmp` value is a:

    x -> x -> Order

But `sortWith` needs the 1st argument to be:

    asd -> asd -> Order

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

Detected problems in 1 module.

lamdera-1.5.0

fail
compile failed (exit 1):
Dependencies ready!
Detected problems in 1 module.
-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

Something is off with the body of the `sortBy` definition:

38|     sortWith cmp list
        ^^^^^^^^^^^^^^^^^
This `sortWith` call produces:

    List asd

But the type annotation on `sortBy` says it should be:

    List x

Hint: Your type annotation uses `asd` and `x` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 2nd argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                     ^^^^
This `list` value is a:

    List x

But `sortWith` needs the 2nd argument to be:

    List asd

Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

-- TYPE MISMATCH ------ src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm

The 1st argument to `sortWith` is not what I expect:

38|     sortWith cmp list
                 ^^^
This `cmp` value is a:

    x -> x -> Order

But `sortWith` needs the 1st argument to be:

    asd -> asd -> Order

Hint: Your type annotation uses `x` and `asd` as separate type variables. Your
code seems to be saying they are the same though. Maybe they should be the same
in your type annotation? Maybe your code uses them in a weird way?

Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CompilerIssue2057CallSiteChangesInferredTypeTest exposing (..)
{-| Two annotated callers of a function with unannotated mutually recursive let functions are wrongly rejected.
<https://github.com/elm/compiler/issues/2057>
`sortWith` contains the unannotated mutually recursive `f` and `g`, and `sort` and `sortBy` call it
at their own type variables. Each function is well-typed on its own. Elm 0.19.1 rejects the
program ("This `sortWith` call produces: List asd / But the type annotation on `sortBy` says it
should be: List x"), unifying the rigid variables of different functions. It should compile.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-dec-group, s-valbind-var, sm-topdec-value
-- CHECK: sort: []
import Html exposing (text)
sort : List cm -> List cm
sort xs =
let
f : cm -> cm -> Order
f a b =
LT
in
sortWith f xs
sortBy : (x -> cmpl) -> List x -> List x
sortBy f list =
let
cmp : x -> x -> Order
cmp a b =
LT
in
sortWith cmp list
sortWith : (asd -> asd -> Order) -> List asd -> List asd
sortWith cmp list =
let
f arg =
g arg
g bs =
case bs of
[] ->
[]
_ :: rest ->
f rest
in
always [] (f list)
main =
let
_ =
Debug.log "sort" (sort [ 3, 1, 2 ])
in
text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_CompilerIssue2057CallSiteChangesInferredTypeTest, in StandardElmMech/Generated/Elm_CombinatorSP.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.

CheckExpected (CHECK)Lean evaluatorProved by
sort[][]t_elm_CompilerIssue2057CallSiteChangesInferredTypeTest
/-- tests/elm/src/CompilerIssue2057CallSiteChangesInferredTypeTest.elm -/
def g_elm_CompilerIssue2057CallSiteChangesInferredTypeTest : Program := {
  name := "CompilerIssue2057CallSiteChangesInferredTypeTest", source := "tests/elm/src",
  exposing := .all, imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "sortWith" [pv "cmp", pv "list"] (letDefs [.fn "f" [pv "arg"] (ap (v "g") [v "arg"]), .fn "g" [pv "bs"] (caseOf (v "bs") [(P (listP []), listE []), (.cons (P pw) (P (pv "rest")), ap (v "f") [v "rest"])])] (ap (v "always") [listE [], .atexp (.paren (ap (v "f") [v "list"]))])),
    .fn "sort" [pv "xs"] (letDefs [.fn "f" [pv "a", pv "b"] (c "LT")] (ap (v "sortWith") [v "f", v "xs"])),
    .fn "sortBy" [pv "f", pv "list"] (letDefs [.fn "cmp" [pv "a", pv "b"] (c "LT")] (ap (v "sortWith") [v "cmp", v "list"])),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "sort", .atexp (.paren (ap (v "sort") [listE [.atexp (.scon (.intF 3)), .atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))]]))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "sort: []" .data ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_CompilerIssue2057CallSiteChangesInferredTypeTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_CompilerIssue2057CallSiteChangesInferredTypeTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_CompilerIssue2057CallSiteChangesInferredTypeTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue2057CallSiteChangesInferredTypeTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.