@@ -714,13 +714,13 @@ def _map_index(self, length, index, one_past_the_end=False, loc=None):
714
714
715
715
return mapped_index
716
716
717
- def _make_check (self , cond , exn_gen ):
717
+ def _make_check (self , cond , exn_gen , loc = None ):
718
718
# cond: bool Value, condition
719
719
# exn_gen: lambda()->exn Value, exception if condition not true
720
720
cond_block = self .current_block
721
721
722
722
self .current_block = body_block = self .add_block ()
723
- self .raise_exn (exn_gen ())
723
+ self .raise_exn (exn_gen (), loc = loc )
724
724
725
725
self .current_block = tail_block = self .add_block ()
726
726
cond_block .append (ir .BranchIf (cond , tail_block , body_block ))
@@ -789,7 +789,8 @@ def visit_SubscriptT(self, node):
789
789
self ._make_check (
790
790
self .append (ir .Compare (ast .NotEq (loc = None ), step , ir .Constant (0 , step .type ))),
791
791
lambda : self .alloc_exn (builtins .TValueError (),
792
- ir .Constant ("step cannot be zero" , builtins .TStr ())))
792
+ ir .Constant ("step cannot be zero" , builtins .TStr ())),
793
+ loc = node .slice .step .loc )
793
794
else :
794
795
step = ir .Constant (1 , node .slice .type )
795
796
counting_up = self .append (ir .Compare (ast .Gt (loc = None ), step ,
@@ -811,7 +812,8 @@ def visit_SubscriptT(self, node):
811
812
lambda : self .alloc_exn (builtins .TValueError (),
812
813
ir .Constant ("slice size {0} is larger than iterable length {1}" ,
813
814
builtins .TStr ()),
814
- slice_size , length ))
815
+ slice_size , length ),
816
+ loc = node .slice .loc )
815
817
816
818
if self .current_assign is None :
817
819
is_neg_size = self .append (ir .Compare (ast .Lt (loc = None ),
@@ -992,20 +994,23 @@ def visit_CoerceT(self, node):
992
994
993
995
def visit_BinOpT (self , node ):
994
996
if builtins .is_numeric (node .type ):
997
+ lhs = self .visit (node .left )
995
998
rhs = self .visit (node .right )
996
999
if isinstance (node .op , (ast .LShift , ast .RShift )):
997
1000
# Check for negative shift amount.
998
1001
self ._make_check (
999
1002
self .append (ir .Compare (ast .GtE (loc = None ), rhs , ir .Constant (0 , rhs .type ))),
1000
1003
lambda : self .alloc_exn (builtins .TValueError (),
1001
- ir .Constant ("shift amount must be nonnegative" , builtins .TStr ())))
1004
+ ir .Constant ("shift amount must be nonnegative" , builtins .TStr ())),
1005
+ loc = node .right .loc )
1002
1006
elif isinstance (node .op , (ast .Div , ast .FloorDiv )):
1003
1007
self ._make_check (
1004
1008
self .append (ir .Compare (ast .NotEq (loc = None ), rhs , ir .Constant (0 , rhs .type ))),
1005
1009
lambda : self .alloc_exn (builtins .TZeroDivisionError (),
1006
- ir .Constant ("cannot divide by zero" , builtins .TStr ())))
1010
+ ir .Constant ("cannot divide by zero" , builtins .TStr ())),
1011
+ loc = node .right .loc )
1007
1012
1008
- return self .append (ir .Arith (node .op , self . visit ( node . left ) , rhs ))
1013
+ return self .append (ir .Arith (node .op , lhs , rhs ))
1009
1014
elif isinstance (node .op , ast .Add ): # list + list, tuple + tuple
1010
1015
lhs , rhs = self .visit (node .left ), self .visit (node .right )
1011
1016
if types .is_tuple (node .left .type ) and types .is_tuple (node .right .type ):
0 commit comments