From 043c29cf95bff81b8077ebfbb3762c4dbcb91a33 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 6 Mar 2021 19:47:19 +0100 Subject: [PATCH] fmt: fix string interpolation with CastExpr (#9137) --- vlib/v/ast/str.v | 2 ++ ...terpolation_literal_keep.vv => string_interpolation_keep.vv} | 1 + 2 files changed, 3 insertions(+) rename vlib/v/fmt/tests/{string_interpolation_literal_keep.vv => string_interpolation_keep.vv} (89%) diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 8c8415053c..e02e7a7173 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -162,6 +162,8 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) { } else if sub_expr.left is CallExpr { sub_expr = sub_expr.left continue + } else if sub_expr.left is CastExpr { + needs_braces = true } break } diff --git a/vlib/v/fmt/tests/string_interpolation_literal_keep.vv b/vlib/v/fmt/tests/string_interpolation_keep.vv similarity index 89% rename from vlib/v/fmt/tests/string_interpolation_literal_keep.vv rename to vlib/v/fmt/tests/string_interpolation_keep.vv index 133b15b270..0e54967d32 100644 --- a/vlib/v/fmt/tests/string_interpolation_literal_keep.vv +++ b/vlib/v/fmt/tests/string_interpolation_keep.vv @@ -11,4 +11,5 @@ fn main() { eprintln('e: $e') _ = ' ${foo.method(bar).str()} ' println('(${some_struct.@type}, $some_struct.y)') + _ := 'CastExpr ${int(d.e).str()}' }