Skip to content

Commit

Permalink
* VerifyError with unnamed pattern variable in instanceof (eclipse-jd…
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran authored and gayanper committed Sep 7, 2024
1 parent ffb721e commit 2915ed0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public TypeReference getType() {
}
@Override
public LocalVariableBinding[] bindingsWhenTrue() {
return (this.local.binding == null || this.local.isUnnamed(this.local.binding.declaringScope)) ?
NO_VARIABLES : new LocalVariableBinding[] { this.local.binding };
return this.local.binding == null ? NO_VARIABLES : new LocalVariableBinding[] { this.local.binding };
}
@Override
public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding expressionType, TypeBinding match, boolean isNarrowing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,67 @@ public void test005() {
----------
""");
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2024
// [Patterns][Unnamed] VerifyError with unnamed pattern variable in instanceof
public void testIssue2024() {
runConformTest(new String[] {
"X.java",
"""
record A(){}
record R<T>(T t) {}
public class X {
private static boolean foo(R<A> r) {
return r instanceof R(var _);
}
public static void main(String argv[]) {
System.out.println(foo(new R<A>(new A())) ? "Pass" : "Fail");
}
}
"""
},
"Pass");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2024
// [Patterns][Unnamed] VerifyError with unnamed pattern variable in instanceof
public void testIssue2024_2() {
runConformTest(new String[] {
"X.java",
"""
record A(){}
record R<T>(T t) {}
public class X {
private static boolean foo(R<? extends A> r) {
return r instanceof R(var _);
}
public static void main(String argv[]) {
System.out.println(foo(new R<A>(new A())) ? "Pass" : "Fail");
}
}
"""
},
"Pass");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2024
// [Patterns][Unnamed] VerifyError with unnamed pattern variable in instanceof
public void testIssue2024_3() {
runConformTest(new String[] {
"X.java",
"""
interface I {}
record A() implements I {}
record R<T>(T t) {}
public class X {
private static boolean foo(R<? extends I> r) {
return r instanceof R(var _);
}
public static void main(String argv[]) {
System.out.println(foo(new R<A>(new A())) ? "Pass" : "Fail");
}
}
"""
},
"Pass");
}
}

0 comments on commit 2915ed0

Please sign in to comment.