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/21 15:10:00 UTC
[jira] [Resolved] (GROOVY-9984) Wrong type inference when passing
null
[ https://issues.apache.org/jira/browse/GROOVY-9984?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-9984.
---------------------------------
Fix Version/s: 4.0.0-alpha-3
Resolution: Fixed
> Wrong type inference when passing null
> --------------------------------------
>
> Key: GROOVY-9984
> URL: https://issues.apache.org/jira/browse/GROOVY-9984
> Project: Groovy
> Issue Type: Bug
> 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) {
> final A<Integer> x = new A<>(null);
> baz(x);
> }
> public static void baz(A<Integer> x) {}
> }
> class A<T> {
> 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:
> Test.groovy: 4: [Static type checking] - Incompatible generic argument types. Cannot assign A <java.lang.Object> to: A <Integer>
> @ line 4, column 26.
> final A<Integer> x = new A<>(null);
> ^
> Test.groovy: 5: [Static type checking] - Cannot call Main#baz(A <java.lang.Integer>) with arguments [A <java.lang.Object>]
> @ line 5, column 5.
> baz(x);
> ^
> 2 errors
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Comment
> This should be a regression bug because it compiles with the 4.0.0-alpha-2 compiler.
> h2. Affected Version
> This programs fails when compiled with the compiler from the master (commit: f0eea862549529ef4e93fafe337f86dd4ac98751).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)