Skip to content

Commit 25c07c2

Browse files
committed
v.ast: handle more expressions in Expr.str()
1 parent 80ac1aa commit 25c07c2

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

vlib/v/ast/str.v

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) {
209209
// string representation of expr
210210
pub fn (x Expr) str() string {
211211
match x {
212+
AnonFn {
213+
return 'anon_fn'
214+
}
215+
DumpExpr {
216+
return 'dump($x.expr.str())'
217+
}
212218
ArrayInit {
213219
mut fields := []string{}
214220
if x.has_len {
@@ -226,6 +232,12 @@ pub fn (x Expr) str() string {
226232
return x.exprs.str()
227233
}
228234
}
235+
AsCast {
236+
return '$x.expr.str() as Type($x.typ)'
237+
}
238+
AtExpr {
239+
return '$x.val'
240+
}
229241
CTempVar {
230242
return x.orig.str()
231243
}
@@ -235,9 +247,6 @@ pub fn (x Expr) str() string {
235247
CastExpr {
236248
return '${x.typname}($x.expr.str())'
237249
}
238-
AtExpr {
239-
return '$x.val'
240-
}
241250
CallExpr {
242251
sargs := args2str(x.args)
243252
if x.is_method {

vlib/v/checker/checker.v

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ import v.util
1313
import v.errors
1414
import v.pkgconfig
1515

16-
const (
17-
max_nr_errors = 300
18-
match_exhaustive_cutoff_limit = 10
19-
int_min = int(0x80000000)
20-
int_max = 0x7FFFFFFF
21-
)
16+
const int_min = int(0x80000000)
17+
18+
const int_max = int(0x7FFFFFFF)
2219

2320
const (
2421
valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx',
@@ -78,6 +75,7 @@ mut:
7875
fn_scope &ast.Scope = voidptr(0)
7976
used_fns map[string]bool // used_fns['println'] == true
8077
main_fn_decl_node ast.FnDecl
78+
match_exhaustive_cutoff_limit int = 10
8179
// TODO: these are here temporarily and used for deprecations; remove soon
8280
using_new_err_struct bool
8381
inside_selector_expr bool
@@ -94,6 +92,7 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker {
9492
pref: pref
9593
cur_fn: 0
9694
timers: util.new_timers(timers_should_print)
95+
match_exhaustive_cutoff_limit: pref.checker_match_exhaustive_cutoff_limit
9796
}
9897
}
9998

@@ -4707,11 +4706,11 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym table.TypeS
47074706
mut err_details := 'match must be exhaustive'
47084707
if unhandled.len > 0 {
47094708
err_details += ' (add match branches for: '
4710-
if unhandled.len < checker.match_exhaustive_cutoff_limit {
4709+
if unhandled.len < c.match_exhaustive_cutoff_limit {
47114710
err_details += unhandled.join(', ')
47124711
} else {
4713-
remaining := unhandled.len - checker.match_exhaustive_cutoff_limit
4714-
err_details += unhandled[0..checker.match_exhaustive_cutoff_limit].join(', ')
4712+
remaining := unhandled.len - c.match_exhaustive_cutoff_limit
4713+
err_details += unhandled[0..c.match_exhaustive_cutoff_limit].join(', ')
47154714
err_details += ', and $remaining others ...'
47164715
}
47174716
err_details += ' or `else {}` at the end)'

vlib/v/pref/pref.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ pub mut:
144144
build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache
145145
cache_manager vcache.CacheManager
146146
is_help bool // -h, -help or --help was passed
147+
// checker settings:
148+
checker_match_exhaustive_cutoff_limit int = 10
147149
}
148150

149151
pub fn parse_args(known_external_commands []string, args []string) (&Preferences, string) {
@@ -370,6 +372,11 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
370372
res.build_options << '$arg "$res.ccompiler"'
371373
i++
372374
}
375+
'-checker-match-exhaustive-cutoff-limit' {
376+
res.checker_match_exhaustive_cutoff_limit = cmdline.option(current_args,
377+
arg, '10').int()
378+
i++
379+
}
373380
'-o' {
374381
res.out_name = cmdline.option(current_args, '-o', '')
375382
if res.out_name.ends_with('.js') {

0 commit comments

Comments
 (0)