parser: make old [attr] syntax an error

This commit is contained in:
Alexander Medvednikov 2025-01-19 23:12:44 +03:00
parent 11c59cf8b9
commit f9d3bd39a6
2 changed files with 6 additions and 3 deletions

View file

@ -75,7 +75,7 @@ fn check_assert_continues_works() ! {
result.has('assert_continues_option_works_test.v:5: fn test_fail2') result.has('assert_continues_option_works_test.v:5: fn test_fail2')
result.has('> assert 2 == 4').has('> assert 2 == 1').has('> assert 2 == 0') result.has('> assert 2 == 4').has('> assert 2 == 1').has('> assert 2 == 0')
// Check if a test function, tagged with [assert_continues], has the same behaviour, without needing additional options // Check if a test function, tagged with [assert_continues], has the same behaviour, without needing additional options
create_test('assert_continues_tag_works_test.v', '[assert_continues]fn test_fail1() { assert 2==4\nassert 2==1\nassert 2==0 }\nfn test_ok(){ assert true }\nfn test_fail2() { assert false\n assert false }')! create_test('assert_continues_tag_works_test.v', '@[assert_continues]fn test_fail1() { assert 2==4\nassert 2==1\nassert 2==0 }\nfn test_ok(){ assert true }\nfn test_fail2() { assert false\n assert false }')!
tag_res := check_fail('${vexe} assert_continues_tag_works_test.v') tag_res := check_fail('${vexe} assert_continues_tag_works_test.v')
tag_res.has('assert_continues_tag_works_test.v:1: fn test_fail1') tag_res.has('assert_continues_tag_works_test.v:1: fn test_fail1')
tag_res.has('assert_continues_tag_works_test.v:2: fn test_fail1') tag_res.has('assert_continues_tag_works_test.v:2: fn test_fail1')

View file

@ -1937,12 +1937,15 @@ fn (mut p Parser) is_attributes() bool {
return true return true
} }
// 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() start_pos := p.tok.pos()
mut is_at := false mut is_at := false
if p.tok.kind == .lsbr { if p.tok.kind == .lsbr {
p.warn('`[attr]` has been deprecated, use `@[attr]` instead') if p.pref.is_fmt {
} else {
p.error('`[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 {