diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index f38f1d6c71..aedaa41fff 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -24,7 +24,7 @@ pub mut: method Method = .get header Header host string - cookies map[string]string [deprecated: 'use req.cookie(name) and req.add_cookie(name) instead'] + cookies map[string]string @[deprecated: 'use req.cookie(name) and req.add_cookie(name) instead'] data string url string user_agent string = 'v.http' diff --git a/vlib/v/checker/tests/generic_interface_missing_type_names_err.vv b/vlib/v/checker/tests/generic_interface_missing_type_names_err.vv index bfc68013ff..123160f5c7 100644 --- a/vlib/v/checker/tests/generic_interface_missing_type_names_err.vv +++ b/vlib/v/checker/tests/generic_interface_missing_type_names_err.vv @@ -5,11 +5,11 @@ interface Output[T] { struct Coil { pub mut: val int - pub: name string [required] + pub: name string @[required] } struct Light { pub mut: val int - pub: name string [required] + pub: name string @[required] } fn main() { diff --git a/vlib/v/checker/tests/struct_field_type_err.vv b/vlib/v/checker/tests/struct_field_type_err.vv index 9a022d48ca..5e13c30317 100644 --- a/vlib/v/checker/tests/struct_field_type_err.vv +++ b/vlib/v/checker/tests/struct_field_type_err.vv @@ -2,8 +2,8 @@ struct Data { mut: n int b bool - f1 fn (voidptr) [required] - f2 fn (...voidptr) [required] + f1 fn (voidptr) @[required] + f2 fn (...voidptr) @[required] data &Data } diff --git a/vlib/v/checker/tests/unknown_type_in_anon_fn.out b/vlib/v/checker/tests/unknown_type_in_anon_fn.out index 6fea7a8a90..e23316dd20 100644 --- a/vlib/v/checker/tests/unknown_type_in_anon_fn.out +++ b/vlib/v/checker/tests/unknown_type_in_anon_fn.out @@ -1,7 +1,7 @@ vlib/v/checker/tests/unknown_type_in_anon_fn.vv:5:10: error: unknown type `Another` 3 | struct Struc{ 4 | mut: - 5 | f fn (s Another, i int)? [required] + 5 | f fn (s Another, i int)? @[required] | ~~~~~~~ 6 | } 7 | diff --git a/vlib/v/checker/tests/unknown_type_in_anon_fn.vv b/vlib/v/checker/tests/unknown_type_in_anon_fn.vv index 742675d6d7..6e68684b68 100644 --- a/vlib/v/checker/tests/unknown_type_in_anon_fn.vv +++ b/vlib/v/checker/tests/unknown_type_in_anon_fn.vv @@ -2,7 +2,7 @@ module main struct Struc{ mut: - f fn (s Another, i int)? [required] + f fn (s Another, i int)? @[required] } fn main() {} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index e29a1b5353..3fc146beaf 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -445,10 +445,13 @@ fn (mut p Parser) parse_type() ast.Type { if is_option || is_result { // maybe the '[' is the start of the field attribute + // TODO: remove once old syntax dropped is_required_field := p.inside_struct_field_decl && p.tok.kind == .lsbr && p.peek_tok.kind == .name && p.peek_tok.lit == 'required' + is_attr := p.tok.kind == .at - if p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar, .assign] || is_required_field { + if p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar, .assign] + || (is_attr || is_required_field) { mut typ := ast.void_type if is_option { typ = typ.set_flag(.option) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 86d383c692..8c526126bd 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1812,8 +1812,10 @@ fn (mut p Parser) is_attributes() bool { // when is_top_stmt is true attrs are added to p.attrs fn (mut p Parser) attributes() { + start_pos := p.tok.pos() mut is_at := false if p.tok.kind == .lsbr { + p.note('`[attr]` has been deprecated, use `@[attr]` instead') // [attr] p.check(.lsbr) } else if p.tok.kind == .at { @@ -1824,16 +1826,16 @@ fn (mut p Parser) attributes() { } mut has_ctdefine := false for p.tok.kind != .rsbr { - start_pos := p.tok.pos() + attr_start_pos := p.tok.pos() attr := p.parse_attr(is_at) if p.attrs.contains(attr.name) && attr.name != 'wasm_export' { - p.error_with_pos('duplicate attribute `${attr.name}`', start_pos.extend(p.prev_tok.pos())) + p.error_with_pos('duplicate attribute `${attr.name}`', attr_start_pos.extend(p.prev_tok.pos())) return } if attr.kind == .comptime_define { if has_ctdefine { p.error_with_pos('only one `[if flag]` may be applied at a time `${attr.name}`', - start_pos.extend(p.prev_tok.pos())) + attr_start_pos.extend(p.prev_tok.pos())) return } else { has_ctdefine = true @@ -1851,7 +1853,7 @@ fn (mut p Parser) attributes() { p.next() } if p.attrs.len == 0 { - p.error_with_pos('attributes cannot be empty', p.prev_tok.pos().extend(p.tok.pos())) + p.error_with_pos('attributes cannot be empty', start_pos.extend(p.tok.pos())) return } // TODO: remove when old attr syntax is removed diff --git a/vlib/v/parser/tests/fn_attributes_empty_err.out b/vlib/v/parser/tests/fn_attributes_empty_err.out index d021aee7e1..99c8578623 100644 --- a/vlib/v/parser/tests/fn_attributes_empty_err.out +++ b/vlib/v/parser/tests/fn_attributes_empty_err.out @@ -1,5 +1,5 @@ vlib/v/parser/tests/fn_attributes_empty_err.vv:1:1: error: attributes cannot be empty - 1 | [] fn tt() { - | ~~ + 1 | @[] fn tt() { + | ~~~ 2 | println('text') 3 | } diff --git a/vlib/v/parser/tests/fn_attributes_empty_err.vv b/vlib/v/parser/tests/fn_attributes_empty_err.vv index fd584c2972..e71f63d496 100644 --- a/vlib/v/parser/tests/fn_attributes_empty_err.vv +++ b/vlib/v/parser/tests/fn_attributes_empty_err.vv @@ -1,6 +1,6 @@ -[] fn tt() { +@[] fn tt() { println('text') } fn main() { tt() -} \ No newline at end of file +} diff --git a/vlib/v/parser/tests/struct_field_required_fn_option_type.vv b/vlib/v/parser/tests/struct_field_required_fn_option_type.vv index d33fdb4413..6adde85cd5 100644 --- a/vlib/v/parser/tests/struct_field_required_fn_option_type.vv +++ b/vlib/v/parser/tests/struct_field_required_fn_option_type.vv @@ -1,5 +1,5 @@ struct Foo { - foo fn () ? [required] + foo fn () ? @[required] } fn main() { diff --git a/vlib/v/parser/tests/struct_field_required_fn_result_type.vv b/vlib/v/parser/tests/struct_field_required_fn_result_type.vv index 3892fb63bf..cf017f42b4 100644 --- a/vlib/v/parser/tests/struct_field_required_fn_result_type.vv +++ b/vlib/v/parser/tests/struct_field_required_fn_result_type.vv @@ -1,5 +1,5 @@ struct Foo { - foo fn() ! [required] + foo fn() ! @[required] } fn main() { diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 4f39de161c..f82654a394 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -1181,7 +1181,7 @@ fn (mut w Worker[T]) process_incoming_requests() { @[params] pub struct PoolParams[T] { - handler fn () T [required] = unsafe { nil } + handler fn () T = unsafe { nil } @[required] nr_workers int = runtime.nr_jobs() }