diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 6a0af44a5e..056e93368d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3605,6 +3605,11 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) table.Type { if node.method_name == 'html' { return c.table.find_type_idx('vweb.Result') } + mut var := c.fn_scope.objects[node.method_name] + if mut var is ast.Var { + var.is_used = true + c.fn_scope.objects[node.method_name] = var + } return table.string_type } diff --git a/vlib/v/checker/tests/comptime_call_no_unused_var.out b/vlib/v/checker/tests/comptime_call_no_unused_var.out new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/vlib/v/checker/tests/comptime_call_no_unused_var.out @@ -0,0 +1 @@ + diff --git a/vlib/v/checker/tests/comptime_call_no_unused_var.vv b/vlib/v/checker/tests/comptime_call_no_unused_var.vv new file mode 100644 index 0000000000..51027324eb --- /dev/null +++ b/vlib/v/checker/tests/comptime_call_no_unused_var.vv @@ -0,0 +1,11 @@ +struct Test {} + +fn (test Test) print() { + println('test') +} + +fn main() { + test := Test{} + abc := 'print' + test.$abc() +} \ No newline at end of file