[ 
https://issues.apache.org/jira/browse/GROOVY-9695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17179744#comment-17179744
 ] 

Leonard Brünings commented on GROOVY-9695:
------------------------------------------

For the quick demo the {{@CompileStatic}} works, but for my application code it 
didn't fix my problem and was indeed the first thing I tried. After tinkering a 
bit I figured out why it didn't work for me. If you use this code, i.e. create 
a map key via gstring, then the compiled code does not use the generated bridge 
method for some reason.

{code:groovy}
    def check(String str) {
        Map<String, String> failures = [:]

        def result = PATTERNS.findResult { Pattern pattern ->
            if (pattern.matcher(str).matches()) {
                return str
            } else {
                failures["${PATTERNS.indexOf(pattern)}".toString()] = 'foo'
            }
        }
        if (!result) {
            throw new IllegalArgumentException("Did Match no pattern: 
"+failures.collect{k,v-> "$k: $v" }.join(", "))
        }

        return result
    }
{code}

Anyhow, it is a regression and IMHO one that should be fixed possibly by 
finally fixing GROOVY-5438 after 8 years.

> 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)

Reply via email to