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.63k stars 2.15k forks source link

inconsistent doc for chan try_pop #18231

Open kbkpbot opened 1 year ago

kbkpbot commented 1 year ago

Describe the issue

There are special rules in checker for chan try_pop: https://github.com/vlang/v/tree/master/vlib/v/checker/fn.v/#L1699

        if left_sym.info is ast.Chan {
            if method_name == 'try_push' {
                exp_arg_typ = left_sym.info.elem_type.ref()
            } else if method_name == 'try_pop' {
                exp_arg_typ = left_sym.info.elem_type
                param_is_mut = true
                no_type_promotion = true
            }
        }

I think it is better update the corresponding doc: https://modules.vlang.io/index.html#chan.try_pop

fn (mut ch Channel) try_pop(dest voidptr) ChanState

such as ch.try_pop(mut i) , not ch.try_pop(&i)

Links

https://modules.vlang.io/index.html#chan.try_pop

kbkpbot commented 1 year ago

BTW, in file: https://github.com/vlang/v/blob/master/vlib/sync/bench/many_writers_and_receivers_on_1_channel.v/#L51 if should be:

for ch.try_pop(mut tmp) == .success