fmt: fix eating the attribute from @[deprecated] pub type Alias = int (fix #24968), workaround -usecache bug (#24969)

This commit is contained in:
Delyan Angelov 2025-07-25 10:57:52 +03:00 committed by GitHub
parent 73db18bc0d
commit 6fb46cc30f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 0 deletions

View File

@ -131,12 +131,19 @@ fn build_fast_tcc() {
fn v_self_compilation_usecache_tcc() {
exec('unset VFLAGS')
exec('v wipe-cache')
exec('v -usecache examples/hello_world.v')
exec('./examples/hello_world')
exec('v wipe-cache')
exec('v -o v2 -usecache cmd/v')
exec('./v2 -o v3 -usecache cmd/v')
exec('./v3 version')
exec('v wipe-cache')
exec('./v3 -o tetris -usecache examples/tetris/tetris.v')
exec('rm -f ./examples/hello_world v2 v3 tetris')
}
fn test_password_input_tcc() {
@ -198,13 +205,18 @@ fn v_self_compilation_gcc() {
fn v_self_compilation_usecache_gcc() {
exec('unset VFLAGS')
exec('v wipe-cache')
exec('v -usecache examples/hello_world.v')
exec('examples/hello_world')
exec('v wipe-cache')
exec('v -o v2 -usecache cmd/v')
exec('./v2 -o v3 -usecache cmd/v')
exec('./v3 version')
exec('v wipe-cache')
exec('./v3 -o tetris -usecache examples/tetris/tetris.v')
exec('rm -f ./examples/hello_world v2 v3 tetris')
}
fn verify_v_test_works_gcc() {
@ -312,11 +324,17 @@ fn v_self_compilation_clang() {
fn v_self_compilation_usecache_clang() {
exec('unset VFLAGS')
exec('v wipe-cache')
exec('v -usecache examples/hello_world.v')
exec('./examples/hello_world')
exec('v wipe-cache')
exec('v -o v2 -usecache cmd/v')
exec('./v2 -o v3 -usecache cmd/v')
exec('./v3 version')
exec('v wipe-cache')
exec('./v3 -o tetris -usecache examples/tetris/tetris.v')
exec('rm -f ./examples/hello_world v2 v3 tetris')
}

View File

@ -3,6 +3,7 @@ module time
// A lot of these are taken from the Go library.
pub type Duration = i64
@[markused]
pub const nanosecond = Duration(1)
pub const microsecond = Duration(1000 * nanosecond)
pub const millisecond = Duration(1000 * microsecond)

View File

@ -1483,6 +1483,7 @@ pub:
pos token.Pos
type_pos token.Pos
comments []Comment
attrs []Attr // attributes like @[deprecated] etc
pub mut:
parent_type Type
is_markused bool

View File

@ -1686,6 +1686,7 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
}
pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
f.attrs(node.attrs)
if node.is_pub {
f.write('pub ')
}

View File

@ -30,3 +30,7 @@ enum Example {
value1 = 1
value1_again = 1
}
@[deprecated: 'use Example instead']
@[deprecated_after: '2040-01-24']
pub type Alias = Example

View File

@ -2749,6 +2749,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
return ast.AliasTypeDecl{}
}
comments = sum_variants[0].end_comments.clone()
p.attrs = []
return ast.AliasTypeDecl{
name: name
is_pub: is_pub
@ -2758,6 +2759,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
pos: decl_pos
comments: comments
is_markused: attrs.contains('markused')
attrs: attrs
}
}