Skip to content

Commit 2a8f0e8

Browse files
squeek502ryoppippi
authored andcommitted
More precise error message for unencodable \u escapes
The surrogate code points U+D800 to U+DFFF are valid code points but are not Unicode scalar values. This commit makes the error message more accurately reflect what is actually allowed in `\u` escape sequences. From https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf: > D71 High-surrogate code point: A Unicode code point in the range U+D800 to U+DBFF. > D73 Low-surrogate code point: A Unicode code point in the range U+DC00 to U+DFFF. > > 3.9 Unicode Encoding Forms > D76 Unicode scalar value: Any Unicode code point except high-surrogate and low-surrogate code points. Related: ziglang#20270
1 parent b14a697 commit 2a8f0e8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

doc/langref.html.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,12 @@
728728
</tr>
729729
<tr>
730730
<th scope="row"><code>\u{NNNNNN}</code></th>
731-
<td>hexadecimal Unicode code point UTF-8 encoded (1 or more digits)</td>
731+
<td>hexadecimal Unicode scalar value UTF-8 encoded (1 or more digits)</td>
732732
</tr>
733733
</tbody>
734734
</table>
735735
</div>
736-
<p>Note that the maximum valid Unicode point is {#syntax#}0x10ffff{#endsyntax#}.</p>
736+
<p>Note that the maximum valid Unicode scalar value is {#syntax#}0x10ffff{#endsyntax#}.</p>
737737
{#header_close#}
738738
{#header_open|Multiline String Literals#}
739739
<p>

lib/std/zig/AstGen.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -11306,7 +11306,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
1130611306
return astgen.failOff(
1130711307
token,
1130811308
offset + @as(u32, @intCast(bad_index)),
11309-
"unicode escape does not correspond to a valid codepoint",
11309+
"unicode escape does not correspond to a valid unicode scalar value",
1131011310
.{},
1131111311
);
1131211312
},

src/Package/Manifest.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ const Parse = struct {
522522
try p.appendErrorOff(
523523
token,
524524
offset + @as(u32, @intCast(bad_index)),
525-
"unicode escape does not correspond to a valid codepoint",
525+
"unicode escape does not correspond to a valid unicode scalar value",
526526
.{},
527527
);
528528
},

0 commit comments

Comments
 (0)