[
https://issues.apache.org/jira/browse/GROOVY-9781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-9781.
---------------------------------
Resolution: Information Provided
> Groovy 3 doesn't call implicit constructor properly for inner classes
> ---------------------------------------------------------------------
>
> Key: GROOVY-9781
> URL: https://issues.apache.org/jira/browse/GROOVY-9781
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.0-alpha-1, 3.0.6
> Reporter: Howard
> Priority: Major
>
> Groovy 2 automatically calls the implicit constructor when the function
> definition requires returning a different class. Example
> {code}
> class B{
> class A {
> List a;
> }
>
> A func2() {
> return ['a': []]
> }
> }
> def b = new B().func2()
> b
> {code}
> Func2 automatically calls an implicit constructor for A using the map. The
> same code does not run on groovy 3 resulting in the following error msg
> {code}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
> object '{a=[]}' with class 'java.util.LinkedHashMap' to class 'B$A' due to:
> groovy.lang.GroovyRuntimeException: Could not find named-arg compatible
> constructor. Expecting one of:
> B$A(Map)
> B$A()
> at B.func2(ConsoleScript8:7)
> at B$func2.call(Unknown Source)
> at ConsoleScript8.run(ConsoleScript8:10)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)