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

cgen: fix using reference of sumtype or map as struct field (fix: #15827) (#15828)

This commit is contained in:
shove 2022-09-20 18:22:08 +08:00 committed by GitHub
parent a9d63d729e
commit bbf1ba458e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -921,8 +921,8 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
funcprefix += 'isnil(it.${c_name(field.name)})'
funcprefix += ' ? _SLIT("nil") : '
// struct, floats and ints have a special case through the _str function
if sym.kind !in [.struct_, .alias, .enum_, .interface_] && !field.typ.is_int_valptr()
&& !field.typ.is_float_valptr() {
if sym.kind !in [.struct_, .alias, .enum_, .sum_type, .map, .interface_]
&& !field.typ.is_int_valptr() && !field.typ.is_float_valptr() {
funcprefix += '*'
}
}

View File

@ -0,0 +1,3 @@
SumTypePtr{
ptr: &nil
}

View File

@ -0,0 +1,14 @@
struct S1 {}
struct S2 {}
type T1 = S1 | S2
struct SumTypePtr {
ptr &T1 = unsafe { nil }
}
fn main() {
ptr := SumTypePtr{}
println(ptr)
}