mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
cgen: fix struct ref field with no ref structinit (#21932)
This commit is contained in:
parent
0bf8adb5e6
commit
ac136c08e6
@ -23,7 +23,7 @@ mut:
|
||||
pub struct DownloaderParams {
|
||||
FetchConfig
|
||||
pub mut:
|
||||
downloader &Downloader = TerminalStreamingDownloader{}
|
||||
downloader &Downloader = &TerminalStreamingDownloader{}
|
||||
}
|
||||
|
||||
// download_file_with_progress will save the URL `url` to the filepath `path` .
|
||||
|
@ -111,6 +111,11 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
|
||||
if field.has_default_expr {
|
||||
c.expected_type = field.typ
|
||||
field.default_expr_typ = c.expr(mut field.default_expr)
|
||||
if field.typ.is_ptr() && !field.default_expr_typ.is_ptr()
|
||||
&& field.default_expr is ast.StructInit {
|
||||
c.error('reference field must be initialized with reference', field.default_expr.pos())
|
||||
}
|
||||
|
||||
// disallow map `mut a = b`
|
||||
field_sym := c.table.sym(field.typ)
|
||||
expr_sym := c.table.sym(field.default_expr_typ)
|
||||
|
6
vlib/v/checker/tests/struct_ref_field_no_ptr_err.out
Normal file
6
vlib/v/checker/tests/struct_ref_field_no_ptr_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/struct_ref_field_no_ptr_err.vv:2:13: error: reference field must be initialized with reference
|
||||
1 | struct Foo {
|
||||
2 | bar &Bar = Bar{}
|
||||
| ~~~~~
|
||||
3 | }
|
||||
4 |
|
7
vlib/v/checker/tests/struct_ref_field_no_ptr_err.vv
Normal file
7
vlib/v/checker/tests/struct_ref_field_no_ptr_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
struct Foo {
|
||||
bar &Bar = Bar{}
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
field int
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user