diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index 41a2bc2d35..6d70dcdc06 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -32,6 +32,7 @@ pub mut: // // See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details. pub enum SameSite { + same_site_not_set same_site_default_mode = 1 same_site_lax_mode same_site_strict_mode @@ -162,6 +163,7 @@ pub fn (c &Cookie) str() string { b.write_string('; Secure') } match c.same_site { + .same_site_not_set {} .same_site_default_mode { b.write_string('; SameSite') } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index ef5811ff9e..90a117c799 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6254,6 +6254,18 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { return init_str } } + .enum_ { + // returns the enum's first value + if enum_decl := g.table.enum_decls[sym.name] { + return if enum_decl.fields[0].expr is ast.EmptyExpr { + '0' + } else { + g.expr_string(enum_decl.fields[0].expr) + } + } else { + return '0' + } + } else { return '0' } diff --git a/vlib/v/tests/enum_default_test.v b/vlib/v/tests/enum_default_test.v new file mode 100644 index 0000000000..73196bb1a3 --- /dev/null +++ b/vlib/v/tests/enum_default_test.v @@ -0,0 +1,28 @@ +enum TestEnum { + two = 1 + one +} + +struct Test { + a TestEnum + b TestEnum = .one +} + +fn test_main() { + assert dump(Test{}) == Test{ + a: .two + b: .one + } + assert dump(Test{}) == Test{} + + assert dump(Test{ + a: .one + }) == Test{ + a: .one + } + assert dump(Test{ + b: .two + }) == Test{ + b: .two + } +}