diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index bb2a1bd58c..21bb7755de 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1841,13 +1841,15 @@ pub fn (mut f Fmt) comptime_call(node ast.ComptimeCall) { } else { '${node.method_name}($inner_args)' } - f.write('${node.left}.$$method_expr') + f.expr(node.left) + f.write('.$$method_expr') } } } pub fn (mut f Fmt) comptime_selector(node ast.ComptimeSelector) { - f.write('${node.left}.\$($node.field_expr)') + f.expr(node.left) + f.write('.\$($node.field_expr)') } pub fn (mut f Fmt) concat_expr(node ast.ConcatExpr) { diff --git a/vlib/v/fmt/tests/comptime_method_call_keep.vv b/vlib/v/fmt/tests/comptime_method_call_keep.vv new file mode 100644 index 0000000000..fc6578c24a --- /dev/null +++ b/vlib/v/fmt/tests/comptime_method_call_keep.vv @@ -0,0 +1,15 @@ +import os + +struct Dummy {} + +fn (d Dummy) sample(x int) int { + return x + 1 +} + +fn main() { + $for method in Dummy.methods { + if os.args.len > 1 { + Dummy{}.$method(os.args[1].int()) + } + } +}