Skip to content
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

Working on #13486 #13598

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import grails.web.controllers.ControllerMethod;
import groovy.lang.Closure;
import groovy.transform.CompilationUnitAware;
import org.apache.groovy.ast.tools.AnnotatedNodeUtils;
import org.apache.groovy.ast.tools.ClassNodeUtils;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotationNode;
Expand Down Expand Up @@ -98,6 +97,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import static org.codehaus.groovy.ast.tools.GeneralUtils.*;
import static org.grails.compiler.injection.GrailsASTUtils.applyDefaultMethodTarget;
import static org.grails.compiler.injection.GrailsASTUtils.applyMethodTarget;
import static org.grails.compiler.injection.GrailsASTUtils.buildGetMapExpression;
Expand Down Expand Up @@ -843,16 +843,11 @@ protected void initializeAndValidateCommandObjectParameter(final BlockStatement

protected void initializeCommandObjectParameter(final BlockStatement wrapper,
final ClassNode commandObjectNode, final String paramName, SourceUnit source) {

final ArgumentListExpression initializeCommandObjectArguments = new ArgumentListExpression();
initializeCommandObjectArguments.addExpression(new ClassExpression(commandObjectNode));
initializeCommandObjectArguments.addExpression(new ConstantExpression(paramName));
final MethodCallExpression initializeCommandObjectMethodCall = new MethodCallExpression(new VariableExpression("this"), "initializeCommandObject", initializeCommandObjectArguments);
final ArgumentListExpression initializeCommandObjectArguments = args(classX(commandObjectNode), constX(paramName));
final MethodCallExpression initializeCommandObjectMethodCall = callThisX("initializeCommandObject", initializeCommandObjectArguments);
applyDefaultMethodTarget(initializeCommandObjectMethodCall, commandObjectNode);

final Expression assignCommandObjectToParameter = new BinaryExpression(new VariableExpression(paramName), Token.newSymbol(Types.EQUALS, 0, 0), initializeCommandObjectMethodCall);

wrapper.addStatement(new ExpressionStatement(assignCommandObjectToParameter));
final Expression assignCommandObjectToParameter = declX(localVarX(paramName), initializeCommandObjectMethodCall);
wrapper.addStatement(stmt(assignCommandObjectToParameter));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ class TestController {
[command: co]
}

private seeIssue13486() {
// the presence of this local variable could break
// the compile-time generated no-arg methodActionWithDate()
// see https://github.com/grails/grails-core/issues/13486
String co
}

def methodActionWithArtist(Artist a) {
[artist: a]
}
Expand Down
Loading