From d4bedebaceedc6368e47c43660ee0138cd3af81f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 24 Jul 2023 13:14:52 +0300 Subject: [PATCH] checker: support @STRUCT in static methods --- vlib/v/checker/checker.v | 2 +- vlib/v/tests/comptime_at_test.v | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 9dcae4e486..88d894bef9 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 = '' diff --git a/vlib/v/tests/comptime_at_test.v b/vlib/v/tests/comptime_at_test.v index a34c17d2b5..839113219f 100644 --- a/vlib/v/tests/comptime_at_test.v +++ b/vlib/v/tests/comptime_at_test.v @@ -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() {