From: <zy...@us...> - 2008-08-11 02:56:55
|
Revision: 5141 http://jython.svn.sourceforge.net/jython/?rev=5141&view=rev Author: zyasoft Date: 2008-08-11 02:56:53 +0000 (Mon, 11 Aug 2008) Log Message: ----------- from X import * now raises the appropriate syntax errors (for nested scopes) or warning (otherwise). Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/compiler/ScopeInfo.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 00:32:24 UTC (rev 5140) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 02:56:53 UTC (rev 5141) @@ -768,6 +768,23 @@ code.ldc(node.module); //Note: parser does not allow node.names.length == 0 if (node.names.length == 1 && node.names[0].name.equals("*")) { + if (my_scope.func_level > 0) { + module.error("import * only allowed at module level", false, node); + + if (my_scope.contains_ns_free_vars) { + module.error("import * is not allowed in function '" + + my_scope.scope_name + + "' because it contains a nested function with free variables", + true, node); + } + } + if (my_scope.func_level > 1) { + module.error("import * is not allowed in function '" + + my_scope.scope_name + + "' because it is a nested function", + true, node); + } + loadFrame(); code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } else { Modified: branches/asm/src/org/python/compiler/ScopeInfo.java =================================================================== --- branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-11 00:32:24 UTC (rev 5140) +++ branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-11 02:56:53 UTC (rev 5141) @@ -52,6 +52,7 @@ public boolean unqual_exec; public boolean exec; public boolean from_import_star; + public boolean contains_ns_free_vars; public boolean generator; public int yield_count; public int max_with_count; @@ -179,6 +180,12 @@ names.addElement(purecells.elementAt(i)); } } + + if (some_free && nested) { + up.contains_ns_free_vars = true; + } + // XXX - this doesn't catch all cases - may depend subtly + // on how visiting NOW works with antlr compared to javacc if ((unqual_exec || from_import_star)) { if(some_inner_free) dynastuff_trouble(true, ctxt); else if(func_level > 1 && some_free) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |