paulk-asert commented on a change in pull request #1394:
URL: https://github.com/apache/groovy/pull/1394#discussion_r500214643
##########
File path:
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
##########
@@ -2265,26 +2265,27 @@ protected MethodNode typeCheckMapConstructor(final
ConstructorCallExpression cal
).toArray(ClassNode[]::new);
}
- private ClassNode getInferredTypeFromTempInfo(final Expression exp,
ClassNode result) {
- if (exp instanceof VariableExpression &&
!typeCheckingContext.temporaryIfBranchTypeInformation.isEmpty()) {
- List<ClassNode> classNodes = getTemporaryTypesForExpression(exp);
- if (classNodes != null && !classNodes.isEmpty()) {
- List<ClassNode> types = new ArrayList<>(classNodes.size() + 1);
- if (result != null && !classNodes.contains(result))
types.add(result);
- types.addAll(classNodes);
- // GROOVY-7333: filter out Object
- types.removeIf(OBJECT_TYPE::equals);
+ private ClassNode getInferredTypeFromTempInfo(final Expression expression,
final ClassNode expressionType) {
+ if (expression instanceof VariableExpression &&
!typeCheckingContext.temporaryIfBranchTypeInformation.isEmpty()) {
+ List<ClassNode> tempTypes =
getTemporaryTypesForExpression(expression);
+ if (tempTypes != null && !tempTypes.isEmpty()) {
+ List<ClassNode> types = new ArrayList<>(tempTypes.size() + 1);
+ if (expressionType != null &&
!expressionType.equals(ClassHelper.OBJECT_TYPE) // GROOVY-7333
Review comment:
Removing `Object` is currently the correct behavior but I noticed last
time that I played around with introducing Intersection types (as an addition
to the current Union types) that we had to leave it in but fix in other places
for things to work nicely.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]