Skip to content

checker: fix embedded structure initialization warnings (fix #18376)#18385

Merged
medvednikov merged 1 commit intovlang:masterfrom
yuyi98:check_uninitialize_struct_field
Jun 9, 2023
Merged

checker: fix embedded structure initialization warnings (fix #18376)#18385
medvednikov merged 1 commit intovlang:masterfrom
yuyi98:check_uninitialize_struct_field

Conversation

@yuyi98
Copy link
Copy Markdown
Member

@yuyi98 yuyi98 commented Jun 9, 2023

This PR fix embedded structure initialization warnings (fix #18376).

  • Fix embedded structure initialization warnings.
  • Add test.
struct Embedded {
	a &int
}

fn new_embedded() Embedded {
	return Embedded{
		a: unsafe { nil }
	}
}

struct Outer {
	Embedded
}

fn main() {
	o := Outer{
		Embedded: new_embedded()
	}
	println(o)
}

PS D:\Test\v\tt1> v run .
Outer{
    Embedded: Embedded{
        a: &nil
    }
}

@medvednikov medvednikov merged commit 42db392 into vlang:master Jun 9, 2023
@yuyi98 yuyi98 deleted the check_uninitialize_struct_field branch June 10, 2023 12:57
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.

Wrong warning "reference field must be initialized" when directly initialize embedded struct

2 participants