-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix interception of return statements in closures #100
Fix interception of return statements in closures #100
Conversation
@@ -498,10 +498,13 @@ private Expression innerTransform(Expression exp) { | |||
} | |||
boolean old = visitingClosureBody; | |||
visitingClosureBody = true; | |||
ClassNode oldMethodReturnType = methodReturnType; | |||
methodReturnType = ClassHelper.OBJECT_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"@groovy.transform.Field\n" + | ||
"private static final field = [\n" + | ||
" key: { x -> return x == 123 }\n" + | ||
"]\n" + | ||
"field.key(123)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script used to throw an NPE during compilation in the sandbox.
"File method() {\n" + | ||
" def field = [\n" + | ||
" key: { x -> return x }\n" + | ||
" ]\n" + | ||
" result = field.key(['secret.key'])\n" + | ||
" null\n" + | ||
"}\n" + | ||
"method()\n" + | ||
"result", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script used to return an instance of File
(and intercept the File
constructor call) in the sandbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. Tests make sense to me.
Fixes #99
The code related to intercepting implicit Groovy casts in method return values in 5202432 caused two related bugs for closure expressions with explicit return statements:
@Field
) and have explicit return statements cause an NPE during compilation