You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2018/10/06 13:56:00 UTC
[jira] [Commented] (GROOVY-8832) Type parameters for trait method
and its bridge method
[ https://issues.apache.org/jira/browse/GROOVY-8832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16640727#comment-16640727 ]
Eric Milles commented on GROOVY-8832:
-------------------------------------
I can test for the unresolved type parameter in {{GenericsUtils}} like this:
{code:java}
public static GenericsType[] applyGenericsContextToPlaceHolders(Map<String, ClassNode> genericsSpec, GenericsType[] oldPlaceHolders) {
if (oldPlaceHolders==null || oldPlaceHolders.length==0) return oldPlaceHolders;
if (genericsSpec.isEmpty()) return oldPlaceHolders;
GenericsType[] newTypes = new GenericsType[oldPlaceHolders.length];
for (int i=0; i<oldPlaceHolders.length; i++) {
GenericsType old = oldPlaceHolders[i];
if (!old.isPlaceholder()) throw new GroovyBugError("Given generics type "+old+" must be a placeholder!");
ClassNode fromSpec = genericsSpec.get(old.getName());
if (fromSpec!=null) {
/* GRECLIPSE edit
if (fromSpec.isGenericsPlaceHolder()) {
ClassNode[] upper = new ClassNode[]{fromSpec.redirect()};
newTypes[i] = new GenericsType(fromSpec, upper, null);
} else {
newTypes[i] = new GenericsType(fromSpec);
}
*/
Map<String, ?> placeholders = extractPlaceholders(fromSpec);
genericsSpec.keySet().forEach(placeholders::remove);
if (!placeholders.isEmpty()) {
System.err.println("Unresolved type params: " + placeholders);
}
newTypes[i] = fromSpec.asGenericsType();
// GRECLIPSE end
{code}
> Type parameters for trait method and its bridge method
> ------------------------------------------------------
>
> Key: GROOVY-8832
> URL: https://issues.apache.org/jira/browse/GROOVY-8832
> Project: Groovy
> Issue Type: Question
> Components: Compiler
> Affects Versions: 2.4.15, 2.5.3
> Reporter: Eric Milles
> Priority: Major
> Attachments: Events.zip
>
>
> This is related to GROOVY-8815. When compiling a class that implements the trait {{grails.events.Events}} I am seeing different results for the type parameters. I'm not sure what the correct generics signatures should be. *What are the correct generics for this scenario?*
> {code:groovy}
> import grails.events.Events
> class Service implements Events {}
> {code}
> And the relevant excerpt from Events:
> {code:groovy}
> def <E extends Event<?>> Bus notify(Object key, Closure<E> supplier)
> {code}
> When {{Service}} is compiled with Gradle, the following methods are created in the class file. The synthetic method generics look okay, but the bridge method generics have {{E}} as {{java.lang.Object}}.
> {code}
> // Method descriptor #96 (Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;
> // Signature: <E:Lreactor/bus/Event<+Ljava/lang/Object;>;>(Ljava/lang/Object;Lgroovy/lang/Closure<TE;>;)Lreactor/bus/Bus;
> // Stack: 8, Locals: 4
> public synthetic reactor.bus.Bus grails_events_Eventstrait$super$notify(java.lang.Object param0, groovy.lang.Closure param1);
> // Method descriptor #96 (Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;
> // Signature: <E:Ljava/lang/Object;>(Ljava/lang/Object;Lgroovy/lang/Closure<TE;>;)Lreactor/bus/Bus;
> // Stack: 5, Locals: 4
> @org.codehaus.groovy.transform.trait.Traits.TraitBridge(traitClass=grails.events.Events,
> desc="(Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;")
> public reactor.bus.Bus notify(java.lang.Object arg1, groovy.lang.Closure arg2);
> {code}
> By contrast, when {{Service}} is compiled with Groovy-Eclipse, the following methods are created in the class file. Again the synthetic method looks okay -- in fact, more accurate to the original. However the generics for the bridge method contain the unresolved type parameter {{T}}. This is the actual bug I'm chasing, but I can't say what the right generics should be and why Gradle/Groovyc and Groovy-Eclipse have different answers for both methods.
> {code}
> // Method descriptor #150 (Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;
> // Signature: <E:Lreactor/bus/Event<*>;>(Ljava/lang/Object;Lgroovy/lang/Closure<TE;>;)Lreactor/bus/Bus;
> // Stack: 8, Locals: 4
> public synthetic reactor.bus.Bus grails_events_Eventstrait$super$notify(java.lang.Object arg0, groovy.lang.Closure arg1);
> // Method descriptor #150 (Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;
> // Signature: <E:Lreactor/bus/Event<TT;>;>(Ljava/lang/Object;Lgroovy/lang/Closure<TE;>;)Lreactor/bus/Bus;
> // Stack: 5, Locals: 4
> @org.codehaus.groovy.transform.trait.Traits.TraitBridge(traitClass=grails.events.Events,
> desc="(Ljava/lang/Object;Lgroovy/lang/Closure;)Lreactor/bus/Bus;")
> public reactor.bus.Bus notify(java.lang.Object arg1, groovy.lang.Closure arg2);
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)