[ https://issues.apache.org/jira/browse/GROOVY-8955?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17487530#comment-17487530 ]
Eric Milles commented on GROOVY-8955: ------------------------------------- [~paulk] Can the original change go back in for Groovy 5? It seems reasonable to me to get a cast exception when returning a type that does not meet the bounds of the return type. > 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 > Time Spent: 0.5h > Remaining Estimate: 0h > > 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 (v8.20.1#820001)