mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: much less verbose error messages
This commit is contained in:
parent
1d52847924
commit
0dad1a89e6
@ -32,7 +32,7 @@ pub fn new_builder(pref &pref.Preferences) Builder {
|
|||||||
mod_file_cacher: new_mod_file_cacher()
|
mod_file_cacher: new_mod_file_cacher()
|
||||||
pref: pref
|
pref: pref
|
||||||
table: table
|
table: table
|
||||||
checker: checker.new_checker(table)
|
checker: checker.new_checker(table, pref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
v.ast
|
v.ast
|
||||||
v.table
|
v.table
|
||||||
v.token
|
v.token
|
||||||
|
v.pref
|
||||||
os
|
os
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,14 +21,17 @@ mut:
|
|||||||
file ast.File
|
file ast.File
|
||||||
nr_errors int
|
nr_errors int
|
||||||
errors []string
|
errors []string
|
||||||
|
error_lines []int // to avoid printing multiple errors for the same line
|
||||||
expected_type table.Type
|
expected_type table.Type
|
||||||
fn_return_type table.Type // current function's return type
|
fn_return_type table.Type // current function's return type
|
||||||
// fn_decl ast.FnDecl
|
// fn_decl ast.FnDecl
|
||||||
|
pref &pref.Preferences // Preferences shared from V struct
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_checker(table &table.Table) Checker {
|
pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker {
|
||||||
return Checker{
|
return Checker{
|
||||||
table: table
|
table: table
|
||||||
|
pref: pref
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -947,7 +951,6 @@ pub fn (c mut Checker) ident(ident mut ast.Ident) table.Type {
|
|||||||
if ident.is_c {
|
if ident.is_c {
|
||||||
return table.int_type
|
return table.int_type
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
if ident.name != '_' {
|
if ident.name != '_' {
|
||||||
c.error('unknown ident: `$ident.name`', ident.pos)
|
c.error('unknown ident: `$ident.name`', ident.pos)
|
||||||
}
|
}
|
||||||
@ -1171,17 +1174,24 @@ pub fn (c mut Checker) map_init(node mut ast.MapInit) table.Type {
|
|||||||
pub fn (c mut Checker) error(s string, pos token.Position) {
|
pub fn (c mut Checker) error(s string, pos token.Position) {
|
||||||
c.nr_errors++
|
c.nr_errors++
|
||||||
//if c.pref.is_verbose {
|
//if c.pref.is_verbose {
|
||||||
|
if c.pref.verbosity.is_higher_or_equal(.level_one) {
|
||||||
print_backtrace()
|
print_backtrace()
|
||||||
//}
|
}
|
||||||
mut path := c.file.path
|
mut path := c.file.path
|
||||||
// Get relative path
|
// Get relative path
|
||||||
workdir := os.getwd() + os.path_separator
|
workdir := os.getwd() + os.path_separator
|
||||||
if path.starts_with(workdir) {
|
if path.starts_with(workdir) {
|
||||||
path = path.replace(workdir, '')
|
path = path.replace(workdir, '')
|
||||||
}
|
}
|
||||||
final_msg_line := '$path:$pos.line_nr: checker error #$c.nr_errors: $s'
|
mut final_msg_line := '$path:$pos.line_nr: $s'
|
||||||
|
if c.pref.verbosity.is_higher_or_equal(.level_one) {
|
||||||
|
final_msg_line = '$path:$pos.line_nr: checker error #$c.nr_errors: $s'
|
||||||
|
}
|
||||||
c.errors << final_msg_line
|
c.errors << final_msg_line
|
||||||
eprintln(final_msg_line)
|
if !(pos.line_nr in c.error_lines) {
|
||||||
|
eprintln(final_msg_line)
|
||||||
|
}
|
||||||
|
c.error_lines << pos.line_nr
|
||||||
/*
|
/*
|
||||||
if colored_output {
|
if colored_output {
|
||||||
eprintln(term.bold(term.red(final_msg_line)))
|
eprintln(term.bold(term.red(final_msg_line)))
|
||||||
|
Loading…
Reference in New Issue
Block a user