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/03/24 14:46:00 UTC
[jira] [Resolved] (GROOVY-9995) Wrong inference inside closure when
having a bounded type parameter
[ https://issues.apache.org/jira/browse/GROOVY-9995?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-9995.
---------------------------------
Fix Version/s: 4.0.0-alpha-3
Resolution: Fixed
> Wrong inference inside closure when having a bounded type parameter
> -------------------------------------------------------------------
>
> Key: GROOVY-9995
> URL: https://issues.apache.org/jira/browse/GROOVY-9995
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 3.0.7, 4.0.0-alpha-2
> Reporter: Stefanos Chaliasos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-3
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.CompileStatic
> public class Main {
> public static void main(String[] args) {
> Closure<A<Long>> closure = { -> {
> final x = (Long) 1;
> new A<>(x);
> }}
> // If I remove 'extends Number' in class A, the following code
> // works as expected.
> final Long y = closure().f;
> }
> }
> class A<T extends Number> {
> T f;
> public A(T f) {
> this.f = f;
> }
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Main.groovy: 10: [Static type checking] - Cannot assign value of type java.lang.Number to variable of type java.lang.Long
> @ line 10, column 20.
> final Long y = closure().f;
> ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Affected Version
> I have also tested it with the compiler from Master (commit: e69c874e1a6a3cdeb236bad6a6faa061a30c88ca).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)