From: Robert Bradshaw Date: Fri, 4 May 2007 20:05:53 +0000 (-0700) Subject: Added warning about infinite loops in for-from-by statement. X-Git-Tag: 0.9.6.14~29^2~185 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6ebf941f6097b835d00b06b7282dbb638674b9c6;p=cython.git Added warning about infinite loops in for-from-by statement. One rarely, if ever, wants the [step] argument to be negative. --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 6947fb85..ebbe9f3c 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -5,7 +5,7 @@ import os, string, sys, time import Code -from Errors import error, InternalError +from Errors import error, warning, InternalError import Naming import PyrexTypes from PyrexTypes import py_object_type, error_type, CTypedefType @@ -3320,6 +3320,8 @@ class ForFromStatNode(StatNode): self.bound1 = self.bound1.coerce_to_integer(env) self.bound2 = self.bound2.coerce_to_integer(env) if self.step is not None: + if isinstance(self.step, ExprNodes.UnaryMinusNode): + warning(self.step.pos, "Probable infinite loop in for-from-by statment. Consider switching the directions of the relations.", 2) self.step.analyse_types(env) self.step = self.step.coerce_to_integer(env) if not (self.bound2.is_name or self.bound2.is_literal):