1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: support @STRUCT in static methods

This commit is contained in:
Delyan Angelov 2023-07-24 13:14:52 +03:00
parent b29a084257
commit d4bedebace
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 8 additions and 1 deletions

View File

@ -3203,7 +3203,7 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
node.val = c.table.cur_fn.mod
}
.struct_name {
if c.table.cur_fn.is_method {
if c.table.cur_fn.is_method || c.table.cur_fn.is_static_type_method {
node.val = c.table.type_to_str(c.table.cur_fn.receiver.typ).all_after_last('.')
} else {
node.val = ''

View File

@ -19,6 +19,11 @@ fn (mut t TestStruct) test_struct_w_high_order(cb fn (int) string) string {
return 'test' + cb(2)
}
fn TestStruct.static_method() string {
assert @STRUCT == 'TestStruct'
return @STRUCT
}
struct Abc {
}
@ -112,6 +117,8 @@ fn test_at_struct() {
})
assert r1 == 'test'
assert r2 == 'test2'
assert TestStruct.static_method() == 'TestStruct'
assert @STRUCT == ''
}
fn test_vmod_file() {