daniellansun commented on code in PR #2784:
URL: https://github.com/apache/groovy/pull/2784#discussion_r3785695674


##########
src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java:
##########
@@ -1160,26 +1141,34 @@ public void visitThrowStatement(ThrowStatement 
statement) {
                         }
                     }
 
-                    if (!(exprOrBlockStatement instanceof ReturnStatement || 
exprOrBlockStatement instanceof ThrowStatement)) {
+                    if (!(exprOrBlockStatement instanceof YieldStatement || 
exprOrBlockStatement instanceof ThrowStatement)) {
                         if (isArrow) {
-                            MethodCallExpression callClosure = callX(
-                                    configureAST(
-                                            closureX(null, 
exprOrBlockStatement),
-                                            exprOrBlockStatement
-                                    ), CALL_STR);
-                            callClosure.setImplicitThis(false);
-                            Expression resultExpr = exprOrBlockStatement 
instanceof ExpressionStatement
-                                    ? ((ExpressionStatement) 
exprOrBlockStatement).getExpression()
-                                    : callClosure;
-
-                            codeBlock = configureAST(
-                                    createBlockStatement(configureAST(
-                                            returnS(resultExpr),
-                                            exprOrBlockStatement
-                                    )),
-                                    exprOrBlockStatement
-                            );
+                            if (exprOrBlockStatement instanceof 
ExpressionStatement expressionStatement) {
+                                codeBlock = configureAST(
+                                        createBlockStatement(configureAST(
+                                                
yieldS(expressionStatement.getExpression()),
+                                                exprOrBlockStatement
+                                        )),
+                                        exprOrBlockStatement
+                                );
+                            } else if 
(!containsYieldOrThrow(exprOrBlockStatement)) {
+                                throw createParsingFailedException("`yield` or 
`throw` is expected", exprOrBlockStatement);
+                            } else {
+                                codeBlock = configureAST(
+                                        
createBlockStatement(exprOrBlockStatement),
+                                        exprOrBlockStatement
+                                );
+                            }
                         }
+                    } else if (exprOrBlockStatement instanceof YieldStatement 
|| exprOrBlockStatement instanceof ThrowStatement) {
+                        codeBlock = configureAST(
+                                createBlockStatement(exprOrBlockStatement),
+                                exprOrBlockStatement
+                        );
+                    }
+
+                    if (isArrow && 
org.codehaus.groovy.ast.tools.GeneralUtils.maybeFallsThrough(codeBlock)) {

Review Comment:
   Tweaked in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to