Skip to content

Commit

Permalink
checker: support @struct in static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jul 24, 2023
1 parent b29a084 commit d4bedeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Expand Up @@ -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 = ''
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/comptime_at_test.v
Expand Up @@ -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 {
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d4bedeb

Please sign in to comment.