You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/09/25 01:31:00 UTC
[jira] [Updated] (GROOVY-9759) CLONE - Regression for accessing
private static constants in closures from Map
[ https://issues.apache.org/jira/browse/GROOVY-9759?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-9759:
------------------------------
Description:
The following code works in 2.5.12 and 3.0.4 but fails with a STC error in 3.0.5 and 2.5.13:
{code:groovy}
import java.util.regex.Pattern
import groovy.transform.CompileStatic
@CompileStatic
class Foo {
private static final Pattern PATTERNS = ~/.*Test/
def checkMap() {
Map failures = [:]
def closure = {
println PATTERNS.pattern()
failures[PATTERNS.pattern()] = 1
}
closure()
println failures
}
}
new Foo().checkMap()
{code}
was:
The following code worked in 2.5.12, in 2.5.13 {{testChildClass}} fails with {{groovy.lang.MissingPropertyException: No such property: PATTERNS for class: Child}}
[~emilles] probably related to the changes mentioned here GROOVY-9665
{code:groovy}
class Example {
@Test
void testBaseClass() {
new Base().check("FooSpec")
}
@Test
void testChildClass() {
new Child().check("FooSpec")
}
}
class Base {
private static final List<Pattern> PATTERNS = [~/.*Test/, ~/.*Spec/]
def check(String str) {
List failures = []
def result = PATTERNS.findResult { Pattern pattern ->
if (pattern.matcher(str).matches()) {
return str
} else {
failures.add("Pattern ${PATTERNS.indexOf(pattern)} did not match")
}
}
if (!result) {
throw new IllegalArgumentException("Did Match no pattern: "+failures.join(", "))
}
return result
}
}
class Child extends Base {
}
{code}
> CLONE - Regression for accessing private static constants in closures from Map
> ------------------------------------------------------------------------------
>
> Key: GROOVY-9759
> URL: https://issues.apache.org/jira/browse/GROOVY-9759
> Project: Groovy
> Issue Type: Bug
> Reporter: Leonard Brünings
> Priority: Major
>
> The following code works in 2.5.12 and 3.0.4 but fails with a STC error in 3.0.5 and 2.5.13:
> {code:groovy}
> import java.util.regex.Pattern
> import groovy.transform.CompileStatic
> @CompileStatic
> class Foo {
> private static final Pattern PATTERNS = ~/.*Test/
> def checkMap() {
> Map failures = [:]
> def closure = {
> println PATTERNS.pattern()
> failures[PATTERNS.pattern()] = 1
> }
> closure()
> println failures
> }
> }
> new Foo().checkMap()
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)