Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit bdf9902

Browse files
committed
8288120: VerifyError with JEP 405 pattern match
Reviewed-by: vromero
1 parent b0db333 commit bdf9902

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import com.sun.tools.javac.tree.JCTree.LetExpr;
9898
import com.sun.tools.javac.tree.TreeInfo;
9999
import com.sun.tools.javac.util.Assert;
100+
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
100101
import com.sun.tools.javac.util.List;
101102

102103
/**
@@ -284,7 +285,7 @@ public void visitRecordPattern(JCRecordPattern tree) {
284285
names.fromString(target.syntheticNameChar() + "c" + target.syntheticNameChar() + component.name),
285286
component.erasure(types),
286287
currentMethodSym);
287-
Symbol accessor = getAccessor(component);
288+
Symbol accessor = getAccessor(tree.pos(), component);
288289
JCVariableDecl nestedTempVar =
289290
make.VarDef(nestedTemp,
290291
make.App(make.QualIdent(accessor),
@@ -344,12 +345,8 @@ public void visitRecordPattern(JCRecordPattern tree) {
344345
result = test != null ? test : makeLit(syms.booleanType, 1);
345346
}
346347

347-
private MethodSymbol getAccessor(RecordComponent component) {
348+
private MethodSymbol getAccessor(DiagnosticPosition pos, RecordComponent component) {
348349
return component2Proxy.computeIfAbsent(component, c -> {
349-
MethodSymbol realAccessor = (MethodSymbol) component.owner
350-
.members()
351-
.findFirst(component.name, s -> s.kind == Kind.MTH &&
352-
((MethodSymbol) s).params.isEmpty());
353350
MethodType type = new MethodType(List.of(component.owner.erasure(types)),
354351
types.erasure(component.type),
355352
List.nil(),
@@ -359,7 +356,7 @@ private MethodSymbol getAccessor(RecordComponent component) {
359356
type,
360357
currentClass);
361358
JCStatement accessorStatement =
362-
make.Return(make.App(make.Select(make.Ident(proxy.params().head), realAccessor)));
359+
make.Return(make.App(make.Select(make.Ident(proxy.params().head), c.accessor)));
363360
VarSymbol ctch = new VarSymbol(Flags.SYNTHETIC,
364361
names.fromString("catch" + currentClassTree.pos + target.syntheticNameChar()),
365362
syms.throwableType,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8288120
27+
* @summary Verify an appropriate accessor method is looked up.
28+
* @compile --enable-preview -source ${jdk.version} ProxyMethodLookup.java
29+
* @run main/othervm --enable-preview ProxyMethodLookup
30+
*/
31+
public class ProxyMethodLookup {
32+
33+
public static void main(String[] args) {
34+
Object val = new R(new Component());
35+
boolean b = val instanceof R(var c);
36+
}
37+
38+
interface ComponentBase {}
39+
40+
record Component() implements ComponentBase {}
41+
42+
sealed interface Base {
43+
ComponentBase c();
44+
}
45+
46+
record R(Component c) implements Base {}
47+
}

0 commit comments

Comments
 (0)