FE: Use safe call when searching for suspend modifier

The modifier does not exist, when the parameter type is typealias.

 #KT-35187 Fixed
This commit is contained in:
Ilmir Usmanov
2022-06-24 02:16:56 +02:00
parent 1e0a705ba1
commit 09c9641e23
16 changed files with 110 additions and 5 deletions
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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)
}
@@ -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 {
@@ -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))
}
@@ -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
}
@@ -0,0 +1,5 @@
// FIR_IDENTICAL
// SKIP_TXT
typealias Handler = suspend (String) -> Unit
suspend inline fun foo(handler: Handler) = Unit
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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");
@@ -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 {
@@ -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 {
@@ -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");
@@ -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 {