Skip to content

Commit f4e9e1a

Browse files
committed
Add some missing syntax warnings to parser
1 parent e33c005 commit f4e9e1a

File tree

1 file changed

+19
-7
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl

1 file changed

+19
-7
lines changed

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -2158,8 +2158,11 @@ public Void visit(ExprTy.UnaryOp node) {
21582158

21592159
@Override
21602160
public Void visit(ExprTy.Yield node) {
2161-
beginSourceSection(node, b);
2161+
if (!scope.isFunction()) {
2162+
ctx.errorCallback.onError(ErrorType.Syntax, currentLocation, "'yield' outside function");
2163+
}
21622164

2165+
beginSourceSection(node, b);
21632166
emitYield((statementCompiler) -> {
21642167
if (node.value != null) {
21652168
node.value.accept(this);
@@ -2174,6 +2177,13 @@ public Void visit(ExprTy.Yield node) {
21742177

21752178
@Override
21762179
public Void visit(ExprTy.YieldFrom node) {
2180+
if (!scope.isFunction()) {
2181+
ctx.errorCallback.onError(ErrorType.Syntax, currentLocation, "'yield' outside function");
2182+
}
2183+
if (scopeType == CompilationScope.AsyncFunction) {
2184+
ctx.errorCallback.onError(ErrorType.Syntax, currentLocation, "'yield from' inside async function");
2185+
}
2186+
21772187
beginSourceSection(node, b);
21782188
emitYieldFrom(() -> {
21792189
b.beginGetYieldFromIter();
@@ -4486,22 +4496,24 @@ public Void visit(WithItemTy node) {
44864496

44874497
@Override
44884498
public Void visit(StmtTy.Break aThis) {
4489-
beginSourceSection(aThis, b);
4499+
if (breakLabel == null) {
4500+
ctx.errorCallback.onError(ErrorType.Syntax, currentLocation, "'break' outside loop");
4501+
}
44904502

4491-
assert breakLabel != null;
4503+
beginSourceSection(aThis, b);
44924504
b.emitBranch(breakLabel);
4493-
44944505
endSourceSection(b);
44954506
return null;
44964507
}
44974508

44984509
@Override
44994510
public Void visit(StmtTy.Continue aThis) {
4500-
beginSourceSection(aThis, b);
4511+
if (continueLabel == null) {
4512+
ctx.errorCallback.onError(ErrorType.Syntax, currentLocation, "'continue' not properly in loop");
4513+
}
45014514

4502-
assert continueLabel != null;
4515+
beginSourceSection(aThis, b);
45034516
b.emitBranch(continueLabel);
4504-
45054517
endSourceSection(b);
45064518
return null;
45074519
}

0 commit comments

Comments
 (0)