checker: handle error token positions with negative pos.len
parent
0637feb382
commit
108913c69e
|
@ -1198,11 +1198,12 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
if call_expr.generic_type != table.void_type && f.return_type != 0 { // table.t_type {
|
||||
// Handle `foo<T>() T` => `foo<int>() int` => return int
|
||||
return_sym := c.table.get_type_symbol(f.return_type)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue