@@ -429,7 +429,7 @@ def visit_get_attr(self, op: GetAttr) -> None:
429429 ):
430430 # Generate code for the following branch here to avoid
431431 # redundant branches in the generated code.
432- self .emit_attribute_error (branch , cl . name , op .attr )
432+ self .emit_attribute_error (branch , cl , op .attr )
433433 self .emit_line ("goto %s;" % self .label (branch .true ))
434434 merged_branch = branch
435435 self .emitter .emit_line ("}" )
@@ -937,20 +937,32 @@ def emit_traceback(self, op: Branch) -> None:
937937 if op .traceback_entry is not None :
938938 self .emitter .emit_traceback (self .source_path , self .module_name , op .traceback_entry )
939939
940- def emit_attribute_error (self , op : Branch , class_name : str , attr : str ) -> None :
940+ def emit_attribute_error (self , op : Branch , class_ir : ClassIR , attr : str ) -> None :
941941 assert op .traceback_entry is not None
942942 globals_static = self .emitter .static_name ("globals" , self .module_name )
943- self .emit_line (
944- 'CPy_AttributeError("%s", "%s", "%s", "%s", %d, %s);'
945- % (
946- self .source_path .replace ("\\ " , "\\ \\ " ),
947- op .traceback_entry [0 ],
948- class_name ,
949- attr .removeprefix (GENERATOR_ATTRIBUTE_PREFIX ),
950- op .traceback_entry [1 ],
951- globals_static ,
943+ if class_ir .is_generated :
944+ self .emit_line (
945+ 'CPy_UnboundLocalError("%s", "%s", "%s", "%s", %d, %s);'
946+ % (
947+ self .source_path .replace ("\\ " , "\\ \\ " ),
948+ op .traceback_entry [0 ],
949+ attr .removeprefix (GENERATOR_ATTRIBUTE_PREFIX ),
950+ op .traceback_entry [1 ],
951+ globals_static ,
952+ )
953+ )
954+ else :
955+ self .emit_line (
956+ 'CPy_AttributeError("%s", "%s", "%s", "%s", %d, %s);'
957+ % (
958+ self .source_path .replace ("\\ " , "\\ \\ " ),
959+ op .traceback_entry [0 ],
960+ class_ir .name ,
961+ attr .removeprefix (GENERATOR_ATTRIBUTE_PREFIX ),
962+ op .traceback_entry [1 ],
963+ globals_static ,
964+ )
952965 )
953- )
954966 if DEBUG_ERRORS :
955967 self .emit_line ('assert(PyErr_Occurred() != NULL && "failure w/o err!");' )
956968
0 commit comments