From 6ebf941f6097b835d00b06b7282dbb638674b9c6 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 4 May 2007 13:05:53 -0700 Subject: [PATCH] Added warning about infinite loops in for-from-by statement. One rarely, if ever, wants the [step] argument to be negative. --- Cython/Compiler/Nodes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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): -- 2.26.2