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 2023/04/27 18:28:00 UTC

[jira] [Commented] (GROOVY-11030) CompileStatic: string concatenation in method parameter default value results in NoSuchMethodError

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

Eric Milles commented on GROOVY-11030:
--------------------------------------

Could you retest with Groovy 4.0.12 snapshot?  I think the 4/24 will do.  I just fixed a case like this where an extension method was targeted by the default value expression.

https://repository.apache.org/content/repositories/snapshots/org/apache/groovy/groovy/4.0.12-SNAPSHOT/

> 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
>            Priority: Minor
>
> 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)