From 108913c69e174ef02827c7701afe9c6708263e7e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 4 Jul 2020 21:55:14 +0300 Subject: [PATCH] checker: handle error token positions with negative pos.len --- vlib/v/checker/checker.v | 5 +++-- vlib/v/util/errors.v | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index dd525cfd6b..2f9c04e354 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1198,9 +1198,10 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type { candidate_fn_name := if typ_sym.name.starts_with('anon_') { 'anonymous function' } else { 'fn `$typ_sym.name`' } c.error('cannot use $candidate_fn_name as function type `$arg_typ_sym.str()` in argument ${i+1} to `$fn_name`', call_expr.pos) + } else { + c.error('cannot use type `$typ_sym.str()` as type `$arg_typ_sym.str()` in argument ${i+1} to `$fn_name`', + call_expr.pos) } - c.error('cannot use type `$typ_sym.str()` as type `$arg_typ_sym.str()` in argument ${i+1} to `$fn_name`', - call_expr.pos) } } if call_expr.generic_type != table.void_type && f.return_type != 0 { // table.t_type { diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index 834f4f42db..4228aa10ff 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -110,8 +110,8 @@ pub fn source_context(kind, source string, column int, pos token.Position) []str tab_spaces := ' ' for iline := bline; iline <= aline; iline++ { sline := source_lines[iline] - start_column := imin(column, sline.len) - end_column := imin(column + pos.len, sline.len) + start_column := imax(0, imin(column, sline.len)) + end_column := imax(0, imin(column + imax(0, pos.len), sline.len)) cline := if iline == pos.line_nr { sline[..start_column] + color(kind, sline[start_column..end_column]) + sline[end_column..] } else {