make the unchanged mutable variable error a warning in non-prod builds

pull/3354/head
Alexander Medvednikov 2020-01-06 00:28:29 +01:00
parent 4c3df963fa
commit 126289c19b
2 changed files with 9 additions and 1 deletions

View File

@ -23,6 +23,14 @@ fn (p mut Parser) error(s string) {
p.error_with_token_index(s, p.token_idx - 1) 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) { fn (p mut Parser) warn(s string) {
p.warn_with_token_index(s, p.token_idx - 1) p.warn_with_token_index(s, p.token_idx - 1)
} }

View File

@ -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) 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*' { 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')
} }
} }
} }