Repository: cython/cython

Issue:
Mysterious error with conflicting types
If you declare, for example, _operands to be a list, and cdef _operands(self) to be a function in the same class, mysterious errors can be produced such as:

```
Traceback (most recent call last):
  File "/home/gfurnish/sage-3.0.6/local/bin/cython", line 8, in <module>
    main(command_line = 1)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 527, in main
    result = compile(sources, options)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 505, in compile
    return compile_multiple(source, options)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 472, in compile_multiple
    result = context.compile(source, options)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 327, in compile
    tree.process_implementation(scope, options, result)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/ModuleNode.py", line 59, in process_implementation
    self.generate_c_code(env, options, result)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/ModuleNode.py", line 243, in generate_c_code
    self.body.generate_function_definitions(env, code, options.transforms)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 252, in generate_function_definitions
    stat.generate_function_definitions(env, code, transforms)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 2051, in generate_function_definitions
    self.entry.type.scope, code, transforms)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 252, in generate_function_definitions
    stat.generate_function_definitions(env, code, transforms)
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 892, in generate_function_definitions
    exc_check = self.caller_will_check_exceptions()
  File "/home/gfurnish/sage-3.0.6/local/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 1162, in caller_will_check_exceptions
    return self.entry.type.exception_check
AttributeError: BuiltinObjectType instance has no attribute 'exception_check'
```

Migrated from http://trac.cython.org/ticket/43



Discussion:
@robertwb changed **milestone** to `0.9.8.2`
commented

@robertwb changed **milestone** from `0.10` to `0.11`
commented

@dagss commented

I'm not able to reproduce this?

@robertwb changed **milestone** from `0.11` to `0.11.1`
**priority** from `major` to `minor`
commented

It doesn't crash for me either, but perhaps it should be raising an error here...

@robertwb changed **milestone** from `0.11.1` to `wishlist`
commented


Resolving patch:
diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py
--- a/Cython/Compiler/Symtab.py
+++ b/Cython/Compiler/Symtab.py
@@ -2439,7 +2439,8 @@ def declare_cfunction(self, name, type, pos,
             cname = punycodify_name(c_safe_identifier(name), Naming.unicode_vtabentry_prefix)
         if entry:
             if not entry.is_cfunction:
-                warning(pos, "'%s' redeclared  " % name, 0)
+                error(pos, "'%s' redeclared " % name)
+                entry.already_declared_here()
             else:
                 if defining and entry.func_cname:
                     error(pos, "'%s' already defined" % name)


Test patch:
diff --git a/tests/errors/redeclaration_of_var_by_cfunc_T600.pyx b/tests/errors/redeclaration_of_var_by_cfunc_T600.pyx
new file mode 100644
--- /dev/null
+++ b/tests/errors/redeclaration_of_var_by_cfunc_T600.pyx
@@ -0,0 +1,14 @@
+# ticket: 600
+# mode: error
+
+cdef class Bar:
+    cdef list _operands
+
+    cdef int _operands(self):
+        return -1
+
+
+_ERRORS = """
+7:9: '_operands' redeclared
+5:14: Previous declaration is here
+"""