eric-milles commented on code in PR #2419:
URL: https://github.com/apache/groovy/pull/2419#discussion_r3017798319


##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java:
##########
@@ -982,7 +982,16 @@ && 
isAssignment(enclosingBinaryExpression.getOperation().getType())) {
             } else if (op == KEYWORD_INSTANCEOF) {
                 rType = rightExpression.getType();
                 if (lType instanceof 
WideningCategories.LowestUpperBoundClassNode) lType = 
lType.getUnresolvedSuperClass();
-                if (!lType.isInterface() && !rType.isInterface() && 
!(lType.isDerivedFrom(rType) || rType.isDerivedFrom(lType))) {
+                if (lType instanceof UnionTypeClassNode union) {
+                    boolean compatible = rType.isInterface();
+                    for (int i = 0; !compatible && i < 
union.getDelegates().length; i += 1) {
+                        ClassNode delegate = union.getDelegates()[i];
+                        compatible = delegate.isInterface() || 
delegate.isDerivedFrom(rType) || rType.isDerivedFrom(delegate);
+                    }
+                    if (!compatible) {
+                        addError("Incompatible instanceof types: " + 
prettyPrintTypeName(lType) + " and " + prettyPrintTypeName(rType), expression);
+                    }
+                } else if (!lType.isInterface() && !rType.isInterface() && 
!(lType.isDerivedFrom(rType) || rType.isDerivedFrom(lType))) {

Review Comment:
   Not sure how advanced you want to make this.  I added "if (lType instanceof 
UnionTypeClassNode) lType = getOriginalDeclarationType(leftExpression);" above 
the LUB check and had no other fails.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to