[
https://issues.apache.org/jira/browse/GROOVY-8955?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16831119#comment-16831119
]
Eric Milles edited comment on GROOVY-8955 at 5/1/19 4:47 PM:
-------------------------------------------------------------
This method in {{GenericsUtils}} or its caller could check
{{mn.isDynamicReturnType()}} and set {{correctedType}} accordingly.
{code:java}
public static MethodNode correctToGenericsSpec(Map<String, ClassNode>
genericsSpec, MethodNode mn) {
// GRECLIPSE add -- GROOVY-9059
if (mn.getGenericsTypes() != null)
genericsSpec = addMethodGenerics(mn, genericsSpec);
// GRECLIPSE end
ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec,
mn.getReturnType());
Parameter[] origParameters = mn.getParameters();
Parameter[] newParameters = new Parameter[origParameters.length];
for (int i = 0; i < origParameters.length; i++) {
Parameter origParameter = origParameters[i];
newParameters[i] = new
Parameter(correctToGenericsSpecRecurse(genericsSpec, origParameter.getType()),
origParameter.getName(), origParameter.getInitialExpression());
}
return new MethodNode(mn.getName(), mn.getModifiers(), correctedType,
newParameters, mn.getExceptions(), mn.getCode());
}
{code}
was (Author: emilles):
This method in {{GenericsUtils}} could check {{mn.isDynamicReturnType()}} and
set {{correctedType}} accordingly.
{code:java}
public static MethodNode correctToGenericsSpec(Map<String, ClassNode>
genericsSpec, MethodNode mn) {
// GRECLIPSE add -- GROOVY-9059
if (mn.getGenericsTypes() != null)
genericsSpec = addMethodGenerics(mn, genericsSpec);
// GRECLIPSE end
ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec,
mn.getReturnType());
Parameter[] origParameters = mn.getParameters();
Parameter[] newParameters = new Parameter[origParameters.length];
for (int i = 0; i < origParameters.length; i++) {
Parameter origParameter = origParameters[i];
newParameters[i] = new
Parameter(correctToGenericsSpecRecurse(genericsSpec, origParameter.getType()),
origParameter.getName(), origParameter.getInitialExpression());
}
return new MethodNode(mn.getName(), mn.getModifiers(), correctedType,
newParameters, mn.getExceptions(), mn.getCode());
}
{code}
> VerifyError when AIC with @CS can't be detected as not valid
> ------------------------------------------------------------
>
> Key: GROOVY-8955
> URL: https://issues.apache.org/jira/browse/GROOVY-8955
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Priority: Major
>
> In this buggy code the return type of {{getMappedForm}} method in the AIC
> should be property. None-the-less, it shouldn't result in a {{VerifyError}}:
> {code}
> import groovy.transform.CompileStatic
> class Property {
> String generator
> }
> interface PMapping<T extends Property> {
> T getMappedForm()
> }
> interface PProperty {
> PMapping getMapping()
> }
> @CompileStatic
> class GPEntity {
> def method() {
> PProperty identity = getIdentity()
> String generatorType =
> identity.getMapping().getMappedForm().getGenerator()
> }
> PProperty getIdentity() {
> new PProperty() {
> PMapping getMapping() {
> new PMapping() {
> def getMappedForm() {
> new Property() {
> String getGenerator() { 'foo' }
> }
> }
> }
> }
> }
> }
> }
> new GPEntity().method()
> {code}
> The error is:
> {noformat}
> java.lang.VerifyError: Bad return type
> Exception Details:
> Location:
> GPEntity$1$2.getMappedForm()LProperty; @4: areturn
> Reason:
> Type 'java/lang/Object' (current frame, stack[0]) is not assignable to
> 'Property' (from method signature)
> Current Frame:
> bci: @4
> flags: { }
> locals: { 'GPEntity$1$2' }
> stack: { 'java/lang/Object' }
> Bytecode:
> 0x0000000: 2ab6 0099 b0
> at GPEntity$1.getMapping(ConsoleScript13:25)
> ...
> {noformat}
> If the {{PMapping}} method is written without generics, e.g.:
> {code}
> interface PMapping {
> Property getMappedForm()
> }
> {code}
> Then the error becomes the expected compilation error:
> {noformat}
> The return type of java.lang.Object getMappedForm() in GPEntity$1$2 is
> incompatible with Property in PMapping
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)