From 79df7f51c30abbe540b19eac27d5f5d3d3eb01fa Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 22 Jun 2021 10:30:14 +0300 Subject: [PATCH] v: deprecate `[if ident]` in favour of `[if ident ?]` --- vlib/builtin/option.v | 2 +- vlib/v/ast/str.v | 7 +++---- vlib/v/checker/checker.v | 4 ++-- vlib/v/gen/c/cgen.v | 2 +- vlib/v/parser/parser.v | 2 -- vlib/v/util/module.v | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index 90a352ffaa..4e8a14f194 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -35,7 +35,7 @@ fn (_ None__) str() string { return 'none' } -[if trace_error] +[if trace_error ?] fn trace_error(x string) { eprintln('> ${@FN} | $x') } diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index bf439549d3..2af805430b 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -340,10 +340,9 @@ pub fn (x Expr) str() string { return '($x.expr)' } PostfixExpr { - // TODO: uncomment after [if x] is deprecated - // if x.op == .question { - // return '$x.expr ?' - //} + if x.op == .question { + return '$x.expr ?' + } return '$x.expr$x.op' } PrefixExpr { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 962d337b8e..69f4262e16 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -7259,8 +7259,8 @@ fn (mut c Checker) evaluate_once_comptime_if_attribute(mut a ast.Attr) bool { return a.ct_skip } else { if a.ct_expr.name !in checker.valid_comp_not_user_defined { - // TODO: uncomment after [if x] is deprecated in favour of [if x?], see also vlib/v/ast/str.v:343 - // c.note('`[if $a.ct_expr.name]` is deprecated. Use `[if $a.ct_expr.name ?]` instead', a.pos) + c.note('`[if $a.ct_expr.name]` is deprecated. Use `[if $a.ct_expr.name ?]` instead', + a.pos) a.ct_skip = a.ct_expr.name !in c.pref.compile_defines a.ct_evaled = true return a.ct_skip diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 945f07a812..d30402d58d 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2836,7 +2836,7 @@ fn (mut g Gen) autofree_scope_vars_stop(pos int, line_nr int, free_parent_scopes stop_pos) } -[if trace_autofree] +[if trace_autofree ?] fn (mut g Gen) trace_autofree(line string) { g.writeln(line) } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 34a9069bf2..aac79406d5 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1553,9 +1553,7 @@ fn (mut p Parser) parse_attr() ast.Attr { p.inside_if_expr = false p.inside_ct_if_expr = false if comptime_cond is ast.PostfixExpr { - x := comptime_cond as ast.PostfixExpr comptime_cond_opt = true - comptime_cond = x.expr } name = comptime_cond.str() } else if p.tok.kind == .string { diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index 0742ebd2f0..992c594c1d 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -3,7 +3,7 @@ module util import os import v.pref -[if trace_mod_path_to_full_name] +[if trace_mod_path_to_full_name ?] fn trace_mod_path_to_full_name(line string, mod string, file_path string, res string) { eprintln('> $line ${@FN} mod: ${mod:-20} | file_path: ${file_path:-30} | result: $res') }