mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 10:23:28 +00:00
8288120: VerifyError with JEP 405 pattern match
Reviewed-by: vromero
This commit is contained in:
parent
b0db33333a
commit
bdf9902f75
@ -97,6 +97,7 @@ import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.LetExpr;
|
||||
import com.sun.tools.javac.tree.TreeInfo;
|
||||
import com.sun.tools.javac.util.Assert;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
/**
|
||||
@ -284,7 +285,7 @@ public class TransPatterns extends TreeTranslator {
|
||||
names.fromString(target.syntheticNameChar() + "c" + target.syntheticNameChar() + component.name),
|
||||
component.erasure(types),
|
||||
currentMethodSym);
|
||||
Symbol accessor = getAccessor(component);
|
||||
Symbol accessor = getAccessor(tree.pos(), component);
|
||||
JCVariableDecl nestedTempVar =
|
||||
make.VarDef(nestedTemp,
|
||||
make.App(make.QualIdent(accessor),
|
||||
@ -344,12 +345,8 @@ public class TransPatterns extends TreeTranslator {
|
||||
result = test != null ? test : makeLit(syms.booleanType, 1);
|
||||
}
|
||||
|
||||
private MethodSymbol getAccessor(RecordComponent component) {
|
||||
private MethodSymbol getAccessor(DiagnosticPosition pos, RecordComponent component) {
|
||||
return component2Proxy.computeIfAbsent(component, c -> {
|
||||
MethodSymbol realAccessor = (MethodSymbol) component.owner
|
||||
.members()
|
||||
.findFirst(component.name, s -> s.kind == Kind.MTH &&
|
||||
((MethodSymbol) s).params.isEmpty());
|
||||
MethodType type = new MethodType(List.of(component.owner.erasure(types)),
|
||||
types.erasure(component.type),
|
||||
List.nil(),
|
||||
@ -359,7 +356,7 @@ public class TransPatterns extends TreeTranslator {
|
||||
type,
|
||||
currentClass);
|
||||
JCStatement accessorStatement =
|
||||
make.Return(make.App(make.Select(make.Ident(proxy.params().head), realAccessor)));
|
||||
make.Return(make.App(make.Select(make.Ident(proxy.params().head), c.accessor)));
|
||||
VarSymbol ctch = new VarSymbol(Flags.SYNTHETIC,
|
||||
names.fromString("catch" + currentClassTree.pos + target.syntheticNameChar()),
|
||||
syms.throwableType,
|
||||
|
||||
47
test/langtools/tools/javac/patterns/ProxyMethodLookup.java
Normal file
47
test/langtools/tools/javac/patterns/ProxyMethodLookup.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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 8288120
|
||||
* @summary Verify an appropriate accessor method is looked up.
|
||||
* @compile --enable-preview -source ${jdk.version} ProxyMethodLookup.java
|
||||
* @run main/othervm --enable-preview ProxyMethodLookup
|
||||
*/
|
||||
public class ProxyMethodLookup {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Object val = new R(new Component());
|
||||
boolean b = val instanceof R(var c);
|
||||
}
|
||||
|
||||
interface ComponentBase {}
|
||||
|
||||
record Component() implements ComponentBase {}
|
||||
|
||||
sealed interface Base {
|
||||
ComponentBase c();
|
||||
}
|
||||
|
||||
record R(Component c) implements Base {}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user