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 2019/12/15 18:50:00 UTC
[jira] [Updated] (GROOVY-9342) SC: Lambda in static initializer
that uses field on LHS of += produces error
[ https://issues.apache.org/jira/browse/GROOVY-9342?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-9342:
--------------------------------
Description:
Follow up to GROOVY-9332 and GROOVY-9333. Consider the following:
{code:groovy}
@groovy.transform.CompileStatic
class Test1 {
static int acc = 1
static { [1, 2, 3].forEach(e -> acc += e) }
}
assert Test1.acc == 7
{code}
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
TestScript60.groovy: 5: [Static type checking] - Cannot find matching method int#plus(java.lang.Object). Please check if the declared type is correct and if the method exists.
@ line 5, column 49.
atic { [1, 2, 3].forEach(e -> acc += e)
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:287)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1091)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:612)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:589)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:367)
at groovy.lang.GroovyClassLoader.lambda$parseClass$2(GroovyClassLoader.java:310)
...
{code}
and a different error if lambda uses specific parameter type:
{code:groovy}
@groovy.transform.CompileStatic
class Test1 {
static int acc = 1
static { [1, 2, 3].forEach((Integer i) -> acc += i) }
}
assert Test1.acc == 7
{code}
{code}
java.lang.ExceptionInInitializerError\r\n
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n
at java.lang.reflect.Method.invoke(Method.java:498)\r\n
{code}
was:
Follow up to GROOVY-9332 and GROOVY-9333. Consider the following:
{code:groovy}
@groovy.transform.CompileStatic
class Test1 {
static int acc = 1
static { [1, 2, 3].forEach(e -> acc += e) }
}
assert Test1.acc == 7
{code}
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
TestScript60.groovy: 5: [Static type checking] - Cannot find matching method int#plus(java.lang.Object). Please check if the declared type is correct and if the method exists.
@ line 5, column 49.
atic { [1, 2, 3].forEach(e -> acc += e)
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:287)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1091)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:612)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:589)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:367)
at groovy.lang.GroovyClassLoader.lambda$parseClass$2(GroovyClassLoader.java:310)
...
{code}
> SC: Lambda in static initializer that uses field on LHS of += produces error
> ----------------------------------------------------------------------------
>
> Key: GROOVY-9342
> URL: https://issues.apache.org/jira/browse/GROOVY-9342
> Project: Groovy
> Issue Type: Bug
> Reporter: Eric Milles
> Priority: Major
>
> Follow up to GROOVY-9332 and GROOVY-9333. Consider the following:
> {code:groovy}
> @groovy.transform.CompileStatic
> class Test1 {
> static int acc = 1
> static { [1, 2, 3].forEach(e -> acc += e) }
> }
> assert Test1.acc == 7
> {code}
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> TestScript60.groovy: 5: [Static type checking] - Cannot find matching method int#plus(java.lang.Object). Please check if the declared type is correct and if the method exists.
> @ line 5, column 49.
> atic { [1, 2, 3].forEach(e -> acc += e)
> ^
> 1 error
> at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:287)
> at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1091)
> at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633)
> at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:612)
> at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:589)
> at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:367)
> at groovy.lang.GroovyClassLoader.lambda$parseClass$2(GroovyClassLoader.java:310)
> ...
> {code}
> and a different error if lambda uses specific parameter type:
> {code:groovy}
> @groovy.transform.CompileStatic
> class Test1 {
> static int acc = 1
> static { [1, 2, 3].forEach((Integer i) -> acc += i) }
> }
> assert Test1.acc == 7
> {code}
> {code}
> java.lang.ExceptionInInitializerError\r\n
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n
> at java.lang.reflect.Method.invoke(Method.java:498)\r\n
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)