From 426e9d1734676bdf9e554ee1b1cc323a224095fd Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Fri, 8 Apr 2022 18:25:08 +1000 Subject: [PATCH] checker: fix condition for checking if tmpl var is inherited --- vlib/v/checker/checker.v | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 17a8e0429f..2687a3d858 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3107,14 +3107,15 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type { ast.Var { // inside vweb tmpl ident positions are meaningless, use the position of the comptime call. // if the variable is declared before the comptime call then we can assume all is well. - // `node.name !in node.scope.objects` checks it's an inherited var (not defined in the tmpl). - node_pos := if c.pref.is_vweb && node.name !in node.scope.objects { + // `node.name !in node.scope.objects && node.scope.start_pos < c.comptime_call_pos` (inherited) + node_pos := if c.pref.is_vweb && node.name !in node.scope.objects + && node.scope.start_pos < c.comptime_call_pos { c.comptime_call_pos } else { node.pos.pos } if node_pos < obj.pos.pos { - c.error('undefined variable `$node.name` (used before declaration)', + c.error('undefined variable `$node.name` (used before declaration) # $node_pos < $obj.pos.pos | $node.pos.pos', node.pos) } is_sum_type_cast := obj.smartcasts.len != 0