From 2bbb8526a3098bb997acfdc0f3a065aa0a608a9c Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 24 Feb 2020 18:37:20 +0300 Subject: [PATCH] fmt: process RangeExpr properly --- vlib/v/fmt/fmt.v | 4 +++- vlib/v/fmt/tests/simple_expected.vv | 4 ++++ vlib/v/fmt/tests/simple_input.vv | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 5b220efe55..e82f5ec3b5 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -425,9 +425,11 @@ fn (f mut Fmt) index_expr(node ast.IndexExpr) { ast.RangeExpr { is_range = true f.expr(node.left) + f.write('[') + f.expr(it.low) f.write('..') f.expr(it.high) - f.write(')') + f.write(']') } else {} } diff --git a/vlib/v/fmt/tests/simple_expected.vv b/vlib/v/fmt/tests/simple_expected.vv index 4f3b8b6dcb..afaa6fd48f 100644 --- a/vlib/v/fmt/tests/simple_expected.vv +++ b/vlib/v/fmt/tests/simple_expected.vv @@ -41,6 +41,10 @@ fn new_user() User { } } +fn fn_contains_range_expr() { + a := 1 in arr[0..2] +} + fn voidfn() { println('this is a function that does not return anything') } diff --git a/vlib/v/fmt/tests/simple_input.vv b/vlib/v/fmt/tests/simple_input.vv index 9cffeb837b..72df4137c1 100644 --- a/vlib/v/fmt/tests/simple_input.vv +++ b/vlib/v/fmt/tests/simple_input.vv @@ -45,6 +45,10 @@ User } } +fn fn_contains_range_expr() { + a:=1 in arr[0..2] +} + fn voidfn(){ println('this is a function that does not return anything') } @@ -103,4 +107,3 @@ reserved_types = { 'i128': true } ) -