From b59ffe20e43926797c3bad8e7034c2323749982d Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 18 Jul 2017 18:52:43 +0200 Subject: [PATCH] type arguments in bounds check: ensure capture conversion (IDEA-175899) --- .../src/com/intellij/psi/GenericsUtil.java | 6 +++++- .../CaptureForBoundCheck.java | 20 +++++++++++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CaptureForBoundCheck.java diff --git a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java index 8b1c254dfe5e..9744fb85ba78 100644 --- a/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/GenericsUtil.java @@ -462,8 +462,12 @@ public class GenericsUtil { } public static boolean checkNotInBounds(PsiType type, PsiType bound, PsiReferenceParameterList referenceParameterList) { + //4.10.2 + //Given a generic type declaration C (n > 0), the direct supertypes of the parameterized type C where at least one of the Ri is a wildcard + //type argument, are the direct supertypes of the parameterized type C which is the result of applying capture conversion to C. + PsiType capturedType = PsiUtil.captureToplevelWildcards(type, referenceParameterList); //allow unchecked conversions in method calls but not in type declaration - return checkNotInBounds(type, bound, PsiTreeUtil.getParentOfType(referenceParameterList, PsiCallExpression.class) != null); + return checkNotInBounds(capturedType, bound, PsiTreeUtil.getParentOfType(referenceParameterList, PsiCallExpression.class) != null); } public static boolean checkNotInBounds(PsiType type, PsiType bound, boolean uncheckedConversionByDefault) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CaptureForBoundCheck.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CaptureForBoundCheck.java new file mode 100644 index 000000000000..323840286822 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CaptureForBoundCheck.java @@ -0,0 +1,20 @@ + +class EnumBug { + static class Enum> { + } + + static class Option extends Enum> { + } + + static class EnumSet> { + static > EnumSet noneOf(Class elementType) { + return null; + } + } + + public static void main(String[] args) { + EnumSet<Option> enumSet = EnumSet.<Option>noneOf(Option.class); + EnumSet<Option> enumSetRaw = EnumSet.