Inference Bug related to parametric polymorphism unification

John Napier jnape09 at gmail.com
Thu Jun 6 19:31:10 UTC 2019


Hi all,

The following code compiles against oracle64-1.8.0.162 but fails on both
openjdk64-11.0.2 and oracle64-12.0.1:

public static class Example {

        public static class Pair<A, B> implements Map.Entry<A, B> {
            private final A a;
            private final B b;

            public Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            @Override
            public A getKey() {
                return a;
            }

            @Override
            public B getValue() {
                return b;
            }

            @Override
            public B setValue(B value) {
                throw new UnsupportedOperationException();
            }
        }

        public static <A, B, C> C destructure(BiFunction<A, B, C> fn,
Map.Entry<A, B> entry) {
            return fn.apply(entry.getKey(), entry.getValue());
        }

        public static void main(String[] args) {
            Map.Entry<String, String> entry = new Pair<>("foo", "bar");

            // ill-typed
            String inferred = destructure((x, y) -> x + y,
destructure(Pair::new, entry));

            // well-typed
            String ascribed = destructure((x, y) -> x + y,
destructure(Pair<String, String>::new, entry));
        }
    }

Before submitting more bugs of this same ilk, albeit with slight variations
in occurrence, I must ask: this is not the intentional modern behavior,
correct? Inference should still work as illustrated above, right?

Cheers,

-John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20190606/71be6b91/attachment.html>


More information about the compiler-dev mailing list