vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.79k stars 2.16k forks source link

c error instead of a checker error when comparing `== 0` on a mutable object #14295

Closed vincenzopalazzo closed 2 years ago

vincenzopalazzo commented 2 years ago

V doctor:

OS: linux, Linux Mint 20.2
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

getwd: /home/vincent/Github/vlang/v
vmodules: /home/vincent/.vmodules
vroot: /home/vincent/Github/vlang/v
vexe: /home/vincent/Github/vlang/v/v
vexe mtime: 2022-05-04 10:39:11
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 3bd6455.e968e2b

Git version: git version 2.25.1
Git vroot status: weekly.2022.18-10-ge968e2be-dirty
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 eee03626

What did you do? v -g -o vdbg cmd/v && vdbg vlib/datatypes/rbtree_test.v

fn (mut rbt RBTree<T>) insert_helper(mut node RBTreeNode<T>, value &T) &RBTreeNode<T> {
        // generate a checker error
    if node == 0 {
        return new_rbt_root_node(value, .red)
    }
    return node
}

What did you expect to see?

an V checker error where is explained because I can do a == 0 on a mutable object

What did you see instead?

==================
/tmp/v_1000/rbtree_test.4419769609750008750.tmp.c:12668: error: invalid operand types for binary operation
/tmp/v_1000/rbtree_test.4419769609750008750.tmp.c:12668: error: invalid aggregate type for register load
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang
danieldaeschle commented 2 years ago

To reproduce:

struct Foo {}

fn insert_helper(mut node Foo) {
    if node == 0 {}
}

fn main() {}
medvednikov commented 2 years ago

This should be a checker error. Objects can't be compared to 0.

vincenzopalazzo commented 2 years ago

This should be a checker error. Objects can't be compared to 0.

I will try to fix it by tomorrow