From b635ff80de266e4091f610d1f971d3797ae14862 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 26 Aug 2021 12:18:27 +0800 Subject: [PATCH] fmt: format '1.' to '1.0' (#11312) --- vlib/v/fmt/fmt.v | 3 +++ vlib/v/fmt/tests/float_literals_expected.vv | 4 ++++ vlib/v/fmt/tests/float_literals_input.vv | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 vlib/v/fmt/tests/float_literals_expected.vv create mode 100644 vlib/v/fmt/tests/float_literals_input.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index c1c533fd9c..4ac0dbf8ab 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -549,6 +549,9 @@ pub fn (mut f Fmt) expr(node ast.Expr) { } ast.FloatLiteral { f.write(node.val) + if node.val.ends_with('.') { + f.write('0') + } } ast.GoExpr { f.go_expr(node) diff --git a/vlib/v/fmt/tests/float_literals_expected.vv b/vlib/v/fmt/tests/float_literals_expected.vv new file mode 100644 index 0000000000..ec535d08d3 --- /dev/null +++ b/vlib/v/fmt/tests/float_literals_expected.vv @@ -0,0 +1,4 @@ +fn main() { + a := 1.0 + println(a) +} diff --git a/vlib/v/fmt/tests/float_literals_input.vv b/vlib/v/fmt/tests/float_literals_input.vv new file mode 100644 index 0000000000..e1f2d51813 --- /dev/null +++ b/vlib/v/fmt/tests/float_literals_input.vv @@ -0,0 +1,4 @@ +fn main() { + a := 1. + println(a) +}