Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ public TypeBinding resolveType(BlockScope scope) {
}
}

RecordComponentBinding[] componentBindings = this.resolvedType.components();
LocalVariableBinding [] bindings = NO_VARIABLES;
for (int i = 0, l = this.patterns.length; i < l; ++i) {
Pattern p = this.patterns[i];
p.setOuterExpressionType(componentBindings[i].type);
p.resolveTypeWithBindings(bindings, scope);
bindings = LocalVariableBinding.merge(bindings, p.bindingsWhenTrue());
p.setOuterExpressionType(this.resolvedType.components()[i].type);
}

if (this.resolvedType == null || !this.resolvedType.isValidBinding()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RecordPatternTest extends AbstractRegressionTest9 {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
// TESTS_NAMES = new String[] { "testRecPatExhaust018" };
// TESTS_NAMES = new String[] { "testRecordTypeInfer_4643" };
}
private String extraLibPath;
public static Class<?> testClass() {
Expand Down Expand Up @@ -5046,4 +5046,48 @@ record Wildcard<T>(Class<T> bound) implements ComponentType<List<? extends T>> {
"""
});
}
public void testRecordTypeInfer_4643_001() {
runConformTest(new String[] { "X.java", """
public class X {

private static void foo() {
record Box<T>(T t) {}

Box<Box<String>> bo = new Box<>(new Box<>("str"));
if (bo instanceof Box(Box(var sString))) {
System.out.println(sString.length());
}
}

public static void main(String[] args) {
foo();
}
}
""" }, "3");
}
public void testRecordTypeInfer_4643_002() {
runNegativeTest(new String[] {
"X.java",
"""
public class X {

private static void foo() {
record Box<T>(T t) {}
Box<Box<Integer>> bo = new Box<>(new Box<>(1));
if (bo instanceof Box(Box(String sString))) {}
}
public static void main(String[] args) {
foo();
}
}
"""
},
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
" if (bo instanceof Box(Box(String sString))) {}\n" +
" ^^^^^^^^^^^^^^\n" +
"Record component with type Integer is not compatible with type String\n" +
"----------\n");
}

}
Loading