diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.kt new file mode 100644 index 00000000000..e0ffc0be979 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.kt @@ -0,0 +1,16 @@ +//For testing error messages text see HtmlTabledDescriptorRendererTest.testFunctionPlaceholder +package a + +class A +fun foo(a: A) = a +fun bar(f: (T) -> R) = f + +fun test() { + foo { it } + foo { x -> x} + foo { (x: Int) -> x} + + bar { it + 1 } + bar { x -> x + 1} + bar { (x: Int) -> x + 1} +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index d3220625c18..049e4422375 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2275,6 +2275,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.kt"); } + @TestMetadata("FunctionPlaceholder.kt") + public void testFunctionPlaceholder() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.kt"); + } + @TestMetadata("NoAmbiguityForDifferentFunctionTypes.kt") public void testNoAmbiguityForDifferentFunctionTypes() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt"); diff --git a/idea/testData/htmlTabledRenderer/htmlTabledRenderer.kt b/idea/testData/htmlTabledRenderer/conflictingSubstitutions.kt similarity index 100% rename from idea/testData/htmlTabledRenderer/htmlTabledRenderer.kt rename to idea/testData/htmlTabledRenderer/conflictingSubstitutions.kt diff --git a/idea/testData/htmlTabledRenderer/diagnostic1.html b/idea/testData/htmlTabledRenderer/conflictingSubstitutions1.html similarity index 98% rename from idea/testData/htmlTabledRenderer/diagnostic1.html rename to idea/testData/htmlTabledRenderer/conflictingSubstitutions1.html index 7c0972d4372..d4856e6bdf5 100644 --- a/idea/testData/htmlTabledRenderer/diagnostic1.html +++ b/idea/testData/htmlTabledRenderer/conflictingSubstitutions1.html @@ -1,3 +1,4 @@ + Type inference failed: Cannot infer type parameter T diff --git a/idea/testData/htmlTabledRenderer/diagnostic2.html b/idea/testData/htmlTabledRenderer/conflictingSubstitutions2.html similarity index 98% rename from idea/testData/htmlTabledRenderer/diagnostic2.html rename to idea/testData/htmlTabledRenderer/conflictingSubstitutions2.html index 7fbd9705fc1..9175462f81e 100644 --- a/idea/testData/htmlTabledRenderer/diagnostic2.html +++ b/idea/testData/htmlTabledRenderer/conflictingSubstitutions2.html @@ -1,3 +1,4 @@ + Type inference failed: Cannot infer type parameter T diff --git a/idea/testData/htmlTabledRenderer/functionPlaceholder.kt b/idea/testData/htmlTabledRenderer/functionPlaceholder.kt new file mode 100644 index 00000000000..7ea1effe1ff --- /dev/null +++ b/idea/testData/htmlTabledRenderer/functionPlaceholder.kt @@ -0,0 +1,8 @@ +class A +fun foo(a: A) = a + +fun test() { + foo { it } + foo { x -> x} + foo { (x: Int) -> x} +} \ No newline at end of file diff --git a/idea/testData/htmlTabledRenderer/functionPlaceholder1.html b/idea/testData/htmlTabledRenderer/functionPlaceholder1.html new file mode 100644 index 00000000000..a41e3eb40d7 --- /dev/null +++ b/idea/testData/htmlTabledRenderer/functionPlaceholder1.html @@ -0,0 +1,48 @@ + + +Type inference failed: + + + + + + + + + + + + + + + + + + + +
+ + +fun + <T, R> + foo +( +a : A<T, R> +) + : A<T, R>
+cannot be applied to
+ + + + +( + + + +??? -> ??? + + + +) +
+ \ No newline at end of file diff --git a/idea/testData/htmlTabledRenderer/functionPlaceholder2.html b/idea/testData/htmlTabledRenderer/functionPlaceholder2.html new file mode 100644 index 00000000000..cebdd26caec --- /dev/null +++ b/idea/testData/htmlTabledRenderer/functionPlaceholder2.html @@ -0,0 +1,48 @@ + + +Type inference failed: + + + + + + + + + + + + + + + + + + + +
+ + +fun + <T, R> + foo +( +a : A<T, R> +) + : A<T, R>
+cannot be applied to
+ + + + +( + + + +(???) -> ??? + + + +) +
+ \ No newline at end of file diff --git a/idea/testData/htmlTabledRenderer/functionPlaceholder3.html b/idea/testData/htmlTabledRenderer/functionPlaceholder3.html new file mode 100644 index 00000000000..465a3c5a818 --- /dev/null +++ b/idea/testData/htmlTabledRenderer/functionPlaceholder3.html @@ -0,0 +1,48 @@ + + +Type inference failed: + + + + + + + + + + + + + + + + + + + +
+ + +fun + <T, R> + foo +( +a : A<T, R> +) + : A<T, R>
+cannot be applied to
+ + + + +( + + + +(jet.Int) -> ??? + + + +) +
+ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/highlighter/HtmlTabledDescriptorRendererTest.java b/idea/tests/org/jetbrains/jet/plugin/highlighter/HtmlTabledDescriptorRendererTest.java index 7bcac5fa4e5..9663d48b156 100644 --- a/idea/tests/org/jetbrains/jet/plugin/highlighter/HtmlTabledDescriptorRendererTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/highlighter/HtmlTabledDescriptorRendererTest.java @@ -16,12 +16,14 @@ package org.jetbrains.jet.plugin.highlighter; +import com.google.common.collect.Sets; import com.intellij.openapi.util.Condition; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; +import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.JetFile; @@ -31,7 +33,9 @@ import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.plugin.PluginTestCaseBase; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class HtmlTabledDescriptorRendererTest extends JetLiteFixture { @Override @@ -44,28 +48,37 @@ public class HtmlTabledDescriptorRendererTest extends JetLiteFixture { return PluginTestCaseBase.getTestDataPathBase() + "/htmlTabledRenderer/"; } - public void testHtmlTabledRenderer() throws Exception { - String fileName = "htmlTabledRenderer.kt"; + public void doTest(String name, int diagnosticNumber, AbstractDiagnosticFactory... diagnosticFactories) throws Exception { + String fileName = name + ".kt"; JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName)); AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(psiFile, Collections.emptyList()); BindingContext bindingContext = analyzeExhaust.getBindingContext(); + final Set factoriesSet = Sets.newHashSet(diagnosticFactories); List diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics(), new Condition() { @Override public boolean value(Diagnostic diagnostic) { - return diagnostic.getFactory() == Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS; + return factoriesSet.contains(diagnostic.getFactory()); } }); - assertEquals(diagnostics.size(), 2); + assertEquals("Expected diagnostics number mismatch:", diagnosticNumber, diagnostics.size()); int index = 1; for (Diagnostic diagnostic : diagnostics) { - String readableDiagnosticHtml = IdeErrorMessages.RENDERER.render(diagnostic).replaceAll(">", ">\n"); - assertSameLinesWithFile(getTestDataPath() + "/diagnostic" + index + ".html", readableDiagnosticHtml); + String readableDiagnosticHtml = "\n" + IdeErrorMessages.RENDERER.render(diagnostic).replaceAll(">", ">\n"); + assertSameLinesWithFile(getTestDataPath() + "/" + name + index + ".html", readableDiagnosticHtml); index++; } } + + public void testConflictingSubstitutions() throws Exception { + doTest("conflictingSubstitutions", 2, Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS); + } + + public void testFunctionPlaceholder() throws Exception { + doTest("functionPlaceholder", 3, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH); + } }