mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
parser: deprecate old attribute syntax & update remaining (missed) attributes (#19879)
This commit is contained in:
parent
bc24683608
commit
1e3d38255f
@ -24,7 +24,7 @@ pub mut:
|
|||||||
method Method = .get
|
method Method = .get
|
||||||
header Header
|
header Header
|
||||||
host string
|
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
|
data string
|
||||||
url string
|
url string
|
||||||
user_agent string = 'v.http'
|
user_agent string = 'v.http'
|
||||||
|
@ -5,11 +5,11 @@ interface Output[T] {
|
|||||||
|
|
||||||
struct Coil {
|
struct Coil {
|
||||||
pub mut: val int
|
pub mut: val int
|
||||||
pub: name string [required]
|
pub: name string @[required]
|
||||||
}
|
}
|
||||||
struct Light {
|
struct Light {
|
||||||
pub mut: val int
|
pub mut: val int
|
||||||
pub: name string [required]
|
pub: name string @[required]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -2,8 +2,8 @@ struct Data {
|
|||||||
mut:
|
mut:
|
||||||
n int
|
n int
|
||||||
b bool
|
b bool
|
||||||
f1 fn (voidptr) [required]
|
f1 fn (voidptr) @[required]
|
||||||
f2 fn (...voidptr) [required]
|
f2 fn (...voidptr) @[required]
|
||||||
data &Data
|
data &Data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
vlib/v/checker/tests/unknown_type_in_anon_fn.vv:5:10: error: unknown type `Another`
|
vlib/v/checker/tests/unknown_type_in_anon_fn.vv:5:10: error: unknown type `Another`
|
||||||
3 | struct Struc{
|
3 | struct Struc{
|
||||||
4 | mut:
|
4 | mut:
|
||||||
5 | f fn (s Another, i int)? [required]
|
5 | f fn (s Another, i int)? @[required]
|
||||||
| ~~~~~~~
|
| ~~~~~~~
|
||||||
6 | }
|
6 | }
|
||||||
7 |
|
7 |
|
||||||
|
@ -2,7 +2,7 @@ module main
|
|||||||
|
|
||||||
struct Struc{
|
struct Struc{
|
||||||
mut:
|
mut:
|
||||||
f fn (s Another, i int)? [required]
|
f fn (s Another, i int)? @[required]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -445,10 +445,13 @@ fn (mut p Parser) parse_type() ast.Type {
|
|||||||
|
|
||||||
if is_option || is_result {
|
if is_option || is_result {
|
||||||
// maybe the '[' is the start of the field attribute
|
// 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
|
is_required_field := p.inside_struct_field_decl && p.tok.kind == .lsbr
|
||||||
&& p.peek_tok.kind == .name && p.peek_tok.lit == 'required'
|
&& 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
|
mut typ := ast.void_type
|
||||||
if is_option {
|
if is_option {
|
||||||
typ = typ.set_flag(.option)
|
typ = typ.set_flag(.option)
|
||||||
|
@ -1812,8 +1812,10 @@ fn (mut p Parser) is_attributes() bool {
|
|||||||
|
|
||||||
// when is_top_stmt is true attrs are added to p.attrs
|
// when is_top_stmt is true attrs are added to p.attrs
|
||||||
fn (mut p Parser) attributes() {
|
fn (mut p Parser) attributes() {
|
||||||
|
start_pos := p.tok.pos()
|
||||||
mut is_at := false
|
mut is_at := false
|
||||||
if p.tok.kind == .lsbr {
|
if p.tok.kind == .lsbr {
|
||||||
|
p.note('`[attr]` has been deprecated, use `@[attr]` instead')
|
||||||
// [attr]
|
// [attr]
|
||||||
p.check(.lsbr)
|
p.check(.lsbr)
|
||||||
} else if p.tok.kind == .at {
|
} else if p.tok.kind == .at {
|
||||||
@ -1824,16 +1826,16 @@ fn (mut p Parser) attributes() {
|
|||||||
}
|
}
|
||||||
mut has_ctdefine := false
|
mut has_ctdefine := false
|
||||||
for p.tok.kind != .rsbr {
|
for p.tok.kind != .rsbr {
|
||||||
start_pos := p.tok.pos()
|
attr_start_pos := p.tok.pos()
|
||||||
attr := p.parse_attr(is_at)
|
attr := p.parse_attr(is_at)
|
||||||
if p.attrs.contains(attr.name) && attr.name != 'wasm_export' {
|
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
|
return
|
||||||
}
|
}
|
||||||
if attr.kind == .comptime_define {
|
if attr.kind == .comptime_define {
|
||||||
if has_ctdefine {
|
if has_ctdefine {
|
||||||
p.error_with_pos('only one `[if flag]` may be applied at a time `${attr.name}`',
|
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
|
return
|
||||||
} else {
|
} else {
|
||||||
has_ctdefine = true
|
has_ctdefine = true
|
||||||
@ -1851,7 +1853,7 @@ fn (mut p Parser) attributes() {
|
|||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
if p.attrs.len == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
// TODO: remove when old attr syntax is removed
|
// TODO: remove when old attr syntax is removed
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
vlib/v/parser/tests/fn_attributes_empty_err.vv:1:1: error: attributes cannot be empty
|
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')
|
2 | println('text')
|
||||||
3 | }
|
3 | }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[] fn tt() {
|
@[] fn tt() {
|
||||||
println('text')
|
println('text')
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
struct Foo {
|
struct Foo {
|
||||||
foo fn () ? [required]
|
foo fn () ? @[required]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
struct Foo {
|
struct Foo {
|
||||||
foo fn() ! [required]
|
foo fn() ! @[required]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1181,7 +1181,7 @@ fn (mut w Worker[T]) process_incoming_requests() {
|
|||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PoolParams[T] {
|
pub struct PoolParams[T] {
|
||||||
handler fn () T [required] = unsafe { nil }
|
handler fn () T = unsafe { nil } @[required]
|
||||||
nr_workers int = runtime.nr_jobs()
|
nr_workers int = runtime.nr_jobs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user