From 945f964c0c51c9cfbf9a1d349794c5c4e50ee2e3 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 25 Apr 2020 15:37:32 +0300 Subject: [PATCH] parser: stay silent about unused variables starting with _ --- vlib/encoding/csv/reader_test.v | 4 ++-- vlib/v/parser/parser.v | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vlib/encoding/csv/reader_test.v b/vlib/encoding/csv/reader_test.v index 21358c9b50..6e0750d350 100644 --- a/vlib/encoding/csv/reader_test.v +++ b/vlib/encoding/csv/reader_test.v @@ -112,11 +112,11 @@ fn test_no_line_ending() { mut row_count := 0 for { - row := csv_reader.read() or { + _row := csv_reader.read() or { break } row_count++ } assert row_count == 2 -} \ No newline at end of file +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index b7e40e901c..3b5e3135bf 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -195,8 +195,11 @@ pub fn (mut p Parser) open_scope() { } pub fn (mut p Parser) close_scope() { - if !p.pref.is_repl && !scanner.is_fmt { + if !p.pref.is_repl && !p.scanner.is_fmt { for v in p.scope.unused_vars() { + if v.name.len > 0 && v.name[0]==`_` { + continue + } if p.pref.is_prod { p.error_with_pos('Unused variable: $v.name', v.pos) } else {