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

8271583: [lworld] primitive records can't be reference favoring #533

Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -2526,7 +2526,8 @@ JCTree generateRecordMethod(JCClassDecl tree, Name name, List<VarSymbol> vars, M
syms.typeDescriptorType).appendList(staticArgTypes),
staticArgsValues, bootstrapName, name, false);

VarSymbol _this = new VarSymbol(SYNTHETIC, names._this, tree.sym.type, tree.sym);
Type receiverType = tree.sym.type.isPrimitiveReferenceType() ? tree.sym.type.asValueType() : tree.sym.type;
VarSymbol _this = new VarSymbol(SYNTHETIC, names._this, receiverType, tree.sym);

JCMethodInvocation proxyCall;
if (!isEquals) {
@@ -2610,8 +2611,9 @@ JCFieldAccess makeIndyQualifier(
bootstrapName, staticArgTypes, List.nil());

MethodType indyType = msym.type.asMethodType();
Type receiverType = tree.sym.type.isPrimitiveReferenceType() ? tree.sym.type.asValueType() : tree.sym.type;
indyType = new MethodType(
isStatic ? List.nil() : indyType.argtypes.prepend(tree.sym.type),
isStatic ? List.nil() : indyType.argtypes.prepend(receiverType),
indyType.restype,
indyType.thrown,
syms.methodClass
@@ -4062,6 +4062,15 @@ protected JCClassDecl recordDeclaration(JCModifiers mods, Comment dc) {
nextToken();
mods.flags |= Flags.RECORD;
Name name = typeName();
if ((mods.flags & Flags.PRIMITIVE_CLASS) != 0) {
if (token.kind == DOT) {
final Token pastDot = S.token(1);
if (pastDot.kind == IDENTIFIER && pastDot.name() == names.val) {
nextToken(); nextToken(); // discard .val
mods.flags |= Flags.REFERENCE_FAVORING;
}
}
}

List<JCTypeParameter> typarams = typeParametersOpt();

@@ -4497,6 +4506,7 @@ protected boolean isRecordStart() {
if (token.kind == IDENTIFIER && token.name() == names.record &&
(peekToken(TokenKind.IDENTIFIER, TokenKind.LPAREN) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.EOF) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.DOT) ||
peekToken(TokenKind.IDENTIFIER, TokenKind.LT))) {
checkSourceLevel(Feature.RECORDS);
return true;
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021, 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 8271583
* @summary [lworld] primitive records can't be reference favoring
* @run main/othervm RefFlavoredRecord
*/

This comment has been minimized.

@sadayapalam

sadayapalam Aug 23, 2021
Collaborator

I think this test should not require XDallowWithFieldOperator and also likely "othervm" in the run tag.

And you should also be able to condense the @compile and @run into just @run ??


public primitive record RefFlavoredRecord.val(int theInteger, String theString) {
public static void main(String[] args) {
RefFlavoredRecord rec = RefFlavoredRecord.default;
if (rec != null) {
throw new AssertionError("Ref-favoring record .default should be null?");
}

if (! new RefFlavoredRecord(42, "Fortytwo").equals(new RefFlavoredRecord(42, "Fortytwo"))) {
throw new AssertionError("Records should be equal");
}
}
}