@@ -465,7 +465,7 @@ def _emit_stmt(
465465 uop : CodeSection ,
466466 storage : Storage ,
467467 inst : Instruction | None ,
468- ) -> tuple [bool , Token , Storage ]:
468+ ) -> tuple [bool , Token | None , Storage ]:
469469 if isinstance (stmt , SimpleStmt ):
470470 return self ._emit_simple (stmt , uop , storage , inst )
471471 elif isinstance (stmt , BlockStmt ):
@@ -488,17 +488,16 @@ def _emit_simple(
488488 uop : CodeSection ,
489489 storage : Storage ,
490490 inst : Instruction | None ,
491- ) -> tuple [bool , Token , Storage ]:
491+ ) -> tuple [bool , Token | None , Storage ]:
492492 local_stores = set (uop .local_stores )
493493 reachable = True
494- tkn_iter = TokenIterator (stmt .contents )
495- tkn = tkn_iter .peek ()
496494 try :
497495 if stmt in uop .properties .escaping_calls :
498496 escape = uop .properties .escaping_calls [stmt ]
499497 if escape .kills is not None :
500498 self .stackref_kill (escape .kills , storage , True )
501499 self .emit_save (storage )
500+ tkn_iter = TokenIterator (stmt .contents )
502501 for tkn in tkn_iter :
503502 if tkn .kind == "GOTO" :
504503 label_tkn = next (tkn_iter )
@@ -538,11 +537,11 @@ def _emit_simple(
538537
539538 def _emit_macro_if (
540539 self ,
541- stmt : IfStmt ,
540+ stmt : MacroIfStmt ,
542541 uop : CodeSection ,
543542 storage : Storage ,
544543 inst : Instruction | None ,
545- ) -> tuple [bool , Token , Storage ]:
544+ ) -> tuple [bool , Token | None , Storage ]:
546545 self .out .emit (stmt .condition )
547546 branch = stmt .else_ is not None
548547 reachable = True
@@ -554,7 +553,9 @@ def _emit_macro_if(
554553 reachable = False
555554 if branch :
556555 else_storage = storage .copy ()
556+ assert stmt .else_ is not None
557557 self .out .emit (stmt .else_ )
558+ assert stmt .else_body is not None
558559 for s in stmt .else_body :
559560 r , tkn , else_storage = self ._emit_stmt (s , uop , else_storage , inst )
560561 if tkn is not None :
@@ -572,7 +573,7 @@ def _emit_if(
572573 uop : CodeSection ,
573574 storage : Storage ,
574575 inst : Instruction | None ,
575- ) -> tuple [bool , Token , Storage ]:
576+ ) -> tuple [bool , Token | None , Storage ]:
576577 self .out .emit (stmt .if_ )
577578 for tkn in stmt .condition :
578579 self .out .emit (tkn )
@@ -604,6 +605,7 @@ def _emit_if(
604605 return reachable , rbrace , storage
605606 except StackError as ex :
606607 self ._print_storage (if_storage )
608+ assert rbrace is not None
607609 raise analysis_error (ex .args [0 ], rbrace ) from None
608610
609611 def _emit_block (
@@ -627,7 +629,9 @@ def _emit_block(
627629 break
628630 return reachable , stmt .close , storage
629631 except StackError as ex :
630- raise analysis_error (ex .args [0 ], rbrace ) from None
632+ if tkn is None :
633+ tkn = stmt .close
634+ raise analysis_error (ex .args [0 ], tkn ) from None
631635
632636 def _emit_for (
633637 self ,
@@ -665,6 +669,7 @@ def emit_tokens(
665669 ) -> Storage :
666670 self .out .start_line ()
667671 reachable , tkn , storage = self ._emit_block (code .body , code , storage , inst , emit_braces )
672+ assert tkn is not None
668673 try :
669674 if reachable :
670675 self ._print_storage (storage )
0 commit comments