You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/05/11 10:19:00 UTC
[jira] [Created] (GROOVY-10080) Closure with type argument
inference does not work as expected
Stefanos Chaliasos created GROOVY-10080:
-------------------------------------------
Summary: Closure with type argument inference does not work as expected
Key: GROOVY-10080
URL: https://issues.apache.org/jira/browse/GROOVY-10080
Project: Groovy
Issue Type: Bug
Reporter: Stefanos Chaliasos
I have the following Groovy program.
{code:groovy}
@groovy.transform.CompileStatic
public class Main {
public static void main(String[] args) {
def closure = {
new Bar<>(new Foo<Long>());
}
closure().f.m(new BigDecimal[0]) // this doesn't work
// the following works
// Bar<Foo<Long>> x = closure()
// x.f.m(new BigDecimal[0]);
}
}
class Foo<X> {
void m(Object[] x) {}
}
class Bar<X> {
X f;
Bar(X f) {
this.f = f;
}
}
class Baz {}
{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: 7: [Static type checking] - Cannot find matching method java.lang.Object#m(java.math.BigDecimal[]). Please check if the declared type is correct and if the method exists.
@ line 7, column 5.
closure().f.m(new BigDecimal[0]) // this doesn't work
^
1 error
{code}
h2. Expected Behavior
Compile successfully.
h2. Affected Version
This programs fails when compiled with the compiler from the master (commit: a8023b1b0d1d79800677ce2b4665ee3fb14688f4) and with 4.0.0-alpha-2.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)