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/11/01 19:04:00 UTC
[jira] [Resolved] (GROOVY-10324) STC is unable to infer type
variable when combining parameterized types and the diamond operator
[ https://issues.apache.org/jira/browse/GROOVY-10324?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-10324.
----------------------------------
Fix Version/s: 4.0.0-beta-2
Resolution: Fixed
https://github.com/apache/groovy/commit/e685390fbd77c9b24986ba24044cd84841c5d579
> STC is unable to infer type variable when combining parameterized types and the diamond operator
> ------------------------------------------------------------------------------------------------
>
> Key: GROOVY-10324
> URL: https://issues.apache.org/jira/browse/GROOVY-10324
> Project: Groovy
> Issue Type: Bug
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-beta-2
>
>
> I have the following program
> {code:java}
> class A {
> <T> T foo(C<T> t) { return null; }
> }
> class C<T> {}
> class B {
> void test() {
> C<String> x = (new A()).foo(new C<>());
> }
> }
> {code}
> h3. Actual behaviour
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 12: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type C<java.lang.String>
> @ line 12, column 19.
> C<String> x = (new A()).foo(new C<>());
> ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> Note that compilation fails only if the expected return type is parameterized (i.e., `D<String>`). If I replace the declared type of `x` with a regular type (i.e., `String`), the code compiles fine.
> Tested against master.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)