Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirahc cannot deal with type parameters which refer to type parameters #433

Open
felixvf opened this issue Mar 4, 2016 · 4 comments
Open

Comments

@felixvf
Copy link
Contributor

felixvf commented Mar 4, 2016

Consider this Java code

package org.foo;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public class TypeFixture {
    public CompletableFuture<List<Runnable>> load(List filter, int flags){
        return null;
    }
}

to be called using this Mirah code

      import org.foo.TypeFixture
      import java.util.function.BiConsumer
      import java.util.Map
      import java.util.List

      class Issue417Test

         def initialize(filters:List, flags:int)
            @filters = filters
            @flags = flags
            @loader = TypeFixture.new
            @future = nil
         end

         def run():void
             @future = @loader.load(@filters, @flags)
         end

         def handle(block:BiConsumer):Issue417Test
            @future.whenComplete(block)
            self
         end

         def join():void
            @future.join
         end

      end

(taken from here and here).

Then the compiler may fail (at least in this version) with a NullPointerException:

java.lang.NullPointerException
        at org.mirah.jvm.mirrors.generics.BaseSignatureReader.finishTypeParam(xx_base_signature_reader.mirah:53)
        at org.mirah.jvm.mirrors.generics.BaseSignatureReader.visitFormalTypeParameter(xx_base_signature_reader.mirah:72)
        at org.objectweb.asm.signature.SignatureReader.accept(Unknown Source)
        at org.mirah.jvm.mirrors.generics.BaseSignatureReader.read(xx_base_signature_reader.mirah:94)
        at org.mirah.jvm.mirrors.BytecodeMirror.link_internal(bytecode_mirror.mirah:86)
        at org.mirah.jvm.mirrors.BytecodeMirror.ensure_linked(bytecode_mirror.mirah:77)
        at org.mirah.jvm.mirrors.SimpleMirrorLoader.loadMirror(mirror_loaders.mirah:119)
        at org.mirah.jvm.mirrors.SimpleMirrorLoader.findMirror(mirror_loaders.mirah:127)
@felixvf
Copy link
Contributor Author

felixvf commented Mar 4, 2016

Further analysis reveals that the NullPointerException is triggered by trying to read 00this signature:

<T:Ljava/lang/Object;U:TT;V:Ljava/lang/Object;>Ljava/util/concurrent/CompletableFuture$BiCompletion<TT;TU;TV;>;

The situation where the failure occurs is U:TT;: Type variable U is not bound to a proper class (e.g. Ljava/lang/Object;), but to another local type variable T. The current signature reader code does not seem to be prepared for that.

@felixvf
Copy link
Contributor Author

felixvf commented Mar 4, 2016

Apparently, the Java 1.8 compiler allows producing this signature

<U:TT;T:Ljava/lang/Object;>Ljava/lang/Object;

(e.g. using Java source code

        public class Someclass<U extends T,T> {
        }

).

This means that type variables are allowed to depend on type variables which are defined later.

@ribrdb
Copy link
Contributor

ribrdb commented Mar 4, 2016

Oh, now that's lovely.

On Fri, Mar 4, 2016 at 8:11 AM Felix von Ferey notifications@github.com
wrote:

Apparently, the Java 1.8 compiler allows producing this signature

<U:TT;T:Ljava/lang/Object;>Ljava/lang/Object;

(e.g. using Java source code

    public class Someclass<U extends T,T> {
    }

).

This means that type variables are allowed to depend on type variables
which are defined later.


Reply to this email directly or view it on GitHub
#433 (comment).

@baroquebobcat
Copy link
Member

Fun. I guess that makes sense.

felixvf pushed a commit to felixvf/mirah that referenced this issue May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants