8298184: Incorrect record component type in record patterns
Reviewed-by: vromero
This commit is contained in:
parent
58170f657c
commit
cf63f2e3ea
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/patterns
@ -4204,13 +4204,15 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
tree.type = tree.deconstructor.type = type;
|
||||
Type site = types.removeWildcards(tree.type);
|
||||
Type site = types.capture(tree.type);
|
||||
List<Type> expectedRecordTypes;
|
||||
if (site.tsym.kind == Kind.TYP && ((ClassSymbol) site.tsym).isRecord()) {
|
||||
ClassSymbol record = (ClassSymbol) site.tsym;
|
||||
expectedRecordTypes = record.getRecordComponents()
|
||||
.stream()
|
||||
.map(rc -> types.memberType(site, rc)).collect(List.collector());
|
||||
.map(rc -> types.memberType(site, rc))
|
||||
.map(t -> types.upward(t, types.captures(t)).baseType())
|
||||
.collect(List.collector());
|
||||
tree.record = record;
|
||||
} else {
|
||||
log.error(tree.pos(), Errors.DeconstructionPatternOnlyRecords(site.tsym));
|
||||
|
@ -23,7 +23,10 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8298184
|
||||
* @enablePreview
|
||||
* @compile GenericRecordDeconstructionPattern.java
|
||||
* @run main GenericRecordDeconstructionPattern
|
||||
*/
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -46,6 +49,8 @@ public class GenericRecordDeconstructionPattern {
|
||||
testInference3();
|
||||
assertEquals(0, forEachInference(List.of(new Box(""))));
|
||||
assertEquals(1, forEachInference(List.of(new Box(null))));
|
||||
assertEquals(1, runIfSuperBound(new Box<>(new StringBuilder())));
|
||||
assertEquals(1, runIfSuperBound(new Box<>(0)));
|
||||
}
|
||||
|
||||
void runTest(Function<Box<String>, Integer> test) {
|
||||
@ -120,6 +125,11 @@ public class GenericRecordDeconstructionPattern {
|
||||
}
|
||||
}
|
||||
|
||||
int runIfSuperBound(I<? super String> b) {
|
||||
if (b instanceof Box(var v)) return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sealed interface I<T> {}
|
||||
record Box<V>(V v) implements I<V> {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user