1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix condition for checking if tmpl var is inherited

This commit is contained in:
Joe Conigliaro 2022-04-08 18:25:08 +10:00
parent e1c8b07fa5
commit 426e9d1734
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -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