Björn Kautler created GROOVY-12543:
--------------------------------------
Summary: STC: Strange behavior depending on source position
Key: GROOVY-12543
URL: https://issues.apache.org/jira/browse/GROOVY-12543
Project: Groovy
Issue Type: Bug
Affects Versions: 6.0.0, 5.1.3, 4.0.33, 5.0.3, 3.0.25, 2.5.23
Reporter: Björn Kautler
I'm not sure whether most of this is maybe expected behavior, so sorry if so,
but I assume that at least on detail is not intended.
Given this snippet:
{code:groovy}
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.expr.ConstantExpression
import org.codehaus.groovy.ast.expr.ListExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression
import org.codehaus.groovy.ast.expr.MethodPointerExpression
import org.codehaus.groovy.ast.expr.TupleExpression
import org.codehaus.groovy.ast.stmt.ExpressionStatement
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.AbstractASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformationClass
@GroovyASTTransformationClass('Bar')
@interface Foo {}
@GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS)
class Bar extends AbstractASTTransformation {
@Override
void visit(final ASTNode[] nodes, final SourceUnit source) {
def methodName = new ConstantExpression('does_not_exist').tap {
lineNumber = 2
columnNumber = 3
}
nodes
.find { it instanceof ClassNode }
.getMethods('baz')
.first()
.code = new ExpressionStatement(new MethodPointerExpression(new
ListExpression(), methodName))
/*.code = new ExpressionStatement(new MethodCallExpression(new
ListExpression(), methodName, new TupleExpression()).tap {
lineNumber = 2
columnNumber = 3
})*/
}
}
new GroovyShell(getClass().getClassLoader()).evaluate '''
import groovy.transform.CompileStatic
@CompileStatic
@Foo
class Baz {
def baz() {
}
}
new Baz().baz()
'done'
'''
{code}
If you execute this in Groovy Web Console, it correctly fails type-checking due
to missing {{ArrayList#does_not_exist}} method.
If you comment out either {{lineNumber = 2}} or {{columnNumber = 3}} or both,
it compiles and runs, returning "done".
If you comment out the first {{.code =}} part and instead comment in the second
one, it also correctly fails type-checking due to missing
{{ArrayList#does_not_exist}} method.
If you comment out the {{{}lineNumber = 4{}}}, or {{lineNumber = 4}} and
{{columnNumber = 5}} you are getting a {{MissingMethodException}} at runtime.
If you comment out only the {{{}columnNumber = 5{}}}, - and this is probably a
bug even if the other cases are intended - you get "Target method for method
call expression hasn't been set" error.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)