Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix struct field with default optional value (fix #11119) #22167

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 6, 2024

This PR fix struct field with default optional value (fix #11119).

  • Fix struct field with default optional value.
  • Add test.
import regex

struct RegexCache {
mut:
	tag_script_start regex.RE = regex.regex_opt(r'^script.*>') or { panic(err) }
}

pub struct Tokenizer {
mut:
	regex_cache RegexCache = RegexCache{}
}

fn new_parser() &Parser {
	mut parser := &Parser{}
	return parser
}

pub struct Parser {
mut:
	tnzr Tokenizer
}

fn main() {
	p := new_parser()
	println(p)
}

PS D:\Test\v\tt1> v run .    
&Parser{
    tnzr: Tokenizer{
        regex_cache: RegexCache{
            tag_script_start: regex.RE{
                prog: [regex.Token{
                    ist: 2147483647
                    ch: 115
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 99
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 114
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 105
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 112
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 116
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2550136832
                    ch: 0
                    ch_len: 0
                    flag: 0
                    rep_min: 0
                    rep_max: 1073741824
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: 7
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2147483647
                    ch: 62
                    ch_len: 1
                    flag: 0
                    rep_min: 1
                    rep_max: 1
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 2281701376
                    ch: 0
                    ch_len: 0
                    flag: 0
                    rep_min: 0
                    rep_max: 0
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 0
                    ch: 0
                    ch_len: 0
                    flag: 0
                    rep_min: 0
                    rep_max: 0
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }, regex.Token{
                    ist: 0
                    ch: 0
                    ch_len: 0
                    flag: 0
                    rep_min: 0
                    rep_max: 0
                    greedy: false
                    cc_index: -1
                    rep: 0
                    validator: fn (u8) bool
                    group_neg: false
                    group_rep: 0
                    group_id: -1
                    goto_pc: -1
                    next_is_or: false
                    dot_check_pc: -1
                    bsls_check_pc: -1
                    cc_check_pc: -1
                    last_dot_flag: false
                    source_index: 0
                }]
                prog_len: 8
                cc: [regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }, regex.CharClass{
                    cc_type: 0
                    ch0: 0
                    ch1: 0
                    validator: fn (u8) bool
                }]
                cc_index: 0
                group_count: 0
                groups: []
                group_max_nested: 5
                group_max: 5
                state_list: []
                group_csave_flag: false
                group_csave: []
                group_map: {}
                group_stack: [-1, -1, -1, -1, -1]
                group_data: [-1, -1, -1, -1, -1]
                flag: 2
                debug: 0
                log_func: fn (string)
                query: '^script.*>'
            }
        }
    }
}

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 023fd92 into vlang:master Sep 6, 2024
75 checks passed
@yuyi98 yuyi98 deleted the fix_struct_init_with_options branch September 7, 2024 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cgen: error when using or { } block in struct field init
2 participants