Skip to content

Commit

Permalink
Merge pull request #13598 from grails/issue13486
Browse files Browse the repository at this point in the history
Working on #13486
  • Loading branch information
jeffscottbrown authored Sep 16, 2024
2 parents b802c01 + 3609180 commit 9135770
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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

0 comments on commit 9135770

Please sign in to comment.