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 2021/05/24 14:02:00 UTC
[jira] [Commented] (GROOVY-10106) Cannot call dynamic method from
CompileStatic method in a trait
[ https://issues.apache.org/jira/browse/GROOVY-10106?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17350442#comment-17350442 ]
Eric Milles commented on GROOVY-10106:
--------------------------------------
Does this work if you remove {{CompileDynamic}} from "config"? Have you tried using 4.0a3 to see if the issue still exists there? Besides static to dynamic, you also have a field initializer with a closure that calls out to a static trait method.
> Cannot call dynamic method from CompileStatic method in a trait
> ---------------------------------------------------------------
>
> Key: GROOVY-10106
> URL: https://issues.apache.org/jira/browse/GROOVY-10106
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.14
> Reporter: Renato Athaydes
> Priority: Major
>
> The following code fails to compile:
>
>
> {code:java}
> class Foo {
> String foo
> }
> @CompileStatic
> trait A {
> final Foo foo = new Foo().with {
> config(it)
> it
> }
> @CompileDynamic
> static void config(foo) {
> foo.foo = 'bar'
> }
> }
> {code}
>
> The error is:
>
>
> {code:java}
> src/test/groovy/bar/Foo.groovy: 14: [Static type checking] - Cannot find matching method bar.A#config(bar.Foo). Please check if the declared type is correct and if the method exists.
> @ line 14, column 9.
> config(it)
> ^
> 1 error
> {code}
>
> If I change {{trait}} to {{class}}, it compiles successfully.
> I think this has to do with the fact that trait cannot have constructors, and hence the context in which the code executes does not have the right imports?
> Anyway, this was working fine before we upgraded to the latest Groovy 2.5.x version from 2.4.x.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)