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.75k stars 2.16k forks source link

c error: invalid use of void expression #6198

Closed serkonda7 closed 3 years ago

serkonda7 commented 4 years ago

V version: V 0.1.29 542b149 OS: Manjaro

What did you do? I run the following code:

module main

fn main() {
    foo()
}

fn foo() {
    mut err_count := 0
    throw_error() or {
        print_err(err)
        err_count++
    }
       println(err_count)
}

fn throw_error() ? {
    return error('Some error')
}

fn print_err(err string) {
    println(err)
}

What did you expect to see? Working program and output of:

Some error
1

What did you see instead?

/tmp/v/symlinker.tmp.c:7745:22: error: invalid use of void expression
 7745 |   *(void*) _t74.data = err_count++;
      |                      ^
/tmp/v/symlinker.tmp.c: In function ‘_vinit’:
/tmp/v/symlinker.tmp.c:7782:38: warning: integer constant is so large that it is unsigned
 7782 |  _const_math__bits__max_u64 = ((u64)(18446744073709551615));
      |                                      ^~~~~~~~~~~~~~~~~~~~
/tmp/v/symlinker.tmp.c:7809:409: warning: integer constant is so large that it is unsigned
 7809 |   ((u64)(1)), ((u64)(10)), ((u64)(100)), ((u64)(1000)), ((u64)(10000)), ((u64)(100000)), ((u64)(1000000)), ((u64)(10000000)), ((u64)(100000000)), ((u64)(1000000000)), ((u64)(10000000000)), ((u64)(100000000000)), ((u64)(1000000000000)), ((u64)(10000000000000)), ((u64)(100000000000000)), ((u64)(1000000000000000)), ((u64)(10000000000000000)), ((u64)(100000000000000000)), ((u64)(1000000000000000000)), ((u64)(10000000000000000000))}));
      |                                                                                                                                                                                                                                                                                                                                                                                                                         ^~~~~~~~~~~~~~~~~~~~
...

Workaround It works if the or-block is switched to

err_count++
print_err(err)
medvednikov commented 4 years ago

++ is not an expression, V needs to detect that.

serkonda7 commented 3 years ago

Fixed in newer versions of V.