Skip to content

Commit

Permalink
Fix for #1017: VariableExpression#isThisExpression() for THIS_EXPRESSION
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 6, 2020
1 parent a15850d commit 155ccf5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,4 +112,22 @@ public void testTypeChecked4() {

runNegativeTest(sources, "");
}

@Test
public void testTypeChecked5() {
//@formatter:off
String[] sources = {
"Foo.groovy",
"@groovy.transform.TypeChecked\n" +
"class Foo {\n" +
" private Closure<String> normalizer\n" +
" String normalize(String s) {\n" +
" normalizer(s)" +
" }\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3189,7 +3189,10 @@ public void visitMethodCallExpression(MethodCallExpression call) {
boolean callArgsVisited = false;
if (isCallOnClosure) {
// this is a closure.call() call
if (objectExpression == VariableExpression.THIS_EXPRESSION) {
// GRECLIPSE edit
//if (objectExpression == VariableExpression.THIS_EXPRESSION) {
if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) {
// GRECLIPSE end
// isClosureCall() check verified earlier that a field exists
FieldNode field = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name);
GenericsType[] genericsTypes = field.getType().getGenericsTypes();
Expand Down Expand Up @@ -3571,7 +3574,10 @@ protected void storeTargetMethod(final Expression call, final MethodNode directM

protected boolean isClosureCall(final String name, final Expression objectExpression, final Expression arguments) {
if (objectExpression instanceof ClosureExpression && ("call".equals(name)||"doCall".equals(name))) return true;
if (objectExpression == VariableExpression.THIS_EXPRESSION) {
// GRECLIPSE edit
//if (objectExpression == VariableExpression.THIS_EXPRESSION) {
if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) {
// GRECLIPSE end
FieldNode fieldNode = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name);
if (fieldNode != null) {
ClassNode type = fieldNode.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3322,7 +3322,10 @@ public void visitMethodCallExpression(MethodCallExpression call) {
boolean callArgsVisited = false;
if (isCallOnClosure) {
// this is a closure.call() call
if (objectExpression == VariableExpression.THIS_EXPRESSION) {
// GRECLIPSE edit
//if (objectExpression == VariableExpression.THIS_EXPRESSION) {
if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) {
// GRECLIPSE end
// isClosureCall() check verified earlier that a field exists
FieldNode field = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name);
GenericsType[] genericsTypes = field.getType().getGenericsTypes();
Expand Down Expand Up @@ -3719,7 +3722,10 @@ protected void storeTargetMethod(final Expression call, final MethodNode directM
protected boolean isClosureCall(final String name, final Expression objectExpression, final Expression arguments) {
if (objectExpression instanceof ClosureExpression && ("call".equals(name) || "doCall".equals(name)))
return true;
if (objectExpression == VariableExpression.THIS_EXPRESSION) {
// GRECLIPSE edit
//if (objectExpression == VariableExpression.THIS_EXPRESSION) {
if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) {
// GRECLIPSE end
FieldNode fieldNode = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name);
if (fieldNode != null) {
ClassNode type = fieldNode.getType();
Expand Down

0 comments on commit 155ccf5

Please sign in to comment.