mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: skip checking [required]
fields for struct update syntax (#10500)
This commit is contained in:
parent
64f34f6d61
commit
751f2950ea
@ -929,7 +929,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
|
||||
}
|
||||
*/
|
||||
// Check for `[required]` struct attr
|
||||
if field.attrs.contains('required') && !node.is_short {
|
||||
if field.attrs.contains('required') && !node.is_short && !node.has_update_expr {
|
||||
mut found := false
|
||||
for init_field in node.fields {
|
||||
if field.name == init_field.name {
|
||||
|
32
vlib/v/tests/struct_fields_required_test.v
Normal file
32
vlib/v/tests/struct_fields_required_test.v
Normal file
@ -0,0 +1,32 @@
|
||||
struct Fns {
|
||||
f1 fn () [required]
|
||||
f2 fn () [attr1; required]
|
||||
}
|
||||
|
||||
fn func() {
|
||||
}
|
||||
|
||||
fn test_struct_fields_storing_required_functions() {
|
||||
s := Fns{
|
||||
f1: func
|
||||
f2: func
|
||||
}
|
||||
|
||||
assert s.f1 == func
|
||||
assert s.f2 == func
|
||||
}
|
||||
|
||||
struct Data {
|
||||
v1 int [required]
|
||||
v2 int [required]
|
||||
}
|
||||
|
||||
fn test_required_fields() {
|
||||
data := Data{1, 2}
|
||||
assert data.v1 == 1
|
||||
data2 := Data{
|
||||
...data
|
||||
v1: 10
|
||||
}
|
||||
assert data.v2 == data2.v2
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
struct Struct {
|
||||
f1 fn () [required]
|
||||
f2 fn () [attr1; required]
|
||||
}
|
||||
|
||||
fn func() {
|
||||
}
|
||||
|
||||
fn test_struct_fields_storing_required_functions() {
|
||||
s := Struct{
|
||||
f1: func
|
||||
f2: func
|
||||
}
|
||||
|
||||
assert s.f1 == func
|
||||
assert s.f2 == func
|
||||
}
|
Loading…
Reference in New Issue
Block a user