1
0
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:
yuyi 2021-12-26 22:44:41 +08:00 committed by GitHub
parent 8a10dbcf27
commit 55d9c24063
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 2 deletions

View File

@ -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 += ', '
} }

View 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 }
}