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

8244796: [lworld] Javac does not compile test/hotspot/jtreg/runtime/valhalla/valuetypes/UnsafeTest.java anymore #46

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -52,6 +52,7 @@
import com.sun.tools.javac.code.Type.JCVoidType;
import com.sun.tools.javac.code.Type.MethodType;
import com.sun.tools.javac.code.Type.UnknownType;
import com.sun.tools.javac.code.Type.WildcardType;
import com.sun.tools.javac.code.Types.UniqueType;
import com.sun.tools.javac.comp.Modules;
import com.sun.tools.javac.jvm.Target;
@@ -268,8 +269,17 @@ public VarSymbol getClassField(Type type, Types types) {
return classFields.computeIfAbsent(
new UniqueType(type, types), k -> {
Type arg = null;
if (type.getTag() == ARRAY || type.getTag() == CLASS)
arg = types.erasure(type);
if (type.getTag() == ARRAY || type.getTag() == CLASS) {
/* Temporary treatment for inline class: Given an inline class V that implements
I1, I2, ... In, V.class is typed to be Class<? extends Object & I1 & I2 .. & In>
*/
if (type.isValue()) {
Type it = types.makeIntersectionType(((ClassType)type).interfaces_field, true);
arg = new WildcardType(it, BoundKind.EXTENDS, boundClass);
} else {
arg = types.erasure(type);
}
}
else if (type.isPrimitiveOrVoid())
arg = types.boxedClass(type).type;
else
@@ -2518,8 +2518,13 @@ Type adjustMethodReturnType(Symbol msym, Type qualifierType, Name methodName, Li
methodName == names.getClass &&
argtypes.isEmpty()) {
// as a special case, x.getClass() has type Class<? extends |X|>
// Temporary treatment for inline class: Given an inline class V that implements
// I1, I2, ... In, v.getClass() is typed to be Class<? extends Object & I1 & I2 .. & In>
Type wcb = qualifierType.isValue()
? types.makeIntersectionType(((ClassType) qualifierType).interfaces_field, true)
: types.erasure(qualifierType);
return new ClassType(restype.getEnclosingType(),
List.of(new WildcardType(types.erasure(qualifierType),
List.of(new WildcardType(wcb,
BoundKind.EXTENDS,
syms.boundClass)),
restype.tsym,
@@ -898,9 +898,7 @@ boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2)
}

void checkParameterizationWithValues(DiagnosticPosition pos, Type t) {
if (t.tsym != syms.classType.tsym) { // tolerate Value.class.
valueParameterizationChecker.visit(t, pos);
}
valueParameterizationChecker.visit(t, pos);
}

/** valueParameterizationChecker: A type visitor that descends down the given type looking for instances of value types
@@ -0,0 +1,12 @@
/*
* @test /nodynamiccopyright/
* @bug 8244796 8244799
* @summary Value class literal tests
* @compile/fail/ref=ClassLiteralNegativeTest.out -XDrawDiagnostics ClassLiteralNegativeTest.java
*/

final inline class ClassLiteralNegativeTest {
Class<ClassLiteralNegativeTest> c1 = null; // error
Class<? extends ClassLiteralNegativeTest> c2 = null; // error
Class<? super ClassLiteralNegativeTest> c3 = null; // error
}
@@ -0,0 +1,4 @@
ClassLiteralNegativeTest.java:9:11: compiler.err.type.found.req: ClassLiteralNegativeTest, (compiler.misc.type.req.ref)
ClassLiteralNegativeTest.java:10:11: compiler.err.type.found.req: ClassLiteralNegativeTest, (compiler.misc.type.req.ref)
ClassLiteralNegativeTest.java:11:11: compiler.err.type.found.req: ClassLiteralNegativeTest, (compiler.misc.type.req.ref)
3 errors
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020, 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.
*
* 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
* @bug 8244796 8244799
* @summary Temporary typing of inline class literals.
*/

/* Given an inline class V that implements I1, I2, ... In,
V.class and v.getClass() are typed to be Class<? extends Object & I1 & I2 .. & In>
*/
public class ClassLiteralTypingTest {

interface I {}

public static <T> long size(Class<T> c) {
return 0;
}

public static long foo(Class<? extends I> p) {
return 1;
}

static inline class V implements I {
int x = 42;
}

public static void main(String[] args) {
if (size(V.class) != 0 || size(new V().getClass()) != 0 ||
foo(V.class) != 1 || foo(new V().getClass()) != 1)
throw new AssertionError("Unexpected behavior");
}
}