diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 4942a7bee5..79a03a476e 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -15,10 +15,13 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { if expected == ast.byteptr_type { return true } + if expected == ast.voidptr_type { + return true + } if expected.is_any_kind_of_pointer() { //&& !got.is_any_kind_of_pointer() { // Allow `int` as `&i8` etc in C code. - // deref := expected.deref() - deref := expected.set_nr_muls(0) + deref := expected.deref() + // deref := expected.set_nr_muls(0) got_sym := c.table.sym(got) if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum_) { return true diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index 593cb7431f..1e00231315 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -197,8 +197,11 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr { pos := p.tok.position() is_known_var := p.mark_var_as_used(p.tok.lit) || p.table.global_scope.known_const(p.mod + '.' + p.tok.lit) + //|| p.table.known_fn(p.mod + '.' + p.tok.lit) // assume `mod.` prefix leads to a type - if is_known_var || !(p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type()) { + is_type := p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type() + || (p.tok.lit.len > 0 && p.tok.lit[0].is_capital()) + if is_known_var || !is_type { expr := p.expr(0) if is_reftype { node = ast.IsRefType{ diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 0ba8464ef1..c94a892f0b 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3596,6 +3596,7 @@ fn (mut p Parser) rewind_scanner_to_current_token_in_new_mode() { } } +// returns true if `varname` is known pub fn (mut p Parser) mark_var_as_used(varname string) bool { if obj := p.scope.find(varname) { match mut obj { @@ -3603,6 +3604,10 @@ pub fn (mut p Parser) mark_var_as_used(varname string) bool { obj.is_used = true return true } + ast.GlobalField { + // obj.is_used = true + return true + } // ast.ConstField { // return true //}