javac can not infer a var inside a record pattern correctly
Remi Forax
forax at univ-mlv.fr
Sat Oct 12 21:11:08 UTC 2024
Hello,
this code does not compile correctly:
public class StaticSelect<T> {
record A<T>(T value) {}
record Pair<T>(A<T> a, int size) {}
static <T> Pair<T> bar(A<T> a) {
return new Pair<>(a, 0);
}
void foo(A<T> a) {
switch (bar(a)) {
case Pair<T>(/*A<T>*/ var a2, int s) -> {}
}
}
}
Fails with javac either JDK 23 or JDK 24 build 19
javac StaticSelect.java
error: cannot select a static class from a parameterized type
1 error
No idea why, but changing "var a2" by "A<T> a2" fixes the issue.
regards,
Rémi
More information about the amber-dev
mailing list