[ https://issues.apache.org/jira/browse/GROOVY-9781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Howard updated GROOVY-9781: --------------------------- Description: 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} was: 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} Fun2 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} > 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 > 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.3.4#803005) |
Free forum by Nabble | Edit this page |