From 6a9504f26a933e53c218267f785f678ce951a6ba Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 22 Jun 2020 17:36:23 +0300 Subject: [PATCH] [FIR-TEST] Add coroutines diagnostic tests from old FE to FIR test suite --- ...endDiagnosticsTestWithStdlibGenerated.java | 882 +++++++++++++++++- .../allowNullOperatorsForResult_1_3.fir.kt | 7 + .../allowNullOperatorsForResult_1_4.kt | 1 + .../allowResultInReturnTypeWithFlag.fir.kt | 9 + .../allowResultInReturnType_1_3.fir.kt | 4 + .../coroutines/allowResultInReturnType_1_4.kt | 1 + .../coroutines/basicBuildListBuildMap.kt | 1 + .../callableReference/bigArity.fir.kt | 19 + .../callableReferenceOnUnresolvedLHS.fir.kt | 13 + .../callableReference/property.fir.kt | 14 + ...pendConversionForCallableReferences.fir.kt | 17 + .../coroutines/callableReferences.kt | 1 + .../coroutines/coroutineContext.fir.kt | 53 ++ .../coroutines/coroutinesDisabled.fir.kt | 18 + .../coroutinesEnabledWithWarning.fir.kt | 18 + .../coroutines/illegalSuspendCalls.fir.kt | 22 + .../illegalSuspendCallsForDelegated.fir.kt | 8 + .../inference/applyInsideCoroutine.fir.kt | 37 + ...InferenceForMaterializeWithExpectedType.kt | 1 + ...callableReferenceToASuspendFunction.fir.kt | 22 + .../chainCallWithExtensionExplicitTypes.kt | 1 + ...neInferenceWithCapturedTypeVariable.fir.kt | 19 + .../coroutines/inference/correctMember.fir.kt | 25 + ...olonExpressionToClassWithParameters.fir.kt | 38 + .../elvisOperatorAgainstFlexibleType.kt | 1 + .../coroutines/inference/extensionPriority.kt | 1 + .../inference/extensionSuspend.fir.kt | 43 + ...extensionWithNonValuableConstraints.fir.kt | 62 ++ ...thNonValuableConstraintsGenericBase.fir.kt | 52 ++ ...sionsWithNonValuableConstraints_1_2.fir.kt | 17 + .../inference/incorrectCalls.fir.kt | 36 + .../inferCoroutineTypeInOldVersion.fir.kt | 30 + .../inferenceFromMethodInsideLocalVariable.kt | 1 + .../coroutines/inference/kt15516.fir.kt | 19 + .../coroutines/inference/kt32097.kt | 1 + .../coroutines/inference/kt32203.kt | 1 + .../coroutines/inference/kt32271.kt | 1 + .../coroutines/inference/kt33542.fir.kt | 27 + .../coroutines/inference/kt35306.kt | 1 + .../coroutines/inference/kt35684.fir.kt | 35 + .../coroutines/inference/kt36202.kt | 1 + .../coroutines/inference/kt36220.fir.kt | 20 + .../coroutines/inference/kt38420.kt | 1 + .../coroutines/inference/kt38667.fir.kt | 34 + .../nestedLambdaInferenceWithListMap.kt | 1 + .../nestedSuspendCallInsideLambda.kt | 1 + .../plusAssignInCoroutineContext.fir.kt | 37 + .../inference/plusAssignWithLambda.fir.kt | 42 + .../inference/plusAssignWithLambda2.fir.kt | 20 + ...vedExpressionInsideBuilderInference.fir.kt | 20 + .../inference/recursiveGenerators.fir.kt | 22 + .../inference/recursiveGenerators2.fir.kt | 24 + ...esolveUsualCallWithBuilderInference.fir.kt | 37 + .../inference/returnTypeInference.kt | 1 + .../inference/returnTypeInference2.kt | 1 + ...everalCandidatesWithDifferentVisibility.kt | 1 + .../inference/simpleGenerator.fir.kt | 34 + .../inference/suspendCallsWithErrors.fir.kt | 24 + .../suspendCallsWrongUpperBound.fir.kt | 13 + .../inference/twoReceiversInScope.kt | 1 + .../inference/typeFromReceiver.fir.kt | 17 + ...seInferenceInformationFromExtension.fir.kt | 33 + .../variableCallInsideBuilderFunction.kt | 1 + .../inference/variableOfAFunctionTypeCall.kt | 1 + .../coroutines/inference/withParameter.kt | 1 + .../inference/withUninferredParameter.fir.kt | 21 + ...inlineOrdinaryOfCrossinlineOrdinary.fir.kt | 34 + .../inlineOrdinaryOfCrossinlineSuspend.fir.kt | 38 + .../inlineOrdinaryOfNoinlineOrdinary.fir.kt | 33 + .../inlineOrdinaryOfNoinlineSuspend.fir.kt | 38 + .../inlineOrdinaryOfOrdinary.fir.kt | 40 + .../inlineOrdinaryOfSuspend.fir.kt | 40 + .../inlineSuspendOfCrossinlineOrdinary.fir.kt | 39 + .../inlineSuspendOfCrossinlineSuspend.fir.kt | 41 + .../inlineSuspendOfNoinlineOrdinary.fir.kt | 39 + .../inlineSuspendOfNoinlineSuspend.kt | 1 + .../inlineSuspendOfOrdinary.fir.kt | 37 + .../inlineSuspendOfSuspend.fir.kt | 42 + .../irrelevantSuspendDeclarations.kt | 1 + .../kSuspendFunctionAsSupertype.fir.kt | 5 + .../testsWithStdLib/coroutines/kt18292.fir.kt | 19 + .../testsWithStdLib/coroutines/kt28658.fir.kt | 34 + .../testsWithStdLib/coroutines/kt36947.fir.kt | 6 + .../testsWithStdLib/coroutines/kt37309.fir.kt | 24 + .../testsWithStdLib/coroutines/kt38179.kt | 1 + .../coroutines/lambdaExpectedType.fir.kt | 53 ++ .../coroutines/mixingSuspendability.fir.kt | 6 + .../modifierFormForNonBuiltInSuspend.fir.kt | 76 ++ ...orNonBuiltInSuspendWithAnyParameter.fir.kt | 84 ++ .../noDefaultCoroutineImports.fir.kt | 9 + .../coroutines/nonLocalSuspension.fir.kt | 81 ++ .../nonModifierFormForBuiltIn.fir.kt | 45 + ...odifierFormForBuiltInRenameOnImport.fir.kt | 30 + .../coroutines/operators.fir.kt | 60 ++ .../release/coroutineContext.fir.kt | 8 + ...nguageVersionIsNotEqualToApiVersion.fir.kt | 38 + .../coroutines/release/suspend.kt | 1 + .../restrictSuspension/allMembersAllowed.kt | 1 + .../restrictSuspension/extensions.fir.kt | 130 +++ .../restrictSuspension/memberExtension.fir.kt | 62 ++ .../restrictSuspension/notRelatedFun.fir.kt | 73 ++ .../restrictSuspension/outerYield_1_2.fir.kt | 94 ++ .../restrictSuspension/outerYield_1_3.fir.kt | 99 ++ .../restrictSuspension/sameInstance.fir.kt | 54 ++ .../restrictSuspension/simpleForbidden.fir.kt | 15 + .../wrongEnclosingFunction.fir.kt | 18 + .../returnLabelForBuiltInSuspend.fir.kt | 27 + .../coroutines/suspendApplicability.kt | 1 + .../suspendConflictsWithNoSuspend.fir.kt | 15 + .../suspendCoroutineOrReturn.fir.kt | 37 + .../suspendCoroutineOrReturn_1_2.fir.kt | 38 + .../suspendCoroutineUnavailableWithNewAPI.kt | 1 + ...spendCoroutineUnavailableWithOldAPI.fir.kt | 14 + .../suspendCovarianJavaOverride.fir.kt | 48 + .../coroutines/suspendDestructuring.fir.kt | 13 + .../suspendExternalFunctions.fir.kt | 48 + .../coroutines/suspendFunctionN.fir.kt | 8 + .../functionVsSuspendFunction.fir.kt | 19 + .../suspendFunctionType/inference1.kt | 1 + .../suspendFunctionType/inference2.kt | 1 + .../suspendFunctionType/inference3.kt | 1 + .../suspendFunctionType/inference4.kt | 1 + .../suspendFunctionType/inline.fir.kt | 45 + .../suspendFunctionType/invoke.fir.kt | 10 + .../lambdaInOverriddenValInitializer.fir.kt | 23 + .../lambdaInValInitializer.kt | 1 + .../modifierApplicability.fir.kt | 37 + .../noInvokeForSuspendFunction.fir.kt | 2 + .../suspendFunctionType/noValueParameters.kt | 1 + .../nullableSuspendFunction.fir.kt | 9 + .../suspendFunctionN.fir.kt | 4 + .../coroutines/suspendFunctions.fir.kt | 44 + ...avaImplementationFromDifferentClass.fir.kt | 51 + .../coroutines/suspendJavaOverrides.fir.kt | 48 + .../coroutines/suspendLambda.kt | 1 + .../coroutines/suspendOverridability.fir.kt | 37 + .../coroutines/suspendTest.fir.kt | 20 + .../suspensionPointInMonitor.fir.kt | 59 ++ .../suspensionPointInMonitorNewInf.fir.kt | 61 ++ .../coroutines/suspesionInDefaultValue.fir.kt | 17 + .../coroutines/tailCalls/forbidden.kt | 1 + .../coroutines/tailCalls/localFunctions.kt | 1 + .../nothingTypedSuspendFunction_1_2.kt | 1 + .../nothingTypedSuspendFunction_1_3.kt | 1 + .../coroutines/tailCalls/recursive.kt | 1 + .../coroutines/tailCalls/tryCatch.kt | 1 + .../coroutines/tailCalls/valid.kt | 1 + .../coroutines/tryCatchLambda.fir.kt | 17 + .../coroutines/unsupported.fir.kt | 18 + .../usageOfResultTypeInReturnType.fir.kt | 124 +++ .../usageOfResultTypeInReturnType_1_4.fir.kt | 124 +++ ...geOfResultTypeWithNullableOperators.fir.kt | 40 + .../checkers/AbstractDiagnosticsTest.kt | 1 + .../AbstractDiagnosticsTestWithStdLib.kt | 3 +- .../kotlin/fir/AbstractFirDiagnosticTest.kt | 16 +- .../generators/tests/GenerateCompilerTests.kt | 2 +- .../tests/generator/SimpleTestClassModel.java | 14 +- .../tests/generator/TestGenerationDSL.kt | 6 +- .../kotlin/generators/util/coroutines.kt | 32 +- 159 files changed, 4638 insertions(+), 26 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_3.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnTypeWithFlag.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_3.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/suspendConversionForCallableReferences.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutineContext.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesDisabled.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesEnabledWithWarning.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCalls.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/doubleColonExpressionToClassWithParameters.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraintsGenericBase.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36220.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38667.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignInCoroutineContext.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/qualifiedResolvedExpressionInsideBuilderInference.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/simpleGenerator.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWithErrors.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWrongUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfOrdinary.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kt28658.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspendWithAnyParameter.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/noDefaultCoroutineImports.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/nonLocalSuspension.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltIn.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltInRenameOnImport.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/release/coroutineContext.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/release/languageVersionIsNotEqualToApiVersion.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/extensions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/memberExtension.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/notRelatedFun.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_3.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/sameInstance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/simpleForbidden.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/wrongEnclosingFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/returnLabelForBuiltInSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendConflictsWithNoSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn_1_2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithOldAPI.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCovarianJavaOverride.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendDestructuring.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/functionVsSuspendFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inline.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/invoke.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noInvokeForSuspendFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/nullableSuspendFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaImplementationFromDifferentClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendTest.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/tryCatchLambda.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/unsupported.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType_1_4.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.fir.kt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java index 97e8cf86bef..f6b0470a4c3 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir; import com.intellij.testFramework.TestDataPath; import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; import org.junit.runner.RunWith; @@ -30,7 +31,7 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi } public void testAllFilesPresentInTestsWithStdLib() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true, "coroutines"); + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } @TestMetadata("ArrayOfNothing.kt") @@ -1592,6 +1593,885 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi } } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Coroutines extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInCoroutines() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("allowNullOperatorsForResult_1_3.kt") + public void testAllowNullOperatorsForResult_1_3() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_3.kt"); + } + + @TestMetadata("allowNullOperatorsForResult_1_4.kt") + public void testAllowNullOperatorsForResult_1_4() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_4.kt"); + } + + @TestMetadata("allowResultInReturnTypeWithFlag.kt") + public void testAllowResultInReturnTypeWithFlag() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnTypeWithFlag.kt"); + } + + @TestMetadata("allowResultInReturnType_1_3.kt") + public void testAllowResultInReturnType_1_3() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_3.kt"); + } + + @TestMetadata("allowResultInReturnType_1_4.kt") + public void testAllowResultInReturnType_1_4() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_4.kt"); + } + + @TestMetadata("basicBuildListBuildMap.kt") + public void testBasicBuildListBuildMap() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/basicBuildListBuildMap.kt"); + } + + @TestMetadata("callableReferences.kt") + public void testCallableReferences() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReferences.kt"); + } + + @TestMetadata("coroutineContext.kt") + public void testCoroutineContext() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutineContext.kt"); + } + + @TestMetadata("coroutinesDisabled.kt") + public void testCoroutinesDisabled() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesDisabled.kt"); + } + + @TestMetadata("coroutinesEnabledWithWarning.kt") + public void testCoroutinesEnabledWithWarning() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesEnabledWithWarning.kt"); + } + + @TestMetadata("illegalSuspendCalls.kt") + public void testIllegalSuspendCalls() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCalls.kt"); + } + + @TestMetadata("illegalSuspendCallsForDelegated.kt") + public void testIllegalSuspendCallsForDelegated() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.kt"); + } + + @TestMetadata("irrelevantSuspendDeclarations.kt") + public void testIrrelevantSuspendDeclarations() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt"); + } + + @TestMetadata("kSuspendFunctionAsSupertype.kt") + public void testKSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.kt"); + } + + @TestMetadata("kt18292.kt") + public void testKt18292() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.kt"); + } + + @TestMetadata("kt28658.kt") + public void testKt28658() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt28658.kt"); + } + + @TestMetadata("kt36947.kt") + public void testKt36947() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.kt"); + } + + @TestMetadata("kt37309.kt") + public void testKt37309() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.kt"); + } + + @TestMetadata("kt38179.kt") + public void testKt38179() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt"); + } + + @TestMetadata("lambdaExpectedType.kt") + public void testLambdaExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.kt"); + } + + @TestMetadata("mixingSuspendability.kt") + public void testMixingSuspendability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.kt"); + } + + @TestMetadata("modifierFormForNonBuiltInSuspend.kt") + public void testModifierFormForNonBuiltInSuspend() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspend.kt"); + } + + @TestMetadata("modifierFormForNonBuiltInSuspendWithAnyParameter.kt") + public void testModifierFormForNonBuiltInSuspendWithAnyParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspendWithAnyParameter.kt"); + } + + @TestMetadata("noDefaultCoroutineImports.kt") + public void testNoDefaultCoroutineImports_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/noDefaultCoroutineImports.kt", "kotlin.coroutines"); + } + + @TestMetadata("nonLocalSuspension.kt") + public void testNonLocalSuspension() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/nonLocalSuspension.kt"); + } + + @TestMetadata("nonModifierFormForBuiltIn.kt") + public void testNonModifierFormForBuiltIn() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltIn.kt"); + } + + @TestMetadata("nonModifierFormForBuiltInRenameOnImport.kt") + public void testNonModifierFormForBuiltInRenameOnImport() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltInRenameOnImport.kt"); + } + + @TestMetadata("operators.kt") + public void testOperators() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.kt"); + } + + @TestMetadata("returnLabelForBuiltInSuspend.kt") + public void testReturnLabelForBuiltInSuspend() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/returnLabelForBuiltInSuspend.kt"); + } + + @TestMetadata("suspendApplicability.kt") + public void testSuspendApplicability_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendApplicability.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendConflictsWithNoSuspend.kt") + public void testSuspendConflictsWithNoSuspend() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendConflictsWithNoSuspend.kt"); + } + + @TestMetadata("suspendCoroutineOrReturn.kt") + public void testSuspendCoroutineOrReturn() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn.kt"); + } + + @TestMetadata("suspendCoroutineOrReturn_1_2.kt") + public void testSuspendCoroutineOrReturn_1_2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn_1_2.kt"); + } + + @TestMetadata("suspendCoroutineUnavailableWithNewAPI.kt") + public void testSuspendCoroutineUnavailableWithNewAPI() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithNewAPI.kt"); + } + + @TestMetadata("suspendCoroutineUnavailableWithOldAPI.kt") + public void testSuspendCoroutineUnavailableWithOldAPI() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithOldAPI.kt"); + } + + @TestMetadata("suspendCovarianJavaOverride.kt") + public void testSuspendCovarianJavaOverride_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCovarianJavaOverride.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendDestructuring.kt") + public void testSuspendDestructuring() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendDestructuring.kt"); + } + + @TestMetadata("suspendExternalFunctions.kt") + public void testSuspendExternalFunctions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.kt"); + } + + @TestMetadata("suspendFunctionN.kt") + public void testSuspendFunctionN() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt"); + } + + @TestMetadata("suspendFunctions.kt") + public void testSuspendFunctions_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendJavaImplementationFromDifferentClass.kt") + public void testSuspendJavaImplementationFromDifferentClass_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaImplementationFromDifferentClass.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendJavaOverrides.kt") + public void testSuspendJavaOverrides_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaOverrides.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendLambda.kt") + public void testSuspendLambda_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendOverridability.kt") + public void testSuspendOverridability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt"); + } + + @TestMetadata("suspendTest.kt") + public void testSuspendTest() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendTest.kt"); + } + + @TestMetadata("suspensionPointInMonitor.kt") + public void testSuspensionPointInMonitor() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitor.kt"); + } + + @TestMetadata("suspensionPointInMonitorNewInf.kt") + public void testSuspensionPointInMonitorNewInf() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.kt"); + } + + @TestMetadata("suspesionInDefaultValue.kt") + public void testSuspesionInDefaultValue() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.kt"); + } + + @TestMetadata("tryCatchLambda.kt") + public void testTryCatchLambda() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/tryCatchLambda.kt"); + } + + @TestMetadata("unsupported.kt") + public void testUnsupported() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/unsupported.kt"); + } + + @TestMetadata("usageOfResultTypeInReturnType.kt") + public void testUsageOfResultTypeInReturnType() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType.kt"); + } + + @TestMetadata("usageOfResultTypeInReturnType_1_4.kt") + public void testUsageOfResultTypeInReturnType_1_4() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType_1_4.kt"); + } + + @TestMetadata("usageOfResultTypeWithNullableOperators.kt") + public void testUsageOfResultTypeWithNullableOperators() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.kt"); + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CallableReference extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInCallableReference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt"); + } + + @TestMetadata("callableReferenceOnUnresolvedLHS.kt") + public void testCallableReferenceOnUnresolvedLHS() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.kt"); + } + + @TestMetadata("property.kt") + public void testProperty_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt", "kotlin.coroutines"); + } + + @TestMetadata("suspendConversionForCallableReferences.kt") + public void testSuspendConversionForCallableReferences() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/suspendConversionForCallableReferences.kt"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Inference extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("applyInsideCoroutine.kt") + public void testApplyInsideCoroutine() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt"); + } + + @TestMetadata("builderInferenceForMaterializeWithExpectedType.kt") + public void testBuilderInferenceForMaterializeWithExpectedType() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt"); + } + + @TestMetadata("callableReferenceToASuspendFunction.kt") + public void testCallableReferenceToASuspendFunction() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt"); + } + + @TestMetadata("chainCallWithExtensionExplicitTypes.kt") + public void testChainCallWithExtensionExplicitTypes() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt"); + } + + @TestMetadata("coroutineInferenceWithCapturedTypeVariable.kt") + public void testCoroutineInferenceWithCapturedTypeVariable() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.kt"); + } + + @TestMetadata("correctMember.kt") + public void testCorrectMember() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt"); + } + + @TestMetadata("doubleColonExpressionToClassWithParameters.kt") + public void testDoubleColonExpressionToClassWithParameters() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/doubleColonExpressionToClassWithParameters.kt"); + } + + @TestMetadata("elvisOperatorAgainstFlexibleType.kt") + public void testElvisOperatorAgainstFlexibleType() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt"); + } + + @TestMetadata("extensionPriority.kt") + public void testExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt"); + } + + @TestMetadata("extensionSuspend.kt") + public void testExtensionSuspend() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionSuspend.kt"); + } + + @TestMetadata("extensionWithNonValuableConstraints.kt") + public void testExtensionWithNonValuableConstraints() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.kt"); + } + + @TestMetadata("extensionsWithNonValuableConstraintsGenericBase.kt") + public void testExtensionsWithNonValuableConstraintsGenericBase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraintsGenericBase.kt"); + } + + @TestMetadata("extensionsWithNonValuableConstraints_1_2.kt") + public void testExtensionsWithNonValuableConstraints_1_2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt"); + } + + @TestMetadata("incorrectCalls.kt") + public void testIncorrectCalls() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt"); + } + + @TestMetadata("inferCoroutineTypeInOldVersion.kt") + public void testInferCoroutineTypeInOldVersion() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt"); + } + + @TestMetadata("inferenceFromMethodInsideLocalVariable.kt") + public void testInferenceFromMethodInsideLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferenceFromMethodInsideLocalVariable.kt"); + } + + @TestMetadata("kt15516.kt") + public void testKt15516() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.kt"); + } + + @TestMetadata("kt32097.kt") + public void testKt32097() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32097.kt"); + } + + @TestMetadata("kt32203.kt") + public void testKt32203() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32203.kt"); + } + + @TestMetadata("kt32271.kt") + public void testKt32271() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32271.kt"); + } + + @TestMetadata("kt33542.kt") + public void testKt33542() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.kt"); + } + + @TestMetadata("kt35306.kt") + public void testKt35306() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35306.kt"); + } + + @TestMetadata("kt35684.kt") + public void testKt35684() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.kt"); + } + + @TestMetadata("kt36202.kt") + public void testKt36202() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36202.kt"); + } + + @TestMetadata("kt36220.kt") + public void testKt36220() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36220.kt"); + } + + @TestMetadata("kt38420.kt") + public void testKt38420() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38420.kt"); + } + + @TestMetadata("kt38667.kt") + public void testKt38667() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38667.kt"); + } + + @TestMetadata("nestedLambdaInferenceWithListMap.kt") + public void testNestedLambdaInferenceWithListMap() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt"); + } + + @TestMetadata("nestedSuspendCallInsideLambda.kt") + public void testNestedSuspendCallInsideLambda() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedSuspendCallInsideLambda.kt"); + } + + @TestMetadata("plusAssignInCoroutineContext.kt") + public void testPlusAssignInCoroutineContext() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignInCoroutineContext.kt"); + } + + @TestMetadata("plusAssignWithLambda.kt") + public void testPlusAssignWithLambda() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda.kt"); + } + + @TestMetadata("plusAssignWithLambda2.kt") + public void testPlusAssignWithLambda2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda2.kt"); + } + + @TestMetadata("qualifiedResolvedExpressionInsideBuilderInference.kt") + public void testQualifiedResolvedExpressionInsideBuilderInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/qualifiedResolvedExpressionInsideBuilderInference.kt"); + } + + @TestMetadata("recursiveGenerators.kt") + public void testRecursiveGenerators() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.kt"); + } + + @TestMetadata("recursiveGenerators2.kt") + public void testRecursiveGenerators2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.kt"); + } + + @TestMetadata("resolveUsualCallWithBuilderInference.kt") + public void testResolveUsualCallWithBuilderInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt"); + } + + @TestMetadata("returnTypeInference.kt") + public void testReturnTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference.kt"); + } + + @TestMetadata("returnTypeInference2.kt") + public void testReturnTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference2.kt"); + } + + @TestMetadata("severalCandidatesWithDifferentVisibility.kt") + public void testSeveralCandidatesWithDifferentVisibility() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt"); + } + + @TestMetadata("simpleGenerator.kt") + public void testSimpleGenerator() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/simpleGenerator.kt"); + } + + @TestMetadata("suspendCallsWithErrors.kt") + public void testSuspendCallsWithErrors() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWithErrors.kt"); + } + + @TestMetadata("suspendCallsWrongUpperBound.kt") + public void testSuspendCallsWrongUpperBound() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWrongUpperBound.kt"); + } + + @TestMetadata("twoReceiversInScope.kt") + public void testTwoReceiversInScope() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/twoReceiversInScope.kt"); + } + + @TestMetadata("typeFromReceiver.kt") + public void testTypeFromReceiver() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.kt"); + } + + @TestMetadata("useInferenceInformationFromExtension.kt") + public void testUseInferenceInformationFromExtension() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt"); + } + + @TestMetadata("variableCallInsideBuilderFunction.kt") + public void testVariableCallInsideBuilderFunction() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt"); + } + + @TestMetadata("variableOfAFunctionTypeCall.kt") + public void testVariableOfAFunctionTypeCall() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableOfAFunctionTypeCall.kt"); + } + + @TestMetadata("withParameter.kt") + public void testWithParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withParameter.kt"); + } + + @TestMetadata("withUninferredParameter.kt") + public void testWithUninferredParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.kt"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineCrossinline extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInInlineCrossinline() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("inlineOrdinaryOfCrossinlineOrdinary.kt") + public void testInlineOrdinaryOfCrossinlineOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineOrdinaryOfCrossinlineSuspend.kt") + public void testInlineOrdinaryOfCrossinlineSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineSuspend.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineOrdinaryOfNoinlineOrdinary.kt") + public void testInlineOrdinaryOfNoinlineOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineOrdinaryOfNoinlineSuspend.kt") + public void testInlineOrdinaryOfNoinlineSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineSuspend.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineOrdinaryOfOrdinary.kt") + public void testInlineOrdinaryOfOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineOrdinaryOfSuspend.kt") + public void testInlineOrdinaryOfSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfSuspend.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt") + public void testInlineSuspendOfCrossinlineOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfCrossinlineSuspend.kt") + public void testInlineSuspendOfCrossinlineSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineSuspend.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfNoinlineOrdinary.kt") + public void testInlineSuspendOfNoinlineOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfNoinlineSuspend.kt") + public void testInlineSuspendOfNoinlineSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineSuspend.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfOrdinary.kt") + public void testInlineSuspendOfOrdinary_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfOrdinary.kt", "kotlin.coroutines"); + } + + @TestMetadata("inlineSuspendOfSuspend.kt") + public void testInlineSuspendOfSuspend_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfSuspend.kt", "kotlin.coroutines"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/release") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Release extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInRelease() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/release"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("coroutineContext.kt") + public void testCoroutineContext() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/release/coroutineContext.kt"); + } + + @TestMetadata("languageVersionIsNotEqualToApiVersion.kt") + public void testLanguageVersionIsNotEqualToApiVersion() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/release/languageVersionIsNotEqualToApiVersion.kt"); + } + + @TestMetadata("suspend.kt") + public void testSuspend() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/release/suspend.kt"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RestrictSuspension extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRestrictSuspension() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("allMembersAllowed.kt") + public void testAllMembersAllowed_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/allMembersAllowed.kt", "kotlin.coroutines"); + } + + @TestMetadata("extensions.kt") + public void testExtensions_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/extensions.kt", "kotlin.coroutines"); + } + + @TestMetadata("memberExtension.kt") + public void testMemberExtension_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/memberExtension.kt", "kotlin.coroutines"); + } + + @TestMetadata("notRelatedFun.kt") + public void testNotRelatedFun_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/notRelatedFun.kt", "kotlin.coroutines"); + } + + @TestMetadata("outerYield_1_2.kt") + public void testOuterYield_1_2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_2.kt"); + } + + @TestMetadata("outerYield_1_3.kt") + public void testOuterYield_1_3() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_3.kt"); + } + + @TestMetadata("sameInstance.kt") + public void testSameInstance_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/sameInstance.kt", "kotlin.coroutines"); + } + + @TestMetadata("simpleForbidden.kt") + public void testSimpleForbidden_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/simpleForbidden.kt", "kotlin.coroutines"); + } + + @TestMetadata("wrongEnclosingFunction.kt") + public void testWrongEnclosingFunction_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/wrongEnclosingFunction.kt", "kotlin.coroutines"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendFunctionType extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInSuspendFunctionType() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("functionVsSuspendFunction.kt") + public void testFunctionVsSuspendFunction() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/functionVsSuspendFunction.kt"); + } + + @TestMetadata("inference1.kt") + public void testInference1() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference1.kt"); + } + + @TestMetadata("inference2.kt") + public void testInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference2.kt"); + } + + @TestMetadata("inference3.kt") + public void testInference3() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference3.kt"); + } + + @TestMetadata("inference4.kt") + public void testInference4() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference4.kt"); + } + + @TestMetadata("inline.kt") + public void testInline() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inline.kt"); + } + + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/invoke.kt"); + } + + @TestMetadata("lambdaInOverriddenValInitializer.kt") + public void testLambdaInOverriddenValInitializer() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.kt"); + } + + @TestMetadata("lambdaInValInitializer.kt") + public void testLambdaInValInitializer() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt"); + } + + @TestMetadata("modifierApplicability.kt") + public void testModifierApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.kt"); + } + + @TestMetadata("noInvokeForSuspendFunction.kt") + public void testNoInvokeForSuspendFunction() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noInvokeForSuspendFunction.kt"); + } + + @TestMetadata("noValueParameters.kt") + public void testNoValueParameters() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noValueParameters.kt"); + } + + @TestMetadata("nullableSuspendFunction.kt") + public void testNullableSuspendFunction() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/nullableSuspendFunction.kt"); + } + + @TestMetadata("suspendFunctionN.kt") + public void testSuspendFunctionN() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.kt"); + } + } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TailCalls extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInTailCalls() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("forbidden.kt") + public void testForbidden_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt", "kotlin.coroutines"); + } + + @TestMetadata("localFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/localFunctions.kt"); + } + + @TestMetadata("nothingTypedSuspendFunction_1_2.kt") + public void testNothingTypedSuspendFunction_1_2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_2.kt"); + } + + @TestMetadata("nothingTypedSuspendFunction_1_3.kt") + public void testNothingTypedSuspendFunction_1_3() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_3.kt"); + } + + @TestMetadata("recursive.kt") + public void testRecursive() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/recursive.kt"); + } + + @TestMetadata("tryCatch.kt") + public void testTryCatch_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt", "kotlin.coroutines"); + } + + @TestMetadata("valid.kt") + public void testValid_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt", "kotlin.coroutines"); + } + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/deprecated") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_3.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_3.fir.kt new file mode 100644 index 00000000000..ed5dc2c90dd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_3.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -AllowNullOperatorsForResult +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun test(r: Result?) { + r ?: 0 + r?.isFailure +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_4.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_4.kt index 17e42466635..811c76599b8 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_4.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowNullOperatorsForResult_1_4.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +AllowNullOperatorsForResult // !DIAGNOSTICS: -UNUSED_EXPRESSION diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnTypeWithFlag.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnTypeWithFlag.fir.kt new file mode 100644 index 00000000000..13a2618d5d3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnTypeWithFlag.fir.kt @@ -0,0 +1,9 @@ +// !ALLOW_RESULT_RETURN_TYPE +// !LANGUAGE: -AllowNullOperatorsForResult + +fun result(): Result = TODO() +val resultP: Result = result() + +fun f(r1: Result?) { + r1 ?: 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_3.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_3.fir.kt new file mode 100644 index 00000000000..6a97c6b91ef --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_3.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: +InlineClasses -AllowResultInReturnType + +fun result(): Result = TODO() +val resultP: Result = result() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_4.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_4.kt index 22c66bbf4bc..fd24179fba9 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_4.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/allowResultInReturnType_1_4.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +InlineClasses +AllowResultInReturnType fun result(): Result = TODO() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/basicBuildListBuildMap.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/basicBuildListBuildMap.kt index 5e9eec543e2..bdadb61746e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/basicBuildListBuildMap.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/basicBuildListBuildMap.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn @OptIn(ExperimentalStdlibApi::class) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.fir.kt new file mode 100644 index 00000000000..184291e5ab6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -FunctionTypesWithBigArity +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +class A { + suspend fun foo( + p00: Long = 1, p01: A = A(), p02: A = A(), p03: A = A(), p04: A = A(), p05: A = A(), p06: A = A(), p07: A = A(), p08: A = A(), p09: A = A(), + p10: A = A(), p11: A = A(), p12: A = A(), p13: A = A(), p14: A = A(), p15: A = A(), p16: A = A(), p17: A = A(), p18: A = A(), p19: A = A(), + p20: A = A(), p21: A = A(), p22: A = A(), p23: A = A(), p24: A = A(), p25: A = A(), p26: A = A(), p27: A = A(), p28: A = A(), p29: String + ): String { + return p29 + } +} + +suspend fun expectsLambdaWithBigArity(c: suspend (Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, String) -> String): String { + return c.invoke(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, "OK") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt new file mode 100644 index 00000000000..c94a7379e3a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +NewInference + +interface Inv +class Impl : Inv + +class Scope(private val implClass: j.Class) { + fun foo(c: Collection) { + val hm = c.asSequence() + .filter(implClass::isInstance) + .map(implClass::cast) + .toSet() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt new file mode 100644 index 00000000000..3c3106e6bfa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.fir.kt @@ -0,0 +1,14 @@ +// SKIP_TXT +// COMMON_COROUTINES_TEST + +import COROUTINES_PACKAGE.coroutineContext + +val c = ::coroutineContext + +fun test() { + c() +} + +suspend fun test2() { + c() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/suspendConversionForCallableReferences.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/suspendConversionForCallableReferences.fir.kt new file mode 100644 index 00000000000..110f7d31685 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/suspendConversionForCallableReferences.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun go1(f: () -> String) = f() +inline suspend fun go2(f: () -> String) = f() + +fun builder(c: suspend () -> Unit) {} + +suspend fun String.id(): String = this + +fun box() { + val x = "f" + builder { + go1(x::id) + go2(x::id) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReferences.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReferences.kt index 55848bd402b..7c7efa2938b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReferences.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReferences.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ReleaseCoroutines // !DIAGNOSTICS: -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutineContext.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutineContext.fir.kt new file mode 100644 index 00000000000..b3852686867 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutineContext.fir.kt @@ -0,0 +1,53 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +import kotlin.coroutines.* + +fun ordinal() { + kotlin.coroutines.coroutineContext + coroutineContext +} + +suspend fun named() { + kotlin.coroutines.coroutineContext + coroutineContext +} + +class A { + val coroutineContextNew = kotlin.coroutines.coroutineContext + val context = coroutineContext +} + +class Controller { + fun ordinal() { + kotlin.coroutines.coroutineContext + coroutineContext + } + + suspend fun named() { + kotlin.coroutines.coroutineContext + coroutineContext + } + + suspend fun severalArgs(s: String, a: Any) { + kotlin.coroutines.coroutineContext + coroutineContext + } +} + +fun builder(c: () -> CoroutineContext) = {} +fun builderSuspend(c: suspend () -> CoroutineContext) = {} + +fun builderSeveralArgs(c: (Int, Int, Int) -> CoroutineContext) = {} +fun builderSuspendSeveralArgs(c: suspend (Int, Int, Int) -> CoroutineContext) = {} + +fun test() { + builder { kotlin.coroutines.coroutineContext } + builder { coroutineContext } + builderSuspend { kotlin.coroutines.coroutineContext } + builderSuspend { coroutineContext } + builderSeveralArgs { _, _, _ -> kotlin.coroutines.coroutineContext } + builderSeveralArgs { _, _, _ -> coroutineContext } + builderSuspendSeveralArgs { _, _, _ -> kotlin.coroutines.coroutineContext } + builderSuspendSeveralArgs { _, _, _ -> coroutineContext } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesDisabled.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesDisabled.fir.kt new file mode 100644 index 00000000000..c0821913df0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesDisabled.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: -Coroutines -ReleaseCoroutines + +suspend fun suspendHere(): String = "OK" + +fun builder(c: suspend () -> Unit) { + +} + +fun box(): String { + var result = "" + + builder { + suspendHere() + } + + return result +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesEnabledWithWarning.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesEnabledWithWarning.fir.kt new file mode 100644 index 00000000000..58a01cd04e3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/coroutinesEnabledWithWarning.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: warn:Coroutines -ReleaseCoroutines + +suspend fun suspendHere(): String = "OK" + +fun builder(c: suspend () -> Unit) { + +} + +fun box(): String { + var result = "" + + builder { + suspendHere() + } + + return result +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCalls.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCalls.fir.kt new file mode 100644 index 00000000000..6a8211895d0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCalls.fir.kt @@ -0,0 +1,22 @@ +import Host.bar + +object Host { + suspend fun bar() {} +} + +suspend fun foo() {} + +fun noSuspend() { + foo() + bar() +} + +class A { + init { + foo() + bar() + } +} + +val x = foo() +val y = bar() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt new file mode 100644 index 00000000000..5adf399939f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt @@ -0,0 +1,8 @@ +fun bar(d: Delegate): String { + val x: String by d + return x +} + +class Delegate { + suspend operator fun getValue(thisRef: Any?, property: Any?): String = "" +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.fir.kt new file mode 100644 index 00000000000..9aacb4b796b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Controller { + suspend fun yield(t: T) {} +} + +fun generate(g: suspend Controller.() -> Unit): S = TODO() + +val test1 = generate { + apply { + yield(4) + } +} + +val test2 = generate { + yield(B) + apply { + yield(C) + } +} + +val test3 = generate { + this.let { + yield(B) + } + + apply { + yield(C) + } +} + +interface A +object B : A +object C : A \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt index dbb757d1b64..f6d412038ff 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.fir.kt new file mode 100644 index 00000000000..844ca85ec37 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn + +import kotlin.reflect.KSuspendFunction0 +import kotlin.reflect.KSuspendFunction1 +import kotlin.reflect.KFunction0 +import kotlin.reflect.KFunction1 + +fun test0(serialize: KSuspendFunction0) {} +fun test1(serialize: KSuspendFunction1) {} + +suspend fun foo() {} +suspend fun bar(x: Int) {} + +fun test() { + test0(::foo) + test1(::foo) + + test0(::bar) + test1(::bar) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt index 88944aa04a6..32921707c31 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_PARAMETER // !USE_EXPERIMENTAL: kotlin.RequiresOptIn diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.fir.kt new file mode 100644 index 00000000000..dacc9396e43 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/coroutineInferenceWithCapturedTypeVariable.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn + +import kotlin.experimental.ExperimentalTypeInference + +suspend fun main() { + iFlow { emit(1) } +} + + +@OptIn(ExperimentalTypeInference::class) +fun iFlow(@BuilderInference block: suspend iFlowCollector.() -> Unit): iFlow = TODO() + +interface iFlowCollector { + suspend fun emit(value: S) +} + +interface iFlow \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.fir.kt new file mode 100644 index 00000000000..1ca70df48f9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.fir.kt @@ -0,0 +1,25 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +interface Controller { + suspend fun yield(t: T) {} + + fun justString(): String = "" + + fun generidFun(t: Z) = t +} + +fun generate(@BuilderInference g: suspend Controller.() -> Unit): S = TODO() + +val test1 = generate { + yield(justString()) +} + +val test2 = generate { + yield(generidFun(2)) +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/doubleColonExpressionToClassWithParameters.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/doubleColonExpressionToClassWithParameters.fir.kt new file mode 100644 index 00000000000..07677c31ef0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/doubleColonExpressionToClassWithParameters.fir.kt @@ -0,0 +1,38 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_EXPRESSION + +@file:OptIn(ExperimentalTypeInference::class) + +package a.b + +import kotlin.experimental.ExperimentalTypeInference + +class BatchInfo1(val batchSize: Int) +class BatchInfo2(val data: T) + +object Obj + +fun test1() { + val a: Sequence = sequence { + val x = BatchInfo1::class + val y = a.b.BatchInfo1::class + val z = Obj::class + + val x1 = BatchInfo1::batchSize + val y1 = a.b.BatchInfo1::class + } +} + +interface Scope { + fun yield(t: T) {} +} + +fun generate(@BuilderInference g: Scope.() -> Unit): S = TODO() + +val test2 = generate { + { yield("foo") }::class +} + +val test3 = generate { + ({ yield("foo") })::class +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt index 1c3cd886044..3cd187206dc 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt index 2a88a3c9544..2a3a03a02ca 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionSuspend.fir.kt new file mode 100644 index 00000000000..026b4bdceff --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionSuspend.fir.kt @@ -0,0 +1,43 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} +} + +@BuilderInference +suspend fun GenericController.yieldAll(s: Collection) {} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): S = TODO() + +val test1 = generate { + yield(4) + yieldAll(setOf(4, 5)) +} + +val test2 = generate { + yieldAll(setOf(B)) +} + +val test3 = generate { + yieldAll(setOf(B, C)) +} + +val test4 = generate { + yieldAll(setOf(B)) + + yield(C) +} + + + +// Utils +fun setOf(vararg x: X): Set = TODO() + +interface A +object B : A +object C : A \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt new file mode 100644 index 00000000000..98f15521687 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.fir.kt @@ -0,0 +1,62 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +interface Base + +interface Controller : Base { + suspend fun yield(t: T) {} +} + +fun generate(@BuilderInference g: suspend Controller.() -> Unit): S = TODO() + +fun Base.baseExtension() {} +fun Controller.outNullableAnyExtension() {} +fun Controller.outAnyExtension() {} +fun Controller.invNullableAnyExtension() {} +fun Controller.genericExtension() {} + +@BuilderInference +fun Controller.safeExtension() {} + +val test1 = generate { + yield("foo") + baseExtension() +} + +val test2 = generate { + baseExtension() +} + +val test3 = generate { + yield(42) + outNullableAnyExtension() +} + +val test4 = generate { + outNullableAnyExtension() +} + +val test5 = generate { + yield(42) + outAnyExtension() +} + +val test6 = generate { + yield("bar") + invNullableAnyExtension() +} + +val test7 = generate { + yield("baz") + genericExtension() +} + +val test8 = generate { + safeExtension() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraintsGenericBase.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraintsGenericBase.fir.kt new file mode 100644 index 00000000000..4e995beb5c8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraintsGenericBase.fir.kt @@ -0,0 +1,52 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +interface Base + +interface Controller : Base { + suspend fun yield(t: T) {} +} + +interface SpecificController : Base { + suspend fun yield(t: T) {} +} + +fun generate(@BuilderInference g: suspend Controller.() -> Unit): S = TODO() +fun generateSpecific(@BuilderInference g: suspend SpecificController.() -> Unit): S = TODO() + +fun Base<*>.starBase() {} +fun Base.stringBase() {} + +val test1 = generate { + starBase() + yield("foo") +} + +val test2 = generate { + starBase() +} + +val test3 = generate { + yield("bar") + stringBase() +} + +val test4 = generateSpecific { + yield(42) + starBase() +} + +val test5 = generateSpecific { + yield(42) + stringBase() +} + +val test6 = generateSpecific { + stringBase() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt new file mode 100644 index 00000000000..ad18793da9d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: -ExperimentalBuilderInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Base + +interface Controller : Base { + suspend fun yield(t: T) {} +} + +fun generate(g: suspend Controller.() -> Unit): S = TODO() + +suspend fun Base.baseExtension() {} + +val test1 = generate { + yield("foo") + baseExtension() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt new file mode 100644 index 00000000000..adf0fe1bd86 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt @@ -0,0 +1,36 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} + fun notYield(t: T) {} + + suspend fun yieldBarReturnType(t: T) = t + fun barReturnType(): T = TODO() +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val test1 = generate { + yield(3) +} + +val test2 = generate { + yield(3) + notYield(3) +} + +val test3 = generate { + yield(3) + yieldBarReturnType(3) +} + +val test4 = generate { + yield(3) + barReturnType() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt new file mode 100644 index 00000000000..dcb7ce0f233 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: -ExperimentalBuilderInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +class Builder { + suspend fun add(t: T) {} +} + +fun build(g: suspend Builder.() -> Unit): List = TODO() +fun wrongBuild(g: Builder.() -> Unit): List = TODO() + +fun Builder.extensionAdd(s: S) {} + +suspend fun Builder.safeExtensionAdd(s: S) {} + +val member = build { + add(42) +} + +val memberWithoutAnn = wrongBuild { + add(42) +} + +val extension = build { + extensionAdd("foo") +} + +val safeExtension = build { + safeExtensionAdd("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferenceFromMethodInsideLocalVariable.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferenceFromMethodInsideLocalVariable.kt index 783131e780c..228d2a7377c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferenceFromMethodInsideLocalVariable.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferenceFromMethodInsideLocalVariable.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE // !USE_EXPERIMENTAL: kotlin.RequiresOptIn diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.fir.kt new file mode 100644 index 00000000000..523cb3de6ed --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt15516.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// SKIP_TXT +class StateMachine internal constructor() { + fun getInputStub(): Q = null as Q +} + +fun stateMachine(block: suspend StateMachine.() -> Unit): StateMachine { + return StateMachine() +} + +class Problem(){ + fun getInputStub(): F = null as F + + fun createStateMachine(): StateMachine = stateMachine { + val letter = getInputStub() + if (letter is Any) + println("yes") + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32097.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32097.kt index 201207fc09b..bf5fa86800b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32097.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32097.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32203.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32203.kt index c1a19aed201..47fdf10a348 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32203.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32203.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32271.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32271.kt index 3b036fe1dac..4aefe728397 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32271.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt32271.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER suspend fun threadSafeSuspendCallback(startAsync: (CompletionLambda) -> CancellationLambda): T = TODO() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt new file mode 100644 index 00000000000..ac991e566ba --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt33542.fir.kt @@ -0,0 +1,27 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !LANGUAGE: +NewInference + +import kotlin.experimental.ExperimentalTypeInference + +interface In { + fun send(element: E) +} + +class InImpl : In { + override fun send(element: E) {} +} + +@OptIn(ExperimentalTypeInference::class) +public fun builder(@BuilderInference block: In.() -> Unit) { + InImpl().block() +} + +suspend fun yield() {} + +fun test() { + builder { + send(run { + yield() // No error but `yield` is not inside "suspension" context actually + }) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35306.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35306.kt index 3e09c421f91..eb09bfddf33 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35306.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35306.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt new file mode 100644 index 00000000000..08dbf3a4b27 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt35684.fir.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +NewInference +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-35684 + +import kotlin.experimental.ExperimentalTypeInference + +fun test_1() { + sequence { + yield(")!>materialize()) + yield(materialize()) + } +} + +fun test_2() { + sequence { + yield(materialize()) + } +} + +fun test_3() { + sequence { + yield(materialize()) + materialize() + } +} + +@OptIn(ExperimentalTypeInference::class) +fun sequence(@BuilderInference block: suspend Inv.() -> Unit): U = null!! + +interface Inv { + fun yield(element: T) +} + +fun materialize(): Inv = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36202.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36202.kt index e39dfe42af3..612979c3a51 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36202.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36202.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36220.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36220.fir.kt new file mode 100644 index 00000000000..bd5060ad377 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt36220.fir.kt @@ -0,0 +1,20 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +import kotlin.experimental.ExperimentalTypeInference + +class TypeDefinition { + fun parse(parser: (serializedValue: String) -> KotlinType?): Unit = TODO() + fun serialize(parser: (value: KotlinType) -> Any?): Unit = TODO() +} + +@OptIn(ExperimentalTypeInference::class) +fun defineType(@BuilderInference definition: TypeDefinition.() -> Unit): Unit = TODO() + +fun main() { + defineType { + parse { it.toInt() } + serialize { it.toString() } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38420.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38420.kt index 611c9585d19..d77d7c75da7 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38420.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38420.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn @OptIn(ExperimentalStdlibApi::class) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38667.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38667.fir.kt new file mode 100644 index 00000000000..e6d86e171ff --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt38667.fir.kt @@ -0,0 +1,34 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION + +import kotlin.experimental.ExperimentalTypeInference + +abstract class AnimationVector +class AnimationVector1D : AnimationVector() +interface PropKey +class IntPropKey : PropKey +abstract class AnimationBuilder +abstract class DurationBasedAnimationBuilder : AnimationBuilder() +class TweenBuilder : DurationBasedAnimationBuilder() +class TransitionSpec { + fun tween(init: TweenBuilder.() -> Unit): DurationBasedAnimationBuilder = TweenBuilder().apply(init) + infix fun PropKey.using(builder: AnimationBuilder) {} +} +class TransitionDefinition { + fun transition(fromState: T? = null, toState: T? = null, init: TransitionSpec.() -> Unit) {} +} +@OptIn(ExperimentalTypeInference::class) +fun transitionDefinition(@BuilderInference init: TransitionDefinition.() -> Unit) = TransitionDefinition().apply(init) + +fun main() { + val intProp = IntPropKey() + val defn = transitionDefinition { + transition(1, 2) { + intProp using tween { + + } + } + } + + ")!>defn +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt index 8a0a39d25c3..9a6d48d36dd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference val configurations4 = listOf( diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedSuspendCallInsideLambda.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedSuspendCallInsideLambda.kt index 047c8cad174..3ef76e7bb0c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedSuspendCallInsideLambda.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedSuspendCallInsideLambda.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignInCoroutineContext.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignInCoroutineContext.fir.kt new file mode 100644 index 00000000000..73f2e088755 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignInCoroutineContext.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNCHECKED_CAST -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_PARAMETER + +class Bar + +fun materialize() = null as T + +interface FlowCollector { + suspend fun emit(value: T) +} + +interface Flow + +public fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit) = materialize>() + +fun foo(total: Int, next: Int) = 10 +fun foo(total: Int, next: Float) = 10 +fun foo(total: Float, next: Int) = 10 + +fun call(x: String) {} + +suspend fun foo(x: Int) = flow { + var y = 1 + y += if (x > 2) 1 else 2 + + var newValue = 1 + newValue += listOf().asSequence().fold(0) { total, next -> + call(11) + total + next + } + newValue += listOf().asSequence().fold(0, fun(total, next): Int { return total + next }) + newValue += listOf().asSequence().fold(0, fun(total, next) = total + next) + newValue += listOf().asSequence().fold(0, ::foo) + + emit(materialize()) + + newValue += listOf().asSequence().fold(0) { total, next -> total + next } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda.fir.kt new file mode 100644 index 00000000000..26372d350a2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER + +fun foo(total: Int, next: Int) = 10 +fun foo(total: Int, next: Float) = 10 +fun foo(total: Float, next: Int) = 10 + +fun call(x: String) {} + +fun foo(x: Float, y: Float) = { + var newValue = 1 + newValue += listOf().asSequence().fold(0) { total, next -> + call(11) + total + next + } + newValue += listOf().asSequence().fold(0, fun(total, next): Int { return total + next }) + newValue += listOf().asSequence().fold(0, fun(total, next) = total + next) + newValue += listOf().asSequence().fold(0, ::foo) +} + +class A { + operator fun plus(x: Int) = A() + operator fun plusAssign(x: Float) {} +} + +fun id(x: T) = x + +fun foo2() = { + var x = A() + x += { "" } + var y = A() + y += 1 +} + +class B { + operator fun plus(x: () -> String) = A() + operator fun plusAssign(x: () -> Int) {} +} + +fun foo3(x: B) = { + x += { "" } + x += id { "" } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda2.fir.kt new file mode 100644 index 00000000000..72884822191 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/plusAssignWithLambda2.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER + +open class A + +operator fun T.plus(x: (T) -> Int) = A() +operator fun T.plusAssign(x: (Int) -> T) {} + +fun foo(total: Int) = 10 +fun foo(total: Float) = 10 +fun foo(total: String) = 10 + +fun id(x: T) = x + +fun main() { + var newValue = A() + newValue += id { total -> A() } + newValue += id(fun(total) = A()) + newValue += id(fun(total): A { return A() }) + newValue += id(::foo) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/qualifiedResolvedExpressionInsideBuilderInference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/qualifiedResolvedExpressionInsideBuilderInference.fir.kt new file mode 100644 index 00000000000..628e88980c9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/qualifiedResolvedExpressionInsideBuilderInference.fir.kt @@ -0,0 +1,20 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.experimental.ExperimentalTypeInference + +fun test() { + flow { + emit(42) + kotlin.coroutines.coroutineContext + } +} + +@OptIn(ExperimentalTypeInference::class) +fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit): Flow = TODO() + +interface Flow + +interface FlowCollector { + suspend fun emit(value: T) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.fir.kt new file mode 100644 index 00000000000..8876e91e10e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators.fir.kt @@ -0,0 +1,22 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val test1 = generate { + yield(generate { + yield(generate { + yield(generate { + yield(3) + }) + }) + }) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.fir.kt new file mode 100644 index 00000000000..163ed6bdcd1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.fir.kt @@ -0,0 +1,24 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +@BuilderInference +suspend fun GenericController>.yieldGenerate(g: suspend GenericController.() -> Unit): Unit = TODO() + +val test1 = generate { + // TODO: KT-15185 + yieldGenerate { + yield(4) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt new file mode 100644 index 00000000000..1168a2133ce --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class Builder { + fun add(t: T) {} +} + +fun build(@BuilderInference g: Builder.() -> Unit): List = TODO() +fun wrongBuild(g: Builder.() -> Unit): List = TODO() + +fun Builder.extensionAdd(s: S) {} + +@BuilderInference +fun Builder.safeExtensionAdd(s: S) {} + +val member = build { + add(42) +} + +val memberWithoutAnn = wrongBuild { + add(42) +} + +val extension = build { + extensionAdd("foo") +} + +val safeExtension = build { + safeExtensionAdd("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference.kt index 98725a175e1..2b9c932baf6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE class Controller diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference2.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference2.kt index a07ead124ad..2b98fec18e1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/returnTypeInference2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt index 5fab846cd57..30d6368359f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/simpleGenerator.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/simpleGenerator.fir.kt new file mode 100644 index 00000000000..9c77bd81531 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/simpleGenerator.fir.kt @@ -0,0 +1,34 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} + suspend fun yieldSet(t: Set) {} + suspend fun yieldVararg(vararg t: T) {} +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): S = TODO() + +val test1 = generate { + yield(4) +} + +val test2 = generate { + yieldSet(setOf(1, 2, 3)) +} + +val test3 = generate { + yieldVararg(1, 2, 3) +} + +val test4 = generate { + yieldVararg(1, 2, "") +} + + +// Util function +fun setOf(vararg x: X): Set = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWithErrors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWithErrors.fir.kt new file mode 100644 index 00000000000..5e54cf716e4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWithErrors.fir.kt @@ -0,0 +1,24 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class Controller { + suspend fun yield(t: T) {} +} + +fun generate(@BuilderInference g: suspend Controller.() -> Unit): S = TODO() + +class A + +val test1 = generate { + yield(A) +} + +val test2: Int = generate { + yield(A()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWrongUpperBound.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWrongUpperBound.fir.kt new file mode 100644 index 00000000000..7a585a63ab7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/suspendCallsWrongUpperBound.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Controller { + suspend fun yield(t: T) {} +} + +fun generate(g: suspend Controller.() -> Unit): S = TODO() + +val test = generate { + yield("foo") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/twoReceiversInScope.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/twoReceiversInScope.kt index f1ff3d9f549..c94d5992b8a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/twoReceiversInScope.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/twoReceiversInScope.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.fir.kt new file mode 100644 index 00000000000..dbbef596d4c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.fir.kt @@ -0,0 +1,17 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +@BuilderInference +suspend fun GenericController>.test() {} + +val test1 = generate { + test() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt new file mode 100644 index 00000000000..233bebd2e15 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class GenericController { + suspend fun yield(t: T) {} +} + +suspend fun GenericController.extensionYield(s: S) {} + +@BuilderInference +suspend fun GenericController.safeExtensionYield(s: S) {} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val normal = generate { + yield(42) +} + +val extension = generate { + extensionYield("foo") +} + +val safeExtension = generate { + safeExtensionYield("foo") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt index 875bc67b821..65f3b238e36 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_PARAMETER // !USE_EXPERIMENTAL: kotlin.RequiresOptIn diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableOfAFunctionTypeCall.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableOfAFunctionTypeCall.kt index 04ad43ef3a2..6a193ef64cf 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableOfAFunctionTypeCall.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableOfAFunctionTypeCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withParameter.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withParameter.kt index 3694584cbc4..767108d4ea1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withParameter.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.fir.kt new file mode 100644 index 00000000000..5fe162f1c98 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class GenericController { + suspend fun yield(t: T) {} +} + +fun generate(g: suspend GenericController.(S) -> Unit): S = TODO() + +val test1 = generate { + yield(4) +} + +val test2 = generate { + yield(4) +} + +val test3 = generate { bar: Int -> + yield(4) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineOrdinary.fir.kt new file mode 100644 index 00000000000..ddbc650d602 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineOrdinary.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// COMMON_COROUTINES_TEST +// WITH_COROUTINES +// SKIP_TXT +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is NOT suspend +// parameter is crossinline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls NOT possible inside lambda matching to the parameter + +inline fun test(crossinline c: () -> Unit) { + c() + val o = object: Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + test { + calculate() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineSuspend.fir.kt new file mode 100644 index 00000000000..9577cee6faf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfCrossinlineSuspend.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +interface SuspendRunnable { + suspend fun run() +} + +// Function is NOT suspend +// parameter is crossinline +// parameter is suspend +// Block is NOT allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter + +inline fun test(crossinline c: suspend () -> Unit) { + c() + val o = object : SuspendRunnable { + override suspend fun run() { + c() + } + } + val l: suspend () -> Unit = { c() } + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + test { + calculate() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineOrdinary.fir.kt new file mode 100644 index 00000000000..6a071da0963 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineOrdinary.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is NOT suspend +// parameter is noinline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls NOT possible inside lambda matching to the parameter +inline fun test(noinline c: () -> Unit) { + c() + val o = object: Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + test { + calculate() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineSuspend.fir.kt new file mode 100644 index 00000000000..0de218dc6e9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfNoinlineSuspend.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +interface SuspendRunnable { + suspend fun run() +} + +// Function is NOT suspend +// parameter is noinline +// parameter is suspend +// Block is NOT allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter + +inline fun test(noinline c: suspend () -> Unit) { + c() + val o = object : SuspendRunnable { + override suspend fun run() { + c() + } + } + val l: suspend () -> Unit = { c() } + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + test { + calculate() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfOrdinary.fir.kt new file mode 100644 index 00000000000..f759654dc3a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfOrdinary.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is NOT suspend +// parameter is inline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter + +inline fun test(c: () -> Unit) { + c() + val o = object : Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfSuspend.fir.kt new file mode 100644 index 00000000000..cb56e6f083c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineOrdinaryOfSuspend.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +interface SuspendRunnable { + suspend fun run() +} + +// Function is NOT suspend +// parameter is inline +// parameter is suspend +// Block is NOT allowed to be called inside the body of owner inline function +// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter + +inline fun test(c: suspend () -> Unit) { + c() + val o = object: SuspendRunnable { + override suspend fun run() { + c() + } + } + val l: suspend () -> Unit = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) {} + +suspend fun calculate() = "OK" + +fun box() { + test { + calculate() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineOrdinary.fir.kt new file mode 100644 index 00000000000..ae87366f501 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineOrdinary.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is suspend +// parameter is crossinline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls NOT possible inside lambda matching to the parameter +suspend inline fun test(crossinline c: () -> Unit) { + c() + val o = object : Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineSuspend.fir.kt new file mode 100644 index 00000000000..5946e802530 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfCrossinlineSuspend.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +interface SuspendRunnable { + suspend fun run() +} + +// Function is suspend +// parameter is crossinline +// parameter is suspend +// Block is allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter +suspend inline fun test(crossinline c: suspend () -> Unit) { + c() + val o = object : SuspendRunnable { + override suspend fun run() { + c() + } + } + val l: suspend () -> Unit = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) {} + +suspend fun calculate() = "OK" + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineOrdinary.fir.kt new file mode 100644 index 00000000000..7dd80fd573c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineOrdinary.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is suspend +// parameter is noinline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls NOT possible inside lambda matching to the parameter +suspend inline fun test(noinline c: () -> Unit) { + c() + val o = object : Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineSuspend.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineSuspend.kt index baa54b3cecb..e0918cd51a4 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineSuspend.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfNoinlineSuspend.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER // COMMON_COROUTINES_TEST // SKIP_TXT diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfOrdinary.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfOrdinary.fir.kt new file mode 100644 index 00000000000..e6a297f600e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfOrdinary.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +// Function is suspend +// parameter is inline +// parameter is NOT suspend +// Block is allowed to be called inside the body of owner inline function +// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter +suspend inline fun test(c: () -> Unit) { + c() + val o = object: Runnable { + override fun run() { + c() + } + } + val l = { c() } + c.startCoroutine(EmptyContinuation) +} + +suspend fun calculate() = "OK" + +fun builder(c: suspend () -> Unit) {} + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfSuspend.fir.kt new file mode 100644 index 00000000000..25fcfa6329b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inlineCrossinline/inlineSuspendOfSuspend.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE +// COMMON_COROUTINES_TEST +// SKIP_TXT +// WITH_COROUTINES +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* +import helpers.* + +interface SuspendRunnable { + suspend fun run() +} + +// Function is suspend +// parameter is inline +// parameter is suspend +// Block is allowed to be called inside the body of owner inline function +// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines) +// It is NOT possible to call startCoroutine on the parameter +// suspend calls possible inside lambda matching to the parameter +suspend inline fun test(c: suspend () -> Unit) { + c() + val o = object: SuspendRunnable { + override suspend fun run() { + c() + } + } + val l: suspend () -> Unit = { c() } + c.startCoroutine(EmptyContinuation) +} + +fun builder(c: suspend () -> Unit) { +} + +suspend fun calculate() = "OK" + +fun box() { + builder { + test { + calculate() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt index 91df56b8371..e90b1bddcde 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !CHECK_TYPE class Controller { diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.fir.kt new file mode 100644 index 00000000000..ad940515d8c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.fir.kt @@ -0,0 +1,5 @@ +// SKIP_TXT + +import kotlin.reflect.* + +class A: KSuspendFunction0 {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.fir.kt new file mode 100644 index 00000000000..8061049251e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// SKIP_TXT +// WITH_RUNTIME + +import kotlin.coroutines.* + +interface Job : CoroutineContext.Element {} +interface Deferred : Job { + suspend fun await(): T +} +fun async(block: suspend () -> T): Deferred = TODO() + +suspend fun fib(n: Long) = + async { + when { + n < 2 -> n + else -> fib(n - 1).await() + fib(n - 2).await() + } + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt28658.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt28658.fir.kt new file mode 100644 index 00000000000..b5344f01fb8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt28658.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +NewInference +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +import kotlin.experimental.ExperimentalTypeInference + +fun test1() { + sequence { + val a: Array = arrayOf(1, 2, 3) + val b = arrayOf(1, 2, 3) + } +} + +fun test2() = sequence { arrayOf(1, 2, 3) } + + +class Foo + +fun f1(f: Foo.() -> Unit) {} + +@OptIn(ExperimentalTypeInference::class) +fun f2(@BuilderInference f: Foo.() -> Unit) { +} + +fun test3() { + f1 { + val a: Array = arrayOf(1, 2, 3) + } + + f2 { + val a: Array = arrayOf(1, 2, 3) + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt new file mode 100644 index 00000000000..2e8706b4919 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt @@ -0,0 +1,6 @@ +val foo = iterator { + yield(0) + val nullable: String? = null + nullable.length + nullable.get(2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt new file mode 100644 index 00000000000..aee1b1c7925 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt37309.fir.kt @@ -0,0 +1,24 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import kotlin.experimental.ExperimentalTypeInference + +@OptIn(ExperimentalTypeInference::class) +fun myBuildList(@BuilderInference builderAction: MutableList.() -> Unit) { + ArrayList().builderAction() +} + +@OptIn(ExperimentalStdlibApi::class) +fun main() { + val newList1 = myBuildList { + addAll( + listOf(1).map { Foo(null) } + ) + } + + val newList2 = buildList { + addAll(listOf(1,2,3).map{ Foo(null) }) + } +} + +class Foo(val notNullProp: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt index 112257d46e4..e7d03f9d283 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt38179.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FULL_JDK import java.util.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.fir.kt new file mode 100644 index 00000000000..c27814f0caa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/lambdaExpectedType.fir.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: -SuspendConversion +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_VARIABLE + +fun builder(c: suspend () -> Int) = 1 +fun genericBuilder(c: suspend () -> T): T = null!! +fun unitBuilder(c: suspend () -> Unit) = 1 +fun emptyBuilder(c: suspend () -> Unit) = 1 + +fun manyArgumentsBuilder( + c1: suspend () -> Unit, + c2: suspend () -> T, + c3: suspend () -> Int +):T = null!! + +fun severalParamsInLambda(c: suspend (String, Int) -> Unit) {} + +fun foo() { + builder({ 1 }) + builder { 1 } + + val x = { 1 } + builder(x) + builder({1} as (suspend () -> Int)) + + var i: Int = 1 + i = genericBuilder({ 1 }) + i = genericBuilder { 1 } + genericBuilder { 1 } + genericBuilder { 1 } + genericBuilder { "" } + + val y = { 1 } + genericBuilder(y) + + unitBuilder {} + unitBuilder { 1 } + unitBuilder({}) + unitBuilder({ 1 }) + + manyArgumentsBuilder({}, { "" }) { 1 } + + val s: String = manyArgumentsBuilder({}, { "" }) { 1 } + + manyArgumentsBuilder({}, { "" }, { 1 }) + manyArgumentsBuilder({}, { 1 }, { 2 }) + + severalParamsInLambda { x, y -> + x checkType { _() } + y checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.fir.kt new file mode 100644 index 00000000000..083722fdefb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.fir.kt @@ -0,0 +1,6 @@ +interface AsyncVal { suspend fun getVal(): Int = 1} +interface SyncVal { fun getVal(): Int = 1 } + +class MixSuspend : AsyncVal, SyncVal { + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspend.fir.kt new file mode 100644 index 00000000000..50156f2eafa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspend.fir.kt @@ -0,0 +1,76 @@ +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +fun suspend(block: suspend () -> R): suspend () -> R = block + +class A { + infix fun suspend(block: suspend () -> R): suspend () -> R = block +} + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun bar() { + suspend { + println() + } + + @Ann suspend { + println() + } + + suspend @Ann { + println() + } + + suspend() { + println() + } + + suspend({ println() }) + + suspend { + println() + } + + val w: (suspend () -> Int) -> Any? = ::suspend + + A().suspend { + println() + } + + A().suspend() { + println() + } + + A().suspend({ println() }) + + A().suspend { + println() + } + + with(A()) { + suspend { + println() + } + + suspend() { + println() + } + + suspend({ println() }) + + suspend { + println() + } + } + + A() suspend { + println() + } + + A() suspend ({ + println() + }) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspendWithAnyParameter.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspendWithAnyParameter.fir.kt new file mode 100644 index 00000000000..902a4c26f30 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/modifierFormForNonBuiltInSuspendWithAnyParameter.fir.kt @@ -0,0 +1,84 @@ +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +fun suspend(block: R) = block + +class A { + infix fun suspend(block: R) = block +} + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun bar() { + suspend { + println() + } + + @Ann suspend { + println() + } + + suspend @Ann { + println() + } + + suspend() { + println() + } + + suspend({ println() }) + + suspend Unit> { + println() + } + + suspend(null) + + val w: (Any?) -> Any? = ::suspend + + A().suspend { + println() + } + + A().suspend() { + println() + } + + A().suspend({ println() }) + + A().suspend Unit> { + println() + } + + A().suspend(null) + + with(A()) { + suspend { + println() + } + + suspend() { + println() + } + + suspend({ println() }) + + suspend Unit> { + println() + } + + suspend(null) + } + + A() suspend { + println() + } + + A() suspend ({ + println() + }) + + A() suspend "" +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/noDefaultCoroutineImports.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/noDefaultCoroutineImports.fir.kt new file mode 100644 index 00000000000..1db1a12faeb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/noDefaultCoroutineImports.fir.kt @@ -0,0 +1,9 @@ +// FILE: 1.kt +// COMMON_COROUTINES_TEST + +fun test(c: Continuation) {} + +// FILE: 2.kt +import COROUTINES_PACKAGE.* + +fun test2(c: Continuation) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonLocalSuspension.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonLocalSuspension.fir.kt new file mode 100644 index 00000000000..b365bef4375 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonLocalSuspension.fir.kt @@ -0,0 +1,81 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +import Host.suspendFromObject + +suspend fun suspendHere() = 1 +suspend fun another(a: T) = 1 + +object Host { + suspend fun suspendFromObject() = 1 +} + +fun builder(c: suspend () -> Unit) { } + +inline fun run(x: () -> Unit) {} + +inline fun runCross(crossinline x: () -> Unit) {} + +fun noinline(x: () -> Unit) {} + +fun foo() { + var result = 1 + builder { + suspendHere() + suspendFromObject() + + another("") + another(1) + + result += suspendHere() + result += suspendFromObject() + + run { + result += suspendHere() + result += suspendFromObject() + + run { + suspendHere() + suspendFromObject() + } + } + + runCross { + result += suspendHere() + result += suspendFromObject() + runCross { + suspendHere() + suspendFromObject() + } + } + + noinline { + result += suspendHere() + result += suspendFromObject() + noinline { + suspendHere() + suspendFromObject() + } + } + + class A { + fun bar() { + suspendHere() + suspendFromObject() + } + } + + object : Any() { + fun baz() { + suspendHere() + suspendFromObject() + } + } + + builder { + suspendHere() + suspendFromObject() + + another(1) + another("") + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltIn.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltIn.fir.kt new file mode 100644 index 00000000000..fb4a185b06d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltIn.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +fun bar() { + suspend { + println() + } + + @Ann suspend { + println() + } + + suspend @Ann { + println() + } + + kotlin.suspend { + + } + + suspend() { + println() + } + + suspend({ println() }) + + suspend { + println() + } + + val w: (suspend () -> Int) -> Any? = ::suspend +} + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun main(suspend: WLambdaInvoke) { + + suspend {} +} + +class WLambdaInvoke { + operator fun invoke(l: () -> Unit) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltInRenameOnImport.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltInRenameOnImport.fir.kt new file mode 100644 index 00000000000..f05256a54dd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/nonModifierFormForBuiltInRenameOnImport.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +import kotlin.suspend as suspendLambda + +fun bar() { + suspend { + println() + } + + kotlin.suspend { + + } + + suspendLambda { + println() + } + + suspendLambda() { + println() + } + + suspendLambda({ println() }) + + suspendLambda { + println() + } + + val w: (suspend () -> Int) -> Any? = ::suspendLambda +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt new file mode 100644 index 00000000000..9a9b4df845a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt @@ -0,0 +1,60 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +import kotlin.reflect.KProperty + +class A { + suspend operator fun get(x: Int) = 1 + suspend operator fun set(x: Int, v: String) {} + + operator suspend fun contains(y: String): Boolean = true + + suspend operator fun unaryPlus() = this + suspend operator fun unaryMinus() = this + suspend operator fun not() = this + suspend operator fun inc() = this + suspend operator fun dec() = this + + suspend operator fun plus(a: A) = a + suspend operator fun minus(a: A) = a + suspend operator fun times(a: A) = a + suspend operator fun div(a: A) = a + suspend operator fun rem(a: A) = a + suspend operator fun rangeTo(a: A) = a + + suspend operator fun invoke(a: A) = a + + suspend operator fun compareTo(a: A) = hashCode().compareTo(a.hashCode()) + + suspend operator fun iterator() = this + suspend operator fun hasNext() = false + suspend operator fun next() = this + + suspend operator fun contains(b: A) = this == b + suspend operator fun get(a: A) = a + suspend operator fun equals(a: A) = a === this + suspend operator fun set(a: A, b: A) {} + + suspend operator fun provideDelegate(a: A, p: KProperty<*>) = a + suspend operator fun getValue(a: A, p: KProperty<*>) = a + suspend operator fun setValue(a: A, p: KProperty<*>, b: A) {} +} + +class B +suspend operator fun B.get(x: Int) =1 +suspend operator fun B.set(x: Int, v: String) {} + +operator suspend fun B.contains(y: String): Boolean = true + +class C { + suspend fun get(x: Int) = 1 + suspend fun set(x: Int, v: String) {} + + suspend fun contains(y: String): Boolean = true +} + +class D +suspend fun D.get(x: Int) =1 +suspend fun D.set(x: Int, v: String) {} + +suspend fun D.contains(y: String): Boolean = true diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/coroutineContext.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/coroutineContext.fir.kt new file mode 100644 index 00000000000..63667e6256c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/coroutineContext.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +import kotlin.coroutines.experimental.coroutineContext + +suspend fun test() { + coroutineContext +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/languageVersionIsNotEqualToApiVersion.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/languageVersionIsNotEqualToApiVersion.fir.kt new file mode 100644 index 00000000000..f4138438849 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/languageVersionIsNotEqualToApiVersion.fir.kt @@ -0,0 +1,38 @@ +// !API_VERSION: 1.2 +// !DIAGNOSTICS: -PRE_RELEASE_CLASS, -UNUSED_PARAMETER +// !LANGUAGE: +ReleaseCoroutines +// !WITH_NEW_INFERENCE +// SKIP_TXT + +suspend fun dummy() {} + +// TODO: Forbid +fun builder(c: suspend () -> Unit) {} + +suspend fun test1() { + kotlin.coroutines.coroutineContext + + kotlin.coroutines.experimental.coroutineContext + + suspend {}() + + dummy() + + val c: suspend () -> Unit = {} + c() + + builder {} +} + +fun test2() { + kotlin.coroutines.experimental.buildSequence { + yield(1) + } + kotlin.sequences.buildSequence { + yield(1) + } +} + +suspend fun test3(): Unit = kotlin.coroutines.experimental.suspendCoroutine { _ -> Unit } + +suspend fun test4(): Unit = kotlin.coroutines.suspendCoroutine { _ -> Unit } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/suspend.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/suspend.kt index cacff65422f..b61afde9a46 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/suspend.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/release/suspend.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ReleaseCoroutines // SKIP_TXT diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/allMembersAllowed.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/allMembersAllowed.kt index 6821e1eb87d..7e40a04e7cd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/allMembersAllowed.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/allMembersAllowed.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE // COMMON_COROUTINES_TEST diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/extensions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/extensions.fir.kt new file mode 100644 index 00000000000..0645a203746 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/extensions.fir.kt @@ -0,0 +1,130 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE +// COMMON_COROUTINES_TEST + +interface SuperInterface + +@COROUTINES_PACKAGE.RestrictsSuspension +open class RestrictedController : SuperInterface + +class SubClass : RestrictedController() + +suspend fun Any?.extAny() {} +suspend fun SuperInterface.extSuper() {} +suspend fun RestrictedController.ext() {} +suspend fun SubClass.extSub() {} + +class A { + suspend fun Any?.memExtAny() {} + suspend fun SuperInterface.memExtSuper() {} + suspend fun RestrictedController.memExt() {} + suspend fun SubClass.memExtSub() {} +} + + +fun generate1(f: suspend SuperInterface.() -> Unit) {} +fun generate2(f: suspend RestrictedController.() -> Unit) {} +fun generate3(f: suspend SubClass.() -> Unit) {} + +fun A.test() { + generate1 { + extAny() + memExtAny() + extSuper() + memExtSuper() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + } + } + generate2 { + extAny() + memExtAny() + extSuper() + memExtSuper() + + ext() + memExt() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + ext() + memExt() + } + } + generate3 { + extAny() + memExtAny() + extSuper() + memExtSuper() + + ext() + memExt() + extSub() + memExtSub() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + ext() + memExt() + extSub() + memExtSub() + } + } + + suspend fun SuperInterface.fun1() { + extAny() + memExtAny() + extSuper() + memExtSuper() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + } + } + suspend fun RestrictedController.fun2() { + extAny() + memExtAny() + extSuper() + memExtSuper() + + ext() + memExt() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + ext() + memExt() + } + } + suspend fun SubClass.fun3() { + extAny() + memExtAny() + extSuper() + memExtSuper() + + ext() + memExt() + extSub() + memExtSub() + with(A()) { + extAny() + memExtAny() + extSuper() + memExtSuper() + ext() + memExt() + extSub() + memExtSub() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/memberExtension.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/memberExtension.fir.kt new file mode 100644 index 00000000000..a48b3936b18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/memberExtension.fir.kt @@ -0,0 +1,62 @@ +// COMMON_COROUTINES_TEST +// SKIP_TXT +@COROUTINES_PACKAGE.RestrictsSuspension +class RestrictedController { + suspend fun member() { + ext() + member() + memberExt() + } + + suspend fun RestrictedController.memberExt() { + ext() + member() + memberExt() + } +} + +suspend fun RestrictedController.ext() { + ext() + member() + memberExt() +} + +fun generate(c: suspend RestrictedController.() -> Unit) {} + +fun runBlocking(x: suspend () -> Unit) {} + +fun test() { + generate a@{ + ext() + member() + memberExt() + + this@a.ext() + this@a.member() + this@a.memberExt() + + generate b@{ + ext() + member() + memberExt() + + this@a.ext() + this@a.member() + this@a.memberExt() + + this@b.ext() + this@b.member() + this@b.memberExt() + } + + runBlocking { + ext() + member() + memberExt() + + this@a.ext() + this@a.member() + this@a.memberExt() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/notRelatedFun.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/notRelatedFun.fir.kt new file mode 100644 index 00000000000..23c472769a3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/notRelatedFun.fir.kt @@ -0,0 +1,73 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE +// COMMON_COROUTINES_TEST + +interface SuperInterface + +@COROUTINES_PACKAGE.RestrictsSuspension +open class RestrictedController : SuperInterface + +class SubClass : RestrictedController() + +suspend fun topLevel() {} + +class A { + suspend fun member() {} +} + +fun generate1(f: suspend SuperInterface.() -> Unit) {} +fun generate2(f: suspend RestrictedController.() -> Unit) {} +fun generate3(f: suspend SubClass.() -> Unit) {} + +fun A.test() { + generate1 { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + generate2 { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + generate3 { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + + suspend fun SuperInterface.fun1() { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + suspend fun RestrictedController.fun2() { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + suspend fun SubClass.fun3() { + topLevel() + member() + with(A()) { + topLevel() + member() + } + } + +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_2.fir.kt new file mode 100644 index 00000000000..cb9c725dd29 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_2.fir.kt @@ -0,0 +1,94 @@ +// !LANGUAGE: -ReleaseCoroutines -ExperimentalBuilderInference +// !DIAGNOSTICS: -EXPERIMENTAL_FEATURE_WARNING +// !WITH_NEW_INFERENCE +// SKIP_TXT + +@kotlin.coroutines.experimental.RestrictsSuspension +class RestrictedController { + suspend fun yield(x: T) {} + + suspend fun anotherYield(x: T) { + yield(x) + this.yield(x) + + yield2(x) + this.yield2(x) + + with(this) { + yield(x) + this@with.yield(x) + + yield2(x) + this@with.yield2(x) + } + } +} + +fun buildSequence(c: suspend RestrictedController.() -> Unit) {} +suspend fun RestrictedController.yield2(x: T) {} + +fun test() { + buildSequence a@{ + buildSequence b@{ + yield(1) + yield2(1) + this@b.yield(1) + this@b.yield2(1) + + this@a.yield(2) // Should be error + this@a.yield2(2) // Should be error + + with(this) { + yield(3) + this@with.yield(3) + + yield2(3) + this@with.yield2(3) + } + } + } + + buildSequence { + buildSequence { + yield("a") + yield2("a") + this.yield("b") + this.yield2("b") + + yield(1) // Should be error + yield2(1) // Should be error + + with(this) { + yield("") + this@with.yield("") + + yield2("") + this@with.yield2("") + } + } + } + + buildSequence a@{ + yield(1) + yield2(1) + buildSequence { + yield("") + yield2("") + this@a.yield(1) + this@a.yield2(1) + + with(this) { + yield("") + this@with.yield("") + + yield2("") + this@with.yield2("") + } + } + } + + buildSequence { + yield("") + RestrictedController().yield("1") + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_3.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_3.fir.kt new file mode 100644 index 00000000000..5135c5e569a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/outerYield_1_3.fir.kt @@ -0,0 +1,99 @@ +// !LANGUAGE: +ReleaseCoroutines +ExperimentalBuilderInference +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// SKIP_TXT + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +@kotlin.coroutines.RestrictsSuspension +class RestrictedController { + suspend fun yield(x: T) {} + + suspend fun anotherYield(x: T) { + yield(x) + this.yield(x) + + yield2(x) + this.yield2(x) + + with(this) { + yield(x) + this@with.yield(x) + + yield2(x) + this@with.yield2(x) + } + } +} + +fun buildSequence(@BuilderInference c: suspend RestrictedController.() -> Unit) {} + +@BuilderInference +suspend fun RestrictedController.yield2(x: T) {} + +fun test() { + buildSequence a@{ + buildSequence b@{ + yield(1) + yield2(1) + this@b.yield(1) + this@b.yield2(1) + + this@a.yield(2) // Should be error + this@a.yield2(2) // Should be error + + with(this) { + yield(3) + this@with.yield(3) + + yield2(3) + this@with.yield2(3) + } + } + } + + buildSequence { + buildSequence { + yield("a") + yield2("a") + this.yield("b") + this.yield2("b") + + yield(1) // Should be error + yield2(1) // Should be error + + with(this) { + yield("") + this@with.yield("") + + yield2("") + this@with.yield2("") + } + } + } + + buildSequence a@{ + yield(1) + yield2(1) + buildSequence { + yield("") + yield2("") + this@a.yield(1) + this@a.yield2(1) + + with(this) { + yield("") + this@with.yield("") + + yield2("") + this@with.yield2("") + } + } + } + + buildSequence { + yield("") + RestrictedController().yield("1") + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/sameInstance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/sameInstance.fir.kt new file mode 100644 index 00000000000..18e7fdc5a87 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/sameInstance.fir.kt @@ -0,0 +1,54 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE +// COMMON_COROUTINES_TEST + +@COROUTINES_PACKAGE.RestrictsSuspension +class RestrictedController { + suspend fun member() {} +} + +suspend fun RestrictedController.extension() {} + +fun generate(f: suspend RestrictedController.() -> Unit) {} + +fun test() { + generate() l@ { + member() + extension() + + this.member() + this.extension() + + val foo = this + foo.member() + foo.extension() + + this@l.member() + this@l.extension() + + with(1) { + this@l.member() + this@l.extension() + } + } +} + +suspend fun RestrictedController.l() { + member() + extension() + + this.member() + this.extension() + + val foo = this + foo.member() + foo.extension() + + this@l.member() + this@l.extension() + + with(1) { + this@l.member() + this@l.extension() + } + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/simpleForbidden.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/simpleForbidden.fir.kt new file mode 100644 index 00000000000..877b528ccf9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/simpleForbidden.fir.kt @@ -0,0 +1,15 @@ +// COMMON_COROUTINES_TEST +@COROUTINES_PACKAGE.RestrictsSuspension +class RestrictedController + +suspend fun Any?.extFun() {} +suspend fun suspendFun() {} + +fun generate(c: suspend RestrictedController.() -> Unit) {} + +fun test() { + generate { + extFun() + suspendFun() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/wrongEnclosingFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/wrongEnclosingFunction.fir.kt new file mode 100644 index 00000000000..60d2895331d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/restrictSuspension/wrongEnclosingFunction.fir.kt @@ -0,0 +1,18 @@ +// COMMON_COROUTINES_TEST +// SKIP_TXT +@COROUTINES_PACKAGE.RestrictsSuspension +class RestrictedController { + suspend fun yield() {} +} + +fun generate(c: suspend RestrictedController.() -> Unit) {} + +fun runBlocking(x: suspend () -> Unit) {} + +fun test() { + generate { + runBlocking { + yield() + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/returnLabelForBuiltInSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/returnLabelForBuiltInSuspend.fir.kt new file mode 100644 index 00000000000..3a06ee8d777 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/returnLabelForBuiltInSuspend.fir.kt @@ -0,0 +1,27 @@ +// SKIP_TXT +fun bar() { + suspend { + return@suspend + } + + suspend { + run { + return@suspend + } + } + + suspend l@{ + return@l + } + + suspend suspend@{ + return@suspend + } + + val x = suspend@{ + suspend { + // Might be resolved to outer lambda, but doesn't make sense because suspend-lambdas here is noinline + return@suspend + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendApplicability.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendApplicability.kt index 39b3b622924..210edcdbf6b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendApplicability.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendApplicability.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE // COMMON_COROUTINES_TEST import COROUTINES_PACKAGE.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendConflictsWithNoSuspend.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendConflictsWithNoSuspend.fir.kt new file mode 100644 index 00000000000..93bb56959b7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendConflictsWithNoSuspend.fir.kt @@ -0,0 +1,15 @@ +// FILE: main.kt +interface A { + suspend fun foo() + fun foo() +} + +interface B : A { + suspend override fun foo() { + + } + + override fun foo() { + + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn.fir.kt new file mode 100644 index 00000000000..f065c107b35 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// SKIP_TXT + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +class Controller { + suspend fun noParams(): Unit = suspendCoroutineUninterceptedOrReturn { + if (hashCode() % 2 == 0) { + it.resume(Unit) + COROUTINE_SUSPENDED + } + else { + Unit + } + } + suspend fun yieldString(value: String) = suspendCoroutineUninterceptedOrReturn { + it.resume(1) + it checkType { _>() } + it.resume("") + + // We can return anything here, 'suspendCoroutineUninterceptedOrReturn' is not very type-safe + // Also we can call resume and then return the value too, but it's still just our problem + "Not-int" + } +} + +fun builder(c: suspend Controller.() -> Unit) {} + +fun test() { + builder { + noParams() checkType { _() } + yieldString("abc") checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn_1_2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn_1_2.fir.kt new file mode 100644 index 00000000000..889f79e95eb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineOrReturn_1_2.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: -ReleaseCoroutines +// !DIAGNOSTICS: -UNUSED_PARAMETER -EXPERIMENTAL_FEATURE_WARNING +// !CHECK_TYPE +// !WITH_NEW_INFERENCE +// SKIP_TXT + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +class Controller { + suspend fun noParams(): Unit = suspendCoroutineUninterceptedOrReturn { + if (hashCode() % 2 == 0) { + it.resume(Unit) + COROUTINE_SUSPENDED + } + else { + Unit + } + } + suspend fun yieldString(value: String) = suspendCoroutineUninterceptedOrReturn { + it.resume(1) + it checkType { _>() } + it.resume("") + + // We can return anything here, 'suspendCoroutineUninterceptedOrReturn' is not very type-safe + // Also we can call resume and then return the value too, but it's still just our problem + "Not-int" + } +} + +fun builder(c: suspend Controller.() -> Unit) {} + +fun test() { + builder { + noParams() checkType { _() } + yieldString("abc") checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithNewAPI.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithNewAPI.kt index c50c3af6c06..2e262aa0861 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithNewAPI.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithNewAPI.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !API_VERSION: 1.1 // !LANGUAGE: +Coroutines -ReleaseCoroutines // SKIP_TXT diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithOldAPI.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithOldAPI.fir.kt new file mode 100644 index 00000000000..a7f1c382a1f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCoroutineUnavailableWithOldAPI.fir.kt @@ -0,0 +1,14 @@ +// !API_VERSION: 1.0 +// SKIP_TXT + +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +suspend fun foo(): Unit = suspendCoroutine { + it.resume(Unit) +} + +suspend fun bar(): Unit = suspendCoroutineUninterceptedOrReturn { + it.resume(Unit) + COROUTINE_SUSPENDED +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCovarianJavaOverride.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCovarianJavaOverride.fir.kt new file mode 100644 index 00000000000..e4d376125b0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendCovarianJavaOverride.fir.kt @@ -0,0 +1,48 @@ +// COMMON_COROUTINES_TEST +// FILE: I.kt + +interface I { + suspend fun foo(x: Int): String +} + +// FILE: JavaClass.java +public class JavaClass implements I { + @Override + public String foo(int x, COROUTINES_PACKAGE.Continuation continuation) { + return null; + } +} + +// FILE: main.kt + +import COROUTINES_PACKAGE.Continuation +class K1 : JavaClass() + +class K2 : JavaClass() { + override suspend fun foo(x: Int): String = "" +} + +class K3 : JavaClass() { + override fun foo(x: Int, y: Continuation): Any? = null +} + +fun builder(block: suspend () -> Unit) {} + +fun main(x: Continuation) { + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + + builder { + JavaClass().foo(1) + K1().foo(2) + K2().foo(3) + K3().foo(4) + + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendDestructuring.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendDestructuring.fir.kt new file mode 100644 index 00000000000..0c974541763 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendDestructuring.fir.kt @@ -0,0 +1,13 @@ +// SKIP_TXT +class A { + suspend operator fun component1(): String = "K" +} + +fun foo(c: suspend (A) -> Unit) {} + +fun bar() { + foo { + (x) -> + x.length + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.fir.kt new file mode 100644 index 00000000000..c2013feafb8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE +suspend fun noParams() { +} + +suspend fun yieldString(value: String) {} + +suspend fun await(f: () -> V) = f() + +suspend fun await(f: Int): V = null!! + +suspend fun severalParams(x: String, y: Int) = 1.0 + +suspend fun String.stringReceiver(y: Int) = 1.0 + +suspend fun Any.anyReceiver(y: Int) = 1.0 + +fun builder(c: suspend () -> Unit) {} + +fun test() { + builder { + noParams() + yieldString("abc") checkType { _() } + yieldString(1) checkType { _() } + + await { "123" } checkType { _() } + + // Inference from lambda return type + await { 123 } checkType { _() } + + // Inference from expected type + checkSubtype(await(567)) + + await(123) checkType { _() } + + severalParams("", 89) checkType { _() } + // TODO: should we allow somehow to call with passing continuation explicitly? + severalParams("", 89, 6.9) checkType { _() } + + "".stringReceiver(1) + Any().anyReceiver(1) + + with("") { + stringReceiver(2) + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.fir.kt new file mode 100644 index 00000000000..e6cbea1e0f2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +Coroutines +// !DIAGNOSTICS: -USELESS_IS_CHECK +// SKIP_TXT + +fun test() { + suspend {} is SuspendFunction0<*> + suspend {} is kotlin.coroutines.SuspendFunction0<*> +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/functionVsSuspendFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/functionVsSuspendFunction.fir.kt new file mode 100644 index 00000000000..2b700c28389 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/functionVsSuspendFunction.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -SuspendConversion +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun useSuspendFn(sfn: suspend () -> Unit) = sfn +fun useFn(fn: () -> Unit) = fn + +fun ambiguous(sfn: suspend () -> Unit) = sfn +fun ambiguous(fn: () -> Unit) = fn + +fun test1(sfn: suspend () -> Unit) = useFn(sfn) +fun test2(fn: () -> Unit) = useSuspendFn(fn) + +fun test3(sfn: suspend () -> Unit) = useSuspendFn(sfn) +fun test4(): suspend () -> Unit = useSuspendFn {} +fun test5() = useSuspendFn {} + +fun test5(sfn: suspend () -> Unit) = ambiguous(sfn) +fun test6(fn: () -> Unit) = ambiguous(fn) +fun test7(): () -> Unit = ambiguous {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference1.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference1.kt index 7ebf47f7ec1..a40eaa248ea 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference1.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER fun withS(x: T, sfn: suspend (T) -> Unit) = x diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference2.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference2.kt index ca95fcc3f5b..839a5348322 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER fun withS2(x: T1, sfn1: suspend (T1) -> T2, sfn2: suspend (T2) -> Unit): T2 = null!! diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference3.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference3.kt index 30b51cf9f36..bbff94259d6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference3.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference3.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER fun withS(x: T, sfn: suspend T.() -> Unit) = x diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference4.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference4.kt index 6df1d160a2e..c26d23b65b0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference4.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inference4.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER fun withS2(x: T1, sfn1: suspend T1.() -> T2, sfn2: suspend T2.() -> Unit): T2 = null!! diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inline.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inline.fir.kt new file mode 100644 index 00000000000..6acb6e04c2d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/inline.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +inline fun foo1(x: suspend () -> Unit) {} +inline fun foo2(crossinline x: suspend () -> Unit) {} +inline fun foo3(noinline x: suspend () -> Unit) {} +inline fun foo4(noinline crossinline x: suspend () -> Unit) {} + +suspend inline fun bar1(x: suspend () -> Unit) {} +suspend inline fun bar2(crossinline x: suspend () -> Unit) {} +suspend inline fun bar3(noinline x: suspend () -> Unit) {} +suspend inline fun bar4(noinline crossinline x: suspend () -> Unit) {} + +suspend fun baz() { + foo1 { + return@baz + } + + foo2 { + return@baz + } + + foo3 { + return@baz + } + + foo4 { + return@baz + } + + bar1 { + return@baz + } + + bar2 { + return@baz + } + + bar3 { + return@baz + } + + bar4 { + return@baz + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/invoke.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/invoke.fir.kt new file mode 100644 index 00000000000..c9b275d0b46 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/invoke.fir.kt @@ -0,0 +1,10 @@ +suspend fun foo1(q: suspend () -> Unit) = q() +suspend fun foo2(x: suspend (Int) -> String) = x(1) + + +suspend fun foo3(y: suspend String.(Int) -> Double) = "".y(1) +suspend fun String.foo4(y: suspend String.(Int) -> Double) = "".y(1) + +fun noSuspend(x: suspend (Int) -> String) { + x(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.fir.kt new file mode 100644 index 00000000000..dd982fe46f5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.fir.kt @@ -0,0 +1,23 @@ +interface Foo { + val foo: suspend () -> Unit +} + +interface Bar { + val bar: T +} + +class Test1 : Foo { + override val foo = {} +} + +class Test2 : Foo { + override val foo: suspend () -> Unit = {} +} + +class Test3 : Bar Unit> { + override val bar = {} +} + +class Test4 : Bar Unit> { + override val bar: suspend () -> Unit = {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt index d54b82ca84d..4f47e96df16 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/lambdaInValInitializer.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL typealias SuspendFn = suspend () -> Unit val test1: suspend () -> Unit = {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt new file mode 100644 index 00000000000..f5cd4c8888b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt @@ -0,0 +1,37 @@ +typealias Action = () -> Unit + +interface SAM { + fun run() +} + +typealias Test1 = suspend () -> Unit +typealias Test2 = suspend Int.() -> Unit +typealias Test3 = suspend Function0 +typealias Test4 = suspend Action +typealias Test5 = List Unit> +typealias Test6 = suspend List<() -> Unit> +typealias Test7 = suspend SAM +typealias Test8 = suspend kotlin.coroutines.SuspendFunction0 +typealias Test9 = suspend (() -> Unit) -> Unit +typealias Test10 = suspend (suspend () -> Unit) -> Unit +typealias Test11 = suspend () -> (suspend () -> Unit) +typealias Test12 = suspend (suspend (() -> Unit)) -> Unit +typealias Test13 = @A() suspend () -> Unit +typealias Test14 = @A suspend () -> Unit +typealias Test15 = (@A() suspend () -> Unit)? +typealias Test16 = (@A suspend () -> Unit)? +typealias Test17 = @A suspend RS.() -> Unit +typealias Test18 = (suspend () -> Unit)? + +interface Supertype1 : suspend () -> Unit { + +} + +interface Supertype2 : suspend String.() -> Unit { + +} + +@Target(AnnotationTarget.TYPE) +annotation class A + +interface RS diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noInvokeForSuspendFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noInvokeForSuspendFunction.fir.kt new file mode 100644 index 00000000000..b83e4b42cb9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noInvokeForSuspendFunction.fir.kt @@ -0,0 +1,2 @@ +fun test1(sfn: suspend () -> Unit) = sfn() +fun test2(sfn: suspend () -> Unit) = sfn.invoke() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noValueParameters.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noValueParameters.kt index bddc9b15182..3ebf68b412b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noValueParameters.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/noValueParameters.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL typealias Test1 = suspend (Int) -> Unit typealias Test2 = suspend Int.(Int) -> Unit typealias Test3 = List Unit> diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/nullableSuspendFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/nullableSuspendFunction.fir.kt new file mode 100644 index 00000000000..b572f13731c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/nullableSuspendFunction.fir.kt @@ -0,0 +1,9 @@ +val test1: (suspend () -> Unit)? = null +val test2: suspend (() -> Unit)? = null +val test3: suspend ( (() -> Unit)? ) = null + +fun foo() { + test1?.invoke() + test2?.invoke() + test3?.invoke() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.fir.kt new file mode 100644 index 00000000000..d81d77f6fa0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.fir.kt @@ -0,0 +1,4 @@ +// JAVAC_SKIP +typealias Test1 = SuspendFunction0 +typealias Test2 = kotlin.SuspendFunction0 +typealias Test3 = kotlin.coroutines.SuspendFunction0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.fir.kt new file mode 100644 index 00000000000..edf2d483b96 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE +// COMMON_COROUTINES_TEST +import COROUTINES_PACKAGE.* + +class Controller { + suspend fun noParams() { + + } + suspend fun yieldString(value: String) {} + + suspend fun await(f: () -> V): V = f() + + suspend fun await(f: Int): V = null!! + + suspend fun severalParams(x: String, y: Int) = 1.0 +} + +fun builder(c: suspend Controller.() -> Unit) {} + +fun test() { + builder { + noParams() + yieldString("abc") checkType { _() } + yieldString(1) checkType { _() } + + await { "123" } checkType { _() } + + // Inference from lambda return type + await { 123 } checkType { _() } + + // Inference from expected type + checkSubtype(await(567)) + + await(123) checkType { _() } + + severalParams("", 89) checkType { _() } + + // TODO: should we allow somehow to call with passing continuation explicitly? + severalParams("", 89, 6.9) checkType { _() } + severalParams("", 89, this as Continuation) checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaImplementationFromDifferentClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaImplementationFromDifferentClass.fir.kt new file mode 100644 index 00000000000..7c7440c533c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaImplementationFromDifferentClass.fir.kt @@ -0,0 +1,51 @@ +// COMMON_COROUTINES_TEST +// FILE: I.kt + +interface I { + suspend fun foo(x: Int): String +} + +// FILE: BaseJavaClass.java +public class BaseJavaClass { + public Object foo(int x, COROUTINES_PACKAGE.Continuation continuation) { + return null; + } +} + +// FILE: JavaClass.java +public class JavaClass extends BaseJavaClass implements I { +} + +// FILE: main.kt + +import COROUTINES_PACKAGE.Continuation +class K1 : JavaClass() + +class K2 : JavaClass() { + override suspend fun foo(x: Int): String = "" +} + +class K3 : JavaClass() { + override fun foo(x: Int, y: Continuation): Any? = null +} + +fun builder(block: suspend () -> Unit) {} + +fun main(x: Continuation) { + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + + builder { + JavaClass().foo(1) + K1().foo(2) + K2().foo(3) + K3().foo(4) + + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaOverrides.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaOverrides.fir.kt new file mode 100644 index 00000000000..0c2d26716df --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendJavaOverrides.fir.kt @@ -0,0 +1,48 @@ +// COMMON_COROUTINES_TEST +// FILE: I.kt + +interface I { + suspend fun foo(x: Int): String +} + +// FILE: JavaClass.java +public class JavaClass implements I { + @Override + public Object foo(int x, COROUTINES_PACKAGE.Continuation continuation) { + return null; + } +} + +// FILE: main.kt + +import COROUTINES_PACKAGE.Continuation +class K1 : JavaClass() + +class K2 : JavaClass() { + override suspend fun foo(x: Int): String = "" +} + +class K3 : JavaClass() { + override fun foo(x: Int, y: Continuation): Any? = null +} + +fun builder(block: suspend () -> Unit) {} + +fun main(x: Continuation) { + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + + builder { + JavaClass().foo(1) + K1().foo(2) + K2().foo(3) + K3().foo(4) + + JavaClass().foo(5, x) + K1().foo(6, x) + K2().foo(7, x) + K3().foo(8, x) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt index a3490524c29..3bf0483cb69 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendLambda.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // COMMON_COROUTINES_TEST // SKIP_TXT import COROUTINES_PACKAGE.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.fir.kt new file mode 100644 index 00000000000..fb98c19ac93 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.fir.kt @@ -0,0 +1,37 @@ +// FILE: main.kt +interface A { + suspend fun foo() + fun bar() +} + +interface B : A { + override fun foo() { + + } + + override suspend fun bar() { + + } +} + +interface C : A { + suspend override fun foo() { + + } + + override fun bar() { + + } +} + +class D : J { + suspend override fun foo() { + + } +} + +// FILE: J.java + +public interface J extends A { + Object foo(kotlin.coroutines.Continuation y); +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendTest.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendTest.fir.kt new file mode 100644 index 00000000000..373341f675f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendTest.fir.kt @@ -0,0 +1,20 @@ +// SKIP_TXT +// FILE: test.kt + +package kotlin.test + +annotation class IrrelevantClass + +public typealias Test = IrrelevantClass + +// FILE: main.kt + +import kotlin.test.Test + +class A { + @Test + suspend fun test() {} +} + +@Test +suspend fun test() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitor.fir.kt new file mode 100644 index 00000000000..4a5225ecd55 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitor.fir.kt @@ -0,0 +1,59 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -USELESS_IS_CHECK +// SKIP_TXT +import kotlin.concurrent.withLock + +val lock = java.util.concurrent.locks.ReentrantLock() + +fun builder(c: suspend () -> Unit) {} + +suspend fun getLock() = lock + +suspend fun suspensionPoint() {} + +fun test() { + builder { + synchronized(lock) { + suspensionPoint() + } + + synchronized(lock) label@{ + suspensionPoint() + } + + synchronized(lock, { suspensionPoint() }) + + synchronized(getLock()) { + println("") + } + synchronized(suspend { getLock() } ()) { + println("") + } + synchronized(run { getLock() }) { + println("") + } + lock.withLock { + suspensionPoint() + } + } +} + +suspend fun run() { + synchronized(lock) { + suspensionPoint() + } +} + +suspend fun ifWhenAndOtherNonsence() { + synchronized(lock) { + if (lock == Any()) { + when (1) { + is Int -> { + return@synchronized 1 + returnsInt() + } + else -> {} + } + } else {} + } +} + +suspend fun returnsInt(): Int = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.fir.kt new file mode 100644 index 00000000000..3c620bda83e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.fir.kt @@ -0,0 +1,61 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -USELESS_IS_CHECK +// !LANGUAGE: +NewInference +// SKIP_TXT + +import kotlin.concurrent.withLock + +val lock = java.util.concurrent.locks.ReentrantLock() + +fun builder(c: suspend () -> Unit) {} + +suspend fun getLock() = lock + +suspend fun suspensionPoint() {} + +fun test() { + builder { + synchronized(lock) { + suspensionPoint() + } + + synchronized(lock) label@{ + suspensionPoint() + } + + synchronized(lock, { suspensionPoint() }) + + synchronized(getLock()) { + println("") + } + synchronized(suspend { getLock() } ()) { + println("") + } + synchronized(run { getLock() }) { + println("") + } + lock.withLock { + suspensionPoint() + } + } +} + +suspend fun run() { + synchronized(lock) { + suspensionPoint() + } +} + +suspend fun ifWhenAndOtherNonsence() { + synchronized(lock) { + if (lock == Any()) { + when (1) { + is Int -> { + return@synchronized 1 + returnsInt() + } + else -> {} + } + } else {} + } +} + +suspend fun returnsInt(): Int = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.fir.kt new file mode 100644 index 00000000000..0a6c51c86b9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +suspend fun foo() = 1 + +suspend fun bar( + x: Int = 2 + foo(), + y: suspend () -> Int = { foo() }, + z: () -> Int = { foo() }, + w: Int = myInline { foo() }, + v: Any? = object { + fun x() = foo() + suspend fun y() = foo() + } +) {} + +inline fun myInline(x: () -> Unit) = 1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt index ac172e444c8..51fb71a4918 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER // COMMON_COROUTINES_TEST import COROUTINES_PACKAGE.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/localFunctions.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/localFunctions.kt index ed50fe169ab..1add190f452 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/localFunctions.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/localFunctions.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL suspend fun baz() = 1 suspend fun unit() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_2.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_2.kt index 2ed2a5338c2..33258efbc9d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -DEPRECATION // Tail calls are not allowed to be Nothing typed. See KT-15051 import kotlin.coroutines.experimental.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_3.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_3.kt index 9cd56e7296f..c9f0c262a7c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_3.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/nothingTypedSuspendFunction_1_3.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // Tail calls are not allowed to be Nothing typed. See KT-15051 import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/recursive.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/recursive.kt index 9322a658a74..28e4943ed3d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/recursive.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/recursive.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL suspend fun unit1() { unit1() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt index 38b9068663c..6fecf4646b6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER // COMMON_COROUTINES_TEST import COROUTINES_PACKAGE.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt index 0a4f1649297..3bb325029f4 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER // COMMON_COROUTINES_TEST import COROUTINES_PACKAGE.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tryCatchLambda.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tryCatchLambda.fir.kt new file mode 100644 index 00000000000..6a3ede0ecb6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tryCatchLambda.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +suspend fun await(f: V): V = f + +fun genericBuilder(c: suspend () -> T): T = null!! + +fun foo() { + var result = "" + genericBuilder { + try { + await("") + } catch(e: Exception) { + result = "fail" + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/unsupported.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/unsupported.fir.kt new file mode 100644 index 00000000000..c0821913df0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/unsupported.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: -Coroutines -ReleaseCoroutines + +suspend fun suspendHere(): String = "OK" + +fun builder(c: suspend () -> Unit) { + +} + +fun box(): String { + var result = "" + + builder { + suspendHere() + } + + return result +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType.fir.kt new file mode 100644 index 00000000000..3675c2e0fc0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType.fir.kt @@ -0,0 +1,124 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_EXPRESSION, -UNUSED_VARIABLE +// !LANGUAGE: +InlineClasses -AllowResultInReturnType + +typealias ResultAlias = Result + +inline class InlineResult(private val r: Result) + +fun params( + r1: Result, + r2: Result?, + r3: ResultAlias, + r4: List>, + r5: InlineResult, + vararg r6: Result +) {} + +class CtorParams(r1: Result) + +fun returnTypePublic(): Result = TODO() +internal fun returnTypeInternal(): Result = TODO() +private fun returnTypePrivate(): Result = TODO() +fun returnTypeNullable(): Result? = TODO() +fun returnTypeAlias(): ResultAlias = TODO() +fun returnInferred(r1: Result, r2: ResultAlias, b: Boolean) = if (b) r1 else r2 + +fun returnTypeInline(): InlineResult = TODO() +fun returnContainer(): List> = TODO() + +val topLevelP: Result = TODO() +val topLevelPInferred = topLevelP +internal val topLevelPInternal: Result = TODO() + +private val topLevelPPrivate: Result = TODO() +private val topLevelPPrivateInferred = topLevelP + +private val topLevelPPrivateCustomGetter: Result + get() = TODO() + +val asFunctional: () -> Result = TODO() + +open class PublicCls( + val r1: Result, + val r2: Result?, + val r3: ResultAlias, + val r4: ResultAlias?, + + val r5: InlineResult, + + internal val r6: Result, + + private val r7: Result, + val r8: List> +) { + val p1: Result = TODO() + var p2: Result = TODO() + val p3: ResultAlias? = TODO() + + val p4 = p1 + + internal val p5: Result = TODO() + + private var p6: Result = TODO() + + internal val p7 = p1 + protected val p8 = p1 + + fun returnInCls(): Result = TODO() + protected fun returnInClsProtected(): Result = TODO() + private fun returnInClsPrivate(): Result = TODO() +} + +internal open class InternalCls( + val r1: Result, + val r2: ResultAlias?, + + val r3: List> +) { + companion object { + val cr1: Result = TODO() + + private val cr2: Result = TODO() + } + + val p1 = r1 + val p2: Result = TODO() + + protected val p3 = p1 + + fun returnInInternal(): Result = TODO() + protected fun returnInClsProtected(): Result = TODO() +} + +private class PrivateCls( + val r1: Result, + val r2: ResultAlias?, + val r3: List> +) { + companion object { + val cr1: Result = TODO() + private val cr2: Result = TODO() + } + + val p1 = r1 + val p2: Result = TODO() + + fun returnInPrivate(): Result = TODO() +} + +fun local(r: Result) { + val l1: Result? = null + val l2 = r + + fun localFun(): Result = TODO() + + class F { + val p1: Result = r + val p2 = r + } +} + +fun resultInGenericFun(r: Result): T = r as T + +val asFunPublic: () -> Result = TODO() +private val asFun: () -> Result? = TODO() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType_1_4.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType_1_4.fir.kt new file mode 100644 index 00000000000..215c99e1c6a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeInReturnType_1_4.fir.kt @@ -0,0 +1,124 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_EXPRESSION, -UNUSED_VARIABLE +// !LANGUAGE: +InlineClasses +AllowResultInReturnType + +typealias ResultAlias = Result + +inline class InlineResult(private val r: Result) + +fun params( + r1: Result, + r2: Result?, + r3: ResultAlias, + r4: List>, + r5: InlineResult, + vararg r6: Result +) {} + +class CtorParams(r1: Result) + +fun returnTypePublic(): Result = TODO() +internal fun returnTypeInternal(): Result = TODO() +private fun returnTypePrivate(): Result = TODO() +fun returnTypeNullable(): Result? = TODO() +fun returnTypeAlias(): ResultAlias = TODO() +fun returnInferred(r1: Result, r2: ResultAlias, b: Boolean) = if (b) r1 else r2 + +fun returnTypeInline(): InlineResult = TODO() +fun returnContainer(): List> = TODO() + +val topLevelP: Result = TODO() +val topLevelPInferred = topLevelP +internal val topLevelPInternal: Result = TODO() + +private val topLevelPPrivate: Result = TODO() +private val topLevelPPrivateInferred = topLevelP + +private val topLevelPPrivateCustomGetter: Result + get() = TODO() + +val asFunctional: () -> Result = TODO() + +open class PublicCls( + val r1: Result, + val r2: Result?, + val r3: ResultAlias, + val r4: ResultAlias?, + + val r5: InlineResult, + + internal val r6: Result, + + private val r7: Result, + val r8: List> +) { + val p1: Result = TODO() + var p2: Result = TODO() + val p3: ResultAlias? = TODO() + + val p4 = p1 + + internal val p5: Result = TODO() + + private var p6: Result = TODO() + + internal val p7 = p1 + protected val p8 = p1 + + fun returnInCls(): Result = TODO() + protected fun returnInClsProtected(): Result = TODO() + private fun returnInClsPrivate(): Result = TODO() +} + +internal open class InternalCls( + val r1: Result, + val r2: ResultAlias?, + + val r3: List> +) { + companion object { + val cr1: Result = TODO() + + private val cr2: Result = TODO() + } + + val p1 = r1 + val p2: Result = TODO() + + protected val p3 = p1 + + fun returnInInternal(): Result = TODO() + protected fun returnInClsProtected(): Result = TODO() +} + +private class PrivateCls( + val r1: Result, + val r2: ResultAlias?, + val r3: List> +) { + companion object { + val cr1: Result = TODO() + private val cr2: Result = TODO() + } + + val p1 = r1 + val p2: Result = TODO() + + fun returnInPrivate(): Result = TODO() +} + +fun local(r: Result) { + val l1: Result? = null + val l2 = r + + fun localFun(): Result = TODO() + + class F { + val p1: Result = r + val p2 = r + } +} + +fun resultInGenericFun(r: Result): T = r as T + +val asFunPublic: () -> Result = TODO() +private val asFun: () -> Result? = TODO() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.fir.kt new file mode 100644 index 00000000000..968a83ad72e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// !LANGUAGE: -AllowNullOperatorsForResult -AllowResultInReturnType + +fun id(x: T): T = x + +private val asFun: () -> Result? = TODO() +private val Int.intResult: Result? + get() = null + +fun returnInt(): Int? = 0 + + +fun nullableOperators(r1: Result?, b: Boolean) { + if (b) { + r1!! + asFun()!! + returnInt()?.intResult!!.toString() + } + + if (b) { + id(r1)!! + } + + if (b) { + r1?.toString() + r1?.let { } + returnInt()?.intResult?.toString() + asFun()?.toString() + id(r1)?.toString() + } + + if (b) { + r1 ?: 0 + r1 ?: r1 + asFun() ?: r1 ?: 0 + id(asFun()) ?: 0 + + returnInt() ?: returnInt() ?: asFun() ?: 0 + } +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt index 738acd12f85..d2f4643a485 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt @@ -281,6 +281,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { val testRunner = object : AbstractFirOldFrontendDiagnosticsTest() { init { environment = this@AbstractDiagnosticsTest.environment + coroutinesPackage = this@AbstractDiagnosticsTest.coroutinesPackage } } if (testDataFile.readText().contains("// FIR_IDENTICAL")) { diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithStdLib.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithStdLib.kt index e6614db84c8..b443807ca83 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithStdLib.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithStdLib.kt @@ -4,6 +4,7 @@ */ package org.jetbrains.kotlin.checkers +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.test.ConfigurationKind import java.io.File @@ -15,6 +16,6 @@ abstract class AbstractDiagnosticsTestWithStdLib : AbstractDiagnosticsTest() { override fun shouldValidateFirTestData(testDataFile: File): Boolean { val path = testDataFile.absolutePath - return !path.endsWith(".kts") && !path.contains("coroutines") + return !path.endsWith(".kts") && coroutinesPackage != DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString() } } \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt index 1745a41b440..df80bec70d4 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt @@ -64,10 +64,14 @@ import java.io.File abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { companion object { val DUMP_CFG_DIRECTIVE = "DUMP_CFG" + val COMMON_COROUTINES_DIRECTIVE ="COMMON_COROUTINES_TEST" val TestFile.withDumpCfgDirective: Boolean get() = DUMP_CFG_DIRECTIVE in directives + val TestFile.withCommonCoroutinesDirective: Boolean + get() = COMMON_COROUTINES_DIRECTIVE in directives + val File.cfgDumpFile: File get() = File(absolutePath.replace(".kt", ".dot")) } @@ -110,7 +114,7 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { protected open fun checkDiagnostics(file: File, testFiles: List, firFiles: List) { val diagnostics = collectDiagnostics(firFiles) - val actualText = StringBuilder() + val actualTextBuilder = StringBuilder() for (testFile in testFiles) { val firFile = firFiles.firstOrNull { it.psi == testFile.ktFile } if (firFile != null) { @@ -118,13 +122,17 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { collectDebugInfoDiagnostics(firFile, testFile.diagnosedRangesToDiagnosticNames) testFile.getActualText( diagnostics.getValue(firFile) + debugInfoDiagnostics, - actualText, + actualTextBuilder, ) } else { - actualText.append(testFile.expectedText) + actualTextBuilder.append(testFile.expectedText) } } - KotlinTestUtils.assertEqualsToFile(file, actualText.toString()) + var actualText = actualTextBuilder.toString() + if (testFiles.any { it.withCommonCoroutinesDirective }) { + actualText = actualText.replace(coroutinesPackage, "COROUTINES_PACKAGE") + } + KotlinTestUtils.assertEqualsToFile(file, actualText) } protected fun collectDebugInfoDiagnostics( diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index b609d872c0c..06825289927 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -593,7 +593,7 @@ fun main(args: Array) { model( "diagnostics/testsWithStdLib", excludedPattern = excludedFirTestdataPattern, - excludeDirs = listOf("coroutines") + skipTestsForExperimentalCoroutines = true ) } } diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java index 5d65888ff7e..c2bdff95e45 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java @@ -53,6 +53,8 @@ public class SimpleTestClassModel extends TestClassModel { private final String testRunnerMethodName; private final List additionalRunnerArguments; + private boolean skipTestsForExperimentalCoroutines; + public SimpleTestClassModel( @NotNull File rootFile, boolean recursive, @@ -68,7 +70,8 @@ public class SimpleTestClassModel extends TestClassModel { String testRunnerMethodName, List additionalRunnerArguments, Integer deep, - @NotNull Collection annotations + @NotNull Collection annotations, + boolean skipTestsForExperimentalCoroutines ) { this.rootFile = rootFile; this.recursive = recursive; @@ -85,6 +88,7 @@ public class SimpleTestClassModel extends TestClassModel { this.additionalRunnerArguments = additionalRunnerArguments; this.deep = deep; this.annotations = annotations; + this.skipTestsForExperimentalCoroutines = skipTestsForExperimentalCoroutines; } @NotNull @@ -104,7 +108,8 @@ public class SimpleTestClassModel extends TestClassModel { children.add(new SimpleTestClassModel( file, true, excludeParentDirs, filenamePattern, excludePattern, checkFilenameStartsLowerCase, doTestMethodName, innerTestClassName, targetBackend, excludesStripOneDirectory(file.getName()), - skipIgnored, testRunnerMethodName, additionalRunnerArguments, deep != null ? deep - 1 : null, annotations) + skipIgnored, testRunnerMethodName, additionalRunnerArguments, deep != null ? deep - 1 : null, annotations, + skipTestsForExperimentalCoroutines) ); } @@ -156,7 +161,7 @@ public class SimpleTestClassModel extends TestClassModel { if (CoroutinesKt.isCommonCoroutineTest(rootFile)) { testMethods = CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, rootFile, filenamePattern, checkFilenameStartsLowerCase, targetBackend, - skipIgnored); + skipIgnored, skipTestsForExperimentalCoroutines); } else { testMethods = Collections.singletonList(new SimpleTestMethodModel( @@ -189,7 +194,8 @@ public class SimpleTestClassModel extends TestClassModel { result.addAll(CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, file, filenamePattern, checkFilenameStartsLowerCase, - targetBackend, skipIgnored)); + targetBackend, skipIgnored, + skipTestsForExperimentalCoroutines)); } else { result.add(new SimpleTestMethodModel(rootFile, file, filenamePattern, diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/TestGenerationDSL.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/TestGenerationDSL.kt index e0d31bd80a6..f9ca7941677 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/TestGenerationDSL.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/TestGenerationDSL.kt @@ -66,7 +66,8 @@ class TestGroup( excludeDirs: List = listOf(), filenameStartsLowerCase: Boolean? = null, skipIgnored: Boolean = false, - deep: Int? = null + deep: Int? = null, + skipTestsForExperimentalCoroutines: Boolean = false ) { val rootFile = File("$testDataRoot/$relativeRootPath") val compiledPattern = Pattern.compile(pattern) @@ -83,7 +84,8 @@ class TestGroup( SimpleTestClassModel( rootFile, recursive, excludeParentDirs, compiledPattern, compiledExcludedPattern, filenameStartsLowerCase, testMethod, className, - targetBackend, excludeDirs, skipIgnored, testRunnerMethodName, additionalRunnerArguments, deep, annotations + targetBackend, excludeDirs, skipIgnored, testRunnerMethodName, additionalRunnerArguments, deep, annotations, + skipTestsForExperimentalCoroutines ) } ) diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/coroutines.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/coroutines.kt index 4b98fe51453..6f526277d52 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/coroutines.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/coroutines.kt @@ -52,7 +52,8 @@ fun createCommonCoroutinesTestMethodModels( filenamePattern: Pattern, checkFilenameStartsLowerCase: Boolean?, targetBackend: TargetBackend, - skipIgnored: Boolean + skipIgnored: Boolean, + skipExperimental: Boolean ): Collection { return if (targetBackend.isIR || targetBackend == TargetBackend.JS) listOf( @@ -66,8 +67,8 @@ fun createCommonCoroutinesTestMethodModels( true ) ) - else - listOf( + else { + mutableListOf( CoroutinesTestModel( rootDir, file, @@ -76,15 +77,20 @@ fun createCommonCoroutinesTestMethodModels( targetBackend, skipIgnored, true - ), - CoroutinesTestModel( - rootDir, - file, - filenamePattern, - checkFilenameStartsLowerCase, - targetBackend, - skipIgnored, - false ) - ) + ).apply { + if (!skipExperimental) { + this += CoroutinesTestModel( + rootDir, + file, + filenamePattern, + checkFilenameStartsLowerCase, + targetBackend, + skipIgnored, + false + ) + + } + } + } } \ No newline at end of file