Skip to content

Commit ed9c087

Browse files
committed
Default except must be last
1 parent 3944116 commit ed9c087

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public abstract class ErrorMessages {
166166
public static final String COUNT_FUNC_MATH = "count function in Math";
167167
public static final String COVERAGE_TRACKER_NOT_RUNNING = "coverage tracker not running";
168168
public static final String CREATING_SOCKETS_NOT_ALLOWED = "creating sockets not allowed";
169+
public static final String DEFAULT_EXCEPT_MUST_BE_LAST = "default 'except:' must be last";
169170
public static final String DESC_S_FOR_S_DOESNT_APPLY_TO_S = "descriptor '%s' for '%s' objects doesn't apply to '%s' object";
170171
public static final String DESCRIPTOR_REQUIRES_OBJ = "descriptor '%s' requires a '%s' object but received a '%p'";
171172
public static final String DICT_CHANGED_DURING_COMPARISON = "dictionary changed during comparison operation";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/FactorySSTVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,9 @@ public PNode visit(TrySSTNode node) {
11801180
ExceptNode[] exceptNodes = new ExceptNode[node.exceptNodes.length];
11811181
for (int i = 0; i < exceptNodes.length; i++) {
11821182
ExceptSSTNode exceptNode = node.exceptNodes[i];
1183+
if (exceptNode.test == null && i < exceptNodes.length - 1) {
1184+
throw errors.raiseInvalidSyntax(source, createSourceSection(exceptNode.startOffset, exceptNode.endOffset), ErrorMessages.DEFAULT_EXCEPT_MUST_BE_LAST);
1185+
}
11831186
ExpressionNode exceptTest = exceptNode.test != null ? (ExpressionNode) exceptNode.test.accept(this) : null;
11841187
StatementNode exceptBody = (StatementNode) exceptNode.body.accept(this);
11851188
WriteNode exceptName = exceptNode.asName != null ? (WriteNode) scopeEnvironment.findVariable(exceptNode.asName).makeWriteNode(null) : null;

0 commit comments

Comments
 (0)