mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
Merge e75940e34a
into a8d200ac0e
This commit is contained in:
commit
a10ad725a5
3 changed files with 21 additions and 4 deletions
|
@ -7574,8 +7574,9 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
|
|||
}
|
||||
}
|
||||
.struct {
|
||||
mut has_none_zero := false
|
||||
info := sym.info as ast.Struct
|
||||
mut has_none_zero := info.fields.len == 0
|
||||
|
||||
mut init_str := if info.is_anon && !g.inside_global_decl {
|
||||
'(${g.styp(typ)}){'
|
||||
} else {
|
||||
|
|
18
vlib/v/tests/sumtypes/sumtype_empty_struct_test.v
Normal file
18
vlib/v/tests/sumtypes/sumtype_empty_struct_test.v
Normal file
|
@ -0,0 +1,18 @@
|
|||
struct Empty {
|
||||
}
|
||||
|
||||
type Sum = int | Empty
|
||||
|
||||
fn do_generic[T](val T) T {
|
||||
$for v in Sum.variants {
|
||||
if val is v {
|
||||
return T(v)
|
||||
}
|
||||
}
|
||||
return T{}
|
||||
}
|
||||
|
||||
fn test_empty_cast() {
|
||||
assert do_generic(Sum(0)) == Sum(0)
|
||||
assert do_generic(Sum(Empty{})) == Sum(Empty{})
|
||||
}
|
|
@ -24,9 +24,7 @@ pub type Any = []Any
|
|||
| Null
|
||||
|
||||
// Null is a simple representation of the `null` value in JSON.
|
||||
pub struct Null {
|
||||
is_null bool = true
|
||||
}
|
||||
pub struct Null {}
|
||||
|
||||
// null is an instance of the Null type, to ease comparisons with it.
|
||||
pub const null = Null{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue