Commit 77761743 authored by Stefan Behnel's avatar Stefan Behnel

Add a warning about range(enum) iteration since it's really not a good idea...

Add a warning about range(enum) iteration since it's really not a good idea usually, so requiring an explicit cast to say "I know what I'm doing" seems best.
parent 64412f90
...@@ -6443,6 +6443,9 @@ class ForFromStatNode(LoopNode, StatNode): ...@@ -6443,6 +6443,9 @@ class ForFromStatNode(LoopNode, StatNode):
if target_type.is_numeric: if target_type.is_numeric:
loop_type = target_type loop_type = target_type
else: else:
if target_type.is_enum:
warning(self.target.pos,
"Integer loops over enum values are fragile. Please cast to a safe integer type instead.")
loop_type = PyrexTypes.c_long_type if target_type.is_pyobject else PyrexTypes.c_int_type loop_type = PyrexTypes.c_long_type if target_type.is_pyobject else PyrexTypes.c_int_type
if not self.bound1.type.is_pyobject: if not self.bound1.type.is_pyobject:
loop_type = PyrexTypes.widest_numeric_type(loop_type, self.bound1.type) loop_type = PyrexTypes.widest_numeric_type(loop_type, self.bound1.type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment