diff --git a/ROADMAP.md b/ROADMAP.md index 1edc66f47a9386..017213fb514ca5 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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] diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 8c0185163abba8..32b658a3c0d79b 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -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 } diff --git a/vlib/v/checker/tests/reference_field_must_be_initialized.out b/vlib/v/checker/tests/reference_field_must_be_initialized.out index 4e298481455f3d..b99c69f61d8327 100644 --- a/vlib/v/checker/tests/reference_field_must_be_initialized.out +++ b/vlib/v/checker/tests/reference_field_must_be_initialized.out @@ -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 } diff --git a/vlib/v/checker/tests/struct_field_reference_type_err.out b/vlib/v/checker/tests/struct_field_reference_type_err.out index 8e168619d5faac..534556e123f45d 100644 --- a/vlib/v/checker/tests/struct_field_reference_type_err.out +++ b/vlib/v/checker/tests/struct_field_reference_type_err.out @@ -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{ diff --git a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out index 400f509bdc818a..1636e861f19ab4 100644 --- a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out +++ b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out @@ -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{} diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 8311c2f4df87c9..16278b4520e551 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -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{} }