v: deprecate `[if ident]` in favour of `[if ident ?]`

pull/10471/head
Delyan Angelov 2021-06-22 10:30:14 +03:00
parent d65aa977b8
commit 79df7f51c3
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
6 changed files with 8 additions and 11 deletions

View File

@ -35,7 +35,7 @@ fn (_ None__) str() string {
return 'none' return 'none'
} }
[if trace_error] [if trace_error ?]
fn trace_error(x string) { fn trace_error(x string) {
eprintln('> ${@FN} | $x') eprintln('> ${@FN} | $x')
} }

View File

@ -340,10 +340,9 @@ pub fn (x Expr) str() string {
return '($x.expr)' return '($x.expr)'
} }
PostfixExpr { PostfixExpr {
// TODO: uncomment after [if x] is deprecated if x.op == .question {
// if x.op == .question { return '$x.expr ?'
// return '$x.expr ?' }
//}
return '$x.expr$x.op' return '$x.expr$x.op'
} }
PrefixExpr { PrefixExpr {

View File

@ -7259,8 +7259,8 @@ fn (mut c Checker) evaluate_once_comptime_if_attribute(mut a ast.Attr) bool {
return a.ct_skip return a.ct_skip
} else { } else {
if a.ct_expr.name !in checker.valid_comp_not_user_defined { 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',
// c.note('`[if $a.ct_expr.name]` is deprecated. Use `[if $a.ct_expr.name ?]` instead', a.pos) a.pos)
a.ct_skip = a.ct_expr.name !in c.pref.compile_defines a.ct_skip = a.ct_expr.name !in c.pref.compile_defines
a.ct_evaled = true a.ct_evaled = true
return a.ct_skip return a.ct_skip

View File

@ -2836,7 +2836,7 @@ fn (mut g Gen) autofree_scope_vars_stop(pos int, line_nr int, free_parent_scopes
stop_pos) stop_pos)
} }
[if trace_autofree] [if trace_autofree ?]
fn (mut g Gen) trace_autofree(line string) { fn (mut g Gen) trace_autofree(line string) {
g.writeln(line) g.writeln(line)
} }

View File

@ -1553,9 +1553,7 @@ fn (mut p Parser) parse_attr() ast.Attr {
p.inside_if_expr = false p.inside_if_expr = false
p.inside_ct_if_expr = false p.inside_ct_if_expr = false
if comptime_cond is ast.PostfixExpr { if comptime_cond is ast.PostfixExpr {
x := comptime_cond as ast.PostfixExpr
comptime_cond_opt = true comptime_cond_opt = true
comptime_cond = x.expr
} }
name = comptime_cond.str() name = comptime_cond.str()
} else if p.tok.kind == .string { } else if p.tok.kind == .string {

View File

@ -3,7 +3,7 @@ module util
import os import os
import v.pref 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) { 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') eprintln('> $line ${@FN} mod: ${mod:-20} | file_path: ${file_path:-30} | result: $res')
} }