File tree 2 files changed +14
-2
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/patterns
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -4204,13 +4204,15 @@ public void visitRecordPattern(JCRecordPattern tree) {
4204
4204
}
4205
4205
}
4206
4206
tree .type = tree .deconstructor .type = type ;
4207
- Type site = types .removeWildcards (tree .type );
4207
+ Type site = types .capture (tree .type );
4208
4208
List <Type > expectedRecordTypes ;
4209
4209
if (site .tsym .kind == Kind .TYP && ((ClassSymbol ) site .tsym ).isRecord ()) {
4210
4210
ClassSymbol record = (ClassSymbol ) site .tsym ;
4211
4211
expectedRecordTypes = record .getRecordComponents ()
4212
4212
.stream ()
4213
- .map (rc -> types .memberType (site , rc )).collect (List .collector ());
4213
+ .map (rc -> types .memberType (site , rc ))
4214
+ .map (t -> types .upward (t , types .captures (t )).baseType ())
4215
+ .collect (List .collector ());
4214
4216
tree .record = record ;
4215
4217
} else {
4216
4218
log .error (tree .pos (), Errors .DeconstructionPatternOnlyRecords (site .tsym ));
Original file line number Diff line number Diff line change 23
23
24
24
/**
25
25
* @test
26
+ * @bug 8298184
26
27
* @enablePreview
28
+ * @compile GenericRecordDeconstructionPattern.java
29
+ * @run main GenericRecordDeconstructionPattern
27
30
*/
28
31
import java .util .List ;
29
32
import java .util .Objects ;
@@ -46,6 +49,8 @@ void run() {
46
49
testInference3 ();
47
50
assertEquals (0 , forEachInference (List .of (new Box ("" ))));
48
51
assertEquals (1 , forEachInference (List .of (new Box (null ))));
52
+ assertEquals (1 , runIfSuperBound (new Box <>(new StringBuilder ())));
53
+ assertEquals (1 , runIfSuperBound (new Box <>(0 )));
49
54
}
50
55
51
56
void runTest (Function <Box <String >, Integer > test ) {
@@ -120,6 +125,11 @@ int runSwitchInferenceNested(I<I<String>> b) {
120
125
}
121
126
}
122
127
128
+ int runIfSuperBound (I <? super String > b ) {
129
+ if (b instanceof Box (var v )) return 1 ;
130
+ return -1 ;
131
+ }
132
+
123
133
sealed interface I <T > {}
124
134
record Box <V >(V v ) implements I <V > {
125
135
}
You can’t perform that action at this time.
0 commit comments