Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Information Provided
-
4.0.0-alpha-1, 3.0.6
-
None
-
None
-
None
Description
Groovy 2 automatically calls the implicit constructor when the function definition requires returning a different class. Example
class B{ class A { List a; } A func2() { return ['a': []] } } def b = new B().func2() b
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
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)