From 4a096bd133d6abbb5c15f7794976014e6f531b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Sun, 3 May 2020 18:12:59 +0200 Subject: [PATCH] parser: fix string interpolation for default conversion --- vlib/v/parser/parser.v | 2 +- vlib/v/tests/string_interpolation_test.v | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 658efeb4f4..d5b1987dbd 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -900,7 +900,7 @@ fn (mut p Parser) string_expr() ast.Expr { efmt << p.tok.lit p.next() } - if p.tok.lit.len == 1 { + if p.tok.kind == .name && p.tok.lit.len == 1 { efmt << p.tok.lit p.next() } diff --git a/vlib/v/tests/string_interpolation_test.v b/vlib/v/tests/string_interpolation_test.v index 3819381219..4a14b35c64 100644 --- a/vlib/v/tests/string_interpolation_test.v +++ b/vlib/v/tests/string_interpolation_test.v @@ -77,6 +77,8 @@ fn test_string_interpolation_string_prefix() { } fn test_inttypes_string_interpolation() { + c := i8(-103) + uc := byte(217) s := i16(-23456) us := u16(54321) i := -1622999040 @@ -86,8 +88,9 @@ fn test_inttypes_string_interpolation() { assert '$s $us' == '-23456 54321' assert '$ui $i' == '3421958087 -1622999040' assert '$l $ul' == '-7694555558525237396 17234006112912956370' - assert '>${s:11}< >${us:-13}<-' == '> -23456< >54321 <-' - assert '0x${ul:-19x}< >${l:22d}<-' == '0xef2b7d4001165bd2 < > -7694555558525237396<-' + assert '>${s:11}:${us:-13}<' == '> -23456:54321 <' + assert '0x${ul:-19x}:${l:22d}' == '0xef2b7d4001165bd2 : -7694555558525237396' + assert '${c:5}${uc:-7}x' == ' -103217 x' } fn test_utf8_string_interpolation() {