changeset 3508:162ea1f3dfd9

Fix: signatures of polysig methods are erased prematurely
author mcimadamore
date Tue, 26 Apr 2016 15:48:22 +0100
parents 9bec39f205ed
children 6949c3d06e8f
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java test/tools/javac/valhalla/typespec/MethodHandle01.java
diffstat 2 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Apr 21 17:51:53 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Apr 26 15:48:22 2016 +0100
@@ -736,7 +736,7 @@
 
             @Override
             public Type visitClassType(ClassType t, Void aVoid) {
-                return types.erasure(t);
+                return t;
             }
 
             @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/typespec/MethodHandle01.java	Tue Apr 26 15:48:22 2016 +0100
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary smoke test for specializable method handles
+ * @clean .*
+ * @compile MethodHandle01.java
+ * @run main MethodHandle01
+ */
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+public class MethodHandle01 {
+
+    static class A<any X> {
+        X id(X x) { return x; }
+    }
+
+    public static void main(String[] args) throws Throwable {
+        testErased();
+        testSpecialized();
+    }
+
+    static void testErased() throws Throwable {
+		MethodHandle mh = MethodHandles.lookup().findVirtual(A.class, "id", MethodType.methodType(Object.class, Object.class));
+        String s = (String)mh.invoke(new A<String>(), "");
+    }
+
+    static void testSpecialized() throws Throwable {
+		MethodHandle mh = MethodHandles.lookup().findVirtual(A<int>.class, "id", MethodType.methodType(int.class, int.class));
+        int i = (int)mh.invoke(new A<int>(), 42);
+    }
+}