1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sync: fix error of empty struct channel (fix #17556) (#17597)

This commit is contained in:
yuyi 2023-03-11 18:02:51 +08:00 committed by GitHub
parent a98376025e
commit 6e4dc82f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -59,7 +59,7 @@ pub:
} }
pub fn new_channel[T](n u32) &Channel { pub fn new_channel[T](n u32) &Channel {
st := sizeof(T) st := if sizeof(T) > 0 { sizeof(T) } else { 1 }
if isreftype(T) { if isreftype(T) {
return new_channel_st(n, st) return new_channel_st(n, st)
} else { } else {

View File

@ -0,0 +1,8 @@
struct User {
}
fn test_empty_struct_chan_init() {
user_ch := chan User{cap: 10}
println(user_ch)
assert true
}

View File

@ -3095,7 +3095,9 @@ fn (mut g Gen) expr(node_ ast.Expr) {
} }
g.write(', sizeof(') g.write(', sizeof(')
g.write(elem_typ_str) g.write(elem_typ_str)
g.write('))') g.write(')>0 ? sizeof(')
g.write(elem_typ_str)
g.write(') : 1)')
} }
ast.CharLiteral { ast.CharLiteral {
g.char_literal(node) g.char_literal(node)