From b137e58593e7600510b8bb8d1c26c5d0241b7edf Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 25 Mar 2009 15:23:46 -0700 Subject: [PATCH] better error when user-declared type conflicts with builtin type (#170) --- Cython/Compiler/Builtin.py | 4 ++++ Cython/Compiler/Nodes.py | 6 ++++++ tests/errors/builtin_type_conflict_T170.pyx | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/errors/builtin_type_conflict_T170.pyx diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index 3140b533..30728d09 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -340,10 +340,14 @@ def init_builtin_funcs(): for desc in builtin_function_table: declare_builtin_func(*desc) +builtin_types = {} + def init_builtin_types(): + global builtin_types for name, cname, funcs in builtin_types_table: utility = builtin_utility_code.get(name) the_type = builtin_scope.declare_builtin_type(name, cname, utility) + builtin_types[name] = the_type for name, args, ret, cname in funcs: sig = Signature(args, ret) the_type.scope.declare_cfunction(name, sig.function_type(), None, cname) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b30e29f7..dc766a31 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2676,6 +2676,12 @@ class CClassDefNode(ClassDefNode): return else: home_scope = env + + if self.visibility == 'extern': + if self.module_name == '__builtin__' and self.class_name in Builtin.builtin_types: + error(self.pos, "%s already a builtin Cython type" % self.class_name) + return + self.entry = home_scope.declare_c_class( name = self.class_name, pos = self.pos, diff --git a/tests/errors/builtin_type_conflict_T170.pyx b/tests/errors/builtin_type_conflict_T170.pyx new file mode 100644 index 00000000..c1c8ac90 --- /dev/null +++ b/tests/errors/builtin_type_conflict_T170.pyx @@ -0,0 +1,8 @@ +cdef extern from *: + ctypedef class __builtin__.list [object PyListObject]: + pass + +cdef list foo = [] +_ERRORS = u""" +:2:4: list already a builtin Cython type +""" -- 2.26.2