Skip to content

(Embedded structs) How can i set field value for my struct at top level? #23740

Discussion options

You must be logged in to vote

Last paragraph under https://docs.vlang.io/structs.html#embedded-structs

module main

struct Test {
        Sa
        f_test string = 'v'
        field  string = 'v'
}

struct Sa {
mut:
        field string = 'v'
}

fn main() {
        mut params := Test{
                Sa:     Sa{'sa'}
                f_test: 'sd1'
                // Sa.field: 'sd2' // error: duplicate field name in struct literal: `field`
        }
        params.Sa.field = 'sd2'

        println(params)
}

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by vodish
Comment options

You must be logged in to vote
5 replies
@JalonSolov
Comment options

@vodish
Comment options

@Wajinn
Comment options

@vodish
Comment options

@Wajinn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants