diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index a72669a5798..d6c2f2c8150 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -195,6 +195,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/comparisonOfGenericInterfaceWithGenericClass.kt"); } + @Test + @TestMetadata("compilerCrashParameterType.kt") + public void testCompilerCrashParameterType() throws Exception { + runTest("compiler/testData/diagnostics/tests/compilerCrashParameterType.kt"); + } + @Test @TestMetadata("Constants.kt") public void testConstants() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index bc30a728984..4752162bc2e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -195,6 +195,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/comparisonOfGenericInterfaceWithGenericClass.kt"); } + @Test + @TestMetadata("compilerCrashParameterType.kt") + public void testCompilerCrashParameterType() throws Exception { + runTest("compiler/testData/diagnostics/tests/compilerCrashParameterType.kt"); + } + @Test @TestMetadata("Constants.kt") public void testConstants() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/cast.kt b/compiler/fir/analysis-tests/testData/resolve/cast.kt index 25782fdfc86..d322b0af741 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cast.kt +++ b/compiler/fir/analysis-tests/testData/resolve/cast.kt @@ -4,4 +4,4 @@ val y = 2 as Any val f = fun() = 3 as Any val g = {} val h: (String) -> Boolean = { _ -> false } -val hError = { _ -> true } +val hError = { _ -> true } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 71120ce37ec..822e8351bfe 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -195,6 +195,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/comparisonOfGenericInterfaceWithGenericClass.kt"); } + @Test + @TestMetadata("compilerCrashParameterType.kt") + public void testCompilerCrashParameterType() throws Exception { + runTest("compiler/testData/diagnostics/tests/compilerCrashParameterType.kt"); + } + @Test @TestMetadata("Constants.kt") public void testConstants() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index c6d5c755ccc..ca2f0a5b632 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -195,6 +195,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/comparisonOfGenericInterfaceWithGenericClass.kt"); } + @Test + @TestMetadata("compilerCrashParameterType.kt") + public void testCompilerCrashParameterType() throws Exception { + runTest("compiler/testData/diagnostics/tests/compilerCrashParameterType.kt"); + } + @Test @TestMetadata("Constants.kt") public void testConstants() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index bb077fef84a..33c259aeeb7 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -118,7 +118,7 @@ private fun ConeDiagnostic.toKtDiagnostic( is ConeSyntaxDiagnostic -> FirSyntaxErrors.SYNTAX.createOn(callOrAssignmentSource ?: source, reason) is ConeSimpleDiagnostic -> when { - source?.kind is KtFakeSourceElementKind && source.kind != KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess -> null + (source?.kind as? KtFakeSourceElementKind)?.canBeIgnored == true -> null else -> this.getFactory(source).createOn(callOrAssignmentSource ?: source) } @@ -155,6 +155,10 @@ private fun ConeDiagnostic.toKtDiagnostic( else -> throw IllegalArgumentException("Unsupported diagnostic type: ${this.javaClass}") } +private val KtFakeSourceElementKind.canBeIgnored: Boolean + get() = this != KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess + && this != KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter + fun FirBasedSymbol<*>.toInvisibleReferenceDiagnostic(source: KtSourceElement?): KtDiagnostic? = when (val symbol = this) { is FirCallableSymbol<*> -> FirErrors.INVISIBLE_REFERENCE.createOn(source, symbol, symbol.visibility, symbol.callableId.classId) is FirClassLikeSymbol<*> -> FirErrors.INVISIBLE_REFERENCE.createOn(source, symbol, symbol.visibility, symbol.classId.outerClassId) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 9a0315107c9..18d92fa46a7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -1077,7 +1077,10 @@ open class FirDeclarationsResolveTransformer( "No type for parameter", DiagnosticKind.ValueParameterWithNoTypeAnnotation ) - ) + ), + fallbackSource = valueParameter.source?.fakeElement( + KtFakeSourceElementKind.ImplicitReturnTypeOfLambdaValueParameter, + ), ) ) } diff --git a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt index 39353186ddc..2900060d260 100644 --- a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt @@ -5,7 +5,7 @@ fun test(a, ) -val bar = fun(a){} +val bar = fun(a){} -val la = { a -> } +val la = { a -> } val las = { a: Int -> } diff --git a/compiler/testData/diagnostics/tests/compilerCrashParameterType.fir.kt b/compiler/testData/diagnostics/tests/compilerCrashParameterType.fir.kt new file mode 100644 index 00000000000..40a62bf8336 --- /dev/null +++ b/compiler/testData/diagnostics/tests/compilerCrashParameterType.fir.kt @@ -0,0 +1,8 @@ +// ISSUE: KT-58906 + +fun someFun(i: Int) = 42 +fun someSad(i: () -> String) = 42 + +fun main(args: Array) { + { x -> someFun(x) } //here should be CANNOT_INFER_PARAMETER_TYPE +} diff --git a/compiler/testData/diagnostics/tests/compilerCrashParameterType.kt b/compiler/testData/diagnostics/tests/compilerCrashParameterType.kt new file mode 100644 index 00000000000..ac0d463e0d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/compilerCrashParameterType.kt @@ -0,0 +1,8 @@ +// ISSUE: KT-58906 + +fun someFun(i: Int) = 42 +fun someSad(i: () -> String) = 42 + +fun main(args: Array) { + { x -> someFun(x) } //here should be CANNOT_INFER_PARAMETER_TYPE +} diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt index a53c1ba8f57..d3f9250447c 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt @@ -1,7 +1,7 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE -val a = fun (x) = x +val a = fun (x) = x val b: (Int) -> Int = fun (x) = x + 3 diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt index cc8a8b93bde..456a84941cd 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt @@ -9,8 +9,8 @@ val returnTypeWithParameter = { (b: Int): Int - val receiverWithFunctionType = { ((Int) -> Int).() -> } -val parenthesizedParameters = { (a: Int) -> } -val parenthesizedParameters2 = { (b) -> } +val parenthesizedParameters = { (a: Int) -> } +val parenthesizedParameters2 = { (b) -> } val none = { -> } @@ -18,7 +18,7 @@ val none = { -> } val parameterWithFunctionType = { a: ((Int) -> Int) -> } // todo fix parser val newSyntax = { a: Int -> } -val newSyntax1 = { a, b -> } +val newSyntax1 = { a, b -> } val newSyntax2 = { a: Int, b: Int -> } -val newSyntax3 = { a, b: Int -> } -val newSyntax4 = { a: Int, b -> } +val newSyntax3 = { a, b: Int -> } +val newSyntax4 = { a: Int, b -> } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt index 4a176c8f6b1..fcc7a7a57cd 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt @@ -24,7 +24,7 @@ fun bar() { y2 checkType { _<(A) -> Unit>() } - val z = { (a: Int, b: String) -> + val z = { (a: Int, b: String) -> a checkType { _() } b checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt index 356cd30d48e..21414f0e215 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -val la = { a -> } +val la = { a -> } val las = { a: Int -> } -val larg = { a -> }(123) -val twoarg = { a, b: String, c -> }(123, "asdf", 123) \ No newline at end of file +val larg = { a -> }(123) +val twoarg = { a, b: String, c -> }(123, "asdf", 123) diff --git a/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt index 07047a5c1eb..2940be33e2a 100644 --- a/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt @@ -1,7 +1,7 @@ -fun test1(i: Int) = { i -> +fun test1(i: Int) = { i -> i }(i) -fun test2() = { i -> i }() +fun test2() = { i -> i }() -fun test3() = { i -> i }(1) +fun test3() = { i -> i }(1) diff --git a/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt b/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt index 216665dfc7e..acd4ad11ecb 100644 --- a/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt @@ -1,3 +1,3 @@ fun foo(a: Any) { - foo({ index -> } { }) + foo({ index -> } { }) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nonFunctionalExpectedTypeForLambdaArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/nonFunctionalExpectedTypeForLambdaArgument.fir.kt index 63780bd4239..09f86b373c6 100644 --- a/compiler/testData/diagnostics/tests/inference/nonFunctionalExpectedTypeForLambdaArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nonFunctionalExpectedTypeForLambdaArgument.fir.kt @@ -32,5 +32,5 @@ fun testParamCall() { } fun testNoContext() { - { it -> it } + { it -> it } } diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 02b1629fa12..7db4d46d1a7 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -195,6 +195,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/comparisonOfGenericInterfaceWithGenericClass.kt"); } + @Test + @TestMetadata("compilerCrashParameterType.kt") + public void testCompilerCrashParameterType() throws Exception { + runTest("compiler/testData/diagnostics/tests/compilerCrashParameterType.kt"); + } + @Test @TestMetadata("Constants.kt") public void testConstants() throws Exception {