[
https://issues.apache.org/jira/browse/GROOVY-11359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17837078#comment-17837078
]
Adrien Guichard edited comment on GROOVY-11359 at 4/15/24 1:29 PM:
-------------------------------------------------------------------
I think something changed in the way *generics* are managed. I try many
combinations.
{noformat}
ClassNode retClassNode0 = ClassHelper.make(GetMethodReturn)
ClassNode retClassNode1 = new GenericsType(ClassHelper.make(GetMethodReturn),
[ClassHelper.make(methodNode.returnType.typeClass)] as ClassNode[],
ClassHelper.make(Object)).type
ClassNode retClassNode2 = new GenericsType(ClassHelper.make(GetMethodReturn),
ClassHelper.make(Object).makeArray() as ClassNode[], methodNode.returnType).type
ClassNode retClassNode3 = new GenericsType(ClassHelper.make(GetMethodReturn,
false), [ClassHelper.make(methodNode.returnType.typeClass)] as ClassNode[],
null).type
ClassNode retClassNode4 = new
GenericsType(ClassHelper.make(GetMethodReturn)).lowerBound
ClassNode retClassNode = retClassNode3
ClassNode retClassNodeNoGenerics =
ClassHelper.make(ClassHelper.make(GetMethodReturn, false).typeClass, false)
{noformat}
*GetMethodReturn* use generics:
{noformat}
@CompileStatic
final class GetMethodReturn<T> {
final Method method
final T value
GetMethodReturn(final Method method, final T value) {
this.method = method
this.value = value
}
}
{noformat}
And the method generator:
{noformat}
ReturnStatement code = new ReturnStatement(
new ConstructorCallExpression(
retClassNodeNoGenerics,
new ArgumentListExpression([
new StaticMethodCallExpression(
classNode,
"getMethod",
new ArgumentListExpression(
[new
ConstantExpression(methodNode.name)] as List<Expression>
)),
new MethodCallExpression(
new VariableExpression('this'),
methodNode.name,
[] as ArgumentListExpression),
] as List<Expression>)
)
)
{noformat}
The objective is to generate something looking like this:
{noformat}
public GetMethodReturn<String> getDisplayName_() {
return new GetMethodReturn(Item.class.getMethod("getDisplayName"),
this.getDisplayName());
}
{noformat}
Ideas are welcomed.
Thanks for your support
was (Author: adrienguichard):
I think something changed in the way generics are managed. I try many
combinations, I am little bit stuck...
{noformat}
ClassNode retClassNode0 = ClassHelper.make(GetMethodReturn)
ClassNode retClassNode1 = new GenericsType(ClassHelper.make(GetMethodReturn),
[ClassHelper.make(methodNode.returnType.typeClass)] as ClassNode[],
ClassHelper.make(Object)).type
ClassNode retClassNode2 = new GenericsType(ClassHelper.make(GetMethodReturn),
ClassHelper.make(Object).makeArray() as ClassNode[], methodNode.returnType).type
ClassNode retClassNode3 = new GenericsType(ClassHelper.make(GetMethodReturn,
false), [ClassHelper.make(methodNode.returnType.typeClass)] as ClassNode[],
null).type
ClassNode retClassNode4 = new
GenericsType(ClassHelper.make(GetMethodReturn)).lowerBound
ClassNode retClassNode = retClassNode3
ClassNode retClassNodeNoGenerics =
ClassHelper.make(ClassHelper.make(GetMethodReturn, false).typeClass, false)
{noformat}
And the method generator:
{noformat}
ReturnStatement code = new ReturnStatement(
new ConstructorCallExpression(
retClassNodeNoGenerics,
new ArgumentListExpression([
new StaticMethodCallExpression(
classNode,
"getMethod",
new ArgumentListExpression(
[new
ConstantExpression(methodNode.name)] as List<Expression>
)),
new MethodCallExpression(
new VariableExpression('this'),
methodNode.name,
[] as ArgumentListExpression),
] as List<Expression>)
)
)
{noformat}
The idea is to generate something like this:
{noformat}
public GetMethodReturn<String> getDisplayName_() {
return new GetMethodReturn(Item.class.getMethod("getDisplayName"),
this.getDisplayName());
}
{noformat}
I have to go... All ideas are welcomed !
> ASTTransformation cause "General error during instruction selection"
> --------------------------------------------------------------------
>
> Key: GROOVY-11359
> URL: https://issues.apache.org/jira/browse/GROOVY-11359
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.21
> Environment: $ java -fullversion
> openjdk full version "17.0.10+7"
> $ uname -a
> Linux auoHome 6.6.26-1-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Apr 10 20:11:08 UTC
> 2024 x86_64 GNU/Linux
> Reporter: Adrien Guichard
> Priority: Major
> Fix For: 3.0.11
>
> Attachments: testcase-asttransform-ko.tar.gz
>
>
> When assembling the *Grails* project, I do obtain the following stacktrace:
> java.lang.ArrayIndexOutOfBoundsException: size==0
> at
> org.codehaus.groovy.classgen.asm.OperandStack.ensureStackNotEmpty(OperandStack.java:279)
> at
> org.codehaus.groovy.classgen.asm.OperandStack.replace(OperandStack.java:271)
> at
> org.codehaus.groovy.classgen.AsmClassGenerator.visitCastExpression(AsmClassGenerator.java:815)
> at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:90)
> at
> org.codehaus.groovy.classgen.asm.StatementWriter.writeReturn(StatementWriter.java:615)
> [. . .]
> Tell me if you need a more complete stacktrace. I try to work around this
> bug, changing the AST, without success. The error looks the same {*}each
> time{*}.
> To reproduce:
> $ tar xvfz testcase-asttransform-ko.tar.gz
> $ cd groovyInfra
> $ ./gradlew publishMavenPublicationToMavenLocal
> $ cd ..
> $ cd t620g
> $ ./gradlew assemble
> => BROKEN HERE
> Thanks for your help !
--
This message was sent by Atlassian Jira
(v8.20.10#820010)