Skip to content
Permalink
Browse files
8221323: [lworld] Javac should support class literals for projection …
…types.
  • Loading branch information
Srikanth Adayapalam committed Aug 4, 2020
1 parent e40d6ba commit 72b3046c3e8b4c53847fe9adf2c68f8a59fe23ae
@@ -272,7 +272,7 @@ public VarSymbol getClassField(Type type, Types types) {
*/
if (type.isValue()) {
List<Type> bounds = List.of(objectType).appendList(((ClassSymbol) type.tsym).getInterfaces());
arg = new WildcardType(types.makeIntersectionType(bounds), BoundKind.EXTENDS, boundClass);
arg = new WildcardType(bounds.size() > 1 ? types.makeIntersectionType(bounds) : objectType, BoundKind.EXTENDS, boundClass);
} else {
arg = types.erasure(type);
}
@@ -2543,7 +2543,7 @@ Type adjustMethodReturnType(Symbol msym, Type qualifierType, Name methodName, Li
Type wcb;
if (qualifierType.isValue()) {
List<Type> bounds = List.of(syms.objectType).appendList(((ClassSymbol) qualifierType.tsym).getInterfaces());
wcb = types.makeIntersectionType(bounds);
wcb = bounds.size() > 1 ? types.makeIntersectionType(bounds) : syms.objectType;
} else {
wcb = types.erasure(qualifierType);
}
@@ -0,0 +1,41 @@
/*
* @test /nodynamiccopyright/
* @bug 8221323
* @summary Javac should support class literals for projection types.
* @compile/fail/ref=ClassLiteralTypingNegativeTest.out -XDrawDiagnostics ClassLiteralTypingNegativeTest.java
*/

public class ClassLiteralTypingNegativeTest {

public static inline class Foo {
final int value = 0;

public static void main(String[] args) {
Class<? extends Foo.ref> cFooRef = Foo.class; // Error
cFooRef = new Foo().getClass(); // Error
cFooRef = Foo.ref.class; // OK.
cFooRef = Foo.val.class; // Error.
Foo.val xv = new Foo();
cFooRef = xv.getClass(); // Error
Foo.ref xr = new Foo();
cFooRef = xr.getClass(); // OK.
}
}

interface I {}

public static inline class Bar implements I {
final int value = 0;

public static void main(String[] args) {
Class<? extends Bar.ref> cBarRef = Bar.class; // Error
cBarRef = new Bar().getClass(); // Error
cBarRef = Bar.ref.class; // OK.
cBarRef = Bar.val.class; // Error.
Bar.val xv = new Bar();
cBarRef = xv.getClass(); // Error
Bar.ref xr = new Bar();
cBarRef = xr.getClass(); // OK.
}
}
}
@@ -0,0 +1,9 @@
ClassLiteralTypingNegativeTest.java:14:51: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Foo$ref>)
ClassLiteralTypingNegativeTest.java:15:41: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Foo$ref>)
ClassLiteralTypingNegativeTest.java:17:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Foo$ref>)
ClassLiteralTypingNegativeTest.java:19:34: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Foo$ref>)
ClassLiteralTypingNegativeTest.java:31:51: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object&ClassLiteralTypingNegativeTest.I>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Bar$ref>)
ClassLiteralTypingNegativeTest.java:32:41: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object&ClassLiteralTypingNegativeTest.I>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Bar$ref>)
ClassLiteralTypingNegativeTest.java:34:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object&ClassLiteralTypingNegativeTest.I>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Bar$ref>)
ClassLiteralTypingNegativeTest.java:36:34: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Class<compiler.misc.type.captureof: 1, ? extends java.lang.Object&ClassLiteralTypingNegativeTest.I>, java.lang.Class<? extends ClassLiteralTypingNegativeTest.Bar$ref>)
8 errors

0 comments on commit 72b3046

Please sign in to comment.