E07904: a surrogate escape (D800-DFFF) is half of a character above U+FFFF - write the character itself
What went wrong
A unicode escape in a String or Character literal names a surrogate (D800 to DFFF) that is not half of a pair. EK9 text is made of Unicode code points, and a surrogate is not one: it is half of the two-unit form Java uses for a character above U+FFFF, such as an emoji. In a String a high surrogate escape directly followed by a low one ("😀") is that one character. Anything else - a high one alone, a low one, or any surrogate escape in a Character literal - is half a character.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 2285 (How long is a String with an emoji in it in EK9?)
How to fix it
Write the character itself:
- '\uD83D' --> '😀'
- "smile \uD83D" --> "smile 😀"
Or, in a String, give both halves together:
- "\uD83D" --> "😀"
Common causes
- An escape copied from Java or JSON text that split an emoji in two
- A character above U+FFFF written as one four-digit escape
See also
- E07903: a unicode escape needs exactly four hex digits
- https://ek9.io/builtInTypes.html#string_literals
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07904: a surrogate escape (D800-DFFF) is half of a character above U+FFFF - write the character itself
#!ek9 defines module error.e07904.bad defines function halves() <- rtn as String? highAlone <- "smile \uD83D" lowAlone <- "\uDE00 smile" inBacktick <- `half \uD83D` character <- '\uD83D' //Both halves together are one character, and the character itself is fine. paired <- "😀" written <- "😀" rtn: highAlone + lowAlone + inBacktick + $character + paired + written
Fixed: Write the character itself, or both halves together
#!ek9 defines module error.e07904.good defines function //Write the character itself... smile() <- rtn as Character: '😀' //...or, in a String, a high surrogate escape directly followed by its low one smiling() <- rtn as String: "smile 😀"
Questions and answers
These Q&A entries show E07904 and its fix: