mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: add support for static methods in @FN
and @METHOD
(#21990)
This commit is contained in:
parent
3ca5bc3bcd
commit
06cf796b21
2 changed files with 14 additions and 1 deletions
|
@ -3546,8 +3546,12 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
|||
if c.table.cur_fn == unsafe { nil } {
|
||||
return ast.void_type
|
||||
}
|
||||
if _ := c.table.cur_fn.name.index('__static__') {
|
||||
node.val = c.table.cur_fn.name.all_after_last('__static__')
|
||||
} else {
|
||||
node.val = c.table.cur_fn.name.all_after_last('.')
|
||||
}
|
||||
}
|
||||
.method_name {
|
||||
if c.table.cur_fn == unsafe { nil } {
|
||||
return ast.void_type
|
||||
|
@ -3556,6 +3560,8 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
|||
if c.table.cur_fn.is_method {
|
||||
node.val = c.table.type_to_str(c.table.cur_fn.receiver.typ).all_after_last('.') +
|
||||
'.' + fname
|
||||
} else if _ := fname.index('__static__') {
|
||||
node.val = fname.all_before('__static__') + '.' + fname.all_after('__static__')
|
||||
} else {
|
||||
node.val = fname
|
||||
}
|
||||
|
|
|
@ -60,6 +60,12 @@ fn (mut t TestFn) tst_2(cb fn (int)) {
|
|||
cb(1)
|
||||
}
|
||||
|
||||
fn TestFn.static_fn() {
|
||||
assert @FN == 'static_fn'
|
||||
assert @METHOD == 'TestFn.static_fn'
|
||||
assert @STRUCT == 'TestFn'
|
||||
}
|
||||
|
||||
fn fn_name_mod_level() {
|
||||
assert @FN == 'fn_name_mod_level'
|
||||
assert @METHOD == 'fn_name_mod_level'
|
||||
|
@ -96,6 +102,7 @@ fn test_at_fn() {
|
|||
t := i + 1
|
||||
assert t == 2
|
||||
})
|
||||
TestFn.static_fn()
|
||||
}
|
||||
|
||||
fn test_at_mod() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue