mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: fix generic fn with multiple return (#12971)
This commit is contained in:
parent
8a10dbcf27
commit
55d9c24063
@ -1056,8 +1056,9 @@ pub fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int {
|
|||||||
mut cname := 'multi_return'
|
mut cname := 'multi_return'
|
||||||
for i, mr_typ in mr_typs {
|
for i, mr_typ in mr_typs {
|
||||||
mr_type_sym := t.sym(mr_typ)
|
mr_type_sym := t.sym(mr_typ)
|
||||||
name += mr_type_sym.name
|
ref, cref := if mr_typ.is_ptr() { '&', 'ref_' } else { '', '' }
|
||||||
cname += '_$mr_type_sym.cname'
|
name += '$ref$mr_type_sym.name'
|
||||||
|
cname += '_$cref$mr_type_sym.cname'
|
||||||
if i < mr_typs.len - 1 {
|
if i < mr_typs.len - 1 {
|
||||||
name += ', '
|
name += ', '
|
||||||
}
|
}
|
||||||
|
53
vlib/v/tests/generic_fn_multi_return_test.v
Normal file
53
vlib/v/tests/generic_fn_multi_return_test.v
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
fn test_generic_fn_multi_return() {
|
||||||
|
mut a1 := GenRef<u32, u32>{32, 99}
|
||||||
|
b1, c1 := a1.generic_reference() or {
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(b1)
|
||||||
|
assert b1 == 32
|
||||||
|
println(c1)
|
||||||
|
assert *c1 == 99
|
||||||
|
|
||||||
|
mut a2 := GenRef<u64, u64>{322, 999}
|
||||||
|
b2, c2 := a2.generic_reference() or {
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(b2)
|
||||||
|
assert b2 == 322
|
||||||
|
println(c2)
|
||||||
|
assert *c2 == 999
|
||||||
|
|
||||||
|
mut a3 := GenRef<i32, u64>{22, 77}
|
||||||
|
b3, c3 := a3.generic_reference() or {
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(b3)
|
||||||
|
assert b3 == 22
|
||||||
|
println(c3)
|
||||||
|
assert *c3 == 77
|
||||||
|
|
||||||
|
mut a4 := GenRef<f64, u64>{2.2, 777}
|
||||||
|
b4, c4 := a4.generic_reference() or {
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(b4)
|
||||||
|
assert b4 == 2.2
|
||||||
|
println(c4)
|
||||||
|
assert *c4 == 777
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GenRef<K, V> {
|
||||||
|
key K
|
||||||
|
val V
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut self GenRef<K, V>) generic_reference() ?(K, &V) {
|
||||||
|
if false {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
return self.key, unsafe { &self.val }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user