[
https://issues.apache.org/jira/browse/GROOVY-9695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17181052#comment-17181052
]
Leonard Brünings edited comment on GROOVY-9695 at 8/20/20, 9:09 AM:
--------------------------------------------------------------------
Should I open a separate bug for the fact that the bridge method is not used
inside map keys?
{code:groovy}
import java.util.regex.Pattern
import org.junit.Test
import groovy.transform.CompileStatic
class Example {
@Test
void testBaseListClass() {
new Base().checkList()
}
@Test
void testChildListClass() {
new Child().checkList()
}
@Test
void testBaseMapClass() {
new Base().checkMap()
}
@Test
void testChildMapClass() {
new Child().checkMap()
}
}
@CompileStatic
class Base {
private static final Pattern PATTERNS = ~/.*Test/
def checkList() {
List failures = []
def closure = {
failures << PATTERNS.pattern()
}
closure()
}
def checkMap() {
Map failures = [:]
def closure = {
failures[PATTERNS.pattern()] = 1
}
closure()
}
}
class Child extends Base {
}
{code}
For the list it works fine (Procyon Decompiler)
{code:java}
public Object doCall(final Object it) {
return
DefaultGroovyMethods.leftShift((List<String>)ScriptBytecodeAdapter.castToType(this.failures.get(),
List.class), Base.pfaccess$0((Base)null).pattern());
}
{code}
For the map it doesn't use the bridge method (Procyon Decompiler)
{code:java}
public Object doCall(final Object it) {
final int n = 1;
DefaultGroovyMethods.putAt((Map<String,
Integer>)ScriptBytecodeAdapter.castToType(this.failures.get(), Map.class),
((Pattern)this.getProperty("PATTERNS")).pattern(), n);
return n;
}
{code}
was (Author: leonard84):
Should I open a separate bug for the fact that the bridge method is not used
inside map keys?
{code:groovy}
import java.util.regex.Pattern
import org.junit.Test
import groovy.transform.CompileStatic
class Example {
@Test
void testBaseListClass() {
new Base().checkList()
}
@Test
void testChildListClass() {
new Child().checkList()
}
@Test
void testBaseMapClass() {
new Base().checkMap()
}
@Test
void testChildMapClass() {
new Child().checkMap()
}
}
@CompileStatic
class Base {
private static final Pattern PATTERNS = ~/.*Test/
def checkList() {
List failures = []
def closure = {
failures << PATTERNS.pattern()
}
closure()
}
def checkMap() {
Map failures = [:]
def closure = {
failures[PATTERNS.pattern()] = 1
}
closure()
}
}
class Child extends Base {
}
{code}
For the list it works fine (Procyon Decompiler)
{code:java}
public Object doCall(final Object it) {
return
DefaultGroovyMethods.leftShift((List<String>)ScriptBytecodeAdapter.castToType(this.failures.get(),
List.class), Base.pfaccess$0((Base)null).pattern());
}
{code}
For the map it doesn't use the bridge method (Procyon Decompiler)
{code:java}
public Object doCall(final Object it) {
final int n = 1;
DefaultGroovyMethods.putAt((Map<String,
Integer>)ScriptBytecodeAdapter.castToType(this.failures.get(), Map.class),
((Pattern)this.getProperty("PATTERNS")).pattern(), n);
return n;
}
{code}
> Regression for accessing private static constants in closures from Parent
> Classes
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-9695
> URL: https://issues.apache.org/jira/browse/GROOVY-9695
> Project: Groovy
> Issue Type: Bug
> Reporter: Leonard Brünings
> Priority: Major
> Fix For: 2.5.13
>
>
> 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}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)