mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
checker: warn -> error for uninitialized ref fields
This commit is contained in:
parent
7bfb35dd1c
commit
a1f5552529
6 changed files with 9 additions and 34 deletions
|
@ -41,8 +41,9 @@
|
|||
- [ ] -skip-unused on by default
|
||||
- [ ] 64/32 bit int depending on arch (will remove array.len limitation on 64 bit systems)
|
||||
- [ ] `copy()` builtin function (e.g. for easier conversion from `[]Foo` to `[4]Foo`)
|
||||
- [ ] Lambdas: `a.sort(|a, b| a > b)`
|
||||
- [x] Lambdas: `a.sort(|a, b| a > b)`
|
||||
- [ ] Custom attributes.
|
||||
- [ ] `arr.first() or { }` like `arr[0] or { }`
|
||||
|
||||
## [Version 1.0]
|
||||
|
||||
|
|
|
@ -716,7 +716,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
|||
if field.typ.is_ptr() && !field.typ.has_flag(.shared_f)
|
||||
&& !field.typ.has_flag(.option) && !node.has_update_expr && !c.pref.translated
|
||||
&& !c.file.is_translated {
|
||||
c.warn('reference field `${type_sym.name}.${field.name}` must be initialized',
|
||||
c.error('reference field `${type_sym.name}.${field.name}` must be initialized',
|
||||
node.pos)
|
||||
continue
|
||||
}
|
||||
|
@ -840,7 +840,7 @@ fn (mut c Checker) check_ref_fields_initialized(struct_sym &ast.TypeSymbol, mut
|
|||
}
|
||||
if field.typ.is_ptr() && !field.typ.has_flag(.shared_f) && !field.typ.has_flag(.option)
|
||||
&& !field.has_default_expr {
|
||||
c.warn('reference field `${linked_name}.${field.name}` must be initialized (part of struct `${struct_sym.name}`)',
|
||||
c.error('reference field `${linked_name}.${field.name}` must be initialized (part of struct `${struct_sym.name}`)',
|
||||
node.pos)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: warning: reference field `Node.next` must be initialized
|
||||
vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: error: reference field `Node.next` must be initialized
|
||||
6 |
|
||||
7 | fn main(){
|
||||
8 | n := Node{ data: 123 }
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: warning: reference field `Animal.duck.age` must be initialized (part of struct `Duck`)
|
||||
10 |
|
||||
11 | fn main() {
|
||||
12 | mut animal := Animal{
|
||||
| ~~~~~~~
|
||||
13 | ageee: 20
|
||||
14 | }
|
||||
vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: warning: reference field `Duck.age` must be initialized
|
||||
vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: error: reference field `Animal.duck.age` must be initialized (part of struct `Duck`)
|
||||
10 |
|
||||
11 | fn main() {
|
||||
12 | mut animal := Animal{
|
||||
|
|
|
@ -1,31 +1,11 @@
|
|||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c1.b` must be initialized (part of struct `ContainsRef`)
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: error: reference field `Outer.c1.b` must be initialized (part of struct `ContainsRef`)
|
||||
23 |
|
||||
24 | fn main() {
|
||||
25 | _ := Outer{}
|
||||
| ~~~~~~~
|
||||
26 | _ := Struct{}
|
||||
27 | }
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `ContainsRef.b` must be initialized
|
||||
23 |
|
||||
24 | fn main() {
|
||||
25 | _ := Outer{}
|
||||
| ~~~~~~~
|
||||
26 | _ := Struct{}
|
||||
27 | }
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c2.b` must be initialized (part of struct `ContainsRef`)
|
||||
23 |
|
||||
24 | fn main() {
|
||||
25 | _ := Outer{}
|
||||
| ~~~~~~~
|
||||
26 | _ := Struct{}
|
||||
27 | }
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:26:7: warning: reference field `Struct.ref2` must be initialized
|
||||
24 | fn main() {
|
||||
25 | _ := Outer{}
|
||||
26 | _ := Struct{}
|
||||
| ~~~~~~~~
|
||||
27 | }
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:26:7: warning: reference field `EmbedStruct.ref2` must be initialized
|
||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:26:7: error: reference field `Struct.ref2` must be initialized
|
||||
24 | fn main() {
|
||||
25 | _ := Outer{}
|
||||
26 | _ := Struct{}
|
||||
|
|
|
@ -315,6 +315,7 @@ pub fn (mut ctx Context) redirect(url string) Result {
|
|||
|
||||
// Send an not_found response
|
||||
pub fn (mut ctx Context) not_found() Result {
|
||||
// TODO add a [must_be_returned] attribute, so that the caller is forced to use `return app.not_found()`
|
||||
if ctx.done {
|
||||
return Result{}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue