Skip to content

Commit b9d1f02

Browse files
fix: Fix region of first variable in decl to include let
1 parent d62a528 commit b9d1f02

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

parser/astgen/astgen.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .ast_node import *
99
from .eval_literal import eval_number, eval_string
1010
from .errors import LocatedAstError
11-
from ..common import region_union, RegionUnionArgT, HasRegion
11+
from ..common import region_union, RegionUnionArgT, HasRegion, StrRegion
1212
from ..cst.base_node import AnyNode, Node, Leaf
1313
from ..cst.named_node import NamedLeafCls, NamedNodeCls, NamedSizedNodeCls
1414
from ..cst.nodes import *
@@ -138,11 +138,17 @@ def _walk_var_decl(self, smt: DeclNode):
138138
else VarDeclScope.GLOBAL)
139139
tp = (VarType.LIST if isinstance(smt.decl_type, DeclType_List)
140140
else VarType.VARIABLE)
141-
return [self._walk_single_decl(d, scope, tp) for d in smt.decl_list.decls]
142-
143-
def _walk_single_decl(self, d: DeclItemNode, scope: VarDeclScope, tp: VarType):
141+
# Add the region from the keywords to first decl (to make single-var
142+
# decls a more sensible .region that includes the `let` keyword as well)
143+
extra_region_first = region_union(smt.decl_scope, smt.decl_type)
144+
return [self._walk_single_decl(d, scope, tp,
145+
extra_region_first if i == 0 else None)
146+
for i, d in enumerate(smt.decl_list.decls)]
147+
148+
def _walk_single_decl(self, d: DeclItemNode, scope: VarDeclScope,
149+
tp: VarType, extra_region: StrRegion | None):
144150
return AstDeclNode(
145-
region_union(d.ident, d.value),
151+
region_union(d.ident, d.value, extra_region),
146152
scope, tp, self._walk_ident(d.ident),
147153
None if d.value is None else self._walk_expr(d.value))
148154

0 commit comments

Comments
 (0)