groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8815) Inconsistent class file - undefined type parameter for trait implementer
Date Mon, 08 Oct 2018 20:33:01 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8815?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16642424#comment-16642424
] 

Eric Milles commented on GROOVY-8815:
-------------------------------------

Pending changes for 2.5.3 have moved this problem a bit.  
{code:java}
    public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<String,
ClassNode> oldSpec) {
        Map<String, ClassNode> ret = new HashMap<String, ClassNode>(oldSpec);
        // ret starts with the original type specs, now add gts for the current method if
any
        GenericsType[] sgts = current.getGenericsTypes();
        if (sgts != null) {
            for (GenericsType sgt : sgts) {
                String name = sgt.getName();
                if (sgt.isPlaceholder()) {
                    ClassNode redirect;
                    if (sgt.getUpperBounds() != null) {
                        redirect = sgt.getUpperBounds()[0];
                    } else if (sgt.getLowerBound() != null) {
                        redirect = sgt.getLowerBound();
                    } else {
                        redirect = ClassHelper.OBJECT_TYPE;
                    }
                    // At this point, name is "E" and redirect is "Event <java.lang.Object>
-> Event <T extends java.lang.Object>"
                    ClassNode type = ClassHelper.makeWithoutCaching(name);
                    type.setGenericsPlaceHolder(true);
                    type.setRedirect(redirect); // this call takes "Event <T extends java.lang.Object>"
only and the inconsistent class file issue returns
                    ret.put(name, type);
                } else {
                    ret.put(name, sgt.getType());
                }
            }
        }
        return ret;
    }
{code}

> Inconsistent class file - undefined type parameter for trait implementer
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-8815
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8815
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.15, 2.5.2
>            Reporter: Eric Milles
>            Priority: Major
>
> When compiling the following classes, the Service class ends up with an incomplete type
parameter in it. This causes errors for the IDE: "Inconsistent classfile encountered: The
undefined type parameter T is referenced from within Service"
> {code}
> import java.util.function.Consumer
> import groovy.transform.CompileStatic
> class Event<T> {
>   Event(String id, T payload) {
>   }
>   Event<T> setReplyTo(Object replyTo) {
>   }
> }
> @CompileStatic
> trait Events {
>   def <E extends Event<?>> Registration<Object, Consumer<E>>
on(Class key, Closure consumer) {
>   }
> }
> interface Registration<K, V> {
> }
> class Service implements Events {
> }
> {code}
> javap output for Events shows:
> {code:java}
>   public abstract <E extends Event<?>> Registration<java.lang.Object,java.util.function.Consumer<E>>
on(java.lang.Class, groovy.lang.Closure);
> {code}
> javap output for Service shows:
> {code:java}
>   public <E extends Event<T>> Registration<java.lang.Object, java.util.function.Consumer<E>>
on(java.lang.Class, groovy.lang.Closure);
>   public <E extends Event<?>> Registration<java.lang.Object, java.util.function.Consumer<E>>
Eventstrait$super$on(java.lang.Class, groovy.lang.Closure);
> {code}
> It is this "T" in the trait method that is not defined. I think it should be "?" instead
when looking at the original method's and the trait bridge method's type parameters.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message