Skip to content

Commit 147f163

Browse files
authored
feat: mark lowering state options as kwargs (#361)
we have been using this convention, just making it more explicit. We also allow `State` to be missing the source information because this is not always available.
1 parent d274308 commit 147f163

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/kirin/lowering/state.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class State(Generic[ASTNodeType]):
3636

3737
parent: LoweringABC[ASTNodeType]
3838
"""the parent lowering transform"""
39-
source: SourceInfo
39+
source: SourceInfo | None = field(default=None, kw_only=True)
4040
"source info of the current node"
41-
lines: list[str]
41+
lines: list[str] = field(default_factory=list, kw_only=True)
4242
"source lines of the code being lowered"
43-
file: str | None = None
43+
file: str | None = field(default=None, kw_only=True)
4444
"file name of the current node"
45-
lineno_offset: int = 0
45+
lineno_offset: int = field(default=0, kw_only=True)
4646
"lineno offset at the beginning of the source"
47-
col_offset: int = 0
47+
col_offset: int = field(default=0, kw_only=True)
4848
"column offset at the beginning of the source"
4949
_current_frame: Frame | None = field(default=None, init=False, repr=False)
5050
"current frame being lowered"
@@ -213,6 +213,9 @@ def error_hint(
213213
Returns:
214214
str: The generated error hint.
215215
"""
216+
if self.source is None:
217+
return str(e)
218+
216219
return self.source.error_hint(
217220
self.lines,
218221
e,

0 commit comments

Comments
 (0)