From 1dc62a5a66970258099937706f4898aff5521790 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 19 Aug 2022 14:44:59 +0800 Subject: [PATCH] ast: fix string interpolation fmt with result call (#15467) --- vlib/v/ast/str.v | 2 +- vlib/v/fmt/tests/string_intp_with_result_keep.vv | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/string_intp_with_result_keep.vv diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index cf9372ea8b..143e54ef0b 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -210,7 +210,7 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) { } CallExpr { if sub_expr.args.len != 0 || sub_expr.concrete_types.len != 0 - || sub_expr.or_block.kind == .propagate_option + || sub_expr.or_block.kind in [.propagate_option, .propagate_result] || sub_expr.or_block.stmts.len > 0 { needs_braces = true } else if sub_expr.left is CallExpr { diff --git a/vlib/v/fmt/tests/string_intp_with_result_keep.vv b/vlib/v/fmt/tests/string_intp_with_result_keep.vv new file mode 100644 index 0000000000..3a052ab533 --- /dev/null +++ b/vlib/v/fmt/tests/string_intp_with_result_keep.vv @@ -0,0 +1,7 @@ +fn err() !u8 { + return 1 +} + +fn main() { + println('${err()!}') +}