Skip to content

Commit

Permalink
GROOVY-11353: SC: native lambda or reference for split declare and init
Browse files Browse the repository at this point in the history
```groovy
@groovy.transform.CompileStatic test() {
  java.util.function.Supplier<String> s;
  s = 1234::toString
}
```
  • Loading branch information
eric-milles committed Apr 24, 2024
1 parent 6ced541 commit 6d33b44
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import static org.codehaus.groovy.transform.sc.StaticCompilationVisitor.ARRAYLIST_CONSTRUCTOR;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isAssignment;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferLoopElementType;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.DECLARATION_INFERRED_TYPE;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.DIRECT_METHOD_CALL_TARGET;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_FUNCTIONAL_INTERFACE_TYPE;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_TYPE;
Expand Down Expand Up @@ -171,8 +172,10 @@ protected void evaluateBinaryExpressionWithAssignment(final String method, final
public void evaluateEqual(final BinaryExpression expression, final boolean defineVariable) {
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
if (defineVariable && (rightExpression instanceof LambdaExpression || rightExpression instanceof MethodReferenceExpression)) {
rightExpression.putNodeMetaData(INFERRED_FUNCTIONAL_INTERFACE_TYPE, leftExpression.getNodeMetaData(INFERRED_TYPE));
if (rightExpression instanceof LambdaExpression || rightExpression instanceof MethodReferenceExpression) {
ClassNode leftType = leftExpression.getNodeMetaData(DECLARATION_INFERRED_TYPE); // GROOVY-11353
if (leftType == null) leftType = leftExpression.getNodeMetaData(INFERRED_TYPE);
rightExpression.putNodeMetaData(INFERRED_FUNCTIONAL_INTERFACE_TYPE, leftType);
}
if (leftExpression instanceof PropertyExpression) {
PropertyExpression pexp = (PropertyExpression) leftExpression;
Expand Down

0 comments on commit 6d33b44

Please sign in to comment.