From d88e67a5ec9bdaaec0698c69f8aefd2ba3682f57 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 9 Dec 2021 04:28:55 +0800 Subject: [PATCH] checker: fix const type with raw string literal (#12761) --- vlib/v/checker/checker.v | 2 +- ...many_pluses_with_raw_string_literal_test.v | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/const_many_pluses_with_raw_string_literal_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f8ffceba90..3e1108254b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -8732,7 +8732,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp return expr.val.i64() } ast.StringLiteral { - return expr.val + return util.smart_quote(expr.val, expr.is_raw) } ast.CharLiteral { runes := expr.val.runes() diff --git a/vlib/v/tests/const_many_pluses_with_raw_string_literal_test.v b/vlib/v/tests/const_many_pluses_with_raw_string_literal_test.v new file mode 100644 index 0000000000..13f5866d8b --- /dev/null +++ b/vlib/v/tests/const_many_pluses_with_raw_string_literal_test.v @@ -0,0 +1,29 @@ +const ca = r'x\n' + +const cb = 'x\n' + +const cc = ca + cb + +const cd = cc + cc + +const ce = cd + cd + +fn test_many_pluses_with_raw_string_literal() { + a := r'x\n' + assert a == ca + b := 'x\n' + assert b == cb + c := a + b + assert c == cc + d := c + c + assert d == cd + e := d + d + assert e == ce + println(e) + result := r'x\nx +x\nx +x\nx +x\nx +' + assert e == result +}