Skip to content

Commit 41ca072

Browse files
committed
Ensure JythonScriptParser.parseAST always returns at the very least an empty Scope.
Facilitates code that consumes Scope instances.
1 parent 1241770 commit 41ca072

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎src/main/java/org/scijava/plugins/scripteditor/jython/JythonScriptParser.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ static public Scope parseAST(final String code) {
8686
// Therefore, remove the last line, which would fail to parse because it is incomplete
8787
try {
8888
final mod m = ParserFacade.parse(code, CompileMode.exec, "<none>", new CompilerFlags());
89-
return parseNode(m.getChildren(), null, null);
89+
final Scope scope = parseNode(m.getChildren(), null, null);
90+
return null == scope ? new Scope(null) : scope;
9091
} catch (Throwable t) {
9192
JythonDev.printError(t);
9293
return new Scope(null);
@@ -103,7 +104,7 @@ static public Scope parseAST(final String code) {
103104
* @return A new {@code Scope} containing {@code DotAutocompletions} to represent each statement.
104105
*/
105106
static public Scope parseNode(final List<PythonTree> children, final Scope parent, final String className) {
106-
if (null == children) return parent;
107+
if (null == children) return parent; // will return null if parent is null
107108
final Scope scope = new Scope(parent, className);
108109
parseNode(scope, children, className);
109110
return scope;

0 commit comments

Comments
 (0)