[GitHub] groovy pull request #635: GROOVY-8255: Odd problems with flow typing and gen...

2017-11-14 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/groovy/pull/635


---


[GitHub] groovy pull request #635: GROOVY-8255: Odd problems with flow typing and gen...

2017-11-14 Thread melix
Github user melix commented on a diff in the pull request:

https://github.com/apache/groovy/pull/635#discussion_r150800145
  
--- Diff: 
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java ---
@@ -3461,6 +3465,36 @@ public void visitTernaryExpression(final 
TernaryExpression expression) {
 popAssignmentTracking(oldTracker);
 }
 
+// currently just for empty literals, not for e.g. 
Collections.emptyList() at present
+/// it seems attractive to want to do this for more cases but perhaps 
not all cases
+private ClassNode checkForTargetType(final Expression expr, final 
ClassNode type) {
+if (typeCheckingContext.getEnclosingBinaryExpression() != null && 
isEmptyCollection(expr)) {
+int op = 
typeCheckingContext.getEnclosingBinaryExpression().getOperation().getType();
+if (isAssignment(op)) {
+VariableExpression target = (VariableExpression) 
typeCheckingContext.getEnclosingBinaryExpression().getLeftExpression();
+return adjustForTargetType(target.getType(), type);
+}
+}
+return type;
+}
+
+private ClassNode adjustForTargetType(final ClassNode targetType, 
final ClassNode resultType) {
+if (targetType.isUsingGenerics() && 
missesGenericsTypes(resultType)) {
+// unchecked assignment within ternary/elvis
+// examples:
+// List list = existingAs ?: []
+// in that case, the inferred type of the RHS is the type of 
the RHS
+// "completed" with generics type information available in the 
LHS
+return GenericsUtils.parameterizeType(targetType, 
resultType.getPlainNodeReference());
+}
+return resultType;
+}
+
+private boolean isEmptyCollection(Expression expr) {
--- End diff --

Could be static.


---


[GitHub] groovy pull request #635: GROOVY-8255: Odd problems with flow typing and gen...

2017-11-13 Thread paulk-asert
GitHub user paulk-asert opened a pull request:

https://github.com/apache/groovy/pull/635

GROOVY-8255: Odd problems with flow typing and generics in Groovy 2.4…

….12+ (target typing for empty literals within Ternary/Elvis)

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/paulk-asert/groovy groovy8255

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/groovy/pull/635.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #635


commit 6c35dcff589929cf80b2e79a246b35aae4afec2a
Author: paulk 
Date:   2017-11-13T08:43:02Z

GROOVY-8255: Odd problems with flow typing and generics in Groovy 2.4.12+ 
(target typing for empty literals within Ternary/Elvis)




---