Elm Exactly
Results / elm /

PortIncomingRejectTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule p-in-rejectrule p-in-accept

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/core#1043

A value that does not decode at an incoming port's type is rejected, and the program goes on.

A Standard Definition of Elm?, rule p-in-reject: a boundary value that does not decode at the type
of the port is rejected; the program never sees it, and is unchanged. <https://elm-test-suite.netlify.app/standard/rules/p-in-reject>

The program sends `Nothing` and then `Just "ok"` out through `echoOut`, whose type is
`Maybe String`, so they go out as JSON `null` and `"ok"`; the test harness sends each back in
through `echoIn`, whose type is `String`. `null` must be dropped and `"ok"` received. Elm 0.19.1
throws an exception for `null` instead (<https://github.com/elm/core/issues/1043>).

Results

elm-0.19.1

failran in 63 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:485
			throw new Error('Trying to send an unexpected type of value through port `' + portName + '`:\n' + problem);
			^

Error: Trying to send an unexpected type of value through port `echoIn`:
[object Object]
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:485:10)
    at Object.send (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:2302:36)
    at Array.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.run.js:4:57)
    at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:2223:19)
    at A3 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:59:28)
    at Object.b (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:1982:7)
    at _Scheduler_step (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:1826:20)
    at _Scheduler_enqueue (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:1788:3)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:1816:5
    at Timeout._onTimeout (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/PortIncomingRejectTest.js:1846:4)

Node.js v22.23.5
received: "ok"

elm-0.19.2

failran in 62 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
received: "ok"
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:485
			throw new Error('Trying to send an unexpected type of value through port `' + portName + '`:\n' + problem);
			^

Error: Trying to send an unexpected type of value through port `echoIn`:
[object Object]
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:485:10)
    at Object.send (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:2302:36)
    at Array.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.run.js:4:57)
    at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:2223:19)
    at A3 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:59:28)
    at Object.b (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:1982:7)
    at _Scheduler_step (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:1826:20)
    at _Scheduler_enqueue (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:1788:3)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:1816:5
    at Timeout._onTimeout (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/PortIncomingRejectTest.js:1846:4)

Node.js v22.23.5

elm-0.19.3

failran in 74 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
received: "ok"
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:485
			throw new Error('Trying to send an unexpected type of value through port `' + portName + '`:\n' + problem);
			^

Error: Trying to send an unexpected type of value through port `echoIn`:
[object Object]
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:485:10)
    at Object.send (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:2302:36)
    at Array.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.run.js:4:57)
    at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:2223:19)
    at A3 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:59:28)
    at Object.b (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:1982:7)
    at _Scheduler_step (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:1826:20)
    at _Scheduler_enqueue (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:1788:3)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:1816:5
    at Timeout._onTimeout (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/PortIncomingRejectTest.js:1846:4)

Node.js v22.23.5

lamdera-1.5.0

failran in 46 ms
exit code 1, expected 0
--- output ---
received: "ok"
/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:504
			throw new Error('Trying to send an unexpected type of value through port `' + portName + '`:\n' + problem);
			^

Error: Trying to send an unexpected type of value through port `echoIn`:
[object Object]
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:504:10)
    at Object.send (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:2636:36)
    at Array.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.run.js:4:57)
    at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:2554:19)
    at A3 (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:64:28)
    at Object.b (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:2310:7)
    at _Scheduler_step (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:1889:20)
    at _Scheduler_enqueue (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:1851:3)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:1879:5
    at Timeout._onTimeout (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm/out/PortIncomingRejectTest.js:1909:4)

Node.js v22.23.5

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module PortIncomingRejectTest exposing (main)
{-| A value that does not decode at an incoming port's type is rejected, and the program goes on.
A Standard Definition of Elm?, rule p-in-reject: a boundary value that does not decode at the type
of the port is rejected; the program never sees it, and is unchanged. <https://elm-test-suite.netlify.app/standard/rules/p-in-reject>
The program sends `Nothing` and then `Just "ok"` out through `echoOut`, whose type is
`Maybe String`, so they go out as JSON `null` and `"ok"`; the test harness sends each back in
through `echoIn`, whose type is `String`. `null` must be dropped and `"ok"` received. Elm 0.19.1
throws an exception for `null` instead (<https://github.com/elm/core/issues/1043>).
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, p-in-reject, p-in-accept
-- CHECK: received: "ok"
-- CHECK-NOT: received: null
port echoOut : Maybe String -> Cmd msg
port echoIn : (String -> msg) -> Sub msg
type Msg
= Received String
main : Program () () Msg
main =
Platform.worker
{ init = \_ -> ( (), Cmd.batch [ echoOut Nothing, echoOut (Just "ok") ] )
, update =
\(Received s) model ->
let
_ =
Debug.log "received" s
in
( model, Cmd.none )
, subscriptions = \_ -> echoIn Received
}

Lean translation

This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_PortIncomingRejectTest, in StandardElmMech/Generated/Worker01.lean). Lean evaluates its modules by the rules of Chapter 7, starts it by r:p-init with no flags (null, A72), and runs it by the transitions of Chapter 9 under the test runner's echo host, which sends every value delivered on echoOut back on echoIn, in order. Its checks become one generated theorem: some execution the book allows, under that host, has a log (the modules', then the start's, then each step's) that meets every check. The theorem trusts the parser and the translator's elaboration ([parse] [elab]), the test basis ([harness]) and the parameters of the basis ([params]), and is proved by the kernel.

Out of date. The test, or a module it imports, has changed since this translation was made; the translation, and so its theorems, describe the program as it was until the mechanisation is rebuilt.

CheckExpected (CHECK)Lean evaluatorProved by
received"ok""ok"t_elm_PortIncomingRejectTest
received: null(no value) (no longer a CHECK line of the test)(not logged)t_elm_PortIncomingRejectTest
/-- tests/elm/src/PortIncomingRejectTest.elm -/
def g_elm_PortIncomingRejectTest : Program := {
  name := "PortIncomingRejectTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [],
  types := [("Msg", [("Received", 1)])],
  aliases := [],
  ports := [("echoOut", .out, (.maybe .string)), ("echoIn", .inn, .string)],
  defs := [
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", lams [pw] (tup2 (.atexp .unit) (ap (qv "Cmd" "batch") [listE [ap (v "echoOut") [c "Nothing"], ap (v "echoOut") [.atexp (.paren (ap (c "Just") [str "ok"]))]]]))), ("update", lams [.paren (pcon "Received" [pv "s"]), pv "model"] (letDefs [.pat pw (ap (qv "Debug" "log") [str "received", v "s"])] (tup2 (v "model") (qv "Cmd" "none")))), ("subscriptions", lams [pw] (ap (v "echoIn") [c "Received"]))]]) ],
  checks := [
    chk .check "received: \"ok\"" .string ] }

/-- The worker test of PortIncomingRejectTest. -/
def w_elm_PortIncomingRejectTest : Prog.WorkerTest := {
  prog := g_elm_PortIncomingRejectTest,
  flagsType := .unit,
  flags := .null,
  host := .echo "echoOut" "echoIn",
  checkNots := ["received: null"],
  checks := [] }

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_PortIncomingRejectTest 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_PortIncomingRejectTest 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_PortIncomingRejectTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortIncomingRejectTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality. One of these theorems is proved by native_decide ([native]).