From 126289c19bb2ff5687817d201ca35aa311c5d9b2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 6 Jan 2020 00:28:29 +0100 Subject: [PATCH] make the unchanged mutable variable error a warning in non-prod builds --- vlib/compiler/compile_errors.v | 8 ++++++++ vlib/compiler/fn.v | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/compiler/compile_errors.v b/vlib/compiler/compile_errors.v index 0614a2c0cb..7e0d4110ba 100644 --- a/vlib/compiler/compile_errors.v +++ b/vlib/compiler/compile_errors.v @@ -23,6 +23,14 @@ fn (p mut Parser) error(s string) { p.error_with_token_index(s, p.token_idx - 1) } +fn (p mut Parser) warn_or_error(s string) { + if p.pref.is_prod { + p.error(s) + } else { + p.warn(s) + } +} + fn (p mut Parser) warn(s string) { p.warn_with_token_index(s, p.token_idx - 1) } diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 8d2ca991d6..d65e505001 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -645,7 +645,7 @@ fn (p mut Parser) check_unused_and_mut_vars() { p.production_error_with_token_index('`$var.name` declared and not used', var.token_idx) } if !var.is_changed && var.is_mut && !p.pref.is_repl && !p.pref.translated && var.typ != 'T*' && p.mod != 'ui' && var.typ != 'App*' { - p.error_with_token_index('`$var.name` is declared as mutable, but it was never changed', var.token_idx) + p.warn_or_error('`$var.name` is declared as mutable, but it was never changed') } } }