Elm Exactly
Results / elm /

CharLiteralSurrogateEscapeTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:restriction core-escape-unicodefigure core-escapes

Not translated into Lean for the mechanisation of the book: see why.

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

Issue: elm/compiler#2366

`'\u{D800}'` is not a Char literal: a surrogate code point is not a character.

A Standard Definition of Elm?, ruling A8: the escape `\u{h}` denotes a Unicode scalar value, so
the surrogate code points D800 to DFFF are not allowed, in Char literals as in String literals.
<https://elm-test-suite.netlify.app/standard/restrictions/core-escape-unicode>

This is how <https://github.com/elm/compiler/issues/2366> is resolved under A8. The issue's program
(`CompilerIssue2366LoneSurrogateCharLiteralTest`, tagged `elm19-bug`) uses `'\u{D800}'` and
`'\u{DFFF}'`; Elm 0.19.2, Elm 0.19.3 and Lamdera 1.5.0 write such literals into the generated
JavaScript as raw surrogates, which are not valid UTF-8, so the literals become replacement
characters. Under A8 the program is rejected instead, and no surrogate literal reaches the code
generator; a program that needs the value computes it, `Char.fromCode 0xD800`. Elm 0.19.1 accepts
the literal, and so do the others. `StandardA8SurrogateEscapeTest` checks the same for a String
literal.

Results

elm-0.19.1

fail
compiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.

    CharLiteralSurrogateEscapeTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm/out/CharLiteralSurrogateEscapeTest.js

elm-0.19.2

fail
compiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.

    CharLiteralSurrogateEscapeTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm/out/CharLiteralSurrogateEscapeTest.js

elm-0.19.3

fail
compiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.

    CharLiteralSurrogateEscapeTest ───> /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm/out/CharLiteralSurrogateEscapeTest.js

lamdera-1.5.0

fail
compiled, but a compile error was expected
--- compiler output ---
Success! Compiled 1 module.

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CharLiteralSurrogateEscapeTest exposing (main)
{-| `'\u{D800}'` is not a Char literal: a surrogate code point is not a character.
A Standard Definition of Elm?, ruling A8: the escape `\u{h}` denotes a Unicode scalar value, so
the surrogate code points D800 to DFFF are not allowed, in Char literals as in String literals.
<https://elm-test-suite.netlify.app/standard/restrictions/core-escape-unicode>
This is how <https://github.com/elm/compiler/issues/2366> is resolved under A8. The issue's program
(`CompilerIssue2366LoneSurrogateCharLiteralTest`, tagged `elm19-bug`) uses `'\u{D800}'` and
`'\u{DFFF}'`; Elm 0.19.2, Elm 0.19.3 and Lamdera 1.5.0 write such literals into the generated
JavaScript as raw surrogates, which are not valid UTF-8, so the literals become replacement
characters. Under A8 the program is rejected instead, and no surrogate literal reaches the code
generator; a program that needs the value computes it, `Char.fromCode 0xD800`. Elm 0.19.1 accepts
the literal, and so do the others. `StandardA8SurrogateEscapeTest` checks the same for a String
literal.
-}
-- TAGS: elm-spec, core-escape-unicode, fig:core-escapes
-- COMPILE-ERROR: a surrogate escape in a Char literal
-- CHECK: {{-- [A-Z ]+ -}}
import Html
isHighSurrogate : Char -> Bool
isHighSurrogate c =
'\u{D800}' <= c && c <= '\u{DBFF}'
main =
Html.text (if isHighSurrogate 'a' then "yes" else "no")

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 the translator's front end refuses it: it breaks a restriction on characters, tokens and layout, which Lean does not model. See the Lean mechanisation for which tests are in Lean, and why.