From 50491670af182e8287ecc57642e8c785712d23f7 Mon Sep 17 00:00:00 2001 From: Enzo Baldisserri Date: Thu, 30 Apr 2020 09:33:43 +0200 Subject: [PATCH] fmt: fix formatting backtick char literal --- vlib/v/fmt/fmt.v | 12 ++++-------- vlib/v/fmt/tests/char_literal_backtick_keep.vv | 3 +++ vlib/v/fmt/tests/functions_expected.vv | 2 +- vlib/v/fmt/tests/functions_input.vv | 2 +- vlib/v/fmt/tests/loops_expected.vv | 1 + vlib/v/fmt/tests/loops_input.vv | 1 + vlib/v/scanner/scanner.v | 3 --- 7 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 vlib/v/fmt/tests/char_literal_backtick_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index e21e8d5f1a..43fadb1e6f 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -40,14 +40,10 @@ pub fn fmt(file ast.File, table &table.Table) string { } f.cur_mod = 'main' for stmt in file.stmts { - // TODO `if stmt is ast.Import` - match stmt { - ast.Import { - // Just remember the position of the imports for now - f.import_pos = f.out.len - // f.imports(f.file.imports) - } - else {} + if stmt is ast.Import { + // Just remember the position of the imports for now + f.import_pos = f.out.len + // f.imports(f.file.imports) } f.stmt(stmt) } diff --git a/vlib/v/fmt/tests/char_literal_backtick_keep.vv b/vlib/v/fmt/tests/char_literal_backtick_keep.vv new file mode 100644 index 0000000000..24205a457a --- /dev/null +++ b/vlib/v/fmt/tests/char_literal_backtick_keep.vv @@ -0,0 +1,3 @@ +fn char_backtick() { + `\`` +} diff --git a/vlib/v/fmt/tests/functions_expected.vv b/vlib/v/fmt/tests/functions_expected.vv index 394882c404..c1158014af 100644 --- a/vlib/v/fmt/tests/functions_expected.vv +++ b/vlib/v/fmt/tests/functions_expected.vv @@ -5,7 +5,7 @@ fn fn_variadic(arg int, args ...string) { } fn fn_with_assign_stmts() { - a, b := fn_with_multi_return() + _, _ := fn_with_multi_return() } fn fn_with_multi_return() (int, string) { diff --git a/vlib/v/fmt/tests/functions_input.vv b/vlib/v/fmt/tests/functions_input.vv index 6bec37d17c..bf40337ba2 100644 --- a/vlib/v/fmt/tests/functions_input.vv +++ b/vlib/v/fmt/tests/functions_input.vv @@ -5,7 +5,7 @@ fn fn_variadic(arg int, args... string) { } fn fn_with_assign_stmts() { - a,b := fn_with_multi_return() + _,_ := fn_with_multi_return() } fn fn_with_multi_return() (int,string) { diff --git a/vlib/v/fmt/tests/loops_expected.vv b/vlib/v/fmt/tests/loops_expected.vv index f623d79983..17d3f66ded 100644 --- a/vlib/v/fmt/tests/loops_expected.vv +++ b/vlib/v/fmt/tests/loops_expected.vv @@ -6,6 +6,7 @@ fn for_in_loop() { fn for_in_loop_with_counter() { for i, item in arr { + println(i) println(item) } } diff --git a/vlib/v/fmt/tests/loops_input.vv b/vlib/v/fmt/tests/loops_input.vv index c4fd2c19dd..1b271a34da 100644 --- a/vlib/v/fmt/tests/loops_input.vv +++ b/vlib/v/fmt/tests/loops_input.vv @@ -6,6 +6,7 @@ fn for_in_loop() { fn for_in_loop_with_counter() { for i, item in arr { + println(i) println(item) } } diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 7fb12f60d5..a726d71fe9 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -929,9 +929,6 @@ fn (s mut Scanner) ident_char() string { s.error('invalid character literal (more than one character)\n' + 'use quotes for strings, backticks for characters') } } - if c == '\\`' { - return '`' - } // Escapes a `'` character return if c == "\'" { '\\' + c } else { c } }