You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/04/06 13:51:00 UTC
[jira] [Commented] (GROOVY-10011) Combining flow typing and type
argument inference does not work as expected
[ https://issues.apache.org/jira/browse/GROOVY-10011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17315577#comment-17315577 ]
Eric Milles commented on GROOVY-10011:
--------------------------------------
If you want to do something like GROOVY-9996 inside the {{instanceof}} block, it will be hard to support this as well.
> Combining flow typing and type argument inference does not work as expected
> ---------------------------------------------------------------------------
>
> Key: GROOVY-10011
> URL: https://issues.apache.org/jira/browse/GROOVY-10011
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
>
> I have the following program
> {code:java}
> class A<T> {
> T f;
> public A(T f) {
> this.f = f;
> }
> }
> class Foo {}
> class Bar extends Foo {}
> public class Main {
> public static void bar(Foo x) {
> if (x instanceof Bar) {
> A<Bar> a = new A<>(x)
> }
> }
> }
> {code}
> h3. Actual Behavior
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 15: [Static type checking] - Incompatible generic argument types. Cannot assign A <Foo> to: A <Bar>
> @ line 15, column 18.
> A<Bar> a = new A<>(x)
> ^1 error
> {code}
> h3. Expected Behavior
> Compile successfully
>
> Tested against https://github.com/apache/groovy/commit/359be2b662be646d2d59db8b999412691891231d
--
This message was sent by Atlassian Jira
(v8.3.4#803005)