You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/06/28 12:24:00 UTC

[jira] [Comment Edited] (GROOVY-10668) Reference to method is ambiguous if block in "if" with "instanceof"

|  ![](cid:jira-generated-image-avatar-608abdf4-4ca2-4a5d-bad9-cc83f86fdb4e) |
[Paul King](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=paulk)
**edited a comment** on [![Bug](cid:jira-generated-image-
avatar-d3ce1ed5-6fc6-4437-83e2-adad46f281b0)
GROOVY-10668](https://issues.apache.org/jira/browse/GROOVY-10668)  
---|---  
|  
---  
|  [Re: Reference to method is ambiguous if block in "if" with
"instanceof"](https://issues.apache.org/jira/browse/GROOVY-10668)  
---  
|  [~blackdrag] There has been discussion about union vs intersection types in
the past to support type checking for duck-typing style code. I admit both
PR#1269 and PR#1293 don't really cover that properly. But I think solving that
would work for all cases. For this case:  
``` {code}  
if (bool || x instanceof Map) x.doSomething()  
``` {code}  
You are right, we shouldn't need to cast above and beyond what would be dene
outside the if. For this case:  
``` {code}  
if (x instanceof ArrayDeque || x instanceof Stack) x.peek()  
``` {code}  
We need two potential casts.  
---  
|  |  [ ![Add Comment](cid:jira-generated-image-static-comment-
icon-0331e279-6012-4e5d-b11e-99ab83f937b2)
](https://issues.apache.org/jira/browse/GROOVY-10668#add-comment "Add
Comment") |  [Add
Comment](https://issues.apache.org/jira/browse/GROOVY-10668#add-comment "Add
Comment")  
---|---  
  
|  This message was sent by Atlassian Jira (v8.20.10#820010-sha1:ace47f9) |  |
![Atlassian logo](https://issues.apache.org/jira/images/mail/atlassian-email-
logo.png)  
---