You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2022/05/20 07:51:00 UTC

[jira] [Commented] (GROOVY-10153) STC: cannot combine use-variance with bounded polymorphism

    [ https://issues.apache.org/jira/browse/GROOVY-10153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17539972#comment-17539972 ] 

Thodoris Sotiropoulos commented on GROOVY-10153:
------------------------------------------------

FYI, the java compiler permits  "Foo<? super C>". I think the rationale is that a there is a capture type whose upper bound is A while its lower bound is C.

> STC: cannot combine use-variance with bounded polymorphism
> ----------------------------------------------------------
>
>                 Key: GROOVY-10153
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10153
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 4.0.0-alpha-3
>            Reporter: Stefanos Chaliasos
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.TypeChecked
> class Test {
>   public void m() {
>     Foo<? super C> x = new Foo<B>();
>   }
> }
> class A {}
> class B extends A {}
> class C extends B {}
> class Foo<T extends A> {
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Test.groovy: 4: The type ? is not a valid substitute for the bounded parameter <T extends A>
>  @ line 4, column 9.
>        Foo<? super C> x = new Foo<B>();
>            ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)