java type system: use captured wildcard bounds in cast context (IDEA-233551)

starting with javac 1.9+ such code starting to compile, javac 8 rejects the code with the same language level used

GitOrigin-RevId: 87a1e4d475927af0ee71cd74f5a66e130908ed82
This commit is contained in:
Anna Kozlova
2020-04-16 12:37:28 +02:00
committed by intellij-monorepo-bot
parent ef5f5bafa1
commit 022c5be762
3 changed files with 3 additions and 2 deletions

View File

@@ -120,6 +120,7 @@ public class TypeConversionUtil {
// 5.5. Casting Contexts
if ((fromTypeRank == SHORT_RANK || fromTypeRank == BYTE_RANK) && toTypeRank == CHAR_RANK) return false;
fromType = uncapture(fromType); //starting from javac 9+
if (fromType instanceof PsiClassType) {
if (languageLevel == null) {
languageLevel = ((PsiClassType)fromType).getLanguageLevel();

View File

@@ -30,6 +30,6 @@ class Foo<T> {
public static void main(String[] args) {
Foo<?> foo = getFoo();
double value = <error descr="Inconvertible types; cannot cast 'capture<?>' to 'double'">(double) foo.getValue()</error>;
double value = (double) foo.getValue();
}
}

View File

@@ -12,6 +12,6 @@ class Foo<T> {
public static void main(String[] args) {
Foo<?> foo = getFoo();
double value = <error descr="Inconvertible types; cannot cast 'capture<?>' to 'double'">(double) foo.getValue()</error>;
double value = (double) foo.getValue();
}
}