Skip to content

Commit

Permalink
Regression test for eclipse-jdt#1788 (eclipse-jdt#1790)
Browse files Browse the repository at this point in the history
* Regression test for
eclipse-jdt#1788
  • Loading branch information
srikanth-sankaran authored and rgrunber committed Jan 9, 2024
1 parent 479b990 commit 62adc55
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3803,4 +3803,58 @@ public int foo(R r) {
"Record pattern should match the signature of the record declaration\n" +
"----------\n");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1788
// Inference issue between the diamond syntax and pattern matching (switch on objects)
public void testGHI1788() {
runConformTest(
new String[] {
"X.java",
"""
public class X {
final static class Entry<K,V> {
K key;
V value;
public Entry(K key, V value) {
this.key = key;
this.value = value;
}
public K key() { return key; }
public V value() { return value; }
public void value(V value) { this.value = value; }
@Override
public String toString() {
return "Key = " + key + " Value = " + value;
}
}
sealed interface I<V> {}
record A<V>(V value) implements I<V> {}
record B<V>(V value) implements I<V> {}
private static <K, V> Entry<K,V> foo(Entry<K, I<V>> entry) {
return new Entry<>(entry.key(), switch (entry.value()) {
case A<V>(V value) -> {
entry.value(new B<>(value));
yield value;
}
case B<V>(V value) -> value;
});
}
public static void main(String[] args) {
Entry<String, I<String>> entry = new Entry<>("KEY", new A<>("VALUE"));
System.out.println(entry);
System.out.println(foo(entry));
System.out.println(entry);
}
}
"""
},
"Key = KEY Value = A[value=VALUE]\n" +
"Key = KEY Value = VALUE\n" +
"Key = KEY Value = B[value=VALUE]");
}
}

0 comments on commit 62adc55

Please sign in to comment.