cython-devel
changeset 1881:dc7359d237b9
better error when user-declared type conflicts with builtin type (#170)
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Wed Mar 25 15:23:46 2009 -0700 (2 years ago) |
| parents | 3aac44b1f28a |
| children | ae066635bb30 |
| files | Cython/Compiler/Builtin.py Cython/Compiler/Nodes.py tests/errors/builtin_type_conflict_T170.pyx |
line diff
1.1 --- a/Cython/Compiler/Builtin.py Wed Mar 25 15:00:06 2009 -0700
1.2 +++ b/Cython/Compiler/Builtin.py Wed Mar 25 15:23:46 2009 -0700
1.3 @@ -340,10 +340,14 @@
1.4 for desc in builtin_function_table:
1.5 declare_builtin_func(*desc)
1.6
1.7 +builtin_types = {}
1.8 +
1.9 def init_builtin_types():
1.10 + global builtin_types
1.11 for name, cname, funcs in builtin_types_table:
1.12 utility = builtin_utility_code.get(name)
1.13 the_type = builtin_scope.declare_builtin_type(name, cname, utility)
1.14 + builtin_types[name] = the_type
1.15 for name, args, ret, cname in funcs:
1.16 sig = Signature(args, ret)
1.17 the_type.scope.declare_cfunction(name, sig.function_type(), None, cname)
2.1 --- a/Cython/Compiler/Nodes.py Wed Mar 25 15:00:06 2009 -0700
2.2 +++ b/Cython/Compiler/Nodes.py Wed Mar 25 15:23:46 2009 -0700
2.3 @@ -2676,6 +2676,12 @@
2.4 return
2.5 else:
2.6 home_scope = env
2.7 +
2.8 + if self.visibility == 'extern':
2.9 + if self.module_name == '__builtin__' and self.class_name in Builtin.builtin_types:
2.10 + error(self.pos, "%s already a builtin Cython type" % self.class_name)
2.11 + return
2.12 +
2.13 self.entry = home_scope.declare_c_class(
2.14 name = self.class_name,
2.15 pos = self.pos,
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/errors/builtin_type_conflict_T170.pyx Wed Mar 25 15:23:46 2009 -0700
3.3 @@ -0,0 +1,8 @@
3.4 +cdef extern from *:
3.5 + ctypedef class __builtin__.list [object PyListObject]:
3.6 + pass
3.7 +
3.8 +cdef list foo = []
3.9 +_ERRORS = u"""
3.10 +:2:4: list already a builtin Cython type
3.11 +"""
