From 4715fb67c163787079fcb6698a92eae5b0adea12 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 25 Jan 2022 20:15:45 +0300 Subject: [PATCH] checker: c2v fixes for enums and pointer to numbers --- vlib/builtin/cfns.c.v | 6 ++++++ vlib/v/checker/check_types.v | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index b1295cbb3a..a2d686511d 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.isspace(c int) int + [trusted] fn C.strchr(s &char, c int) &char @@ -186,6 +189,9 @@ fn C.strncasecmp(s &char, s2 &char, n int) int [trusted] fn C.strcasecmp(s &char, s2 &char) int +[trusted] +fn C.strncmp(s &char, s2 &char, n int) int + [trusted] fn C.strerror(int) &char diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 55587d5df2..a5b979b139 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -11,6 +11,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { if got == expected { return true } + got_is_ptr := got.is_ptr() + exp_is_ptr := expected.is_ptr() if c.pref.translated { if expected == ast.byteptr_type { return true @@ -40,9 +42,18 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { return true } } + if expected_sym.kind == .enum_ && got_sym.is_number() { + // Allow enums as numbers + return true + } + if got_is_ptr && exp_is_ptr { + // deref_sym := c.table.sym(expected.deref()) // set_nr_muls(0)) + if expected_sym.is_number() && got_sym.is_number() { + // Allow `&&u8` used as `&&int` etc + return true + } + } } - got_is_ptr := got.is_ptr() - exp_is_ptr := expected.is_ptr() if got_is_ptr && exp_is_ptr { if got.nr_muls() != expected.nr_muls() { return false