diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 7a4cef8b3580..b41e68eaf762 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -775,7 +775,7 @@ public final class GenericsHighlightUtil { } } } - else { + else if (!typeElement.isInferredType()){ String description = JavaErrorBundle.message("generics.wildcards.may.be.used.only.as.reference.parameters"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create(); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/WildcardInference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/WildcardInference.java new file mode 100644 index 000000000000..325061f95609 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/WildcardInference.java @@ -0,0 +1,7 @@ +class MyTest { + static > void print(T collection) { + for (var item : collection) { + System.out.println(item); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java index ec83e2094a24..5ca9900a8528 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.codeInsight.daemon; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; @@ -61,6 +61,8 @@ public class LightAdvLVTIHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testWildcardInference() { doTest(); } + public void testGotoDeclarationOnVar() { configureByFile(BASE_PATH + "/" + getTestName(false) + ".java"); final int offset = getEditor().getCaretModel().getOffset();