# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1178775173 25200
# Node ID f08253cc52b21e7aef6b6024f7dae5f6d904a822
# Parent  1bf81c6cbca699e1df4b606ec1192acb7fe479ef
fix a basic arithmetic casting problem.

diff -r 1bf81c6cbca6 -r f08253cc52b2 sage/structure/element.pyx
--- a/sage/structure/element.pyx	Wed May 09 22:09:37 2007 -0700
+++ b/sage/structure/element.pyx	Wed May 09 22:32:53 2007 -0700
@@ -1179,6 +1179,12 @@ cdef class RingElement(ModuleElement):
             True
             sage: a^200 * a^(-64) == a^136
             True
+
+        TESTS:
+        This crashed in sage-2.5 due to a mistake in missing type below.
+            sage: 2r**(SR(2)-1-1r)
+            1
+
         """
         cdef int cn
 
@@ -1197,7 +1203,10 @@ cdef class RingElement(ModuleElement):
             # and don't benifit from the code below
             cn = n
             if cn == 0:
-                return (<Element>a)._parent(1)
+                if PY_TYPE_CHECK(a, Element):
+                    return (<Element>a)._parent(1)
+                else:
+                    return (<Element>m)._parent(a)**m
             elif cn == 1:
                 return a
             elif cn == 2:
