diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 116112b42f..38a561478e 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -209,6 +209,12 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) { // string representation of expr pub fn (x Expr) str() string { match x { + AnonFn { + return 'anon_fn' + } + DumpExpr { + return 'dump($x.expr.str())' + } ArrayInit { mut fields := []string{} if x.has_len { @@ -226,6 +232,12 @@ pub fn (x Expr) str() string { return x.exprs.str() } } + AsCast { + return '$x.expr.str() as Type($x.typ)' + } + AtExpr { + return '$x.val' + } CTempVar { return x.orig.str() } @@ -235,9 +247,6 @@ pub fn (x Expr) str() string { CastExpr { return '${x.typname}($x.expr.str())' } - AtExpr { - return '$x.val' - } CallExpr { sargs := args2str(x.args) if x.is_method { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0b6de79c92..54cc35f0e8 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -13,12 +13,9 @@ import v.util import v.errors import v.pkgconfig -const ( - max_nr_errors = 300 - match_exhaustive_cutoff_limit = 10 - int_min = int(0x80000000) - int_max = 0x7FFFFFFF -) +const int_min = int(0x80000000) + +const int_max = int(0x7FFFFFFF) const ( valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx', @@ -78,6 +75,7 @@ mut: fn_scope &ast.Scope = voidptr(0) used_fns map[string]bool // used_fns['println'] == true main_fn_decl_node ast.FnDecl + match_exhaustive_cutoff_limit int = 10 // TODO: these are here temporarily and used for deprecations; remove soon using_new_err_struct bool inside_selector_expr bool @@ -94,6 +92,7 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker { pref: pref cur_fn: 0 timers: util.new_timers(timers_should_print) + match_exhaustive_cutoff_limit: pref.checker_match_exhaustive_cutoff_limit } } @@ -4707,11 +4706,11 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym table.TypeS mut err_details := 'match must be exhaustive' if unhandled.len > 0 { err_details += ' (add match branches for: ' - if unhandled.len < checker.match_exhaustive_cutoff_limit { + if unhandled.len < c.match_exhaustive_cutoff_limit { err_details += unhandled.join(', ') } else { - remaining := unhandled.len - checker.match_exhaustive_cutoff_limit - err_details += unhandled[0..checker.match_exhaustive_cutoff_limit].join(', ') + remaining := unhandled.len - c.match_exhaustive_cutoff_limit + err_details += unhandled[0..c.match_exhaustive_cutoff_limit].join(', ') err_details += ', and $remaining others ...' } err_details += ' or `else {}` at the end)' diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 8e9ce09ffd..700466d462 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -144,6 +144,8 @@ pub mut: build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache cache_manager vcache.CacheManager is_help bool // -h, -help or --help was passed + // checker settings: + checker_match_exhaustive_cutoff_limit int = 10 } 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 res.build_options << '$arg "$res.ccompiler"' i++ } + '-checker-match-exhaustive-cutoff-limit' { + res.checker_match_exhaustive_cutoff_limit = cmdline.option(current_args, + arg, '10').int() + i++ + } '-o' { res.out_name = cmdline.option(current_args, '-o', '') if res.out_name.ends_with('.js') {