Skip to content

Commit 9fef14a

Browse files
committed
8375571: Compiler crash when using record pattern matching with a generic type parameter shadowing a record class
Reviewed-by: vromero
1 parent 2953e0f commit 9fef14a

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4269,7 +4269,7 @@ public void visitRecordPattern(JCRecordPattern tree) {
42694269
}
42704270

42714271
List<Type> expectedRecordTypes;
4272-
if (site.tsym.kind == Kind.TYP && ((ClassSymbol) site.tsym).isRecord()) {
4272+
if (site.tsym instanceof ClassSymbol clazz && clazz.isRecord()) {
42734273
ClassSymbol record = (ClassSymbol) site.tsym;
42744274
expectedRecordTypes = record.getRecordComponents()
42754275
.stream()

test/langtools/tools/javac/patterns/DeconstructionPatternErrors.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @test /nodynamiccopyright/
3+
* @bug 8375571
34
* @summary Verify error reports for erroneous deconstruction patterns are sensible
45
* @compile/fail/ref=DeconstructionPatternErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDdev DeconstructionPatternErrors.java
56
*/
@@ -39,6 +40,10 @@ case GenRecord(String s) -> {}
3940
boolean b = p instanceof P(int i) p; //introducing a variable for the record pattern
4041
}
4142

43+
<T> void typeVarTest(T p) {
44+
if (p instanceof T(int i) && i == 0); //T is a type variable
45+
}
46+
4247
public record P(int i) {
4348
}
4449

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
DeconstructionPatternErrors.java:35:37: compiler.err.illegal.start.of.type
2-
DeconstructionPatternErrors.java:37:28: compiler.err.illegal.start.of.type
3-
DeconstructionPatternErrors.java:39:42: compiler.err.expected: ';'
4-
DeconstructionPatternErrors.java:39:43: compiler.err.not.stmt
5-
DeconstructionPatternErrors.java:15:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.util.List<java.lang.String>, java.util.ArrayList<java.lang.Integer>)
6-
DeconstructionPatternErrors.java:16:29: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, java.util.ArrayList<java.lang.Integer>
7-
DeconstructionPatternErrors.java:17:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
8-
DeconstructionPatternErrors.java:18:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
9-
DeconstructionPatternErrors.java:19:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, DeconstructionPatternErrors.P)
10-
DeconstructionPatternErrors.java:20:26: compiler.err.incorrect.number.of.nested.patterns: java.lang.Runnable,java.lang.Runnable, java.lang.Runnable
1+
DeconstructionPatternErrors.java:36:37: compiler.err.illegal.start.of.type
2+
DeconstructionPatternErrors.java:38:28: compiler.err.illegal.start.of.type
3+
DeconstructionPatternErrors.java:40:42: compiler.err.expected: ';'
4+
DeconstructionPatternErrors.java:40:43: compiler.err.not.stmt
5+
DeconstructionPatternErrors.java:16:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.util.List<java.lang.String>, java.util.ArrayList<java.lang.Integer>)
6+
DeconstructionPatternErrors.java:17:29: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, java.util.ArrayList<java.lang.Integer>
7+
DeconstructionPatternErrors.java:18:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
8+
DeconstructionPatternErrors.java:19:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
9+
DeconstructionPatternErrors.java:20:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, DeconstructionPatternErrors.P)
1110
DeconstructionPatternErrors.java:21:26: compiler.err.incorrect.number.of.nested.patterns: java.lang.Runnable,java.lang.Runnable, java.lang.Runnable
12-
DeconstructionPatternErrors.java:22:26: compiler.err.incorrect.number.of.nested.patterns: int, int,compiler.misc.type.none
13-
DeconstructionPatternErrors.java:23:26: compiler.err.incorrect.number.of.nested.patterns: int, int,int
14-
DeconstructionPatternErrors.java:24:36: compiler.err.cant.resolve.location: kindname.class, Unresolvable, , , (compiler.misc.location: kindname.class, DeconstructionPatternErrors, null)
15-
DeconstructionPatternErrors.java:24:26: compiler.err.incorrect.number.of.nested.patterns: int, int,Unresolvable
16-
DeconstructionPatternErrors.java:25:13: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
17-
DeconstructionPatternErrors.java:26:29: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
18-
DeconstructionPatternErrors.java:27:44: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
19-
DeconstructionPatternErrors.java:27:13: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
20-
DeconstructionPatternErrors.java:28:40: compiler.err.match.binding.exists
21-
DeconstructionPatternErrors.java:29:56: compiler.err.already.defined: kindname.variable, v1, kindname.method, meth()
22-
DeconstructionPatternErrors.java:29:64: compiler.err.already.defined: kindname.variable, v2, kindname.method, meth()
23-
22 errors
11+
DeconstructionPatternErrors.java:22:26: compiler.err.incorrect.number.of.nested.patterns: java.lang.Runnable,java.lang.Runnable, java.lang.Runnable
12+
DeconstructionPatternErrors.java:23:26: compiler.err.incorrect.number.of.nested.patterns: int, int,compiler.misc.type.none
13+
DeconstructionPatternErrors.java:24:26: compiler.err.incorrect.number.of.nested.patterns: int, int,int
14+
DeconstructionPatternErrors.java:25:36: compiler.err.cant.resolve.location: kindname.class, Unresolvable, , , (compiler.misc.location: kindname.class, DeconstructionPatternErrors, null)
15+
DeconstructionPatternErrors.java:25:26: compiler.err.incorrect.number.of.nested.patterns: int, int,Unresolvable
16+
DeconstructionPatternErrors.java:26:13: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
17+
DeconstructionPatternErrors.java:27:29: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
18+
DeconstructionPatternErrors.java:28:44: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
19+
DeconstructionPatternErrors.java:28:13: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, DeconstructionPatternErrors.GenRecord<java.lang.String>
20+
DeconstructionPatternErrors.java:29:40: compiler.err.match.binding.exists
21+
DeconstructionPatternErrors.java:30:56: compiler.err.already.defined: kindname.variable, v1, kindname.method, meth()
22+
DeconstructionPatternErrors.java:30:64: compiler.err.already.defined: kindname.variable, v2, kindname.method, meth()
23+
DeconstructionPatternErrors.java:44:26: compiler.err.deconstruction.pattern.only.records: T
24+
23 errors

0 commit comments

Comments
 (0)