Skip to content

Commit a32cc36

Browse files
committed
parser,checker: support dates in @[deprecated] as alternative to @[deprecated_after]
1 parent 8342968 commit a32cc36

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

test_deprecated_with_date.v

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@[deprecated: '2025-10-10 use new function instead']
2+
fn d0() {}
3+
4+
@[deprecated: '1234567890']
5+
fn d1() {}
6+
7+
@[deprecated: '']
8+
fn d2() {}
9+
10+
@[deprecated: 'a']
11+
fn d3() {}
12+
13+
@[deprecated: 'greater than 10 chars']
14+
fn d4() {}
15+
16+
@[deprecated: '2025-10-10close']
17+
fn d5() {}
18+
19+
@[deprecated: ' 2025-10-10']
20+
fn d6() {}
21+
22+
fn main() {
23+
d0()
24+
d1()
25+
d2()
26+
d3()
27+
d4()
28+
d5()
29+
d6()
30+
}

vlib/v/checker/errors.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ fn (mut c Checker) deprecate(kind string, name string, attrs []ast.Attr, pos tok
202202
}
203203
if attr.name == 'deprecated' {
204204
deprecation_message = attr.arg
205+
left_trimmed := attr.arg.trim_left(' ')
206+
if left_trimmed.len >= 10 {
207+
if t := time.parse_iso8601(left_trimmed[..9]) {
208+
after_time = t
209+
deprecation_message = left_trimmed[10..]
210+
}
211+
}
205212
} else if attr.name == 'deprecated_after' {
206213
after_time = time.parse_iso8601(attr.arg) or {
207214
c.error('invalid time format', attr.pos)

vlib/v/parser/fn.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
227227
'manualfree' {
228228
is_manualfree = true
229229
}
230-
'deprecated' {
230+
'deprecated', 'deprecated_after' {
231231
is_deprecated = true
232232
}
233233
'direct_array_access' {

0 commit comments

Comments
 (0)