From 38d3239b50d168eeafd27df575137a6f1a5dad2b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 19 Jan 2022 15:26:24 +0300 Subject: [PATCH] checker: c2v fixes --- vlib/builtin/cfns.c.v | 3 +++ vlib/v/checker/checker.v | 3 ++- vlib/v/checker/if.v | 2 +- vlib/v/checker/match.v | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index c2bb9a31f3..8cb1b96966 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -171,6 +171,9 @@ fn C.tolower(c int) int [trusted] fn C.toupper(c int) int +[trusted] +fn C.strchr(s &char, c int) &char + [trusted] fn C.getchar() int diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 6214ea0c9f..0f4e4c5a2e 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2704,7 +2704,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } } } - } else if to_type == ast.bool_type && from_type != ast.bool_type && !c.inside_unsafe { + } else if to_type == ast.bool_type && from_type != ast.bool_type && !c.inside_unsafe + && !c.pref.translated { c.error('cannot cast to bool - use e.g. `some_int != 0` instead', node.pos) } else if from_type == ast.none_type && !to_type.has_flag(.optional) { type_name := c.table.type_to_str(to_type) diff --git a/vlib/v/checker/if.v b/vlib/v/checker/if.v index 02ef3e4195..8b943b63a5 100644 --- a/vlib/v/checker/if.v +++ b/vlib/v/checker/if.v @@ -28,7 +28,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type { mut is_comptime_type_is_expr := false // if `$if T is string` for i in 0 .. node.branches.len { mut branch := node.branches[i] - if branch.cond is ast.ParExpr { + if branch.cond is ast.ParExpr && !c.pref.translated { c.error('unnecessary `()` in `$if_kind` condition, use `$if_kind expr {` instead of `$if_kind (expr) {`.', branch.pos) } diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index a9b60b979d..b6df67fdad 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -8,7 +8,7 @@ import strings pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { node.is_expr = c.expected_type != ast.void_type node.expected_type = c.expected_type - if node.cond is ast.ParExpr { + if node.cond is ast.ParExpr && !c.pref.translated { c.error('unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`.', node.cond.pos) }