[ 
https://issues.apache.org/jira/browse/GROOVY-11030?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles resolved GROOVY-11030.
----------------------------------
    Fix Version/s: 4.0.12
         Assignee: Eric Milles
       Resolution: Fixed

> CompileStatic: string concatenation in method parameter default value results 
> in NoSuchMethodError
> --------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11030
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11030
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>    Affects Versions: 4.0.9, 4.0.11
>            Reporter: Jason Garrett
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 4.0.12
>
>
> If a method parameter's default value is defined by concatenating a String 
> literal to a String variable, calling the method throws 
> java.lang.NoSuchMethodError.
> {code:java}
> import groovy.transform.CompileStatic
> import spock.lang.Specification
> @CompileStatic  // works without CompileStatic
> class MyClass {
>     String makePlural(String word, String plural = word + "s") {  // 
> java.lang.NoSuchMethodError: 'java.lang.String 
> java.lang.String.plus(java.lang.CharSequence)'
>         return plural
>     }
> }
> class Test extends Specification {
>     def test() {
>         setup:
>             MyClass myObj = new MyClass()
>         expect:
>             myObj.makePlural("word") == "words"
>     }
> }    {code}
> [Live 
> demo.|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxdUMFugzAMvecrLC4FbaL3SkiTqh3bTWI_kAUDKZAwJ5Siqv--kIZ2zBcn79nP9pNdr8lCRVqfp9QSV6bU1KV73fWyxdxyKwWT9yrTa9GkLVdVmvcoZCmFo7Vi7G1VD7DdwqipMTBKW-vBwlpPtNwYOEx7n68MXOSWpKqg4w1-tgPxNg6IEypeF7r3FGQehReITJTA1Q888TO_L3fU-SDqA7rRxTuRph1snmxQ-g-kTtrET3Rfc8rxZ0AlMNn4FecgtAOpsIdHb-zGwkVfaCzgxaIqDKwsCkcWWIJ1RXESgDmMk-x3j-8cizXd9PF9ctcqHBcsTh6VeHEj7LrTd6R_XIxmp5xJWQb-aaJl6zn9AvUzpMc]
> A workaround is to do the concatenation in a GString:
> {code:java}
> String makePlural(String word, String plural = "${word}s") { {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to