implement #686: turn 'undeclared builtin' error into a visible warning, look up unkno...
authorStefan Behnel <scoder@users.berlios.de>
Sat, 16 Apr 2011 05:56:15 +0000 (07:56 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 16 Apr 2011 05:56:15 +0000 (07:56 +0200)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Symtab.py
tests/run/builtinnames.pyx

index ef2911e6812a6aa545205fdbb613e38a7753d83f..c2baa8d15f26dedf0643ea5aa31db47abebfda9c 100755 (executable)
@@ -1339,7 +1339,7 @@ class NameNode(AtomicExprNode):
             if entry and entry.is_cfunction:
                 var_entry = entry.as_variable
                 if var_entry:
-                    if var_entry.is_builtin and Options.cache_builtins:
+                    if var_entry.is_builtin and var_entry.is_const:
                         var_entry = env.declare_builtin(var_entry.name, self.pos)
                     node = NameNode(self.pos, name = self.name)
                     node.entry = var_entry
@@ -1436,7 +1436,7 @@ class NameNode(AtomicExprNode):
         if entry.is_declared_generic:
             self.result_ctype = py_object_type
         if entry.is_pyglobal or entry.is_builtin:
-            if Options.cache_builtins and entry.is_builtin:
+            if entry.is_builtin and entry.is_const:
                 self.is_temp = 0
             else:
                 self.is_temp = 1
@@ -1447,7 +1447,7 @@ class NameNode(AtomicExprNode):
         if self.is_used_as_rvalue:
             entry = self.entry
             if entry.is_builtin:
-                if not Options.cache_builtins: # cached builtins are ok
+                if not entry.is_const: # cached builtins are ok
                     self.gil_error()
             elif entry.is_pyglobal:
                 self.gil_error()
@@ -1525,7 +1525,7 @@ class NameNode(AtomicExprNode):
         entry = self.entry
         if entry is None:
             return # There was an error earlier
-        if entry.is_builtin and Options.cache_builtins:
+        if entry.is_builtin and entry.is_const:
             return # Lookup already cached
         elif entry.is_pyclass_attr:
             assert entry.type.is_pyobject, "Python global or builtin not a Python object"
index f86bb164bbc1f7440c6006625ea2c14dd7547b7f..d52317bbb770d4f406612141444d058c82074946 100644 (file)
@@ -760,7 +760,7 @@ class BuiltinScope(Scope):
             if self.outer_scope is not None:
                 return self.outer_scope.declare_builtin(name, pos)
             else:
-                error(pos, "undeclared name not builtin: %s"%name)
+                warning(pos, "undeclared name not builtin: %s" % name, 2)
 
     def declare_builtin_cfunction(self, name, type, cname, python_equiv = None,
             utility_code = None):
@@ -916,10 +916,16 @@ class ModuleScope(Scope):
             if self.has_import_star:
                 entry = self.declare_var(name, py_object_type, pos)
                 return entry
-            elif self.outer_scope is not None:
-                return self.outer_scope.declare_builtin(name, pos)
+            ## elif self.outer_scope is not None:
+            ##     entry = self.outer_scope.declare_builtin(name, pos)
+            ##     print entry
+            ##     return entry
             else:
-                error(pos, "undeclared name not builtin: %s"%name)
+                # unknown - assume it's builtin and look it up at runtime
+                warning(pos, "undeclared name not builtin: %s" % name, 2)
+                entry = self.declare(name, None, py_object_type, pos, 'private')
+                entry.is_builtin = 1
+                return entry
         if Options.cache_builtins:
             for entry in self.cached_builtins:
                 if entry.name == name:
index 1d018a55aaeb05e15395ba8c7d2dd13a29d854e4..465395829f507ac913e5e833617c2b29fa86ccf2 100644 (file)
@@ -56,14 +56,3 @@ def test_for_in_range(arg):
     for c in range(arg):
         l.append(c)
     return l
-
-def raise_and_catch_BaseException():
-    """
-    >>> raise_and_catch_BaseException()
-    1
-    """
-    try:
-        raise BaseException
-    except BaseException:
-        return 1
-    return 2