From bf7da14ba1a56022c279f5ce2f802dcccb173325 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 1 Jan 2021 09:06:09 +0000 Subject: [PATCH] cgen: make char literals wide (#7769) --- vlib/builtin/utf8_test.v | 8 ++++++++ vlib/v/gen/cgen.v | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/utf8_test.v b/vlib/builtin/utf8_test.v index 2181406715..536d50173c 100644 --- a/vlib/builtin/utf8_test.v +++ b/vlib/builtin/utf8_test.v @@ -4,3 +4,11 @@ fn test_utf8_char_len() { s := 'п' assert utf8_char_len(s[0]) == 2 } + +fn test_utf8_wide_char() { + r := `🌎` + val := r.str().str + unsafe { + assert '${val[0]:x}${val[1]:x}${val[2]:x}${val[3]:x}' == 'f09f8c8e' + } +} diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 13caaa0cd0..b42067a47e 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2452,7 +2452,7 @@ fn (mut g Gen) expr(node ast.Expr) { if node.val == r'\`' { g.write("'`'") } else { - g.write("'$node.val'") + g.write("L'$node.val'") } } ast.AtExpr {