From 09c9641e23deee704fbf131a1e0ce6778bc389ad Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 24 Jun 2022 02:16:56 +0200 Subject: [PATCH] FE: Use safe call when searching for suspend modifier The modifier does not exist, when the parameter type is typealias. #KT-35187 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../FirInlineDeclarationChecker.kt | 7 +++++- .../FirBlackBoxCodegenTestGenerated.java | 6 +++++ .../checkers/InlineParameterChecker.kt | 8 +++--- .../box/coroutines/inlineSuspendTypealias.kt | 25 +++++++++++++++++++ .../coroutines/inlineSuspendTypealias.kt | 5 ++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../LightAnalysisModeTestGenerated.java | 5 ++++ .../js/test/JsCodegenBoxTestGenerated.java | 6 +++++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 6 +++++ .../IrCodegenBoxWasmTestGenerated.java | 5 ++++ .../NativeCodegenBoxTestGenerated.java | 6 +++++ 16 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index d2f5011f492..855dc7949b6 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -6582,6 +6582,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("modifierFormBuiltinSuspendFun.kt") public void testModifierFormBuiltinSuspendFun() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index f90e2d1c1a8..51ec7fe0789 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -6582,6 +6582,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("modifierFormBuiltinSuspendFun.kt") public void testModifierFormBuiltinSuspendFun() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 2839427dff0..e5638449203 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -6582,6 +6582,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("modifierFormBuiltinSuspendFun.kt") public void testModifierFormBuiltinSuspendFun() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt index efec318dd50..53d1ef1ab85 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollectorV import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.checkers.getModifier import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics import org.jetbrains.kotlin.fir.containingClass import org.jetbrains.kotlin.fir.declarations.* @@ -40,6 +41,7 @@ import org.jetbrains.kotlin.fir.types.isNullable import org.jetbrains.kotlin.fir.types.toSymbol import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor import org.jetbrains.kotlin.fir.visitors.FirVisitor +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.util.OperatorNameConventions abstract class FirInlineDeclarationChecker : FirFunctionChecker() { @@ -375,7 +377,10 @@ abstract class FirInlineDeclarationChecker : FirFunctionChecker() { if (isSuspendFunctionalType && !param.isCrossinline) { if (function.isSuspend) { - reporter.reportOn(param.returnTypeRef.source, FirErrors.REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE, context) + val modifier = param.returnTypeRef.getModifier(KtTokens.SUSPEND_KEYWORD) + if (modifier != null) { + reporter.reportOn(param.returnTypeRef.source, FirErrors.REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE, context) + } } else { reporter.reportOn(param.source, FirErrors.INLINE_SUSPEND_FUNCTION_TYPE_UNSUPPORTED, context) } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index c4738d93d9f..5631ebb6d81 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -10059,6 +10059,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineParameterChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineParameterChecker.kt index a0606a72f3d..5c6287c2409 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineParameterChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/InlineParameterChecker.kt @@ -44,10 +44,10 @@ object InlineParameterChecker : DeclarationChecker { parameterDescriptor?.type?.isSuspendFunctionType == true ) { if (declaration.hasModifier(KtTokens.SUSPEND_KEYWORD)) { - val typeReference = parameter.typeReference!! - val modifierList = typeReference.modifierList!! - val modifier = modifierList.getModifier(KtTokens.SUSPEND_KEYWORD)!! - context.trace.report(Errors.REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE.on(modifier)) + val modifier = parameter.typeReference?.modifierList?.getModifier(KtTokens.SUSPEND_KEYWORD) + if (modifier != null) { + context.trace.report(Errors.REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE.on(modifier)) + } } else { context.trace.report(Errors.INLINE_SUSPEND_FUNCTION_TYPE_UNSUPPORTED.on(parameter)) } diff --git a/compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt b/compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt new file mode 100644 index 00000000000..67ed5afec49 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt @@ -0,0 +1,25 @@ +// WITH_STDLIB + +import kotlin.coroutines.* + +typealias Handler = suspend (String) -> Unit + +suspend inline fun foo(handler: Handler) { + handler("OK") +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(Continuation(EmptyCoroutineContext) { + it.getOrThrow() + }) +} + +fun box(): String { + var result = "FAIL" + builder { + foo { + result = it + } + } + return result +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt b/compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt new file mode 100644 index 00000000000..d6d144fe9c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt @@ -0,0 +1,5 @@ +// FIR_IDENTICAL +// SKIP_TXT + +typealias Handler = suspend (String) -> Unit +suspend inline fun foo(handler: Handler) = Unit \ No newline at end of file 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 0117bd25956..d0b36ab907e 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 @@ -6588,6 +6588,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("modifierFormBuiltinSuspendFun.kt") public void testModifierFormBuiltinSuspendFun() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index bf84b14cd68..82ba436ed07 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -9939,6 +9939,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 7cbcafde2db..bfd4dd7a43d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -10059,6 +10059,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index aaa88745d14..317fec9e844 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7824,6 +7824,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { runTest("compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 48080389343..352647736d2 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -7019,6 +7019,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 8ee5a658539..03ff6b186c0 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -7061,6 +7061,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 108acbd2025..611432bf2df 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -6219,6 +6219,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception { runTest("compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index dfa5f1b6b37..67e640ca6e8 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -7921,6 +7921,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/coroutines/inlineSuspendLambdaNonLocalReturn.kt"); } + @Test + @TestMetadata("inlineSuspendTypealias.kt") + public void testInlineSuspendTypealias() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineSuspendTypealias.kt"); + } + @Test @TestMetadata("inlinedTryCatchFinally.kt") public void testInlinedTryCatchFinally() throws Exception {