From 2536fa0cd5566e665290846339d2c0f02f6b049f Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 11 Dec 2019 16:16:22 +0300 Subject: [PATCH] [FIR-TEST] Add new testdata generated after changes in previous commit --- .../diagnostics/tests/Abstract.fir.kt | 61 +++ .../diagnostics/tests/AbstractAccessor.fir.kt | 21 + .../tests/AbstractInAbstractClass.fir.kt | 45 +++ .../diagnostics/tests/AbstractInClass.fir.kt | 45 +++ .../diagnostics/tests/AbstractInTrait.fir.kt | 45 +++ ...onymousInitializerVarAndConstructor.fir.kt | 10 + .../tests/AnonymousInitializers.fir.kt | 26 ++ .../tests/AssignToArrayElement.fir.kt | 10 + .../diagnostics/tests/AutoCreatedIt.fir.kt | 33 ++ .../diagnostics/tests/BacktickNames.fir.kt | 94 +++++ .../testData/diagnostics/tests/Basic.fir.kt | 16 + .../tests/BinaryCallsOnNullableValues.fir.kt | 32 ++ .../testData/diagnostics/tests/Bounds.fir.kt | 43 ++ .../diagnostics/tests/BreakContinue.fir.kt | 96 +++++ .../tests/BreakContinueInWhen_after.fir.kt | 92 +++++ .../tests/BreakContinueInWhen_before.fir.kt | 57 +++ .../diagnostics/tests/Builders.fir.kt | 159 ++++++++ .../testData/diagnostics/tests/Casts.fir.kt | 23 ++ .../tests/CharacterLiterals.fir.kt | 13 + .../tests/CompareToWithErrorType.fir.kt | 6 + .../diagnostics/tests/Constants.fir.kt | 53 +++ .../diagnostics/tests/Constructors.fir.kt | 35 ++ .../tests/ConstructorsOfPrimitives.fir.kt | 10 + .../tests/CovariantOverrideType.fir.kt | 26 ++ ...aultValueForParameterInFunctionType.fir.kt | 20 + .../DefaultValuesCheckWithoutBody.fir.kt | 9 + .../tests/DefaultValuesTypechecking.fir.kt | 16 + .../diagnostics/tests/DeferredTypes.fir.kt | 5 + ...tedGetSetPropertyDelegateConvention.fir.kt | 53 +++ .../DeprecatedUnaryOperatorConventions.fir.kt | 33 ++ .../diagnostics/tests/DiamondFunction.fir.kt | 9 + .../tests/DiamondFunctionGeneric.fir.kt | 9 + .../diagnostics/tests/DiamondProperty.fir.kt | 11 + .../testData/diagnostics/tests/Dollar.fir.kt | 12 + .../diagnostics/tests/EnumEntryAsType.fir.kt | 55 +++ .../tests/ExtensionCallInvoke.fir.kt | 7 + .../tests/ExternalAccessors.fir.kt | 19 + .../tests/ExternalAndAbstract.fir.kt | 9 + .../tests/ForRangeConventions.fir.kt | 93 +++++ .../FreeFunctionCalledAsExtension.fir.kt | 13 + .../tests/FunctionCalleeExpressions.fir.kt | 84 ++++ .../tests/FunctionParameterWithoutType.fir.kt | 11 + .../tests/FunctionReturnTypes.fir.kt | 209 ++++++++++ .../tests/GenericArgumentConsistency.fir.kt | 43 ++ .../GenericFunctionIsLessSpecific.fir.kt | 10 + .../IdentityComparisonWithPrimitives.fir.kt | 81 ++++ .../testData/diagnostics/tests/IncDec.fir.kt | 46 +++ .../tests/IncorrectCharacterLiterals.fir.kt | 37 ++ .../tests/InferNullabilityInThenBlock.fir.kt | 9 + .../testData/diagnostics/tests/Infix.fir.kt | 38 ++ .../tests/InfixModifierApplicability.fir.kt | 27 ++ .../tests/InvokeAndRecursiveResolve.fir.kt | 19 + .../diagnostics/tests/IsExpressions.fir.kt | 26 ++ .../diagnostics/tests/LValueAssignment.fir.kt | 143 +++++++ .../diagnostics/tests/LiteralAsResult.fir.kt | 3 + .../LocalClassAndShortSubpackageNames.fir.kt | 17 + .../tests/MultilineStringTemplates.fir.kt | 43 ++ .../diagnostics/tests/MultipleBounds.fir.kt | 69 ++++ ...medFunctionTypeParameterInSupertype.fir.kt | 9 + .../diagnostics/tests/Nullability.fir.kt | 296 ++++++++++++++ .../tests/NumberPrefixAndSuffix.fir.kt | 54 +++ .../tests/ObjectWithConstructor.fir.kt | 24 ++ .../diagnostics/tests/OperatorChecks.fir.kt | 219 +++++++++++ .../diagnostics/tests/Operators.fir.kt | 114 ++++++ .../tests/OperatorsWithWrongNames.fir.kt | 11 + ...errideFunctionWithParamDefaultValue.fir.kt | 11 + ...enFunctionAndSpecifiedTypeParameter.fir.kt | 13 + .../tests/OverridenSetterVisibility.fir.kt | 29 ++ .../tests/OverridingVarByVal.fir.kt | 15 + .../tests/PackageInExpressionPosition.fir.kt | 26 ++ .../tests/PackageInTypePosition.fir.kt | 9 + .../diagnostics/tests/PackageQualified.fir.kt | 71 ++++ .../tests/PrimaryConstructors.fir.kt | 29 ++ .../tests/PrivateFromOuterPackage.fir.kt | 25 ++ .../tests/PrivateSetterForOverridden.fir.kt | 70 ++++ .../tests/ProcessingEmptyImport.fir.kt | 3 + .../ProjectionOnFunctionArgumentErrror.fir.kt | 4 + .../tests/ProjectionsInSupertypes.fir.kt | 6 + .../diagnostics/tests/Properties.fir.kt | 22 ++ .../tests/PropertyInitializers.fir.kt | 9 + .../tests/QualifiedExpressions.fir.kt | 14 + .../diagnostics/tests/RecursiveResolve.fir.kt | 75 ++++ .../tests/RecursiveTypeInference.fir.kt | 43 ++ .../diagnostics/tests/ReserveYield.fir.kt | 71 ++++ .../diagnostics/tests/ReserveYield2.fir.kt | 54 +++ .../tests/ResolveOfJavaGenerics.fir.kt | 22 ++ .../diagnostics/tests/ResolveToJava.fir.kt | 58 +++ .../testData/diagnostics/tests/Return.fir.kt | 17 + .../tests/ReturnInFunctionWithoutBody.fir.kt | 3 + .../diagnostics/tests/SafeCallInvoke.fir.kt | 24 ++ .../tests/SafeCallNonNullReceiver.fir.kt | 6 + .../SafeCallNonNullReceiverReturnNull.fir.kt | 7 + .../tests/SafeCallOnFakePackage.fir.kt | 16 + .../tests/SafeCallOnSuperReceiver.fir.kt | 11 + .../diagnostics/tests/Serializable.fir.kt | 55 +++ .../diagnostics/tests/SetterVisibility.fir.kt | 25 ++ .../tests/ShiftFunctionTypes.fir.kt | 52 +++ .../tests/SingleUnderscoreUnsupported.fir.kt | 27 ++ .../tests/StarsInFunctionCalls.fir.kt | 15 + .../tests/StringPrefixAndSuffix.fir.kt | 40 ++ .../diagnostics/tests/StringTemplates.fir.kt | 22 ++ .../tests/SupertypeListChecks.fir.kt | 49 +++ .../SyntaxErrorInTestHighlighting.fir.kt | 5 + .../SyntaxErrorInTestHighlightingEof.fir.kt | 1 + .../tests/TraitOverrideObjectMethods.fir.kt | 6 + .../tests/TraitWithConstructor.fir.kt | 18 + .../diagnostics/tests/TypeInference.fir.kt | 19 + ...eMismatchOnOverrideWithSyntaxErrors.fir.kt | 9 + .../diagnostics/tests/Underscore.fir.kt | 46 +++ .../tests/UnderscoreUsageInAnnotation.fir.kt | 6 + .../tests/UnderscoreUsageInCall.fir.kt | 42 ++ ...UnderscoreUsageInCallableRefTypeLHS.fir.kt | 11 + .../tests/UnderscoreUsageInType.fir.kt | 12 + ...rscoreUsageInVariableAsFunctionCall.fir.kt | 6 + .../UnitByDefaultForFunctionTypes.fir.kt | 3 + .../diagnostics/tests/UnitValue.fir.kt | 5 + .../diagnostics/tests/Unresolved.fir.kt | 32 ++ .../tests/UnusedInDestructuring.fir.kt | 9 + .../diagnostics/tests/UnusedParameters.fir.kt | 43 ++ .../tests/UnusedParametersVersion10.fir.kt | 3 + .../diagnostics/tests/UnusedVariables.fir.kt | 133 +++++++ ...ValAndFunOverrideCompatibilityClash.fir.kt | 9 + .../diagnostics/tests/VarargTypes.fir.kt | 26 ++ .../testData/diagnostics/tests/Varargs.fir.kt | 17 + .../diagnostics/tests/Variance.fir.kt | 41 ++ .../AmbigiousAnnotationConstructor.fir.kt | 6 + .../annotations/AnnotatedConstructor.fir.kt | 2 + .../AnnotatedConstructorParams.fir.kt | 15 + .../AnnotatedLocalObjectFun.fir.kt | 8 + .../AnnotatedLocalObjectProperty.fir.kt | 8 + .../tests/annotations/AnnotatedLoop.fir.kt | 8 + .../annotations/AnnotatedResultType.fir.kt | 5 + .../annotations/AnnotatedTryCatch.fir.kt | 9 + .../AnnotationAsDefaultParameter.fir.kt | 5 + .../AnnotationForClassTypeParameter.fir.kt | 10 + .../AnnotationForFunctionTypeParameter.fir.kt | 12 + .../annotations/AnnotationForObject.fir.kt | 3 + .../annotations/AnnotationIdentifier.fir.kt | 19 + .../annotations/AnnotationOnObject.fir.kt | 6 + .../annotations/AnnotationsForClasses.fir.kt | 1 + ...AnnotationsForPropertyTypeParameter.fir.kt | 12 + .../tests/annotations/BasicAnnotations.fir.kt | 10 + .../tests/annotations/ConstructorCall.fir.kt | 35 ++ .../tests/annotations/DanglingMixed.fir.kt | 22 ++ .../annotations/DanglingNoBrackets.fir.kt | 13 + .../annotations/DanglingWithBrackets.fir.kt | 16 + .../tests/annotations/Deprecated.fir.kt | 5 + .../JavaAnnotationConstructors.fir.kt | 10 + .../tests/annotations/MultiDeclaration.fir.kt | 9 + ...yRecursivelyAnnotatedGlobalFunction.fir.kt | 4 + .../annotations/NonAnnotationClass.fir.kt | 3 + .../annotations/RecursivelyAnnotated.fir.kt | 3 + ...cursivelyAnnotatedFunctionParameter.fir.kt | 3 + .../RecursivelyAnnotatedGlobalFunction.fir.kt | 3 + .../RecursivelyAnnotatedGlobalProperty.fir.kt | 3 + .../RecursivelyAnnotatedParameter.fir.kt | 2 + .../RecursivelyAnnotatedParameterType.fir.kt | 3 + ...RecursivelyAnnotatedParameterWithAt.fir.kt | 2 + .../RecursivelyAnnotatedProperty.fir.kt | 5 + ...sivelyIncorrectlyAnnotatedParameter.fir.kt | 2 + ...nnotationWithExpressionTarget_after.fir.kt | 13 + ...notationWithExpressionTarget_before.fir.kt | 13 + .../UnresolvedAnnotationOnObject.fir.kt | 9 + .../WrongAnnotationArgsOnObject.fir.kt | 8 + ...annotatedExpressionInsideAnnotation.fir.kt | 11 + .../annotations/annotationInheritance.fir.kt | 8 + .../annotations/annotationModifier.fir.kt | 15 + ...annotationOnParameterInFunctionType.fir.kt | 29 ++ ...notationConstructorDefaultParameter.fir.kt | 12 + .../booleanLocalVal.fir.kt | 6 + .../compareAndEquals.fir.kt | 16 + .../enumConst_after.fir.kt | 15 + .../enumConst_before.fir.kt | 15 + .../javaProperties.fir.kt | 25 ++ .../kotlinProperties.fir.kt | 18 + .../standaloneInExpression.fir.kt | 18 + .../strings.fir.kt | 28 ++ .../annotationRenderingInTypes.fir.kt | 26 ++ .../annotationsOnLambdaAsCallArgument.fir.kt | 19 + .../annotationsOnNullableTypes.fir.kt | 44 +++ .../annotations/atAnnotationResolve.fir.kt | 19 + .../blockLevelOnTheSameLineWarning.fir.kt | 62 +++ .../annotations/deprecatedRepeatable.fir.kt | 11 + .../annotations/extensionFunctionType.fir.kt | 11 + .../forParameterAnnotationResolve.fir.kt | 14 + ...onParenthesizedAnnotationsWithError.fir.kt | 70 ++++ ...arenthesizedAnnotationsWithoutError.fir.kt | 67 ++++ .../parenthesizedAnnotations.fir.kt | 46 +++ .../illegalRequireKotlinValue.fir.kt | 38 ++ .../illegalSinceKotlinValue.fir.kt | 74 ++++ .../inheritFromAnnotationClass.fir.kt | 4 + .../inheritFromAnnotationClass2.fir.kt | 25 ++ ...invalidTypesInAnnotationConstructor.fir.kt | 76 ++++ .../tests/annotations/javaRepeatable.fir.kt | 19 + .../javaRepeatableRetention.fir.kt | 20 + .../tests/annotations/javaUnrepeatable.fir.kt | 9 + .../tests/annotations/kt1860-negative.fir.kt | 10 + .../tests/annotations/kt1860-positive.fir.kt | 14 + .../kt1886annotationBody_after.fir.kt | 31 ++ .../kt1886annotationBody_before.fir.kt | 31 ++ .../annotations/missingValOnParameter.fir.kt | 5 + .../nestedClassesInAnnotations.fir.kt | 23 ++ .../tests/annotations/noNameProperty.fir.kt | 1 + .../tests/annotations/onExpression.fir.kt | 5 + .../annotations/onFunctionParameter.fir.kt | 7 + .../tests/annotations/onInitializer.fir.kt | 11 + .../tests/annotations/onLoops.fir.kt | 12 + .../annotations/onLoopsUnreachable.fir.kt | 12 + .../annotations/onMultiDeclaration.fir.kt | 7 + .../options/annotationAsArg.fir.kt | 14 + .../options/annotationAsArgComplex.fir.kt | 10 + .../annotations/options/assignment.fir.kt | 10 + .../annotations/options/documented.fir.kt | 8 + .../tests/annotations/options/forParam.fir.kt | 10 + .../options/functionExpression.fir.kt | 12 + .../annotations/options/functions.fir.kt | 40 ++ .../annotations/options/javaDocumented.fir.kt | 20 + .../options/javaKotlinTargetRetention.fir.kt | 9 + .../annotations/options/javaretention.fir.kt | 35 ++ .../options/multiDeclaration.fir.kt | 7 + .../annotations/options/objectLiteral.fir.kt | 8 + .../tests/annotations/options/prefix.fir.kt | 13 + .../annotations/options/repeatable.fir.kt | 31 ++ .../annotations/options/retention.fir.kt | 4 + .../annotations/options/setterParam.fir.kt | 8 + .../tests/annotations/options/target.fir.kt | 4 + .../options/targets/accessors.fir.kt | 16 + .../options/targets/annotation.fir.kt | 20 + .../options/targets/classifier.fir.kt | 21 + .../options/targets/constructor.fir.kt | 20 + .../annotations/options/targets/empty.fir.kt | 21 + .../annotations/options/targets/expr.fir.kt | 13 + .../annotations/options/targets/field.fir.kt | 45 +++ .../annotations/options/targets/file.fir.kt | 23 ++ .../options/targets/function.fir.kt | 22 ++ .../options/targets/funtypeargs.fir.kt | 14 + .../options/targets/incorrect.fir.kt | 21 + .../annotations/options/targets/init.fir.kt | 6 + .../annotations/options/targets/java.fir.kt | 82 ++++ .../annotations/options/targets/local.fir.kt | 20 + .../annotations/options/targets/nested.fir.kt | 15 + .../options/targets/property.fir.kt | 21 + .../options/targets/returntype.fir.kt | 9 + .../options/targets/suppress.fir.kt | 5 + .../annotations/options/targets/type.fir.kt | 20 + .../options/targets/typeParams.fir.kt | 38 ++ .../options/targets/typeargs.fir.kt | 10 + .../options/targets/valueparam.fir.kt | 21 + .../annotations/options/unrepeatable.fir.kt | 23 ++ .../cannotOverrideInvisibleMember.fir.kt | 15 + .../rendering/conflictingOverloads.fir.kt | 10 + .../differentNamesForParameter.fir.kt | 18 + .../rendering/memberProjectedOut.fir.kt | 16 + .../multipleInheritedDefaults.fir.kt | 26 ++ .../rendering/notImplementedMembers.fir.kt | 48 +++ .../rendering/tooManyArguments.fir.kt | 11 + .../typeMismatchDueToTypeProjections.fir.kt | 18 + .../rendering/typeMismatchOnOverride.fir.kt | 26 ++ .../typeMismatchOnOverrideJavaNullable.fir.kt | 42 ++ .../annotations/rendering/unusedValue.fir.kt | 12 + .../tests/annotations/typeAnnotations.fir.kt | 15 + .../typeParameterAsAnnotation.fir.kt | 9 + .../unresolvedReferenceRange.fir.kt | 5 + .../DelegateAnnotations.fir.kt | 33 ++ .../withUseSiteTarget/FieldAnnotations.fir.kt | 36 ++ .../withUseSiteTarget/FileAnnotations.fir.kt | 12 + .../GetterAnnotations.fir.kt | 39 ++ .../withUseSiteTarget/ParamAnnotations.fir.kt | 24 ++ .../PropertyAnnotations.fir.kt | 39 ++ .../ReceiverAnnotations.fir.kt | 25 ++ .../SetterAnnotations.fir.kt | 38 ++ .../SparamAnnotations.fir.kt | 39 ++ ...iagnosticFileAnnotationInWrongPlace.fir.kt | 20 + .../diagnosticWithoutPackage.fir.kt | 8 + ...cWithoutPackageWithSimpleAnnotation.fir.kt | 8 + .../fileAnnotationWithoutColon_after.fir.kt | 11 + .../fileAnnotationWithoutColon_before.fir.kt | 11 + .../withUseSiteTarget/kt23992.fir.kt | 9 + .../withUseSiteTarget/kt23992_after.fir.kt | 9 + .../withUseSiteTarget/kt26638.fir.kt | 22 ++ .../withUseSiteTarget/kt26638_after.fir.kt | 22 ++ ...SiteTargetOnExtensionFunction_after.fir.kt | 10 + ...iteTargetOnExtensionFunction_before.fir.kt | 10 + .../withUseSiteTarget/repeatable.fir.kt | 59 +++ .../wrongParamAnnotationsOnTypesError.fir.kt | 13 + .../wrongParamAnnotationsOnTypes_after.fir.kt | 13 + ...wrongParamAnnotationsOnTypes_before.fir.kt | 13 + .../tests/backingField/CustomGetSet.fir.kt | 6 + .../tests/backingField/CustomGetVal.fir.kt | 4 + .../backingField/CustomGetValGlobal.fir.kt | 3 + .../tests/backingField/CustomGetVar.fir.kt | 4 + .../tests/backingField/CustomSet.fir.kt | 4 + .../backingField/ExtensionProperty.fir.kt | 17 + .../tests/backingField/FieldAsParam.fir.kt | 8 + .../tests/backingField/FieldAsProperty.fir.kt | 9 + .../tests/backingField/FieldDerived.fir.kt | 18 + .../backingField/FieldInInterface.fir.kt | 4 + .../tests/backingField/FieldInLocal.fir.kt | 11 + .../tests/backingField/FieldOnVal.fir.kt | 2 + .../tests/backingField/FieldOnVar.fir.kt | 5 + .../FieldReassignment_after.fir.kt | 7 + .../FieldReassignment_before.fir.kt | 7 + .../tests/backingField/FieldShadow.fir.kt | 8 + .../backingField/InitCustomSetter.fir.kt | 30 ++ .../tests/backingField/InitOpenSetter.fir.kt | 27 ++ .../SetterWithExplicitType.fir.kt | 26 ++ .../backingField/kt782packageLevel.fir.kt | 16 + .../tests/callableReference/bareType.fir.kt | 8 + .../bound/classVsStarImportedCompanion.fir.kt | 18 + .../bound/classVsStarImportedObject.fir.kt | 19 + .../bound/companionObject.fir.kt | 39 ++ .../bound/controlFlow.fir.kt | 22 ++ .../callableReference/bound/dataFlow.fir.kt | 13 + .../bound/expectedType.fir.kt | 14 + .../bound/expressionWithNullableType.fir.kt | 15 + .../bound/functionCallWithoutArguments.fir.kt | 1 + .../bound/innerNested.fir.kt | 9 + .../callableReference/bound/kt12843.fir.kt | 6 + .../bound/noThisInSuperCall.fir.kt | 3 + .../callableReference/bound/object.fir.kt | 11 + .../bound/privateToThis.fir.kt | 24 ++ .../referenceToStaticMethodOnInstance.fir.kt | 14 + .../bound/reservedExpressionSyntax.fir.kt | 33 ++ .../bound/reservedExpressionSyntax2.fir.kt | 7 + .../bound/reservedExpressionSyntax3.fir.kt | 29 ++ .../bound/syntheticExtensionOnLHS.fir.kt | 13 + .../bound/valueOfTypeParameterType.fir.kt | 3 + ...bleReferenceAsLastExpressionInBlock.fir.kt | 17 + .../callableReference/classVsPackage.fir.kt | 24 ++ ...nstraintFromLHSWithCorrectDirection.fir.kt | 24 ++ .../correctInfoAfterArrayLikeCall.fir.kt | 16 + .../ea81649_errorPropertyLHS.fir.kt | 20 + .../tests/callableReference/emptyLhs.fir.kt | 41 ++ ...expectedTypeAsSubtypeOfFunctionType.fir.kt | 13 + .../function/abstractClassConstructors.fir.kt | 12 + .../ambiguityTopLevelVsTopLevel.fir.kt | 9 + .../annotationClassConstructor.fir.kt | 5 + .../callableRefrenceOnNestedObject.fir.kt | 9 + ...lassMemberVsConstructorLikeFunction.fir.kt | 16 + .../function/constructorFromClass.fir.kt | 19 + .../function/constructorFromCompanion.fir.kt | 22 ++ .../function/constructorFromExtension.fir.kt | 14 + .../constructorFromExtensionInClass.fir.kt | 23 ++ .../function/constructorFromTopLevel.fir.kt | 11 + .../constructorOfNestedClassInObject.fir.kt | 21 + .../function/differentPackageClass.fir.kt | 28 ++ .../function/differentPackageExtension.fir.kt | 28 ++ .../function/differentPackageTopLevel.fir.kt | 28 ++ .../callableReference/function/empty.fir.kt | 6 + .../function/extensionFromTopLevel.fir.kt | 23 ++ .../extensionInClassDisallowed.fir.kt | 20 + .../function/extensionOnNullable.fir.kt | 12 + .../function/extensionToSupertype.fir.kt | 19 + .../function/fakeOverrideType.fir.kt | 17 + .../function/genericClassFromTopLevel.fir.kt | 13 + .../function/importedInnerConstructor.fir.kt | 10 + .../function/innerConstructorFromClass.fir.kt | 34 ++ .../innerConstructorFromExtension.fir.kt | 23 ++ .../innerConstructorFromTopLevel.fir.kt | 14 + .../function/javaStaticMethod.fir.kt | 24 ++ .../function/lhsNotAClass.fir.kt | 9 + .../function/localConstructor.fir.kt | 10 + ...onstructorFromExtensionInLocalClass.fir.kt | 18 + .../localConstructorFromLocalClass.fir.kt | 10 + .../localConstructorFromLocalExtension.fir.kt | 17 + .../function/localNamedFun.fir.kt | 17 + ...alNamedFunFromExtensionInLocalClass.fir.kt | 23 ++ .../localNamedFunFromLocalClass.fir.kt | 21 + .../localNamedFunFromLocalExtension.fir.kt | 21 + .../function/longQualifiedName.fir.kt | 18 + .../function/longQualifiedNameGeneric.fir.kt | 18 + .../function/memberFromTopLevel.fir.kt | 23 ++ .../nestedConstructorFromClass.fir.kt | 33 ++ .../nestedConstructorFromExtension.fir.kt | 21 + .../nestedConstructorFromTopLevel.fir.kt | 13 + .../noAmbiguityLocalVsTopLevel.fir.kt | 8 + .../noAmbiguityMemberVsExtension.fir.kt | 15 + .../noAmbiguityMemberVsTopLevel.fir.kt | 31 ++ .../privateStaticAndPublicMember.fir.kt | 10 + .../function/renameOnImport.fir.kt | 30 ++ .../function/topLevelFromClass.fir.kt | 19 + .../function/topLevelFromExtension.fir.kt | 19 + .../topLevelFromExtensionInClass.fir.kt | 21 + .../function/topLevelFromTopLevel.fir.kt | 17 + .../function/unresolved.fir.kt | 24 ++ ...WithDefaultValueAsOtherFunctionType.fir.kt | 18 + ...ultValueAsOtherFunctionType_enabled.fir.kt | 18 + .../argumentAndReturnExpectedType.fir.kt | 37 ++ .../generic/argumentExpectedType.fir.kt | 12 + .../generic/dependOnArgumentType.fir.kt | 30 ++ .../generic/expectedFunctionType.fir.kt | 24 ++ .../generic/explicitTypeArguments.fir.kt | 25 ++ .../generic/genericExtensionFunction.fir.kt | 31 ++ .../genericFunctionsWithNullableTypes.fir.kt | 37 ++ .../callableReference/generic/kt10968.fir.kt | 11 + .../callableReference/generic/kt11075.fir.kt | 10 + .../callableReference/generic/kt12286.fir.kt | 8 + .../callableReference/generic/kt7470.fir.kt | 8 + .../generic/nestedCallWithOverload.fir.kt | 22 ++ ...ferenceFeatureForCallableReferences.fir.kt | 67 ++++ ...ionGenericCallableWithNullableTypes.fir.kt | 23 ++ .../resolutionWithGenericCallable.fir.kt | 22 ++ .../generic/specialCalls.fir.kt | 23 ++ .../kt15439_completeCall.fir.kt | 11 + .../tests/callableReference/kt25433.fir.kt | 17 + .../tests/callableReference/kt31981.fir.kt | 23 ++ .../tests/callableReference/kt32256.fir.kt | 26 ++ .../kt7430_wrongClassOnLHS.fir.kt | 12 + ...sionsImportedFromObjectsUnsupported.fir.kt | 26 ++ ...ExceptionOnRedCodeWithArrayLikeCall.fir.kt | 13 + .../callableReference/packageInLhs.fir.kt | 16 + ...ingPriorityOfGenericArgumentsVsLess.fir.kt | 9 + .../abstractPropertyViaSubclasses.fir.kt | 36 ++ .../property/accessViaSubclass.fir.kt | 15 + .../property/classFromClass.fir.kt | 12 + .../property/extensionFromTopLevel.fir.kt | 25 ++ .../extensionPropertyOnNullable.fir.kt | 10 + .../property/genericClass.fir.kt | 16 + .../property/javaInstanceField.fir.kt | 26 ++ .../property/javaStaticFieldViaImport.fir.kt | 28 ++ .../callableReference/property/kt7564.fir.kt | 12 + .../property/kt7945_unrelatedClass.fir.kt | 11 + .../property/localVariable.fir.kt | 15 + .../property/memberFromTopLevel.fir.kt | 25 ++ .../property/protectedVarFromClass.fir.kt | 22 ++ ...eturnTypeDependentOnGenericProperty.fir.kt | 8 + ...mePriorityForFunctionsAndProperties.fir.kt | 13 + .../property/syntheticProperties.fir.kt | 19 + .../property/topLevelFromTopLevel.fir.kt | 32 ++ .../propertyOfNestedGenericClass.fir.kt | 43 ++ ...pplicableCallableReferenceCandidate.fir.kt | 11 + .../resolve/ambiguousWithVararg.fir.kt | 16 + ...leCallableReferenceFromDistantScope.fir.kt | 15 + .../resolve/byArgType.fir.kt | 10 + .../resolve/byGenericArgType.fir.kt | 11 + .../resolve/byValType.fir.kt | 9 + ...eferenceDependingOnInferredReceiver.fir.kt | 39 ++ ...andidateDescriptorNotReflectionType.fir.kt | 14 + ...eOuterCallBySingleCallableReference.fir.kt | 18 + ...eFromReturnTypesOfCallableReference.fir.kt | 16 + .../resolve/constructor.fir.kt | 12 + ...eagerAndPostponedCallableReferences.fir.kt | 35 ++ ...gerResolveOfSingleCallableReference.fir.kt | 15 + ...lassConstructorOnOuterClassInstance.fir.kt | 13 + ...ctionTypeOverloadWithWrongParameter.fir.kt | 19 + .../callableReference/resolve/kt10036.fir.kt | 19 + .../resolve/kt10036_bound.fir.kt | 11 + .../callableReference/resolve/kt12338.fir.kt | 9 + .../callableReference/resolve/kt12751.fir.kt | 15 + .../callableReference/resolve/kt8596.fir.kt | 25 ++ .../callableReference/resolve/kt9601.fir.kt | 15 + .../moreSpecificAmbiguousExtensions.fir.kt | 21 + .../resolve/moreSpecificSimple.fir.kt | 12 + ...OutersAndMultipleCallableReferences.fir.kt | 16 + ...ityBetweenTopLevelAndMemberProperty.fir.kt | 16 + .../resolve/noFakeDescriptorForObject.fir.kt | 11 + .../resolve/overloads.fir.kt | 30 ++ .../resolve/overloadsBound.fir.kt | 13 + .../resolve/overloadsMember.fir.kt | 16 + ...ponedResolveOfManyCallableReference.fir.kt | 19 + ...leReferencesAfterAllSimpleArguments.fir.kt | 16 + ...veEqualsOperatorWithAnyExpectedType.fir.kt | 11 + .../callableReference/resolve/valVsFun.fir.kt | 11 + .../callableReference/resolve/withAs.fir.kt | 10 + .../resolve/withExtFun.fir.kt | 27 ++ .../resolve/withGenericFun.fir.kt | 12 + .../resolve/withPlaceholderTypes.fir.kt | 28 ++ .../resolve/withVararg.fir.kt | 10 + .../rewriteAtSliceOnGetOperator.fir.kt | 18 + .../tests/callableReference/sam.fir.kt | 31 ++ .../subtypeArgumentFromRHSForReference.fir.kt | 27 ++ .../suspendCallableReference.fir.kt | 17 + .../callableReference/typealiases.fir.kt | 15 + .../tests/callableReference/unused.fir.kt | 23 ++ .../whitespacesInExpression.fir.kt | 16 + .../diagnostics/tests/cast/AsArray.fir.kt | 1 + .../tests/cast/AsErasedError.fir.kt | 2 + .../tests/cast/AsErasedFine.fir.kt | 2 + .../tests/cast/AsErasedStar.fir.kt | 3 + .../tests/cast/AsErasedWarning.fir.kt | 2 + .../tests/cast/AsInBinaryUnary.fir.kt | 31 ++ .../tests/cast/AsInBlockWithReturnType.fir.kt | 53 +++ .../tests/cast/AsInExpressionBody.fir.kt | 12 + .../AsInPropertyAndPropertyAccessor.fir.kt | 17 + .../diagnostics/tests/cast/AsNothing.fir.kt | 14 + .../diagnostics/tests/cast/AsTypeAlias.fir.kt | 18 + .../tests/cast/AsWithOtherParameter.fir.kt | 34 ++ .../diagnostics/tests/cast/DowncastMap.fir.kt | 10 + .../tests/cast/ExtensionAsNonExtension.fir.kt | 10 + .../tests/cast/FlexibleTargetType.fir.kt | 26 ++ ...WithOneSubstitutedAndOneSameGeneric.fir.kt | 5 + ...IsErasedAllowForExactSupertypeCheck.fir.kt | 5 + ...wForOverridenVarianceWithProjection.fir.kt | 8 + ...wForSupertypeCheckWithContrvariance.fir.kt | 8 + ...llowForSupertypeCheckWithCovariance.fir.kt | 8 + ...asedAllowForTypeWithIrrelevantMixin.fir.kt | 9 + ...ForTypeWithTwoSameTypeSubstitutions.fir.kt | 6 + ...sedAllowForTypeWithoutTypeArguments.fir.kt | 5 + .../tests/cast/IsErasedAllowFromOut.fir.kt | 1 + .../tests/cast/IsErasedAllowFromOut2.fir.kt | 1 + .../cast/IsErasedAllowFromOutAtClass.fir.kt | 1 + .../cast/IsErasedAllowParameterSubtype.fir.kt | 7 + .../IsErasedAllowSameClassParameter.fir.kt | 3 + ...IsErasedAllowSameParameterParameter.fir.kt | 3 + ...sallowDifferentArgInvariantPosition.fir.kt | 1 + ...sErasedDisallowForOverridenVariance.fir.kt | 8 + ...rasedDisallowForTypeWithConstraints.fir.kt | 6 + .../tests/cast/IsErasedDisallowFromAny.fir.kt | 2 + .../tests/cast/IsErasedDisallowFromIn.fir.kt | 1 + .../tests/cast/IsErasedDisallowFromOut.fir.kt | 2 + .../IsErasedDisallowFromOutAtClass.fir.kt | 1 + ...peMappedToTwoParamsWithFirstInvalid.fir.kt | 8 + ...eMappedToTwoParamsWithSecondInvalid.fir.kt | 8 + .../tests/cast/IsErasedNonGeneric.fir.kt | 3 + .../tests/cast/IsErasedNullableTasT.fir.kt | 1 + .../tests/cast/IsErasedStar.fir.kt | 2 + .../tests/cast/IsErasedTasT.fir.kt | 1 + .../tests/cast/IsErasedToErrorType.fir.kt | 1 + .../cast/IsErasedUpcastToNonReified.fir.kt | 27 ++ .../IsForTypeWithComplexUpperBound.fir.kt | 34 ++ .../tests/cast/IsRecursionSustainable.fir.kt | 6 + .../diagnostics/tests/cast/IsTraits.fir.kt | 4 + .../tests/cast/IsWithCycleUpperBounds.fir.kt | 14 + .../tests/cast/NullableToNullable.fir.kt | 7 + .../cast/StableTypeForUselessCast.fir.kt | 14 + .../tests/cast/UselessSafeCast.fir.kt | 23 ++ .../cast/WhenErasedDisallowFromAny.fir.kt | 5 + .../tests/cast/WhenWithExpression.fir.kt | 11 + .../tests/cast/bare/AsNestedBare.fir.kt | 10 + .../tests/cast/bare/AsNullable.fir.kt | 10 + .../cast/bare/AsNullableNotEnough.fir.kt | 10 + .../tests/cast/bare/EitherAs.fir.kt | 18 + .../tests/cast/bare/EitherIs.fir.kt | 25 ++ .../tests/cast/bare/EitherNotIs.fir.kt | 25 ++ .../tests/cast/bare/EitherSafeAs.fir.kt | 18 + .../tests/cast/bare/EitherWhen.fir.kt | 19 + .../cast/bare/ErrorsInSubstitution.fir.kt | 9 + .../tests/cast/bare/FromErrorType.fir.kt | 8 + .../tests/cast/bare/NullableAs.fir.kt | 9 + .../cast/bare/NullableAsNotEnough.fir.kt | 9 + .../tests/cast/bare/NullableAsNullable.fir.kt | 10 + .../bare/NullableAsNullableNotEnough.fir.kt | 9 + .../tests/cast/bare/RedundantNullable.fir.kt | 4 + .../tests/cast/bare/ToErrorType.fir.kt | 6 + .../tests/cast/bare/UnrelatedAs.fir.kt | 9 + .../tests/cast/bare/UnrelatedColon.fir.kt | 7 + .../tests/cast/bare/UnrelatedIs.fir.kt | 4 + .../tests/cast/checkCastToNullableType.fir.kt | 38 ++ .../diagnostics/tests/cast/constants.fir.kt | 51 +++ .../tests/cast/isErasedAnyAndStarred.fir.kt | 3 + .../tests/cast/isErasedTAndStarred.fir.kt | 3 + .../cast/isErasedUnrelatedAndStarred.fir.kt | 4 + .../diagnostics/tests/cast/kt15161.fir.kt | 7 + .../diagnostics/tests/cast/kt614.fir.kt | 1 + .../neverSucceeds/CastToNotNullSuper.fir.kt | 8 + .../cast/neverSucceeds/MappedDirect.fir.kt | 33 ++ .../cast/neverSucceeds/MappedSubtypes.fir.kt | 21 + .../neverSucceeds/NoGenericsRelated.fir.kt | 46 +++ .../neverSucceeds/NoGenericsUnrelated.fir.kt | 34 ++ .../diagnostics/tests/cast/nothingAs.fir.kt | 31 ++ .../tests/checkArguments/SpreadVarargs.fir.kt | 96 +++++ .../checkArguments/arrayAccessSet.fir.kt | 35 ++ .../arrayAccessSetTooManyArgs.fir.kt | 11 + .../checkArguments/booleanExpressions.fir.kt | 7 + .../kt1897_diagnostic_part.fir.kt | 29 ++ .../tests/checkArguments/kt1940.fir.kt | 9 + .../checkArguments/overloadedFunction.fir.kt | 17 + .../checkArguments/twoLambdasFunction.fir.kt | 14 + .../diagnostics/tests/checkType.fir.kt | 12 + .../tests/classLiteral/arrays.fir.kt | 7 + .../classAndObjectLiteralType.fir.kt | 16 + .../classLiteral/classLiteralType.fir.kt | 15 + .../expressionWithNullableType.fir.kt | 15 + .../tests/classLiteral/genericArrays.fir.kt | 11 + .../tests/classLiteral/genericClasses.fir.kt | 26 ++ .../classLiteral/inAnnotationArguments.fir.kt | 45 +++ .../inAnnotationArguments_noTypeParams.fir.kt | 12 + .../classLiteral/integerValueType.fir.kt | 11 + .../tests/classLiteral/nonClassesOnLHS.fir.kt | 20 + .../classLiteral/qualifiedClassLiteral.fir.kt | 7 + .../classLiteral/simpleClassLiteral.fir.kt | 3 + .../tests/classLiteral/smartCast.fir.kt | 23 ++ .../tests/classLiteral/typealiases.fir.kt | 15 + .../tests/classLiteral/unresolvedClass.fir.kt | 2 + .../ClassObjectCannotAccessClassFields.fir.kt | 9 + .../classObjects/ClassObjectVisibility.fir.kt | 30 ++ .../tests/classObjects/ClassObjects.fir.kt | 43 ++ .../InnerClassAccessThroughClassObject.fir.kt | 51 +++ .../InnerClassAccessThroughEnum_after.fir.kt | 50 +++ .../InnerClassAccessThroughEnum_before.fir.kt | 50 +++ .../classObjects/InnerClassClassObject.fir.kt | 25 ++ .../classObjects/builtInClassObjects.fir.kt | 43 ++ .../classObjects/classObjectHeader.fir.kt | 9 + .../classObjectInLocalClass.fir.kt | 9 + .../classObjectRedeclaration.fir.kt | 20 + ...anionObjectOfPrivateClassVisibility.fir.kt | 19 + .../importClassInClassObject.fir.kt | 11 + .../classObjects/invisibleClassObjects.fir.kt | 51 +++ .../tests/classObjects/kt3866.fir.kt | 20 + .../multipleDissallowedDefaultObjects.fir.kt | 17 + .../nestedClassInPrivateClassObject.fir.kt | 15 + .../resolveFunctionInsideClassObject.fir.kt | 9 + .../typeParametersInAnnonymousObject.fir.kt | 39 ++ ...eParametersInAnnonymousObject_after.fir.kt | 40 ++ .../typeParametersInObject.fir.kt | 21 + .../argumentsOfAnnotation.fir.kt | 31 ++ .../argumentsOfAnnotationWithKClass.fir.kt | 31 ++ .../basicCollectionLiterals.fir.kt | 24 ++ ...collectionLiteralsAsPrimitiveArrays.fir.kt | 18 + ...lectionLiteralsOutsideOfAnnotations.fir.kt | 22 ++ .../collectionLiteralsWithVarargs.fir.kt | 41 ++ .../defaultValuesInAnnotation.fir.kt | 26 ++ ...aultValuesWithConstantsInAnnotation.fir.kt | 25 ++ ...noArrayLiteralsInAnnotationsFeature.fir.kt | 19 + .../noCollectionLiterals.fir.kt | 16 + .../resolveToFunctionFromBuiltIns.fir.kt | 18 + .../afterInitialization.fir.kt | 6 + .../constructorConsistency/aliencall.fir.kt | 29 ++ .../constructorConsistency/assignment.fir.kt | 11 + .../constructorConsistency/backing.fir.kt | 30 ++ .../tests/constructorConsistency/basic.fir.kt | 13 + .../constructorConsistency/companion.fir.kt | 19 + .../constructorConsistency/comparison.fir.kt | 10 + .../constructorConsistency/delegate.fir.kt | 13 + .../constructorConsistency/derived.fir.kt | 11 + .../derivedProperty.fir.kt | 11 + .../constructorConsistency/getset.fir.kt | 26 ++ .../tests/constructorConsistency/init.fir.kt | 9 + ...initializerWithSecondaryConstructor.fir.kt | 20 + .../initwithgetter.fir.kt | 19 + .../constructorConsistency/inspection.fir.kt | 56 +++ .../lambdaInObject.fir.kt | 18 + .../constructorConsistency/lateInit.fir.kt | 15 + .../constructorConsistency/localObject.fir.kt | 19 + .../multipleAreNull.fir.kt | 24 ++ .../constructorConsistency/nobacking.fir.kt | 12 + .../tests/constructorConsistency/open.fir.kt | 34 ++ .../openProperty.fir.kt | 14 + .../tests/constructorConsistency/outer.fir.kt | 11 + .../constructorConsistency/property.fir.kt | 5 + .../propertyAccess.fir.kt | 7 + .../twoSecondaryConstructors.fir.kt | 12 + .../UninitializedOrReassignedVariables.fir.kt | 349 ++++++++++++++++ .../assignedInFinally.fir.kt | 10 + .../assignmentInLocalsInConstructor.fir.kt | 67 ++++ .../backingFieldInsideGetter_after.fir.kt | 23 ++ .../backingFieldInsideGetter_before.fir.kt | 23 ++ .../breakContinueInTryFinally.fir.kt | 24 ++ .../breakInsideLocal.fir.kt | 86 ++++ .../breakOrContinueInLoopCondition.fir.kt | 34 ++ .../checkInnerLocalDeclarations.fir.kt | 12 + .../checkPropertyAccessor.fir.kt | 38 ++ .../constructorPropertyInterdependence.fir.kt | 8 + .../deadCode/commasAndWhitespaces.fir.kt | 12 + .../deadCode/commentsInDeadCode.fir.kt | 22 ++ .../deadCode/deadCallInInvokeCall.fir.kt | 11 + .../deadCode/deadCallInReceiver.fir.kt | 11 + .../deadCode/deadCodeDifferentExamples.fir.kt | 168 ++++++++ .../deadCodeFromDifferentSources.fir.kt | 23 ++ .../deadCode/deadCodeInArrayAccess.fir.kt | 40 ++ .../deadCode/deadCodeInAssignment.fir.kt | 18 + .../deadCodeInBinaryExpressions.fir.kt | 39 ++ .../deadCode/deadCodeInCalls.fir.kt | 13 + .../deadCode/deadCodeInDeadCode.fir.kt | 24 ++ .../deadCode/deadCodeInIf.fir.kt | 12 + .../deadCodeInInnerExpressions.fir.kt | 13 + .../deadCodeInLocalDeclarations.fir.kt | 36 ++ .../deadCode/deadCodeInLoops.fir.kt | 21 + .../deadCode/deadCodeInReturn.fir.kt | 5 + .../deadCode/deadCodeInUnaryExpr.fir.kt | 15 + .../deadCode/deadCodeInWhileFromBreak.fir.kt | 55 +++ .../deadCode/expressionInUnitLiteral.fir.kt | 8 + .../deadCode/kt2585_1.fir.kt | 12 + .../deadCode/kt2585_2.fir.kt | 23 ++ .../deadCode/kt2585_3.fir.kt | 9 + .../deadCode/kt3162tryAsInitializer.fir.kt | 12 + .../deadCode/kt5200DeadCodeInLambdas.fir.kt | 25 ++ .../deadCode/returnInDeadLambda.fir.kt | 11 + .../ReturnFromFunctionInObject.fir.kt | 13 + .../kt3444_ReturnFromLocalFunctions.fir.kt | 17 + .../definiteReturn/kt4034.fir.kt | 11 + .../definiteReturn/simpleClass.fir.kt | 19 + .../definiteReturnInWhen.fir.kt | 6 + .../delegatedPropertyEarlyAccess.fir.kt | 32 ++ .../doWhileAssignment.fir.kt | 23 ++ .../doWhileNotDefined.fir.kt | 6 + .../elvisNotProcessed.fir.kt | 39 ++ .../enumCompanionInterdependence.fir.kt | 55 +++ .../enumInterdependence.fir.kt | 35 ++ .../fieldAsClassDelegate.fir.kt | 37 ++ .../controlFlowAnalysis/infiniteLoops.fir.kt | 55 +++ .../initializationInLambda.fir.kt | 77 ++++ .../initializationInLocalClass.fir.kt | 90 +++++ .../initializationInLocalFun.fir.kt | 8 + ...izationInLocalViaExplicitThis_after.fir.kt | 18 + ...zationInLocalViaExplicitThis_before.fir.kt | 18 + .../tests/controlFlowAnalysis/kt1001.fir.kt | 34 ++ .../tests/controlFlowAnalysis/kt1027.fir.kt | 48 +++ .../tests/controlFlowAnalysis/kt1066.fir.kt | 34 ++ .../tests/controlFlowAnalysis/kt10805.fir.kt | 13 + .../tests/controlFlowAnalysis/kt10823.fir.kt | 33 ++ .../tests/controlFlowAnalysis/kt1156.fir.kt | 7 + .../controlFlowAnalysis/kt1185enums.fir.kt | 47 +++ .../tests/controlFlowAnalysis/kt1189.fir.kt | 38 ++ .../tests/controlFlowAnalysis/kt1191.fir.kt | 21 + .../controlFlowAnalysis/kt1219.1301.fir.kt | 25 ++ .../tests/controlFlowAnalysis/kt1571.fir.kt | 42 ++ .../tests/controlFlowAnalysis/kt1977.fir.kt | 51 +++ .../controlFlowAnalysis/kt2166_kt2103.fir.kt | 17 + .../tests/controlFlowAnalysis/kt2226.fir.kt | 15 + .../tests/controlFlowAnalysis/kt2330.fir.kt | 53 +++ .../tests/controlFlowAnalysis/kt2334.fir.kt | 5 + .../tests/controlFlowAnalysis/kt2369.fir.kt | 13 + .../tests/controlFlowAnalysis/kt2845.fir.kt | 18 + .../tests/controlFlowAnalysis/kt2960.fir.kt | 36 ++ .../tests/controlFlowAnalysis/kt2972.fir.kt | 28 ++ .../tests/controlFlowAnalysis/kt3444.fir.kt | 13 + .../tests/controlFlowAnalysis/kt3501.fir.kt | 9 + .../tests/controlFlowAnalysis/kt4126.fir.kt | 3 + .../tests/controlFlowAnalysis/kt4405.fir.kt | 30 ++ .../tests/controlFlowAnalysis/kt510.fir.kt | 18 + .../tests/controlFlowAnalysis/kt607.fir.kt | 18 + .../tests/controlFlowAnalysis/kt609.fir.kt | 20 + .../tests/controlFlowAnalysis/kt610.fir.kt | 10 + .../tests/controlFlowAnalysis/kt6788.fir.kt | 10 + .../tests/controlFlowAnalysis/kt776.fir.kt | 38 ++ .../tests/controlFlowAnalysis/kt843.fir.kt | 8 + .../tests/controlFlowAnalysis/kt897.fir.kt | 20 + .../controlFlowAnalysis/localClasses.fir.kt | 26 ++ .../localObjectInConstructor.fir.kt | 87 ++++ .../mainWithWarningOnUnusedParam.fir.kt | 5 + .../mainWithoutWarningOnUnusedParam.fir.kt | 5 + .../nestedTryFinally.fir.kt | 24 ++ .../nonLocalReturnUnreachable.fir.kt | 26 ++ .../nonLocalReturnWithFinally.fir.kt | 10 + .../controlFlowAnalysis/privateSetter.fir.kt | 17 + .../propertiesInitWithOtherInstance.fir.kt | 12 + ...ropertiesInitWithOtherInstanceInner.fir.kt | 21 + ...rtiesInitWithOtherInstanceThisLabel.fir.kt | 12 + .../propertiesOrderInPackage.fir.kt | 4 + .../reassignmentInTryCatch.fir.kt | 102 +++++ .../reassignmentInTryCatchWithJumps.fir.kt | 55 +++ .../referenceToPropertyInitializer.fir.kt | 32 ++ ...eatUnitializedErrorOnlyForLocalVars.fir.kt | 15 + .../scopeOfAnonymousInitializer.fir.kt | 5 + .../controlFlowAnalysis/throwInLambda.fir.kt | 13 + .../tryWithAssignmentUsedInCatch.fir.kt | 36 ++ .../uninitializedInLocalDeclarations.fir.kt | 50 +++ .../controlFlowAnalysis/unmappedArgs.fir.kt | 5 + .../lateinitRecursiveInLambda.fir.kt | 6 + .../lateinitWithConstructor.fir.kt | 9 + .../lateinitWithErroneousDelegation.fir.kt | 11 + .../lateinitWithInit.fir.kt | 7 + .../lateinitWithMultipleConstructors.fir.kt | 13 + ...thMultipleConstructorsAndDelegation.fir.kt | 15 + .../lateinitWithPlusAssign.fir.kt | 8 + ...ithPrimaryConstructorAndConstructor.fir.kt | 9 + .../unnecessaryLateinit/normalLateinit.fir.kt | 7 + .../normalLateinitWithTwoConstructors.fir.kt | 9 + .../secondaryConstructorDelegateItself.fir.kt | 13 + .../secondaryConstructorDelegateLoop.fir.kt | 18 + .../unresolvedReference.fir.kt | 49 +++ .../unusedInAnonymous.fir.kt | 9 + .../useUninitializedInLambda.fir.kt | 6 + .../varInitializationInIfInCycle.fir.kt | 15 + ...LoopWithExtensionIteratorOnNullable.fir.kt | 22 ++ .../controlStructures/ForWithoutBraces.fir.kt | 8 + ...ForbidStatementAsDirectFunctionBody.fir.kt | 11 + .../controlStructures/catchGenerics.fir.kt | 26 ++ .../catchInnerClassesOfGenerics.fir.kt | 41 ++ ...hInnerClassesOfGenerics_deprecation.fir.kt | 41 ++ .../controlStructures/catchWithDefault.fir.kt | 3 + ...LocalClassesCapturingTypeParameters.fir.kt | 27 ++ .../commonSupertypeOfT.fir.kt | 30 ++ ...ueAndBreakLabelWithSameFunctionName.fir.kt | 53 +++ .../tests/controlStructures/emptyIf.fir.kt | 16 + .../forLoopWithNullableRange.fir.kt | 16 + .../forWithNullableIterator.fir.kt | 12 + .../ifElseIntersection.fir.kt | 55 +++ .../ifInResultOfLambda.fir.kt | 8 + .../ifToAnyDiscriminatingUsages.fir.kt | 62 +++ .../ifWhenToAnyComplexExpressions.fir.kt | 31 ++ .../ifWhenWithoutElse.fir.kt | 86 ++++ .../improperElseInExpression.fir.kt | 34 ++ .../jumpAcrossFunctionBoundary.fir.kt | 17 + .../tests/controlStructures/kt10322.fir.kt | 10 + .../tests/controlStructures/kt10706.fir.kt | 10 + .../tests/controlStructures/kt10717.fir.kt | 47 +++ .../tests/controlStructures/kt1075.fir.kt | 12 + .../tests/controlStructures/kt30406.fir.kt | 16 + .../tests/controlStructures/kt4310.fir.kt | 12 + .../tests/controlStructures/kt657.fir.kt | 20 + ...0.fir.kt351.fir.kt735_StatementType.fir.kt | 163 ++++++++ .../tests/controlStructures/kt786.fir.kt | 26 ++ .../tests/controlStructures/kt799.fir.kt | 25 ++ .../lambdasInExclExclAndElvis.fir.kt | 16 + ...localReturnInsidePropertyAccessor.fir.fail | 2 +- .../localReturnInsidePropertyAccessor.fir.kt | 20 + .../notAFunctionLabel_after.fir.kt | 62 +++ .../notAFunctionLabel_before.fir.kt | 62 +++ .../controlStructures/redundantLabel.fir.kt | 39 ++ .../specialConstructsAndPlatformTypes.fir.kt | 40 ++ ...lConstructsWithNullableExpectedType.fir.kt | 20 + .../controlStructures/tryReturnType.fir.kt | 28 ++ .../typeInferenceForExclExcl.fir.kt | 21 + .../valVarCatchParameter.fir.kt | 13 + .../valVarLoopParameter.fir.kt | 32 ++ .../when.fir.kt234.fir.kt973.fir.kt | 41 ++ .../whenInResultOfLambda.fir.kt | 17 + .../whenToAnyDiscriminatingUsages.fir.kt | 83 ++++ .../invokeOutideSuspend.fir.kt | 8 + .../callableReference/outsideSuspend.fir.kt | 11 + .../classIndirectlyInheritsNested.fir.kt | 4 + .../classInheritsNested.fir.kt | 3 + ...mmonSupertypeForCyclicAndUsualTypes.fir.kt | 8 + .../commonSupertypeForCyclicTypes.fir.kt | 8 + .../cyclicHierarchy/cyclicHierarchy.fir.kt | 30 ++ .../cyclicHierarchy/javaJavaCycle.fir.kt | 28 ++ .../cyclicHierarchy/javaJavaNested.fir.kt | 24 ++ .../javaKotlinJavaCycle.fir.kt | 17 + .../cyclicHierarchy/kotlinJavaCycle.fir.kt | 11 + .../kotlinJavaKotlinCycle.fir.kt | 17 + .../kotlinJavaNestedCycle.fir.kt | 21 + .../tests/cyclicHierarchy/kt303.fir.kt | 12 + .../nestedClassInSuperClassParameter.fir.kt | 5 + .../objectInheritsNested.fir.kt | 22 ++ .../twoClassesWithNestedCycle.fir.kt | 6 + .../everythingInOneScope_after.fir.kt | 15 + .../everythingInOneScope_before.fir.kt | 15 + .../withCompanion/noMembers_after.fir.kt | 15 + .../withCompanion/noMembers_before.fir.kt | 15 + .../withCompanion/onlyInterfaces_after.fir.kt | 18 + .../onlyInterfaces_before.fir.kt | 18 + .../withCompanion/typeIsLowEnough.fir.kt | 20 + .../withIrrelevantInterface_after.fir.kt | 20 + .../withIrrelevantInterface_before.fir.kt | 20 + .../withCompanion/withMembers_after.fir.kt | 58 +++ .../withCompanion/withMembers_before.fir.kt | 64 +++ .../withCompanion/withoutTypeReference.fir.kt | 17 + .../componentNamedComponent1.fir.kt | 6 + .../conflictingCopyOverloads.fir.kt | 6 + .../dataClasses/conflictingOverloads.fir.kt | 4 + .../dataClasses/copyOfPrivateClass.fir.kt | 3 + ...sExplicitlyOverridingCopyNoDefaults.fir.kt | 9 + ...xplicitlyOverridingCopyWithDefaults.fir.kt | 9 + .../tests/dataClasses/dataClassNoName.fir.kt | 9 + .../dataClassNotOverridingCopy.fir.kt | 9 + .../dataClassOverridingCopy_lv12.fir.kt | 7 + .../dataClassOverridingCopy_lv13.fir.kt | 7 + .../dataClasses/dataClassVarargParam.fir.kt | 3 + .../tests/dataClasses/dataInheritance.fir.kt | 13 + .../tests/dataClasses/dataObject.fir.kt | 1 + .../tests/dataClasses/emptyConstructor.fir.kt | 6 + .../errorTypesInDataClasses.fir.kt | 16 + .../extensionComponentsOnNullable.fir.kt | 22 ++ .../finalMembersInBaseClass.fir.kt | 16 + .../implementMethodsFromInterface.fir.kt | 25 ++ .../implementTraitWhichHasComponent1.fir.kt | 5 + ...plementTraitWhichHasFinalComponent1.fir.kt | 5 + .../tests/dataClasses/innerDataClass.fir.kt | 3 + .../dataClasses/innerOuterDataClass.fir.kt | 1 + .../tests/dataClasses/multiDeclaration.fir.kt | 9 + .../dataClasses/multiDeclarationFor.fir.kt | 10 + .../tests/dataClasses/noConstructor.fir.kt | 6 + .../tests/dataClasses/notADataClass.fir.kt | 6 + .../tests/dataClasses/oneValParam.fir.kt | 8 + .../dataClasses/repeatedProperties.fir.kt | 9 + .../tests/dataClasses/sealedDataClass.fir.kt | 4 + .../tests/dataClasses/strange.fir.kt | 10 + .../tests/dataClasses/twoValParams.fir.kt | 8 + .../tests/dataClasses/twoVarParams.fir.kt | 8 + .../tests/dataFlow/CalleeExpression.fir.kt | 7 + .../diagnostics/tests/dataFlow/EmptyIf.fir.kt | 24 ++ .../tests/dataFlow/IsExpression.fir.kt | 6 + .../tests/dataFlow/WhenSubject.fir.kt | 10 + .../dataFlow/assignment/assignToNewVal.fir.kt | 10 + .../tests/dataFlow/assignment/kt6118.fir.kt | 16 + .../assignment/uninitializedValIsCheck.fir.kt | 15 + .../uninitializedValNullability.fir.kt | 15 + .../tests/dataFlow/assignment/when.fir.kt | 12 + .../dataFlow/local/LocalClassBase.fir.kt | 10 + .../local/LocalClassDefaultParameters.fir.kt | 8 + .../LocalClassDelegatedProperties.fir.kt | 17 + .../local/LocalClassDelegation.fir.kt | 11 + .../dataFlow/local/LocalClassFunctions.fir.kt | 18 + .../LocalClassInMemberOfLocalClass.fir.kt | 15 + .../local/LocalClassInitializer.fir.kt | 16 + .../dataFlow/local/LocalClassProperty.fir.kt | 12 + .../tests/dataFlow/local/LocalObject.fir.kt | 9 + .../local/LocalObjectDelegation.fir.kt | 15 + .../dataFlow/local/NestedLocalClass.fir.kt | 11 + .../tests/dataFlow/local/kt2835.fir.kt | 8 + .../tests/dataFlowInfoTraversal/AndOr.fir.kt | 13 + .../dataFlowInfoTraversal/ArrayAccess.fir.kt | 13 + .../ArrayExpression.fir.kt | 8 + .../ArrayGetSetConvention.fir.kt | 28 ++ .../dataFlowInfoTraversal/ArrayIndices.fir.kt | 11 + .../dataFlowInfoTraversal/Assignment.fir.kt | 17 + .../AssignmentInInitializer.fir.kt | 21 + .../AssignmentOperation.fir.kt | 17 + .../AssignmentToArrayElement.fir.kt | 12 + .../BinaryExpression.fir.kt | 11 + .../BinaryExpressionBooleanOperations.fir.kt | 25 ++ ...BinaryExpressionCompareToConvention.fir.kt | 18 + .../BinaryExpressionContainsConvention.fir.kt | 7 + .../BinaryExpressionElvis.fir.kt | 16 + .../BinaryExpressionEqualsConvention.fir.kt | 16 + .../BinaryExpressionIdentifier.fir.kt | 15 + .../BinaryExpressionPlusConvention.fir.kt | 18 + .../dataFlowInfoTraversal/Condition.fir.kt | 7 + .../ContinueOuterLoop.fir.kt | 34 ++ .../tests/dataFlowInfoTraversal/DeepIf.fir.kt | 31 ++ .../dataFlowInfoTraversal/DoWhile.fir.kt | 16 + .../DoWhileCondition.fir.kt | 20 + .../tests/dataFlowInfoTraversal/Elvis.fir.kt | 9 + .../dataFlowInfoTraversal/ExclExcl.fir.kt | 24 ++ .../tests/dataFlowInfoTraversal/For.fir.kt | 22 ++ .../dataFlowInfoTraversal/ForLoopRange.fir.kt | 8 + .../FunctionLiteral.fir.kt | 9 + .../dataFlowInfoTraversal/IfStatement.fir.kt | 31 ++ .../dataFlowInfoTraversal/IfThenElse.fir.kt | 30 ++ .../IfThenElseBothInvalid.fir.kt | 16 + .../dataFlowInfoTraversal/IsExpression.fir.kt | 8 + .../dataFlowInfoTraversal/ManyIfs.fir.kt | 32 ++ .../MultiDeclaration.fir.kt | 9 + .../ObjectExpression.fir.kt | 12 + .../QualifiedExpression.fir.kt | 13 + .../tests/dataFlowInfoTraversal/Return.fir.kt | 18 + .../StringTemplate.fir.kt | 8 + .../dataFlowInfoTraversal/ThisSuper.fir.kt | 21 + .../tests/dataFlowInfoTraversal/Throw.fir.kt | 9 + .../dataFlowInfoTraversal/TryCatch.fir.kt | 15 + .../dataFlowInfoTraversal/TryFinally.fir.kt | 21 + .../UnaryExpression.fir.kt | 14 + .../tests/dataFlowInfoTraversal/When.fir.kt | 18 + .../dataFlowInfoTraversal/WhenEntryAs.fir.kt | 26 ++ .../dataFlowInfoTraversal/WhenEntryIs.fir.kt | 26 ++ .../tests/dataFlowInfoTraversal/WhenIn.fir.kt | 15 + .../dataFlowInfoTraversal/WhenSubject.fir.kt | 8 + .../tests/dataFlowInfoTraversal/While.fir.kt | 22 ++ .../WhileCondition.fir.kt | 26 ++ .../kt4332WhenBranches.fir.kt | 9 + .../kt5155WhenBranches.fir.kt | 11 + .../kt5182WhenBranches.fir.kt | 13 + .../smartcasts/SmartcastAmbiguitites.fir.kt | 16 + .../SmartcastsForStableIdentifiers.fir.kt | 86 ++++ ...ComponentFunctionReturnTypeMismatch.fir.kt | 9 + .../ConflictingAndRedundantProjections.fir.kt | 20 + .../DataFlowInMultiDeclInFor.fir.kt | 15 + .../DataFlowInfoInMultiDecl.fir.kt | 14 + .../FunctionWithMissingNames.fir.kt | 26 ++ .../LocalVariableWithNoTypeInformation.fir.kt | 3 + .../MultiDeclarationErrors.fir.kt | 21 + .../RedeclarationsInMultiDecl.fir.kt | 15 + .../ScalaLikeNamedFun.fir.kt | 36 ++ ...OnFunctionAndPropertyTypeParameters.fir.kt | 17 + .../ambiguousObjectExpressionType.fir.kt | 120 ++++++ ...anonymousFunAsLastExpressionInBlock.fir.kt | 43 ++ ...ymousFunUnusedLastExpressionInBlock.fir.kt | 21 + .../DoubleDeclForLoop.fir.kt | 14 + .../FolLoopTypeComponentTypeMismatch.fir.kt | 15 + .../ForLoopComponentFunctionAmbiguity.fir.kt | 15 + .../ForLoopComponentFunctionMissing.fir.kt | 13 + .../ForLoopMissingLoopParameter.fir.kt | 15 + .../ForLoopWithExtensions.fir.kt | 14 + .../ForWithExplicitTypes.fir.kt | 14 + .../RedeclarationInForLoop.fir.kt | 14 + .../SingleDeclForLoop.fir.kt | 13 + ...turingDeclarationAssignedUnresolved.fir.kt | 11 + ...turingDeclarationMissingInitializer.fir.kt | 11 + .../destructuringDeclarations/kt2829.fir.kt | 16 + ...lastDestructuringDeclarationInBlock.fir.kt | 30 ++ .../underscore.fir.kt | 51 +++ .../CasesWithOneTypeParameter.fir.kt | 17 + .../CasesWithTwoTypeParameters.fir.kt | 12 + .../JavaSuperType.fir.kt | 5 + .../illegalModifiersOnClass.fir.kt | 19 + .../kClassInSignature.fir.kt | 23 ++ .../tests/declarationChecks/kt1141.fir.kt | 21 + .../tests/declarationChecks/kt1193.fir.kt | 13 + .../tests/declarationChecks/kt2096.fir.kt | 7 + .../tests/declarationChecks/kt2142.fir.kt | 8 + .../tests/declarationChecks/kt2397.fir.kt | 17 + .../kt2631_MultipleDeclaration.fir.kt | 27 ++ .../kt2643MultiDeclInControlFlow.fir.kt | 27 ++ .../tests/declarationChecks/kt559.fir.kt | 30 ++ .../localDeclarationModifiers.fir.kt | 12 + .../localFunctionNoInheritVisibility.fir.kt | 16 + ...ocalVariablesWithTypeParameters_1_3.fir.kt | 19 + ...ocalVariablesWithTypeParameters_1_4.fir.kt | 19 + .../mulitpleVarargParameters.fir.kt | 35 ++ .../namedFunAsLastExpressionInBlock.fir.kt | 75 ++++ .../JavaWithKotlin.fir.kt | 14 + .../JavaWithKotlin2.fir.kt | 16 + .../PureKotlin.fir.kt | 28 ++ .../packageDeclarationModifiers.fir.kt | 12 + ...ertyInPackageHasNoInheritVisibility.fir.kt | 10 + .../declarationChecks/sealedOnMembers.fir.kt | 18 + .../unambiguousObjectExpressionType.fir.kt | 175 +++++++++ .../valVarFunctionParameter.fir.kt | 12 + .../tests/defaultArguments/kt5232.fir.kt | 11 + .../tests/defaultArguments/superCall.fir.kt | 28 ++ .../absentErrorAboutInitializer.fir.kt | 11 + .../absentErrorAboutType.fir.kt | 11 + .../abstractDelegatedProperty.fir.kt | 13 + .../delegatedProperty/backingField.fir.kt | 15 + .../delegatedProperty/defaultGetter.fir.kt | 12 + .../delegatedProperty/defaultSetter.fir.kt | 14 + .../delegatedPropertyOverridedInTrait.fir.kt | 21 + ...ropertyOverridedInTraitTypeMismatch.fir.kt | 21 + .../disallowImplInTypeParameter.fir.kt | 7 + .../delegatedProperty/genericGetter.fir.kt | 11 + .../getterWithSubtype.fir.kt | 15 + .../tests/delegatedProperty/inTrait.fir.kt | 13 + .../incompleteTypeInference.fir.kt | 17 + ...erenceArgumentInDelegatedExpression.fir.kt | 17 + .../delegateExpressionAsLambda.fir.kt | 22 ++ .../differentDelegatedExpressions.fir.kt | 53 +++ .../inference/extensionGet.fir.kt | 35 ++ .../inference/extensionProperty.fir.kt | 22 ++ .../genericMethodInGenericClass.fir.kt | 28 ++ .../inference/genericMethods.fir.kt | 27 ++ .../labeledDelegatedExpression.fir.kt | 11 + .../inference/manyIncompleteCandidates.fir.kt | 26 ++ .../noErrorsForImplicitConstraints.fir.kt | 45 +++ ...oExpectedTypeForSupertypeConstraint.fir.kt | 18 + ...ultTypeOfLambdaForConventionMethods.fir.kt | 17 + ...peOfLazyDelegatedPropertyWithObject.fir.kt | 29 ++ .../useCompleterWithoutExpectedType.fir.kt | 15 + .../inference/useExpectedType.fir.kt | 76 ++++ .../inference/useExpectedTypeForVal.fir.kt | 64 +++ .../tests/delegatedProperty/kt4640.fir.kt | 11 + .../delegatedProperty/localVariable.fir.kt | 15 + .../localWithSmartCast.fir.kt | 15 + .../delegatedProperty/missedGetter.fir.kt | 3 + .../delegatedProperty/missedSetter.fir.kt | 11 + .../nonDefaultAccessors.fir.kt | 12 + .../propertyDefferedType.fir.kt | 12 + .../commonCaseForInference.fir.kt | 14 + .../genericProvideDelegate.fir.kt | 13 + .../provideDelegate/hostAndReceiver1.fir.kt | 9 + .../provideDelegate/hostAndReceiver2.fir.kt | 14 + .../provideDelegate/hostAndReceiver3.fir.kt | 12 + .../inferenceFromReceiver1.fir.kt | 15 + .../inferenceFromReceiver2.fir.kt | 14 + .../localDelegatedProperty.fir.kt | 11 + ...noOperatorModifierOnProvideDelegate.fir.kt | 18 + ...esolutionForSeveralProvideDelegates.fir.kt | 19 + .../provideDelegateOperatorDeclaration.fir.kt | 32 ++ .../provideDelegate/setValue.fir.kt | 17 + .../simpleProvideDelegate.fir.kt | 10 + .../unsupportedOperatorProvideDelegate.fir.kt | 15 + .../delegatedProperty/recursiveType.fir.kt | 18 + .../delegatedProperty/redundantGetter.fir.kt | 12 + .../delegatedProperty/redundantSetter.fir.kt | 15 + .../setterThisTypeMismatch.fir.kt | 18 + .../setterWithSupertype.fir.kt | 16 + .../delegatedProperty/severalReceivers.fir.kt | 13 + .../delegatedProperty/thisInDelegate.fir.kt | 15 + .../delegatedProperty/thisOfAnyType.fir.kt | 16 + .../thisOfNothingNullableType.fir.kt | 18 + .../thisOfNothingType.fir.kt | 18 + .../delegatedProperty/twoGetMethods.fir.kt | 17 + .../typeMismatchForGetReturnType.fir.kt | 12 + .../typeMismatchForGetWithGeneric.fir.kt | 23 ++ .../typeMismatchForSetParameter.fir.kt | 16 + .../typeMismatchForThisGetParameter.fir.kt | 18 + .../wrongCountOfParametersInGet.fir.kt | 15 + .../wrongCountOfParametersInSet.fir.kt | 17 + .../wrongSetterReturnType.fir.kt | 15 + .../delegation/DelegationAndOverriding.fir.kt | 38 ++ .../delegation/DelegationExpectedType.fir.kt | 26 ++ .../delegation/DelegationNotTotrait.fir.kt | 15 + .../delegation/DelegationToJavaIface.fir.kt | 4 + .../Delegation_ClashingFunctions.fir.kt | 18 + .../delegation/Delegation_Hierarchy.fir.kt | 12 + .../Delegation_MultipleDelegates.fir.kt | 19 + ...Delegation_ScopeInitializationOrder.fir.kt | 10 + .../clashes/finalMemberOverridden.fir.kt | 56 +++ .../clashes/propertyTypeMismatch.fir.kt | 57 +++ .../clashes/returnTypeMismatch.fir.kt | 59 +++ .../clashes/varOverriddenByVal.fir.kt | 29 ++ .../covariantOverrides/fromClass.fir.kt | 19 + .../covariantOverrides/irrelevant.fir.kt | 19 + .../covariantOverrides/kt13952.fir.kt | 17 + .../covariantOverrides/simple.fir.kt | 19 + .../tests/delegation/kt8154.fir.kt | 11 + .../abstractOverride.fir.kt | 18 + .../delegationToSubType.fir.kt | 19 + .../delegationToSubTypeProperty.fir.kt | 20 + .../delegationToSubTypeWithOverride.fir.kt | 19 + ...gationToSubTypeWithOverrideProperty.fir.kt | 26 ++ .../diamond.fir.kt | 43 ++ .../explicitOverride.fir.kt | 18 + .../fakeOverrideInTheMiddle.fir.kt | 13 + .../generic.fir.kt | 14 + .../sameDelegationInHierarchy.fir.kt | 16 + .../sameDelegationInHierarchy2.fir.kt | 21 + .../severalDelegates.fir.kt | 28 ++ .../simple.fir.kt | 19 + .../simpleNoOverride.fir.kt | 15 + .../simpleProp.fir.kt | 17 + .../ParenthesizedVariable.fir.kt | 3 + .../deparenthesize/annotatedSafeCall.fir.kt | 7 + .../checkDeparenthesizedType.fir.kt | 30 ++ .../deparenthesize/labeledSafeCall.fir.kt | 3 + .../multiParenthesizedSafeCall.fir.kt | 3 + .../parenthesizedSafeCall.fir.kt | 3 + .../tests/deprecated/annotationUsage.fir.kt | 9 + .../classWithCompanionObject.fir.kt | 8 + .../deprecated/companionObjectUsage.fir.kt | 32 ++ .../tests/deprecated/componentUsage.fir.kt | 11 + .../deprecated/deprecatedConstructor.fir.kt | 34 ++ .../tests/deprecated/deprecatedError.fir.kt | 11 + .../deprecated/deprecatedErrorBuilder.fir.kt | 21 + .../tests/deprecated/deprecatedHidden.fir.kt | 11 + .../deprecated/deprecatedInheritance.fir.kt | 140 +++++++ .../deprecatedPropertyInheritance.fir.kt | 135 +++++++ .../tests/deprecated/functionUsage.fir.kt | 51 +++ .../deprecated/genericConstructorUsage.fir.kt | 8 + .../deprecated/hiddenPropertyAccessors.fir.kt | 40 ++ .../deprecated/importJavaSamInterface.fir.kt | 13 + .../tests/deprecated/imports.fir.kt | 8 + .../tests/deprecated/iteratorUsage.fir.kt | 24 ++ .../tests/deprecated/javaDeprecated.fir.kt | 16 + .../javaDeprecatedInheritance.fir.kt | 53 +++ .../tests/deprecated/javaDocDeprecated.fir.kt | 20 + .../tests/deprecated/nestedTypesUsage.fir.kt | 18 + .../tests/deprecated/objectUsage.fir.kt | 9 + .../tests/deprecated/propertyUsage.fir.kt | 66 ++++ .../propertyUseSiteTargetedAnnotations.fir.kt | 31 ++ .../deprecated/propertyWithInvoke.fir.kt | 6 + .../tests/deprecated/thisUsage.fir.kt | 7 + .../tests/deprecated/typeUsage.fir.kt | 42 ++ .../typealiasCompanionObject.fir.kt | 12 + .../deprecated/typealiasConstructor.fir.kt | 17 + .../typealiasForDeprecatedClass.fir.kt | 21 + .../tests/deprecated/typealiasUsage.fir.kt | 24 ++ .../tests/deprecated/unusedImport.fir.kt | 10 + .../warningOnConstructorErrorOnClass.fir.kt | 8 + .../accidentalOverrideFromGrandparent.fir.kt | 14 + .../classFunctionOverriddenByProperty.fir.kt | 8 + ...onOverriddenByPropertyInConstructor.fir.kt | 5 + ...unctionOverriddenByPropertyNoGetter.fir.kt | 7 + .../classPropertyOverriddenByFunction.fir.kt | 8 + .../defaultFunction.fir.kt | 9 + ...legatedFunctionOverriddenByProperty.fir.kt | 10 + .../genericClassFunction.fir.kt | 9 + .../overridesNothing.fir.kt | 7 + ...teClassFunctionOverriddenByProperty.fir.kt | 8 + .../accidentalOverrides/require.fir.kt | 7 + .../traitFunctionOverriddenByProperty.fir.kt | 8 + ...tFunctionOverriddenByPropertyNoImpl.fir.kt | 8 + .../traitPropertyOverriddenByFunction.fir.kt | 8 + ...tPropertyOverriddenByFunctionNoImpl.fir.kt | 7 + .../bridges/class.fir.kt | 11 + .../bridges/fakeOverrideTrait.fir.kt | 9 + .../bridges/trait.fir.kt | 11 + .../caseInProperties.fir.kt | 2 + .../clashFromInterfaceAndSuperClass.fir.kt | 19 + .../erasure/collections.fir.kt | 4 + .../erasure/delegateToTwoTraits.fir.kt | 12 + .../erasure/delegationAndOwnMethod.fir.kt | 9 + .../delegationToTraitImplAndOwnMethod.fir.kt | 15 + .../erasure/extensionProperties.fir.kt | 7 + .../erasure/genericType.fir.kt | 6 + .../erasure/inheritFromTwoTraits.fir.kt | 12 + .../erasure/kotlinAndJavaCollections.fir.kt | 4 + .../erasure/nullableType.fir.kt | 4 + .../superTraitAndDelegationToTraitImpl.fir.kt | 13 + .../erasure/twoTraitsAndOwnFunction.fir.kt | 13 + .../erasure/typeMappedToJava.fir.kt | 4 + .../erasure/typeParameter.fir.kt | 4 + .../erasure/typeParameterWithBound.fir.kt | 6 + .../erasure/typeParameterWithTwoBounds.fir.kt | 8 + .../typeParameterWithTwoBoundsInWhere.fir.kt | 8 + .../enumMembers.fir.kt | 6 + .../waitNotifyGetClass.fir.kt | 19 + .../functionAndProperty/class.fir.kt | 4 + .../functionAndProperty/classObject.fir.kt | 6 + .../classPropertyInConstructor.fir.kt | 3 + .../extensionFunctionAndNormalFunction.fir.kt | 6 + .../extensionPropertyAndFunction.fir.kt | 7 + .../functionAndSetter.fir.kt | 7 + .../functionAndProperty/functionAndVar.fir.kt | 8 + .../functionAndProperty/localClass.fir.kt | 6 + .../localClassInClass.fir.kt | 8 + .../functionAndProperty/nestedClass.fir.kt | 6 + .../functionAndProperty/object.fir.kt | 4 + .../objectExpression.fir.kt | 5 + .../objectExpressionInConstructor.fir.kt | 6 + .../privateClassPropertyNoClash.fir.kt | 13 + .../functionAndProperty/topLevel.fir.kt | 2 + .../topLevelDifferentFiles.fir.kt | 5 + .../functionAndProperty/topLevelGetter.fir.kt | 3 + .../functionAndProperty/trait.fir.kt | 5 + .../functionAndProperty/withErrorTypes.fir.kt | 4 + .../duplicateJvmSignature/missingNames.fir.kt | 68 ++++ .../specialNames/classObject.fir.kt | 5 + .../classObjectCopiedField.fir.kt | 8 + .../classObjectCopiedFieldObject.fir.kt | 13 + .../specialNames/dataClassCopy.fir.kt | 5 + .../specialNames/defaults.fir.kt | 6 + .../specialNames/delegationBy.fir.kt | 5 + .../specialNames/enum.fir.kt | 7 + .../specialNames/innerClassField.fir.kt | 7 + .../specialNames/instance.fir.kt | 3 + .../specialNames/propertyMetadataCache.fir.kt | 13 + .../duplicateJvmSignature/statics/jkjk.fir.kt | 34 ++ .../kotlinClassExtendsJavaClass.fir.kt | 22 ++ ...assExtendsJavaClassExtendsJavaClass.fir.kt | 29 ++ .../kotlinClassImplementsJavaInterface.fir.kt | 22 ++ ...ntsJavaInterfaceExtendsJavaInteface.fir.kt | 29 ++ ...otlinMembersVsJavaNonVisibleStatics.fir.kt | 24 ++ .../synthesized/enumValuesValueOf.fir.kt | 12 + .../traitImpl/oneTrait.fir.kt | 7 + ...FunctionOverriddenByPropertyInTrait.fir.kt | 8 + ...PropertyOverriddenByFunctionInTrait.fir.kt | 8 + .../traitImpl/twoTraits.fir.kt | 11 + .../tests/duplicateJvmSignature/vararg.fir.kt | 8 + .../tests/dynamicTypes/delegationBy.fir.kt | 5 + .../tests/dynamicTypes/unsupported.fir.kt | 7 + .../withInvisibleSynthesized.fir.kt | 35 ++ .../tests/enum/AbstractEnum.fir.kt | 3 + .../tests/enum/AbstractInEnum.fir.kt | 47 +++ .../tests/enum/AbstractOverrideInEnum.fir.kt | 12 + .../enum/ConstructorCallFromOutside.fir.kt | 10 + .../tests/enum/ExplicitConstructorCall.fir.kt | 10 + .../enum/InsideEntryConstructorCall.fir.kt | 15 + .../InsideSecondaryConstructorCall.fir.kt | 13 + .../tests/enum/NonPrivateConstructor.fir.kt | 7 + .../enum/SecondaryConstructorCall.fir.kt | 9 + .../tests/enum/classObjectInEnum.fir.kt | 9 + .../enum/classObjectInEnumPrivate.fir.kt | 10 + .../tests/enum/commonSupertype.fir.kt | 7 + .../enum/compareTwoDifferentEnums.fir.kt | 16 + ...onstructorWithDefaultParametersOnly.fir.kt | 21 + ...CreatePackageTypeForEnumEntry_after.fir.kt | 16 + ...reatePackageTypeForEnumEntry_before.fir.kt | 16 + .../tests/enum/emptyConstructor.fir.kt | 4 + .../tests/enum/entryShouldBeOfEnumType.fir.kt | 9 + .../enumEntryCannotHaveClassObject.fir.kt | 11 + .../tests/enum/enumEntryInAbstractEnum.fir.kt | 13 + .../tests/enum/enumImplementingTrait.fir.kt | 21 + .../tests/enum/enumInheritance.fir.kt | 11 + .../enum/enumIsAssignableToBuiltInEnum.fir.kt | 14 + .../tests/enum/enumMissingName.fir.kt | 6 + .../tests/enum/enumModifier.fir.kt | 15 + .../tests/enum/enumStarImport.fir.kt | 20 + .../tests/enum/enumSubjectTypeCheck.fir.kt | 40 ++ .../enum/enumWithAnnotationKeyword.fir.kt | 3 + .../tests/enum/enumWithEmptyName.fir.kt | 2 + .../tests/enum/extendingEnumDirectly.fir.kt | 9 + .../enum/extensionNamedAsEnumEntry.fir.kt | 8 + .../diagnostics/tests/enum/ifEnumEntry.fir.kt | 6 + .../tests/enum/importEnumFromJava.fir.kt | 7 + .../enum/incompatibleEnumEntryClasses.fir.kt | 90 +++++ .../tests/enum/incompatibleEnums.fir.kt | 145 +++++++ .../tests/enum/incompatibleEnums_1_4.fir.kt | 145 +++++++ .../tests/enum/inheritFromEnumEntry.fir.kt | 5 + .../tests/enum/inheritanceFromEnum.fir.kt | 13 + .../diagnostics/tests/enum/inline.fir.kt | 3 + .../enum/inner/existingClassObject.fir.kt | 19 + .../tests/enum/inner/insideClass.fir.kt | 5 + .../tests/enum/inner/insideClassObject.fir.kt | 7 + .../tests/enum/inner/insideEnum.fir.kt | 7 + .../enum/inner/insideEnumEntry_after.fir.kt | 9 + .../enum/inner/insideEnumEntry_before.fir.kt | 9 + .../inner/insideInnerClassNotAllowed.fir.kt | 7 + .../tests/enum/inner/insideObject.fir.kt | 5 + .../tests/enum/inner/insideTrait.fir.kt | 5 + .../inner/redeclarationInClassObject.fir.kt | 11 + .../tests/enum/inner/twoEnums.fir.kt | 4 + .../twoEnumsInClassObjectAndInnerClass.fir.kt | 9 + .../enum/interfaceWithEnumKeyword.fir.kt | 8 + .../diagnostics/tests/enum/isEnumEntry.fir.kt | 6 + .../tests/enum/javaEnumValueOfMethod.fir.kt | 10 + .../tests/enum/javaEnumValuesMethod.fir.kt | 11 + .../tests/enum/javaEnumWithAbstractFun.fir.kt | 16 + .../tests/enum/javaEnumWithFuns.fir.kt | 16 + .../enum/javaEnumWithNameClashing.fir.kt | 15 + .../tests/enum/javaEnumWithProperty.fir.kt | 19 + .../diagnostics/tests/enum/kt2834.fir.kt | 6 + .../tests/enum/kt8972_cloneNotAllowed.fir.kt | 7 + .../diagnostics/tests/enum/localEnums.fir.kt | 20 + .../tests/enum/modifiersOnEnumEntry.fir.kt | 23 ++ .../tests/enum/multipleConstructors.fir.kt | 8 + .../tests/enum/openMemberInEnum.fir.kt | 17 + .../enum/overrideFinalEnumMethods.fir.kt | 11 + .../starImportNestedClassAndEntries.fir.kt | 24 ++ .../tests/enum/typeParametersInEnum.fir.kt | 7 + ...aluesValueOfAndEntriesAccessibility.fir.kt | 18 + .../enum/wrongUnitializedEnumCompanion.fir.kt | 9 + .../evaluate/binaryMinusDepOnExpType.fir.kt | 30 ++ .../evaluate/binaryMinusIndepWoExpType.fir.kt | 36 ++ .../binaryMinusIndependentExpType.fir.kt | 24 ++ .../tests/evaluate/divisionByZero.fir.kt | 18 + .../diagnostics/tests/evaluate/float.fir.kt | 10 + .../evaluate/floatLiteralOutOfRange.fir.kt | 21 + .../infixFunOverBuiltinMemberInConst.fir.kt | 10 + .../constructorOfUnsignedType.fir.kt | 44 +++ .../tests/evaluate/intOverflow.fir.kt | 77 ++++ .../intOverflowWithJavaProperties.fir.kt | 14 + .../diagnostics/tests/evaluate/integer.fir.kt | 10 + .../tests/evaluate/logicWithNumber.fir.kt | 8 + .../tests/evaluate/longOverflow.fir.kt | 65 +++ .../tests/evaluate/noOverflowWithZero.fir.kt | 11 + .../evaluate/numberBinaryOperations.fir.kt | 26 ++ .../numberBinaryOperationsCall.fir.kt | 31 ++ .../numberBinaryOperationsInfixCall.fir.kt | 31 ++ .../tests/evaluate/otherOverflow.fir.kt | 2 + .../tests/evaluate/parentesized.fir.kt | 12 + .../evaluate/qualifiedExpressions.fir.kt | 8 + .../evaluate/unaryMinusDepOnExpType.fir.kt | 36 ++ .../evaluate/unaryMinusIndepWoExpType.fir.kt | 41 ++ .../unaryMinusIndependentExpType.fir.kt | 29 ++ .../tests/evaluate/wrongLongSuffix.fir.kt | 10 + .../diagnostics/tests/exposed/delegate.fir.kt | 6 + .../exposed/exceptionOnFakeInvisible.fir.kt | 12 + .../tests/exposed/functional.fir.kt | 12 + .../tests/exposed/implements.fir.kt | 4 + .../tests/exposed/inaccessibleType.fir.kt | 89 +++++ .../diagnostics/tests/exposed/internal.fir.kt | 25 ++ .../tests/exposed/internalAndProtected.fir.kt | 10 + .../tests/exposed/internalFromLocal.fir.kt | 10 + .../diagnostics/tests/exposed/local.fir.kt | 18 + .../tests/exposed/localFromInternal.fir.kt | 7 + .../tests/exposed/localFromPrivate.fir.kt | 15 + .../tests/exposed/localInFunReturnType.fir.kt | 60 +++ .../tests/exposed/localInMemberType.fir.kt | 21 + .../tests/exposed/localInPropertyType.fir.kt | 60 +++ .../diagnostics/tests/exposed/nested.fir.kt | 6 + .../diagnostics/tests/exposed/object.fir.kt | 30 ++ .../tests/exposed/packagePrivate.fir.kt | 35 ++ .../tests/exposed/privateFromLocal.fir.kt | 12 + ...privatePropertyInPrivateConstructor.fir.kt | 3 + ...propertyInConstructorOfPrivateClass.fir.kt | 3 + .../propertyInPrivateConstructor.fir.kt | 3 + .../propertyInSimpleConstructor.fir.kt | 3 + .../tests/exposed/protected.fir.kt | 20 + .../tests/exposed/protectedInProtected.fir.kt | 12 + .../tests/exposed/protectedJava.fir.kt | 16 + .../tests/exposed/protectedSameWay.fir.kt | 13 + .../diagnostics/tests/exposed/simple.fir.kt | 23 ++ .../diagnostics/tests/exposed/typeArgs.fir.kt | 17 + .../extensions/ExtensionFunctions.fir.kt | 76 ++++ .../extensions/ExtensionsCalledOnSuper.fir.kt | 22 ++ .../tests/extensions/GenericIterator.fir.kt | 36 ++ .../tests/extensions/GenericIterator2.fir.kt | 15 + .../tests/extensions/classObject.fir.kt | 20 + .../extensionMemberInClassObject.fir.kt | 18 + .../extensionPropertyVsParameter.fir.kt | 8 + .../tests/extensions/kt1875.fir.kt | 22 ++ .../tests/extensions/kt2317.fir.kt | 15 + .../tests/extensions/kt3470.fir.kt | 7 + .../tests/extensions/kt3563.fir.kt | 17 + .../kt819ExtensionProperties.fir.kt | 37 ++ .../extensions/noClassObjectsInJava.fir.kt | 11 + .../tests/extensions/object.fir.kt | 6 + .../throwOutCandidatesByReceiver.fir.kt | 56 +++ .../throwOutCandidatesByReceiver2.fir.kt | 15 + .../tests/extensions/variableInvoke.fir.kt | 11 + .../tests/fileDependencyRecursion.fir.kt | 15 + .../functionAsExpression/AutoLabels.fir.kt | 11 + .../tests/functionAsExpression/Common.fir.kt | 19 + .../DifficultInferenceForParameter.fir.kt | 7 + .../ForbiddenNonLocalReturn.fir.kt | 22 ++ .../functionAsExpression/FunctionType.fir.kt | 32 ++ .../InferenceParametersTypes.fir.kt | 20 + .../MissingParameterTypes.fir.kt | 27 ++ .../NameDeprecation.fir.kt | 9 + .../NoOverloadError.fir.kt | 18 + .../functionAsExpression/Parameters.fir.kt | 18 + .../ReceiverByExpectedType.fir.kt | 3 + .../ReturnAndLabels.fir.kt | 9 + .../ReturnTypeCheck.fir.kt | 9 + .../functionAsExpression/ScopeCheck.fir.kt | 20 + .../WithGenericParameters.fir.kt | 19 + .../WithOuterGeneric.fir.kt | 31 ++ .../functionAsExpression/WithoutBody.fir.kt | 12 + .../functionLiterals/DeprecatedSyntax.fir.kt | 25 ++ ...pectedParameterTypeMismatchVariance.fir.kt | 21 + .../ExpectedParametersTypesMismatch.fir.kt | 45 +++ .../LabeledFunctionLiterals.fir.kt | 16 + .../assignmentOperationInLambda.fir.kt | 17 + ...ntOperationInLambdaWithExpectedType.fir.kt | 16 + .../complexInference.fir.kt | 48 +++ .../extensionComponents.fir.kt | 53 +++ .../inferredFunctionalType.fir.kt | 34 ++ .../destructuringInLambdas/modifiers.fir.kt | 15 + .../noExpectedType.fir.kt | 32 ++ .../redeclaration.fir.kt | 30 ++ .../destructuringInLambdas/shadowing.fir.kt | 25 ++ .../destructuringInLambdas/simple.fir.kt | 54 +++ .../destructuringInLambdas/underscore.fir.kt | 63 +++ .../unsupportedFeature.fir.kt | 13 + .../unusedParameters.fir.kt | 43 ++ ...onExpressionAsLastExpressionInBlock.fir.kt | 15 + .../functionLIteralInBlockInIf.fir.kt | 10 + ...unctionLiteralAsArgumentForFunction.fir.kt | 25 ++ .../functionLiteralInIf.fir.kt | 15 + .../functionLiteralWithoutArgumentList.fir.kt | 7 + ...ericFunctionalTypeOnRHSOfPlusAssign.fir.kt | 11 + .../higherOrderCallMissingParameters.fir.kt | 16 + .../tests/functionLiterals/kt11733.fir.kt | 15 + .../tests/functionLiterals/kt11733_1.fir.kt | 16 + .../tests/functionLiterals/kt16016.fir.kt | 6 + .../tests/functionLiterals/kt2906.fir.kt | 22 ++ .../tests/functionLiterals/kt3343.fir.kt | 25 ++ .../tests/functionLiterals/kt4529.fir.kt | 19 + ...t6541_extensionForExtensionFunction.fir.kt | 10 + .../tests/functionLiterals/kt6869.fir.kt | 10 + .../kt7383_starProjectedFunction.fir.kt | 7 + ...ixingTypeVariableForAnotherArgument.fir.kt | 14 + .../functionLiterals/return/AutoLabels.fir.kt | 22 ++ .../return/AutoLabelsNonLocal.fir.kt | 11 + .../ForbiddenNonLocalReturnNoType.fir.kt | 19 + .../return/IfInReturnedExpression.fir.kt | 9 + .../return/IfWithoutElse.fir.kt | 15 + .../IfWithoutElseWithExplicitType.fir.kt | 22 ++ .../return/LambdaWithParameter.fir.kt | 17 + .../LocalAndNonLocalReturnInLambda.fir.kt | 11 + .../LocalReturnExplicitLabelNoParens.fir.kt | 6 + .../LocalReturnExplicitLabelParens.fir.kt | 12 + .../return/LocalReturnHasTypeNothing.fir.kt | 7 + .../return/LocalReturnInNestedFunction.fir.kt | 12 + .../return/LocalReturnInNestedLambda.fir.kt | 11 + .../return/LocalReturnNoCoercionToUnit.fir.kt | 7 + .../return/LocalReturnNull.fir.kt | 14 + .../return/LocalReturnSecondUnit.fir.kt | 6 + .../return/LocalReturnUnit.fir.kt | 9 + .../LocalReturnUnitAndDontCareType.fir.kt | 21 + .../LocalReturnUnitWithBodyExpression.fir.kt | 7 + .../return/LocalReturnWithExpectedType.fir.kt | 9 + .../return/LocalReturnWithExplicitUnit.fir.kt | 16 + .../LocalReturnsWithExplicitReturnType.fir.kt | 10 + .../return/MixedReturnsFromLambda.fir.kt | 14 + .../return/NoCommonSystem.fir.kt | 19 + .../functionLiterals/return/SmartCast.fir.kt | 19 + .../return/SmartCastWithExplicitType.fir.kt | 17 + .../unresolvedReferenceInReturnBlock.fir.kt | 9 + .../tests/functionLiterals/returnNull.fir.kt | 10 + .../returnNullWithReturn.fir.kt | 11 + .../underscopeParameters.fir.kt | 48 +++ .../functionLiterals/unusedLiteral.fir.kt | 12 + .../unusedLiteralInsideUnitLiteral.fir.kt | 8 + .../InconsistentTypeParameterBounds.fir.kt | 7 + .../tests/generics/Projections.fir.kt | 54 +++ .../tests/generics/PseudoRawTypes.fir.kt | 25 ++ .../generics/RawTypeInIsExpression.fir.kt | 14 + .../tests/generics/RawTypeInIsPattern.fir.kt | 13 + .../generics/RecursiveUpperBoundCheck.fir.kt | 3 + ...RecursiveUpperBoundWithTwoArguments.fir.kt | 1 + .../tests/generics/TypeParameterBounds.fir.kt | 23 ++ ...TypeParametersInTypeParameterBounds.fir.kt | 15 + .../tests/generics/argumentsForT.fir.kt | 7 + .../capturedParameters/captured.fir.kt | 30 ++ .../capturedParameters/innerLocalClass.fir.kt | 35 ++ .../capturedParameters/localClass.fir.kt | 25 ++ .../localWithTypeParameter.fir.kt | 22 ++ .../capturedParameters/objectLiteral.fir.kt | 23 ++ .../capturedParameters/uncheckedCast.fir.kt | 37 ++ .../commonSupertypeContravariant.fir.kt | 10 + .../commonSupertypeContravariant2.fir.kt | 9 + .../generics/cyclicBounds/functions.fir.kt | 7 + .../generics/cyclicBounds/inClass.fir.kt | 7 + .../generics/doNotCaptureSupertype.fir.kt | 15 + .../finalUpperBoundWithOverride.fir.kt | 97 +++++ .../finalUpperBoundWithoutOverride.fir.kt | 82 ++++ .../tests/generics/genericsInType.fir.kt | 36 ++ .../generics/innerClasses/bareTypes.fir.kt | 20 + .../innerClasses/bareTypesComplex.fir.kt | 14 + .../innerClasses/checkBoundsOuter.fir.kt | 5 + .../fromCompanionObject_after.fir.kt | 22 ++ .../fromCompanionObject_before.fir.kt | 22 ++ .../fromOuterClassInObjectLiteral.fir.kt | 15 + .../implicitArguments/fromSuperClasses.fir.kt | 26 ++ .../fromSuperClassesLocal.fir.kt | 55 +++ .../fromSuperClassesLocalInsideInner.fir.kt | 59 +++ .../fromSuperClassesTransitive.fir.kt | 19 + .../implicitArguments/inStaticScope.fir.kt | 7 + .../implicitArguments/secondLevelDepth.fir.kt | 18 + .../innerClasses/importedInner.fir.kt | 20 + .../innerClasses/innerSuperCall.fir.kt | 9 + .../innerSuperCallSecondary.fir.kt | 12 + .../generics/innerClasses/innerTP.fir.kt | 42 ++ .../innerClasses/innerUncheckedCast.fir.kt | 32 ++ .../innerClasses/innerVariance.fir.kt | 14 + .../generics/innerClasses/iterator.fir.kt | 37 ++ .../tests/generics/innerClasses/j+k.fir.kt | 28 ++ .../generics/innerClasses/j+k_complex.fir.kt | 35 ++ .../tests/generics/innerClasses/kt3357.fir.kt | 18 + .../tests/generics/innerClasses/kt408.fir.kt | 12 + .../tests/generics/innerClasses/kt6325.fir.kt | 21 + .../outerArgumentsRequired.fir.kt | 23 ++ .../innerClasses/parameterShadowing.fir.kt | 18 + .../innerClasses/qualifiedOuter.fir.kt | 24 ++ .../qualifiedTypesResolution.fir.kt | 51 +++ .../tests/generics/innerClasses/simple.fir.kt | 36 ++ .../generics/innerClasses/simpleIn.fir.kt | 40 ++ .../generics/innerClasses/simpleOut.fir.kt | 37 ++ .../innerClasses/simpleOutUseSite.fir.kt | 37 ++ .../substitutedMemberScope.fir.kt | 49 +++ .../invalidArgumentsNumberInWhere.fir.kt | 19 + .../tests/generics/kt1575-Class.fir.kt | 1 + .../tests/generics/kt1575-Function.fir.kt | 2 + .../diagnostics/tests/generics/kt30590.fir.kt | 9 + .../diagnostics/tests/generics/kt5508.fir.kt | 24 ++ .../diagnostics/tests/generics/kt9203.fir.kt | 11 + .../tests/generics/kt9203_1.fir.kt | 18 + .../diagnostics/tests/generics/kt9985.fir.kt | 46 +++ .../conflictingReturnType.fir.kt | 13 + .../flexibleTypes.fir.kt | 19 + .../mostSpecific.fir.kt | 13 + .../properties.fir.kt | 19 + .../propertiesConflict.fir.kt | 19 + .../multipleBoundsMemberScope/simple.fir.kt | 14 + .../validTypeParameters.fir.kt | 13 + .../capturedTypeWithPlatformSupertype.fir.kt | 17 + ...rTypeNotNullOnlyIfItHasNotNullBound.fir.kt | 6 + ...stitutionForIncorporationConstraint.fir.kt | 17 + .../declarationsBoundsViolation.fir.kt | 13 + .../expressionsBoundsViolation.fir.kt | 19 + .../nullability/functionalBound.fir.kt | 14 + ...TypeFromIntersectionOfNullableTypes.fir.kt | 38 ++ .../tests/generics/nullability/kt25182.fir.kt | 14 + ...lSmartcastOnIntersectionOfNullables.fir.kt | 18 + .../generics/nullability/nullToGeneric.fir.kt | 35 ++ .../nullability/smartCastRefinedClass.fir.kt | 13 + .../generics/nullability/smartCasts.fir.kt | 46 +++ .../nullability/smartCastsOnThis.fir.kt | 36 ++ .../smartCastsValueArgument.fir.kt | 52 +++ .../nullability/tpBoundsViolation.fir.kt | 49 +++ .../tpBoundsViolationVariance.fir.kt | 67 ++++ .../generics/nullability/tpInBounds.fir.kt | 40 ++ .../generics/nullability/useAsReceiver.fir.kt | 27 ++ .../nullability/useAsValueArgument.fir.kt | 18 + .../generics/projectionsScope/MLOut.fir.kt | 18 + .../generics/projectionsScope/addAll.fir.kt | 32 ++ .../approximateDispatchReceiver.fir.kt | 14 + .../extensionReceiverTypeMismatch.fir.kt | 18 + .../extensionResultSubstitution.fir.kt | 13 + .../flexibleProjectedScope.fir.kt | 16 + .../projectionsScope/inValueParameter.fir.kt | 9 + .../iterateOnExtension.fir.kt | 11 + .../generics/projectionsScope/kt7296.fir.kt | 15 + .../generics/projectionsScope/kt8647.fir.kt | 8 + .../projectionsScope/lambdaArgument.fir.kt | 16 + .../leakedApproximatedType.fir.kt | 19 + .../multipleArgumentProjectedOut.fir.kt | 10 + .../platformSuperClass.fir.kt | 23 ++ .../projectedOutConventions.fir.kt | 14 + .../projectedOutSmartCast.fir.kt | 23 ++ .../recursiveUpperBoundStar.fir.kt | 14 + .../recursiveUpperBoundStarOut.fir.kt | 12 + .../projectionsScope/starNullability.fir.kt | 16 + .../starNullabilityRecursive.fir.kt | 9 + .../projectionsScope/superClass.fir.kt | 12 + .../typeMismatchConventions.fir.kt | 20 + .../typeMismatchInLambda.fir.kt | 27 ++ .../typeParameterBounds.fir.kt | 44 +++ .../unsafeVarianceStar.fir.kt | 10 + .../generics/projectionsScope/varargs.fir.kt | 13 + .../tests/generics/protectedSuperCall.fir.kt | 21 + .../tests/generics/recursive.fir.kt | 11 + ...esolveGenericBoundsBeforeSupertypes.fir.kt | 7 + .../generics/sameTypeParameterUse.fir.kt | 15 + .../starProjections/checkBounds.fir.kt | 3 + .../collectionInheritedFromJava.fir.kt | 14 + .../starProjections/inheritedFromJava.fir.kt | 14 + .../inheritedFromKotlin.fir.kt | 9 + .../generics/starProjections/invalid.fir.kt | 28 ++ .../generics/suppressVarianceConflict.fir.kt | 17 + .../tpAsReified/CapturedAsReified.fir.kt | 9 + .../tpAsReified/ClassDereference.fir.kt | 3 + .../generics/tpAsReified/Conventions.fir.kt | 13 + .../GenericArrayAsReifiedArgument.fir.kt | 19 + ...enericArrayAsReifiedArgumentWarning.fir.kt | 19 + .../GenericAsReifiedArgument.fir.kt | 24 ++ .../generics/tpAsReified/InConstructor.fir.kt | 17 + .../generics/tpAsReified/InFunction.fir.kt | 18 + .../generics/tpAsReified/InProperty.fir.kt | 2 + .../tests/generics/tpAsReified/InType.fir.kt | 4 + .../tpAsReified/InlineableReified.fir.kt | 8 + .../generics/tpAsReified/LocalFun.fir.kt | 9 + .../tpAsReified/NotInlineableReified.fir.kt | 4 + .../generics/tpAsReified/ReifiedClass.fir.kt | 3 + .../unresolvedClassifierInWhere.fir.kt | 14 + .../setterNotProjectedOutAssign.fir.kt | 10 + .../setterProjectedOutAssign.fir.kt | 14 + .../setterProjectedOutNoPlusAssign.fir.kt | 11 + ...setterProjectedOutPlusAssignDefined.fir.kt | 13 + .../generics/wildcardInValueParameter.fir.kt | 14 + ...rongNumberOfTypeArgumentsDiagnostic.fir.kt | 16 + .../tests/implicitIntersection.fir.kt | 30 ++ .../tests/implicitNestedIntersection.fir.kt | 24 ++ .../diagnostics/tests/implicitNothing.fir.kt | 52 +++ .../imports/AllUnderImportsAmbiguity.fir.kt | 17 + .../AllUnderImportsLessPriority.fir.kt | 17 + ...UnderImportsSamePriorityForFunction.fir.kt | 19 + ...UnderImportsSamePriorityForProperty.fir.kt | 19 + .../tests/imports/CheckJavaVisibility.fir.kt | 73 ++++ .../tests/imports/CheckJavaVisibility2.fir.kt | 62 +++ .../tests/imports/CheckVisibility.fir.kt | 28 ++ .../tests/imports/ClassClash.fir.kt | 81 ++++ .../tests/imports/ClassClashStarImport.fir.kt | 76 ++++ .../imports/ClassImportsConflicting.fir.kt | 15 + .../CurrentPackageAndAllUnderImport.fir.kt | 16 + .../CurrentPackageAndExplicitImport.fir.kt | 16 + .../imports/DefaultImportsPriority.fir.kt | 6 + .../imports/ExplicitImportsAmbiguity.fir.kt | 17 + ...plicitImportsUnambiguityForFunction.fir.kt | 19 + .../ExplicitPackageImportsAmbiguity.fir.kt | 17 + .../tests/imports/ImportClassClash.fir.kt | 48 +++ .../imports/ImportFromCompanionObject.fir.kt | 138 +++++++ .../ImportFromCurrentWithDifferentName.fir.kt | 8 + .../tests/imports/ImportFromObject.fir.kt | 132 +++++++ .../imports/ImportFromRootPackage.fir.kt | 32 ++ ...ImportHidingDefinitionInTheSameFile.fir.kt | 9 + .../ImportNestedWithDifferentName.fir.kt | 10 + .../ImportObjectAndUseAsSupertype.fir.kt | 19 + .../ImportObjectHidesCurrentPackage.fir.kt | 12 + .../imports/ImportOverloadFunctions.fir.kt | 45 +++ .../tests/imports/ImportPrivateMember.fir.kt | 37 ++ .../ImportPrivateMemberFromOtherFile.fir.kt | 26 ++ .../ImportPrivateMembersWithStar.fir.kt | 32 ++ .../tests/imports/ImportProtectedClass.fir.kt | 14 + .../imports/ImportResolutionOrder.fir.kt | 23 ++ .../tests/imports/ImportTwoTimes.fir.kt | 14 + .../tests/imports/ImportTwoTimesStar.fir.kt | 14 + .../diagnostics/tests/imports/Imports.fir.kt | 102 +++++ .../tests/imports/ImportsConflicting.fir.kt | 15 + .../imports/InaccessiblePrivateClass.fir.kt | 18 + .../JavaPackageLocalClassNotImported.fir.kt | 12 + .../tests/imports/MalformedImports.fir.kt | 9 + .../tests/imports/NestedClassClash.fir.kt | 31 ++ .../imports/OperatorRenameOnImport.fir.kt | 16 + .../PackageLocalClassNotImported.fir.kt | 17 + .../PackageLocalClassReferencedError.fir.kt | 11 + .../tests/imports/PackageVsClass.fir.kt | 152 +++++++ .../imports/PrivateClassNotImported.fir.kt | 21 + .../PrivateClassReferencedError.fir.kt | 14 + .../tests/imports/RenameOnImport.fir.kt | 22 ++ .../tests/imports/StarImportFromObject.fir.kt | 47 +++ .../tests/imports/SyntaxError.fir.kt | 60 +++ .../imports/TopLevelClassVsPackage.fir.kt | 68 ++++ .../tests/imports/WrongImport.fir.kt | 78 ++++ .../importFunctionWithAllUnderImport.fir.kt | 13 + ...nWithAllUnderImportAfterNamedImport.fir.kt | 22 ++ .../invisibleFakeReferenceInImport.fir.kt | 16 + .../diagnostics/tests/imports/kt13112.fir.kt | 46 +++ ...ropertyClassFileDependencyRecursion.fir.kt | 17 + .../tests/imports/twoImportLists.fir.kt | 105 +++++ .../NoSenselessComparisonForErrorType.fir.kt | 9 + .../SupertypeOfErrorType.fir.kt | 24 ++ .../incompleteCode/arrayBracketsRange.fir.kt | 9 + .../checkNothingIsSubtype.fir.kt | 16 + .../controlStructuresErrors.fir.kt | 26 ++ .../arrayExpression.fir.kt | 8 + .../checkBackingFieldException.fir.kt | 17 + ...pleteFunctionArgumentsOfNestedCalls.fir.kt | 8 + ...declarationAfterDotSelectorExpected.fir.kt | 29 ++ .../declarationAfterIncompleteElvis.fir.kt | 22 ++ .../funEquals.fir.kt | 1 + .../funKeyword.fir.kt | 1 + .../funcitonTypes.fir.kt | 1 + .../incompleteEnumReference.fir.kt | 11 + .../incompleteVal.fir.kt | 3 + .../incompleteValWithAccessor.fir.kt | 3 + .../incompleteWhen.fir.kt | 3 + .../diagnosticWithSyntaxError/namedFun.fir.kt | 1 + .../noTypeParamsInReturnType.fir.kt | 11 + .../typeReferenceError.fir.kt | 3 + .../valNoName.fir.kt | 43 ++ ...eBeforeNextDeclarationWithModifiers.fir.kt | 15 + .../valWithNoNameInBlock.fir.kt | 50 +++ .../illegalSelectorCallableReference.fir.kt | 8 + .../tests/incompleteCode/inExpr.fir.kt | 5 + .../incompleteAssignment.fir.kt | 30 ++ .../incompleteCode/incompleteEquals.fir.kt | 3 + .../incompleteTryCatchBlock.fir.kt | 14 + .../tests/incompleteCode/kt1955.fir.kt | 8 + .../tests/incompleteCode/kt2014.fir.kt | 20 + .../kt4866UnresolvedArrayAccess.fir.kt | 5 + .../incompleteCode/plusOnTheRight.fir.kt | 11 + .../pseudocodeTraverseNextInstructions.fir.kt | 8 + .../senselessComparisonWithNull.fir.kt | 6 + .../typeParameterOnLhsOfDot.fir.kt | 8 + .../incompleteCode/unresolvedArguments.fir.kt | 13 + .../incompleteCode/unresolvedOperation.fir.kt | 4 + .../variableDeclarationInSelector.fir.kt | 4 + .../NoInferenceFromDeclaredBounds.fir.kt | 12 + .../cannotCompleteResolveAmbiguity.fir.kt | 9 + ...ompleteResolveFunctionLiteralsNoUse.fir.kt | 7 + ...otCompleteResolveNoInfoForParameter.fir.kt | 11 + ...cannotCompleteResolveNoneApplicable.fir.kt | 8 + ...CompleteResolveWithFunctionLiterals.fir.kt | 11 + .../capturedInProjectedFlexibleType.fir.kt | 16 + .../approximateBeforeFixation.fir.kt | 8 + .../cannotCaptureInProjection.fir.kt | 17 + .../captureForNullableTypes.fir.kt | 19 + .../captureForPlatformTypes.fir.kt | 27 ++ .../captureFromNullableTypeVariable.fir.kt | 14 + .../capturedTypes/captureFromSubtyping.fir.kt | 9 + .../captureFromTypeParameterUpperBound.fir.kt | 11 + .../captureTypeOnlyOnTopLevel.fir.kt | 10 + .../capturedTypes/capturedType.fir.kt | 16 + .../capturedTypeAndApproximation.fir.kt | 16 + ...peSubstitutedIntoOppositeProjection.fir.kt | 14 + .../capturedTypeWithInnerTypealias.fir.kt | 12 + ...pturedTypeWithTypeVariableSubtyping.fir.kt | 22 ++ .../expectedTypeMismatchWithInVariance.fir.kt | 10 + .../invokeCallWithCapturedReceiver.fir.kt | 10 + .../inference/capturedTypes/kt25302.fir.kt | 18 + .../inference/capturedTypes/kt2570.fir.kt | 9 + .../inference/capturedTypes/kt2872.fir.kt | 7 + .../memberScopeOfCaptured.fir.kt | 12 + .../noCaptureTypeErrorForNonTopLevel.fir.kt | 19 + .../notApproximateWhenCopyDescriptors.fir.kt | 7 + .../overApproximationForInCaptured.fir.kt | 8 + .../overApproximationForOutCaptured.fir.kt | 8 + ...lailityOnSupertypesWhenCaptureTypes.fir.kt | 23 ++ .../starProjectionRegression.fir.kt | 17 + .../topLevelCapturingInsideReturnType.fir.kt | 11 + .../coerceFunctionLiteralToSuspend.fir.kt | 29 ++ ...ToUnitForIfAsLastExpressionInLambda.fir.kt | 42 ++ ...coercionToUnitForLastLambdaInLambda.fir.kt | 13 + .../coercionWithExpectedType.fir.kt | 26 ++ .../coercionWithExpectedTypeAndBound.fir.kt | 13 + .../coercionWithExplicitTypeArgument.fir.kt | 10 + .../coercionWithoutExpectedType.fir.kt | 19 + .../indirectCoercionWithExpectedType.fir.kt | 36 ++ .../inference/coercionToUnit/kt30242.fir.kt | 64 +++ .../coercionToUnit/noCoercion.fir.kt | 26 ++ ...nOfCoercionToUnitInsideNestedLambda.fir.kt | 52 +++ .../boundOnNullableVariable.fir.kt | 6 + ...ullableChildAndNonParameterizedType.fir.kt | 20 + ...tWithTypeContainingNonFixedVariable.fir.kt | 88 +++++ .../dontCaptureTypeVariable.fir.kt | 11 + .../fixVariablesInRightOrder.fir.kt | 17 + .../genericCandidateInGenericClass.fir.kt | 9 + .../inferenceWithUpperBoundsInLambda.fir.kt | 13 + .../inference/commonSystem/kt30300.fir.kt | 21 + .../inference/commonSystem/kt31969.fir.kt | 12 + .../inference/commonSystem/kt32818.fir.kt | 5 + .../inference/commonSystem/kt33197.fir.kt | 19 + .../commonSystem/kt3372toCollection.fir.kt | 12 + ...eForArgumentCallWithExactAnnotation.fir.kt | 17 + ...rArgumentCallWithExactAnnotation_ni.fir.kt | 17 + .../manyArgumentsForVararg.fir.kt | 178 +++++++++ .../commonSystem/nestedLambdas.fir.kt | 10 + .../nonFixedVariableFromBothBranches.fir.kt | 20 + .../nonFixedVariableInsideFlexibleType.fir.kt | 30 ++ .../outProjectedTypeToOutProjected.fir.kt | 12 + ...tponedCompletionWithExactAnnotation.fir.kt | 28 ++ ...nedCompletionWithExactAnnotation_ni.fir.kt | 39 ++ ...tFromCovariantAndContravariantTypes.fir.kt | 20 + .../selectFromTwoIncompatibleTypes.fir.kt | 24 ++ .../selectIntegerValueTypeFromIf.fir.kt | 8 + .../commonSystem/theSameFunctionInArgs.fir.kt | 6 + .../completeInferenceIfManyFailed.fir.kt | 17 + .../inference/conflictingSubstitutions.fir.kt | 20 + ...FromVariantTypeWithNestedProjection.fir.kt | 16 + .../constraintOnFunctionLiteral.fir.kt | 12 + ...initelyNotNullTypeInvariantPosition.fir.kt | 24 ++ .../earlyCompletionForCalls.fir.kt | 15 + .../equalityConstraintOnNullableType.fir.kt | 19 + .../errorUpperBoundConstraint.fir.kt | 26 ++ ...onstraintEarlierThanComplexVariable.fir.kt | 16 + ...noreConstraintFromImplicitInNothing.fir.kt | 16 + ...inferTypeFromCapturedStarProjection.fir.kt | 5 + .../tests/inference/constraints/kt6320.fir.kt | 21 + ...t7351ConstraintFromUnitExpectedType.fir.kt | 19 + .../tests/inference/constraints/kt7433.fir.kt | 9 + .../tests/inference/constraints/kt8879.fir.kt | 13 + ...anyConstraintsDueToFlexibleRawTypes.fir.kt | 32 ++ ...RecursiveFlexibleTypesWithWildcards.fir.kt | 32 ++ .../notNullConstraintOnNullableType.fir.kt | 25 ++ .../operationsOnIntegerValueTypes.fir.kt | 9 + ...recursiveJavaTypeWithStarProjection.fir.kt | 22 ++ ...aintContainingTypeWithoutProjection.fir.kt | 30 ++ .../constraints/returnLambdaFromLambda.fir.kt | 22 ++ .../subtypeConstraintOnNullableType.fir.kt | 22 ++ .../supertypeConstraintOnNullableType.fir.kt | 22 ++ ...tionWithDefNotNullTypesAndDelegates.fir.kt | 15 + .../inference/dependOnExpectedType.fir.kt | 53 +++ .../inference/dependantOnVariance.fir.kt | 69 ++++ .../dependantOnVarianceNullable.fir.kt | 14 + .../expectedTypeAdditionalTest.fir.kt | 13 + .../expectedTypeDoubleReceiver.fir.kt | 20 + .../inference/expectedTypeFromCast.fir.kt | 21 + ...pectedTypeFromCastComplexExpression.fir.kt | 16 + .../expectedTypeFromCastParenthesized.fir.kt | 22 ++ .../inference/expectedTypeWithGenerics.fir.kt | 18 + .../tests/inference/findViewById.fir.kt | 59 +++ .../inference/fixVariableToNothing.fir.kt | 15 + .../fixationOrderForProperConstraints.fir.kt | 7 + .../flexibleTypesAsUpperBound.fir.kt | 13 + .../inference/functionPlaceholderError.fir.kt | 15 + .../genericAssignmentOperator.fir.kt | 9 + .../hasErrorInConstrainingTypes.fir.kt | 8 + .../tests/inference/immutableArrayList.fir.kt | 17 + ...vokeExtensionWithFunctionalArgument.fir.kt | 29 ++ ...mpanionObjectWithFunctionalArgument.fir.kt | 17 + ...nvokeInObjectWithFunctionalArgument.fir.kt | 15 + ...itInvokeWithFunctionLiteralArgument.fir.kt | 38 ++ .../inference/inferInFunctionLiterals.fir.kt | 12 + .../inferInFunctionLiteralsWithReturn.fir.kt | 12 + ...sectionTypeMultipleBoundsAsReceiver.fir.kt | 13 + .../inference/invokeLambdaAsFunction.fir.kt | 7 + .../inference/knownTypeParameters.fir.kt | 30 ++ .../tests/inference/kt11963.fir.kt | 1 + .../tests/inference/kt12399.fir.kt | 3 + .../diagnostics/tests/inference/kt1293.fir.kt | 12 + .../tests/inference/kt28598.fir.kt | 85 ++++ .../tests/inference/kt28654.fir.kt | 10 + .../tests/inference/kt30405.fir.kt | 16 + .../diagnostics/tests/inference/kt3184.fir.kt | 26 ++ .../tests/inference/kt32415.fir.kt | 9 + .../tests/inference/kt32434.fir.kt | 32 ++ .../diagnostics/tests/inference/kt6175.fir.kt | 49 +++ .../diagnostics/tests/inference/kt619.fir.kt | 4 + ...alInitializerWithAnonymousFunctions.fir.kt | 9 + .../tests/inference/listConstructor.fir.kt | 30 ++ .../localFunctionInsideIfBlock.fir.kt | 10 + .../tests/inference/mapFunction.fir.kt | 35 ++ .../mostSpecificAfterInference.fir.kt | 24 ++ .../inference/nestedCalls/arrayAccess.fir.kt | 11 + .../nestedCalls/binaryExpressions.fir.kt | 72 ++++ .../checkTypesForQualifiedProperties.fir.kt | 9 + ...eteNestedCallsForArraySetExpression.fir.kt | 8 + .../completeNestedCallsInference.fir.kt | 19 + ...leteNestedForVariableAsFunctionCall.fir.kt | 16 + .../nestedCalls/externalTypeParameter.fir.kt | 6 + .../inferenceForNestedBinaryCall.fir.kt | 12 + .../tests/inference/nestedCalls/kt3395.fir.kt | 35 ++ .../nestedCalls/kt3461checkTypes.fir.kt | 15 + .../nestedCalls/makeNullableIfSafeCall.fir.kt | 41 ++ .../nontrivialCallExpression.fir.kt | 18 + .../noInformationForParameter.fir.kt | 15 + ...ancyOnVariableWithTrivialConstraint.fir.kt | 15 + ...erateConstraintWithInnerNothingType.fir.kt | 13 + ...implicitNothingConstraintFromReturn.fir.kt | 15 + .../inference/nothingType/kt24490.fir.kt | 13 + .../inference/nothingType/kt32051.fir.kt | 32 ++ .../inference/nothingType/kt32081.fir.kt | 10 + .../inference/nothingType/kt32207.fir.kt | 15 + .../inference/nothingType/kt32388.fir.kt | 13 + .../lambdaNothingAndExpectedType.fir.kt | 12 + ...ferenceWithIncorporationOfVariables.fir.kt | 12 + .../nothingWithCallableReference.fir.kt | 31 ++ .../platformNothingAsUsefulConstraint.fir.kt | 35 ++ ...leTypeArgumentWithNotNullUpperBound.fir.kt | 11 + .../tests/inference/nullableUpperBound.fir.kt | 9 + .../tests/inference/opposite.fir.kt | 11 + .../possibleCycleOnConstraints.fir.kt | 14 + .../inference/recursiveCalls/kt23531.fir.kt | 19 + .../recursiveLocalFuns/localFactorial.fir.kt | 12 + .../recursiveLocalFuns/recursiveFun.fir.kt | 4 + .../recursiveLocalFuns/recursiveLambda.fir.kt | 6 + .../recursiveLocalFuns/selfCall.fir.kt | 9 + .../tests/inference/recursiveTypes.fir.kt | 15 + .../inference/regressions/compareBy.fir.kt | 9 + .../tests/inference/regressions/kt1029.fir.kt | 17 + .../tests/inference/regressions/kt1031.fir.kt | 21 + .../tests/inference/regressions/kt1127.fir.kt | 10 + .../tests/inference/regressions/kt1145.fir.kt | 15 + .../tests/inference/regressions/kt1358.fir.kt | 12 + .../tests/inference/regressions/kt1410.fir.kt | 26 ++ .../tests/inference/regressions/kt1718.fir.kt | 17 + .../tests/inference/regressions/kt1944.fir.kt | 14 + .../tests/inference/regressions/kt2057.fir.kt | 11 + .../tests/inference/regressions/kt2179.fir.kt | 46 +++ .../tests/inference/regressions/kt2200.fir.kt | 18 + .../tests/inference/regressions/kt2283.fir.kt | 14 + .../tests/inference/regressions/kt2286.fir.kt | 28 ++ .../tests/inference/regressions/kt2294.fir.kt | 18 + .../tests/inference/regressions/kt2320.fir.kt | 13 + .../tests/inference/regressions/kt2324.fir.kt | 35 ++ .../tests/inference/regressions/kt2407.fir.kt | 18 + .../tests/inference/regressions/kt2445.fir.kt | 12 + .../tests/inference/regressions/kt2459.fir.kt | 10 + .../tests/inference/regressions/kt2484.fir.kt | 18 + .../tests/inference/regressions/kt2505.fir.kt | 22 ++ .../tests/inference/regressions/kt2514.fir.kt | 16 + .../tests/inference/regressions/kt2588.fir.kt | 18 + .../tests/inference/regressions/kt2741.fir.kt | 11 + .../tests/inference/regressions/kt2754.fir.kt | 28 ++ .../tests/inference/regressions/kt2838.fir.kt | 19 + .../tests/inference/regressions/kt2841.fir.kt | 15 + .../inference/regressions/kt2841_it.fir.kt | 18 + .../regressions/kt2841_it_this.fir.kt | 19 + .../inference/regressions/kt2841_this.fir.kt | 18 + .../tests/inference/regressions/kt2842.fir.kt | 27 ++ .../tests/inference/regressions/kt2883.fir.kt | 33 ++ .../tests/inference/regressions/kt3007.fir.kt | 43 ++ .../tests/inference/regressions/kt3038.fir.kt | 22 ++ .../tests/inference/regressions/kt3150.fir.kt | 24 ++ .../tests/inference/regressions/kt3174.fir.kt | 12 + .../inference/regressions/kt32862_both.fir.kt | 16 + .../inference/regressions/kt32862_none.fir.kt | 11 + .../tests/inference/regressions/kt3301.fir.kt | 20 + .../tests/inference/regressions/kt3344.fir.kt | 16 + .../inference/regressions/kt34029.fir.kt | 6 + .../inference/regressions/kt34282.fir.kt | 10 + .../tests/inference/regressions/kt3496.fir.kt | 9 + .../inference/regressions/kt3496_2.fir.kt | 11 + .../tests/inference/regressions/kt3559.fir.kt | 10 + .../tests/inference/regressions/kt4420.fir.kt | 10 + .../tests/inference/regressions/kt702.fir.kt | 20 + .../tests/inference/regressions/kt731.fir.kt | 19 + .../tests/inference/regressions/kt742.fir.kt | 13 + .../tests/inference/regressions/kt8132.fir.kt | 11 + .../tests/inference/regressions/kt832.fir.kt | 11 + .../tests/inference/regressions/kt943.fir.kt | 22 ++ .../tests/inference/regressions/kt9461.fir.kt | 17 + .../tests/inference/regressions/kt948.fir.kt | 23 ++ ...tlinFunctionAsSyntheticJavaAccessor.fir.kt | 3 + ...boutUnresolvedReferenceAsUnresolved.fir.kt | 7 + .../ErrorTypeAsGenericParameter.fir.kt | 9 + .../FunctionPlaceholder.fir.kt | 17 + ...oAmbiguityForDifferentFunctionTypes.fir.kt | 16 + ...nnotInferParameterTypeWithInference.fir.kt | 17 + .../inferTypeFromUnresolvedArgument.fir.kt | 13 + ...renceWrongReceiverForManyCandidates.fir.kt | 8 + ...ubtypeForInvariantWithErrorGenerics.fir.kt | 13 + .../typeInferenceFailedOnComponentN.fir.kt | 10 + .../typeInferenceFailedOnIteratorCall.fir.kt | 9 + .../wrongArgumentExtensionFunction.fir.kt | 8 + ...umentPassedToLocalExtensionFunction.fir.kt | 21 + .../delegationAndInference.fir.kt | 14 + ...9returnTypeWithTypealiasSubtitution.fir.kt | 22 ++ ...ithTypealiasSubtitutionOldInference.fir.kt | 22 ++ .../kt6081SubstituteIntoClassCorrectly.fir.kt | 14 + ...CheckTypeArgumentsNotTypeParameters.fir.kt | 10 + .../substitutionIntoAnonymousClass.fir.kt | 25 ++ .../substitutionIntoInnerClass.fir.kt | 22 ++ ...yNumberLowerBoundsBeforeUpperBounds.fir.kt | 6 + .../inference/typeConstructorMismatch.fir.kt | 14 + .../typeInferenceExpectedTypeMismatch.fir.kt | 42 ++ .../typeParameterInConstructor.fir.kt | 5 + ...flictingSubstitutionsFromUpperBound.fir.kt | 12 + .../doNotInferFromBoundsOnly.fir.kt | 68 ++++ .../upperBounds/intersectUpperBounds.fir.kt | 33 ++ .../tests/inference/upperBounds/kt2856.fir.kt | 20 + .../upperBounds/nonNullUpperBound.fir.kt | 13 + .../typeParameterAsUpperBound.fir.kt | 16 + .../useBoundsIfUnknownParameters.fir.kt | 12 + .../useBoundsToInferTypeParamsSimple.fir.kt | 23 ++ .../useFunctionLiteralsToInferType.fir.kt | 16 + .../infos/PropertiesWithBackingFields.fir.kt | 59 +++ .../diagnostics/tests/infos/SmartCasts.fir.kt | 228 +++++++++++ .../tests/inline/anonymousObjects.fir.kt | 12 + .../tests/inline/assignment.fir.kt | 14 + .../inline/binaryExpressions/andOr.fir.kt | 17 + .../binaryExpressions/arrayAccess.fir.kt | 22 ++ .../binaryExpressions/assignment.fir.kt | 30 ++ .../binaryExpressions/comparison.fir.kt | 26 ++ .../binaryExpressions/componentAccess.fir.kt | 18 + .../inline/binaryExpressions/contains.fir.kt | 24 ++ .../binaryExpressions/mathOperations.fir.kt | 34 ++ .../inline/binaryExpressions/rangeTo.fir.kt | 29 ++ .../diagnostics/tests/inline/capture.fir.kt | 51 +++ .../tests/inline/constructor.fir.kt | 7 + .../diagnostics/tests/inline/default.fir.kt | 15 + .../inline/defaultLambdaInlineDisable.fir.kt | 48 +++ .../inline/defaultLambdaInlineSuspend.fir.kt | 10 + .../tests/inline/defaultLambdaInlining.fir.kt | 47 +++ .../tests/inline/extensionOnFunction.fir.kt | 28 ++ .../tests/inline/fromInlineToNoInline.fir.kt | 7 + .../diagnostics/tests/inline/functions.fir.kt | 12 + ...nlineLambdaInDefaultInlineParameter.fir.kt | 58 +++ ...bdaInDefaultInlineParameterDisabled.fir.kt | 61 +++ .../tests/inline/inlineReified.fir.kt | 2 + .../diagnostics/tests/inline/invoke.fir.kt | 26 ++ .../diagnostics/tests/inline/isCheck.fir.kt | 10 + .../diagnostics/tests/inline/kt15410.fir.kt | 10 + .../diagnostics/tests/inline/kt19679.fir.kt | 4 + .../diagnostics/tests/inline/kt4869.fir.kt | 6 + .../diagnostics/tests/inline/labeled.fir.kt | 40 ++ .../tests/inline/lambdaCast.fir.kt | 9 + .../diagnostics/tests/inline/localFun.fir.kt | 4 + .../messagesForUnsupportedInInline.fir.kt | 18 + .../nonLocalReturns/anonymousObjects.fir.kt | 23 ++ .../anonymousObjectsNested.fir.kt | 48 +++ .../nonLocalReturns/explicitReturnType.fir.kt | 41 ++ .../nonLocalReturns/fromOnlyLocal.fir.kt | 8 + .../nonLocalReturns/inlineLambda.fir.kt | 16 + .../nonLocalReturns/labeledReturn.fir.kt | 31 ++ .../nonLocalReturns/lambdaAsGeneric.fir.kt | 13 + .../lambdaAsNonFunction.fir.kt | 11 + ...WithGlobalReturnsInsideOnlyLocalOne.fir.kt | 9 + .../inline/nonLocalReturns/localFun.fir.kt | 15 + .../nonLocalReturns/nestedNonLocals.fir.kt | 41 ++ .../nonLocalReturns/noInlineAnnotation.fir.kt | 10 + .../nonLocalReturns/noInlineLambda.fir.kt | 13 + .../nonLocalReturns/nonInlinedClass.fir.kt | 23 ++ .../onlyLocalReturnLambda.fir.kt | 43 ++ .../onlyLocalReturnLambdaBinaryExpr.fir.kt | 25 ++ .../propertyAccessorsAndConstructor.fir.kt | 24 ++ .../inline/nonLocalReturns/toOnlyLocal.fir.kt | 8 + .../nonPublicMember/inNonPublicClass.fir.kt | 47 +++ .../inNonPublicInnerClass.fir.kt | 36 ++ .../inline/nonPublicMember/inPackage.fir.kt | 27 ++ .../nonPublicMember/inPublicClass.fir.kt | 37 ++ .../inline/nonPublicMember/kt14887.fir.kt | 8 + .../inline/nonPublicMember/localClass.fir.kt | 15 + .../inline/nonPublicMember/localClass2.fir.kt | 13 + .../inline/nonPublicMember/localFun.fir.kt | 11 + .../nonPublicMember/publishedApi.fir.kt | 48 +++ .../inline/nonVirtualMembersWithInline.fir.kt | 47 +++ .../tests/inline/nothingToInline.fir.kt | 29 ++ .../tests/inline/nullabilityOperations.fir.kt | 16 + .../tests/inline/nullableFunction.fir.kt | 21 + .../tests/inline/overrideWithInline.fir.kt | 60 +++ .../tests/inline/parenthesized.fir.kt | 27 ++ .../tests/inline/privateClass.fir.kt | 25 ++ .../tests/inline/propagation.fir.kt | 37 ++ .../tests/inline/property/invoke.fir.kt | 20 + .../property/propertyWithBackingField.fir.kt | 21 + .../property/unsupportedConstruction.fir.kt | 20 + .../inline/property/virtualProperty.fir.kt | 38 ++ .../inline/protectedCallDepecation.fir.kt | 102 +++++ .../tests/inline/protectedCallError.fir.kt | 102 +++++ .../tests/inline/publishedApi.fir.kt | 175 +++++++++ .../diagnostics/tests/inline/recursion.fir.kt | 24 ++ .../tests/inline/regressions/kt4341.fir.kt | 6 + .../diagnostics/tests/inline/returns.fir.kt | 20 + .../diagnostics/tests/inline/sam.fir.kt | 58 +++ .../tests/inline/stringTemplate.fir.kt | 10 + .../unaryExpressions/mathOperation.fir.kt | 35 ++ .../inline/unaryExpressions/notOnCall.fir.kt | 3 + .../unaryExpressions/notOperation.fir.kt | 21 + .../inline/unsupportedConstruction.fir.kt | 33 ++ .../diagnostics/tests/inline/vararg.fir.kt | 16 + .../diagnostics/tests/inline/when.fir.kt | 11 + .../tests/inline/wrongUsage.fir.kt | 51 +++ .../basicInlineClassDeclaration.fir.kt | 8 + ...basicInlineClassDeclarationDisabled.fir.kt | 10 + .../constructorsJvmSignaturesClash.fir.kt | 18 + .../delegatedPropertyInInlineClass.fir.kt | 28 ++ .../functionsJvmSignaturesClash.fir.kt | 37 ++ ...sJvmSignaturesConflictOnInheritance.fir.kt | 14 + ...identityComparisonWithInlineClasses.fir.kt | 15 + ...lineClassCanOnlyImplementInterfaces.fir.kt | 13 + ...annotImplementInterfaceByDelegation.fir.kt | 9 + ...onstructorParameterWithDefaultValue.fir.kt | 3 + .../inlineClassDeclarationCheck.fir.kt | 33 ++ .../inlineClassImplementsCollection.fir.kt | 12 + ...ineClassWithForbiddenUnderlyingType.fir.kt | 16 + .../inlineClassesInsideAnnotations.fir.kt | 12 + .../lateinitInlineClasses.fir.kt | 10 + ...OfInitializerBlockInsideInlineClass.fir.kt | 10 + ...licPrimaryConstructorForInlineClass.fir.kt | 7 + ...sWithBackingFieldsInsideInlineClass.fir.kt | 34 ++ .../recursiveInlineClasses.fir.kt | 21 + ...mbersAndConstructsInsideInlineClass.fir.kt | 45 +++ ...dLiteralsWithoutArtifactOnClasspath.fir.kt | 3 + ...arargsOnParametersOfInlineClassType.fir.kt | 21 + .../tests/inner/InnerClassNameClash.fir.kt | 10 + .../inner/accessingToJavaNestedClass.fir.kt | 64 +++ .../inner/accessingToKotlinNestedClass.fir.kt | 44 +++ .../tests/inner/annotationInInnerClass.fir.kt | 5 + .../inner/classesInClassObjectHeader.fir.kt | 11 + .../tests/inner/constructorAccess.fir.kt | 32 ++ .../tests/inner/deepInnerClass.fir.kt | 14 + .../tests/inner/enumEntries.fir.kt | 12 + .../tests/inner/enumInInnerClass.fir.kt | 5 + .../tests/inner/extensionFun.fir.kt | 28 ++ .../extensionLambdaInsideNestedClass.fir.kt | 27 ++ .../tests/inner/illegalModifier.fir.kt | 45 +++ .../tests/inner/illegalModifier_lv12.fir.kt | 45 +++ ...rClassInEnumEntryClassMemberResolve.fir.kt | 13 + .../innerClassInEnumEntryClass_lv11.fir.kt | 19 + .../innerClassInEnumEntryClass_lv12.fir.kt | 19 + .../innerClassInEnumEntryClass_lv13.fir.kt | 19 + .../innerClassesInStaticParameters.fir.kt | 11 + .../innerConstructorsFromQualifiers.fir.kt | 36 ++ ...omQualifiersWithIrrelevantCandidate.fir.kt | 43 ++ .../inner/innerErrorForClassObjects.fir.kt | 26 ++ .../tests/inner/innerErrorForObjects.fir.kt | 27 ++ .../tests/inner/innerThisSuper.fir.kt | 22 ++ .../tests/inner/interfaceInInnerClass.fir.kt | 5 + .../diagnostics/tests/inner/kt5854.fir.kt | 11 + .../diagnostics/tests/inner/kt6026.fir.kt | 8 + .../diagnostics/tests/inner/localClass.fir.kt | 18 + .../tests/inner/localClassInsideNested.fir.kt | 11 + .../tests/inner/localThisSuper.fir.kt | 23 ++ .../diagnostics/tests/inner/modality.fir.kt | 17 + ...edClassAccessedViaInstanceReference.fir.kt | 53 +++ .../inner/nestedClassExtendsOuter.fir.kt | 8 + .../nestedClassExtendsOuterGeneric.fir.kt | 12 + .../tests/inner/nestedClassInObject.fir.kt | 16 + .../inner/nestedClassNotAllowed_after.fir.kt | 26 ++ .../inner/nestedClassNotAllowed_before.fir.kt | 26 ++ .../tests/inner/nestedObject.fir.kt | 12 + .../nestedVsInnerAccessOuterMember.fir.kt | 27 ++ .../tests/inner/outerGenericParam.fir.kt | 13 + .../tests/inner/outerProtectedMember.fir.kt | 13 + .../tests/inner/outerSuperClassMember.fir.kt | 9 + .../classObjectOfNestedClass.fir.kt | 14 + .../constructNestedClass.fir.kt | 17 + .../dataLocalVariable.fir.kt | 5 + .../qualifiedExpression/enumConstant.fir.kt | 7 + .../genericNestedClass.fir.kt | 10 + .../importNestedClass.fir.kt | 17 + .../nestedClassInPackage.fir.kt | 8 + .../nestedEnumConstant.fir.kt | 9 + .../qualifiedExpression/nestedObjects.fir.kt | 7 + .../qualifiedExpression/typePosition.fir.kt | 11 + .../tests/inner/referenceToSelfInLocal.fir.kt | 30 ++ .../inner/resolvePackageClassInObjects.fir.kt | 9 + .../inner/selfAnnotationForClassObject.fir.kt | 9 + .../diagnostics/tests/inner/traits.fir.kt | 11 + .../diagnostics/tests/inner/visibility.fir.kt | 34 ++ .../tests/j+k/GenericsInSupertypes.fir.kt | 49 +++ .../tests/j+k/InheritedGenericFunction.fir.kt | 30 ++ .../tests/j+k/InnerClassFromJava.fir.kt | 16 + .../tests/j+k/KJKInheritance.fir.kt | 18 + .../tests/j+k/KJKInheritanceGeneric.fir.kt | 17 + .../tests/j+k/OverrideVararg.fir.kt | 12 + .../diagnostics/tests/j+k/Simple.fir.kt | 11 + .../j+k/StaticMembersFromSuperclasses.fir.kt | 16 + ...ntsNullability-NotNull-SpecialTypes.fir.kt | 23 ++ ...umentsNullability-NotNull-UserTypes.fir.kt | 23 ++ ...peArgumentsNullability-SpecialTypes.fir.kt | 20 + ...rtypeArgumentsNullability-UserTypes.fir.kt | 20 + .../tests/j+k/UnboxingNulls.fir.kt | 13 + .../j+k/accessClassObjectFromJava.fir.kt | 10 + .../tests/j+k/ambiguousSamAdapters.fir.kt | 17 + ...ionWithArgumentsMissingDependencies.fir.kt | 12 + .../tests/j+k/annotationsInheritance.fir.kt | 19 + .../tests/j+k/arrayOfStarParametrized.fir.kt | 14 + .../j+k/brokenCode/classDuplicates.fir.kt | 13 + .../j+k/brokenCode/fieldDuplicates.fir.kt | 13 + ...callableReferencesStaticMemberClash.fir.kt | 16 + .../canDeclareIfSamAdapterIsInherited.fir.kt | 11 + .../j+k/collectionOverrides/charBuffer.fir.kt | 22 ++ .../collectionStringImpl.fir.kt | 85 ++++ .../commonCollections.fir.kt | 28 ++ .../j+k/collectionOverrides/contains.fir.kt | 66 ++++ .../collectionOverrides/containsAll.fir.kt | 56 +++ .../containsAndOverload.fir.kt | 24 ++ .../getCharSequence.fir.kt | 30 ++ .../irrelevantCharAtAbstract.fir.kt | 19 + .../irrelevantImplCharSequence.fir.kt | 25 ++ .../irrelevantImplCharSequenceKotlin.fir.kt | 28 ++ .../irrelevantImplMutableList.fir.kt | 119 ++++++ .../irrelevantImplMutableListKotlin.fir.kt | 106 +++++ .../irrelevantMapGetAbstract.fir.kt | 19 + .../collectionOverrides/mapGetOverride.fir.kt | 14 + .../overridesBuiltinNoMagic.fir.kt | 163 ++++++++ .../j+k/collectionOverrides/removeAt.fir.kt | 23 ++ .../collectionOverrides/removeAtInt.fir.kt | 23 ++ .../sizeFromKotlinOverriddenInJava.fir.kt | 13 + .../tests/j+k/collectorInference.fir.kt | 14 + .../j+k/computeIfAbsentConcurrent.fir.kt | 22 ++ .../tests/j+k/contravariantIterable.fir.kt | 20 + .../tests/j+k/defaultMethods.fir.kt | 166 ++++++++ .../defaultMethodsIndirectInheritance.fir.kt | 79 ++++ .../tests/j+k/defaultMethods_warning.fir.kt | 168 ++++++++ .../j+k/deprecations/forFakeOverrides.fir.kt | 36 ++ .../j+k/deprecations/forMixedOverride.fir.kt | 27 ++ .../j+k/deprecations/forOverrides.fir.kt | 23 ++ .../tests/j+k/differentFilename.fir.kt | 26 ++ .../tests/j+k/enumGetOrdinal.fir.kt | 12 + .../tests/j+k/exceptionMessage.fir.kt | 20 + .../tests/j+k/fieldOverridesField.fir.kt | 17 + .../fieldOverridesFieldOfDifferentType.fir.kt | 19 + .../tests/j+k/fieldOverridesNothing.fir.kt | 19 + .../tests/j+k/finalCollectionSize.fir.kt | 12 + .../tests/j+k/flexibleNothing.fir.kt | 19 + ...ssTypeParameterInferredFromArgument.fir.kt | 17 + .../j+k/genericConstructor/innerClass.fir.kt | 18 + .../noClassTypeParameters.fir.kt | 18 + .../noClassTypeParametersInvParameter.fir.kt | 21 + .../j+k/genericConstructor/recursive.fir.kt | 12 + .../j+k/genericConstructor/selfTypes.fir.kt | 19 + .../j+k/genericConstructor/superCall.fir.kt | 18 + .../superCallImpossibleToInfer.fir.kt | 21 + .../withClassTypeParameters.fir.kt | 19 + ...enericConstructorWithMultipleBounds.fir.kt | 18 + .../j+k/inheritAbstractSamAdapter.fir.kt | 18 + ...nheritanceStaticMethodFromInterface.fir.kt | 32 ++ .../tests/j+k/innerNestedClassFromJava.fir.kt | 32 ++ ...isiblePackagePrivateInheritedMember.fir.kt | 23 ++ .../tests/j+k/javaStaticImport.fir.kt | 37 ++ .../diagnostics/tests/j+k/kt1402.fir.kt | 26 ++ .../diagnostics/tests/j+k/kt1431.fir.kt | 17 + .../j+k/kt1730_implementCharSequence.fir.kt | 24 ++ .../diagnostics/tests/j+k/kt2152.fir.kt | 10 + .../diagnostics/tests/j+k/kt2394.fir.kt | 15 + .../diagnostics/tests/j+k/kt2606.fir.kt | 11 + .../diagnostics/tests/j+k/kt2619.fir.kt | 15 + .../diagnostics/tests/j+k/kt2641.fir.kt | 18 + .../diagnostics/tests/j+k/kt2890.fir.kt | 20 + .../diagnostics/tests/j+k/kt3307.fir.kt | 21 + .../diagnostics/tests/j+k/kt3311.fir.kt | 19 + .../tests/j+k/kt6720_abstractProperty.fir.kt | 18 + .../diagnostics/tests/j+k/kt7523.fir.kt | 14 + .../diagnostics/tests/j+k/matchers.fir.kt | 18 + .../tests/j+k/mutableIterator.fir.kt | 29 ++ .../tests/j+k/nullForOptionalOrElse.fir.kt | 9 + .../tests/j+k/overrideRawType.fir.kt | 15 + .../overrideWithSamAndTypeParameter.fir.kt | 22 ++ .../packagePrivateClassStaticMember.fir.kt | 17 + .../tests/j+k/packageVisibility.fir.kt | 44 +++ .../j+k/primitiveOverrides/kt11140.fir.kt | 24 ++ .../notNullAnnotated.fir.kt | 22 ++ .../primitiveOverrides/specializedMap.fir.kt | 113 ++++++ .../inlineClassErasedToPrimitiveInt.fir.kt | 29 ++ .../j+k/privateFieldOverridesNothing.fir.kt | 19 + .../j+k/privateNestedClassStaticMember.fir.kt | 18 + .../tests/j+k/properties/interface.fir.kt | 32 ++ .../tests/j+k/properties/isName.fir.kt | 27 ++ .../tests/j+k/properties/val.fir.kt | 25 ++ .../tests/j+k/properties/var.fir.kt | 42 ++ .../j+k/protectedStaticSamePackage.fir.kt | 20 + .../recursionWithJavaSyntheticProperty.fir.kt | 12 + .../tests/j+k/recursiveRawUpperBound.fir.kt | 13 + .../tests/j+k/recursiveRawUpperBound2.fir.kt | 8 + .../tests/j+k/recursiveRawUpperBound3.fir.kt | 8 + .../j+k/sam/enhancedSamConstructor.fir.kt | 28 ++ .../fakeOverrideFunctionForStaticSam.fir.kt | 20 + .../tests/j+k/sam/inheritedStaticSam.fir.kt | 13 + ...privateCandidatesWithWrongArguments.fir.kt | 21 + .../j+k/sam/recursiveSamsAndInvoke.fir.kt | 28 ++ .../tests/j+k/sam/samOnTypeParameter.fir.kt | 17 + .../sam/staticSamFromImportWithStar.fir.kt | 17 + .../sam/staticSamWithExplicitImport.fir.kt | 17 + .../j+k/sam/typeInferenceOnSamAdapters.fir.kt | 19 + .../tests/j+k/sam/withDefaultMethods.fir.kt | 22 ++ .../genericInReturnType.fir.kt | 53 +++ .../genericInValueParameter.fir.kt | 32 ++ .../genericSuperWildcard.fir.kt | 25 ++ ...AdapterBecuaseOfRecursiveUpperBound.fir.kt | 28 ++ .../starProjectionComplexUpperBound.fir.kt | 33 ++ .../j+k/samInConstructorWithGenerics.fir.kt | 23 ++ .../tests/j+k/samWithConsumer.fir.kt | 23 ++ .../tests/j+k/selectMoreSpecific.fir.kt | 16 + .../diagnostics/tests/j+k/serializable.fir.kt | 60 +++ .../j+k/shadowingPrimitiveStaticField.fir.kt | 24 ++ .../signatureAnnotations/defaultEnum.fir.kt | 67 ++++ .../defaultLongLiteral.fir.kt | 49 +++ .../signatureAnnotations/defaultNull.fir.kt | 31 ++ .../defaultNullAndParameter.fir.kt | 57 +++ .../defaultParameter.fir.kt | 45 +++ .../emptyParameterName.fir.kt | 27 ++ .../notNullVarargOverride.fir.kt | 22 ++ .../nullableVarargOverride.fir.kt | 22 ++ .../overridesDefaultValue.fir.kt | 100 +++++ .../overridesParameterName.fir.kt | 98 +++++ .../reorderedParameterNames.fir.kt | 17 + .../sameParameterName.fir.kt | 17 + .../specialCharsParameterName.fir.kt | 24 ++ .../stableParameterName.fir.kt | 20 + .../staticMethodWithDefaultValue.fir.kt | 17 + .../tests/j+k/specialBridges.fir.kt | 7 + .../hashtableInheritance.fir.kt | 6 + .../specialBuiltIns/securityProvider.fir.kt | 5 + .../tests/j+k/staticMethodInClass.fir.kt | 16 + .../tests/j+k/traitDefaultCall.fir.kt | 41 ++ .../j+k/typeAliasWithSamConstructor.fir.kt | 18 + .../tests/j+k/types/arrayList.fir.kt | 15 + .../tests/j+k/types/returnCollection.fir.kt | 13 + .../shapeMismatchInCovariantPosition.fir.kt | 19 + ...eMismatchInCovariantPositionGeneric.fir.kt | 19 + .../tests/j+k/types/typeParameter.fir.kt | 11 + .../tests/j+k/wrongVarianceInJava.fir.kt | 24 ++ ...stractBaseClassMemberNotImplemented.fir.kt | 9 + .../java8Overrides/abstractVsAbstract.fir.kt | 13 + .../java8Overrides/defaultVsAbstract.fir.kt | 13 + .../java8Overrides/hidingMethodOfAny.fir.kt | 5 + .../implementingMethodOfAny.fir.kt | 9 + .../java8Overrides/notAMethodOfAny.fir.kt | 3 + .../overridingMethodOfAnyChain.fir.kt | 13 + .../overridingMethodOfAnyDiamond.fir.kt | 11 + .../singleRelevantDefault.fir.kt | 9 + .../testData/diagnostics/tests/kt13401.fir.kt | 18 + .../testData/diagnostics/tests/kt310.fir.kt | 5 + .../testData/diagnostics/tests/kt435.fir.kt | 7 + .../testData/diagnostics/tests/kt53.fir.kt | 6 + .../automaticLabelFromInfixOperator.fir.kt | 17 + .../diagnostics/tests/labels/kt1703.fir.kt | 15 + .../diagnostics/tests/labels/kt361.fir.kt | 11 + .../diagnostics/tests/labels/kt3920.fir.kt | 9 + .../diagnostics/tests/labels/kt3988.fir.kt | 21 + .../diagnostics/tests/labels/kt4247.fir.kt | 11 + .../diagnostics/tests/labels/kt4586.fir.kt | 17 + .../diagnostics/tests/labels/kt4603.fir.kt | 12 + .../diagnostics/tests/labels/kt591.fir.kt | 11 + ...elReferencesInsideObjectExpressions.fir.kt | 27 ++ .../labels/labeledFunctionLiteral.fir.kt | 17 + .../tests/labels/labelsMustBeNamed.fir.kt | 36 ++ .../local/inapplicableLateinitModifier.fir.kt | 18 + .../tests/lateinit/local/localLateinit.fir.kt | 7 + .../tests/lateinit/local/uninitialized.fir.kt | 24 ++ .../lateinit/modifierApplicability.fir.kt | 71 ++++ .../modifierApplicability_lv12.fir.kt | 71 ++++ .../diagnostics/tests/lateinit/setter.fir.kt | 22 ++ .../tests/library/Collections.fir.kt | 111 ++++++ .../diagnostics/tests/library/kt828.fir.kt | 12 + .../localClasses/localAnnotationClass.fir.kt | 9 + .../localAnnotationClassError.fir.kt | 9 + .../diagnostics/tests/localInterfaces.fir.kt | 14 + .../tests/modifiers/IllegalModifiers.fir.kt | 163 ++++++++ .../tests/modifiers/NoLocalVisibility.fir.kt | 6 + .../tests/modifiers/annotations.fir.kt | 12 + .../modifiers/const/applicability.fir.kt | 110 ++++++ .../arrayInAnnotationArgumentType.fir.kt | 3 + .../modifiers/const/constInteraction.fir.kt | 18 + .../tests/modifiers/const/fromJava.fir.kt | 26 ++ .../modifiers/const/fromJavaSubclass.fir.kt | 15 + .../tests/modifiers/const/kt12248.fir.kt | 19 + .../tests/modifiers/const/kt15913.fir.kt | 19 + .../const/noDivisionByZeroFeature.fir.kt | 21 + .../tests/modifiers/const/types.fir.kt | 17 + .../tests/modifiers/defaultModifier.fir.kt | 55 +++ .../incompatibleVarianceModifiers.fir.kt | 23 ++ .../tests/modifiers/inlineParameters.fir.kt | 20 + .../modifiers/internalInInterface.fir.kt | 7 + .../modifierOnParameterInFunctionType.fir.kt | 52 +++ .../tests/modifiers/openInInterface.fir.kt | 10 + .../operatorInfix/LocalFunctions.fir.kt | 39 ++ .../operatorInfix/MemberFunctions.fir.kt | 45 +++ .../modifiers/operatorInfix/Simple.fir.kt | 45 +++ .../primaryConstructorMissingBrackets.fir.kt | 2 + .../primaryConstructorMissingKeyword.fir.kt | 9 + .../tests/modifiers/privateInInterface.fir.kt | 12 + .../tests/modifiers/protected.fir.kt | 21 + .../tests/modifiers/redundantTargets.fir.kt | 10 + .../tests/modifiers/repeatedModifiers.fir.kt | 41 ++ .../collectionMethodStub.fir.kt | 21 + .../differentGenericArguments.fir.kt | 29 ++ .../differentGenericArgumentsReversed.fir.kt | 29 ++ .../duplicateClass/duplicateClass.fir.kt | 32 ++ .../duplicateNestedClasses.fir.kt | 68 ++++ .../duplicateClass/duplicateSuperClass.fir.kt | 30 ++ .../genericArgumentNumberMismatch.fir.kt | 30 ++ .../duplicateClass/genericSuperClass.fir.kt | 42 ++ .../inTheSameModuleWithUsage.fir.kt | 23 ++ ...SameModuleWithUsageNoTypeAnnotation.fir.kt | 23 ++ .../multimodule/duplicateClass/members.fir.kt | 38 ++ .../sameClassNameDifferentPackages.fir.kt | 22 ++ .../sameGenericArguments.fir.kt | 29 ++ .../classGenericsInParams.fir.kt | 36 ++ .../classGenericsInParamsBoundMismatch.fir.kt | 38 ++ .../classGenericsInParamsIndexMismatch.fir.kt | 34 ++ .../classGenericsInParamsNameMismatch.fir.kt | 36 ++ .../classGenericsInReturnType.fir.kt | 36 ++ ...sVsFunctionGenericsInParamsMismatch.fir.kt | 37 ++ .../covariantReturnTypes.fir.kt | 36 ++ .../differenceInParamNames.fir.kt | 36 ++ .../differentGenericsInParams.fir.kt | 43 ++ .../differentNumberOfParams.fir.kt | 34 ++ .../differentReturnTypes.fir.kt | 36 ++ .../duplicateMethod/extensionMatch.fir.kt | 36 ++ .../functionGenericsInParams.fir.kt | 42 ++ ...ctionGenericsInParamsBoundsMismatch.fir.kt | 40 ++ .../functionGenericsInParamsEqNull.fir.kt | 52 +++ .../functionGenericsInParamsNotIs.fir.kt | 40 ++ .../functionGenericsInParamsReturnFooT.fir.kt | 44 +++ .../functionGenericsInParamsReturnT.fir.kt | 40 ++ .../incompleteCodeNoNoneApplicable.fir.kt | 20 + .../duplicateMethod/noGenericsInParams.fir.kt | 35 ++ .../duplicateMethod/noParams.fir.kt | 36 ++ .../sameGenericsInParams.fir.kt | 43 ++ .../simpleWithInheritance.fir.kt | 38 ++ .../duplicateMethod/sinceKotlin.fir.kt | 34 ++ .../substitutedGenericInParams.fir.kt | 34 ++ .../differentSuperTraits.fir.kt | 31 ++ .../duplicateSuper/sameSuperTrait.fir.kt | 26 ++ .../sameSuperTraitDifferentBounds.fir.kt | 29 ++ .../sameSuperTraitGenerics.fir.kt | 26 ++ .../deprecatedHiddenImportPriority.fir.kt | 37 ++ .../deprecatedHiddenMultipleClasses.fir.kt | 46 +++ .../sinceKotlinImportPriority.fir.kt | 38 ++ .../sinceKotlinMultipleClasses.fir.kt | 47 +++ .../tests/multimodule/internal.fir.kt | 35 ++ .../tests/multimodule/kt14249.fir.kt | 20 + .../tests/multimodule/packagePrivate.fir.kt | 19 + .../multimodule/publishedApiInternal.fir.kt | 56 +++ .../multimodule/redundantElseInWhen.fir.kt | 45 +++ .../tests/multimodule/varargConflict.fir.kt | 26 ++ .../annotationArgumentEquality.fir.kt | 89 +++++ .../defaultArguments/annotations.fir.kt | 33 ++ .../annotationsViaActualTypeAlias.fir.kt | 64 +++ .../annotationsViaActualTypeAlias2.fir.kt | 79 ++++ .../defaultArguments/constructor.fir.kt | 23 ++ .../expectedDeclaresDefaultArguments.fir.kt | 41 ++ .../expectedInheritsDefaultArguments.fir.kt | 37 ++ .../expectedVsNonExpectedWithDefaults.fir.kt | 17 + .../multiplatform/deprecated/header.fir.kt | 30 ++ .../enum/additionalEntriesInImpl.fir.kt | 10 + .../enum/constructorInHeaderEnum.fir.kt | 15 + .../enum/differentEntryOrder.fir.kt | 10 + .../enum/enumEntryWithBody.fir.kt | 11 + .../tests/multiplatform/enum/javaEnum.fir.kt | 32 ++ .../multiplatform/enum/simpleEnum.fir.kt | 16 + .../functionTypeParameterBounds.fir.kt | 12 + .../generic/genericMemberBounds.fir.kt | 25 ++ .../generic/membersInGenericClass.fir.kt | 18 + ...erBoundsDifferentOrderActualMissing.fir.kt | 13 + ...faultValuesInAnnotationViaTypealias.fir.kt | 48 +++ ...ctualClassWithDifferentConstructors.fir.kt | 55 +++ .../headerClass/actualMissing.fir.kt | 14 + .../baseExpectClassWithoutConstructor.fir.kt | 13 + .../headerClass/classKinds.fir.kt | 26 ++ ...ideMethodsFromInterfaceInCommonCode.fir.kt | 28 ++ ...pectClassWithExplicitAbstractMember.fir.kt | 23 ++ .../expectClassWithoutConstructor.fir.kt | 25 ++ ...larationWithStrongIncompatibilities.fir.kt | 33 ++ ...eclarationWithWeakIncompatibilities.fir.kt | 28 ++ .../headerClass/expectFinalActualOpen.fir.kt | 27 ++ .../explicitConstructorDelegation.fir.kt | 14 + ...tendExpectedClassWithAbstractMember.fir.kt | 62 +++ ...lassWithoutExplicitOverrideOfMethod.fir.kt | 36 ++ .../headerClass/extraHeaderOnMembers.fir.kt | 14 + .../functionAndPropertyWithSameName.fir.kt | 15 + .../genericClassImplTypeAlias.fir.kt | 31 ++ .../headerClass/headerClassMember.fir.kt | 24 ++ .../headerClassWithFunctionBody.fir.kt | 27 ++ .../headerClass/implDataClass.fir.kt | 32 ++ .../headerClass/implOpenClass.fir.kt | 18 + ...nheritanceByDelegationInExpectClass.fir.kt | 10 + .../headerClass/memberPropertyKinds.fir.kt | 31 ++ ...CheckForExplicitAndImplicitOverride.fir.kt | 35 ++ .../morePermissiveVisibilityOnActual.fir.kt | 39 ++ ...ssiveVisibilityOnActualViaTypeAlias.fir.kt | 22 ++ .../headerClass/nestedClasses.fir.kt | 58 +++ .../nestedClassesWithErrors.fir.kt | 46 +++ .../headerClass/noImplKeywordOnMember.fir.kt | 14 + .../headerClass/privateMembers.fir.kt | 22 ++ .../headerClass/simpleHeaderClass.fir.kt | 12 + .../headerClass/smartCastOnExpectClass.fir.kt | 13 + .../headerClass/superClass.fir.kt | 23 ++ .../headerFunInNonHeaderClass.fir.kt | 10 + .../multiplatform/implDelegatedMember.fir.kt | 19 + .../tests/multiplatform/implDynamic.fir.kt | 29 ++ .../multiplatform/implFakeOverride.fir.kt | 16 + .../tests/multiplatform/incompatibles.fir.kt | 13 + .../expectActualInlineClass.fir.kt | 28 ++ .../multiplatform/java/flexibleTypes.fir.kt | 32 ++ .../multiplatform/java/parameterNames.fir.kt | 18 + .../modifierApplicability.fir.kt | 35 ++ .../tests/multiplatform/namedArguments.fir.kt | 37 ++ .../privateTopLevelDeclarations.fir.kt | 18 + .../multiplatform/sealedTypeAlias.fir.kt | 17 + .../sealedTypeAliasTopLevel.fir.kt | 16 + .../topLevelFun/callHeaderFun.fir.kt | 25 ++ .../callableReferenceOnExpectFun.fir.kt | 21 + .../conflictingHeaderDeclarations.fir.kt | 8 + .../conflictingImplDeclarations.fir.kt | 17 + .../topLevelFun/functionModifiers.fir.kt | 19 + .../headerAndImplInDIfferentPackages.fir.kt | 18 + .../headerDeclarationWithBody.fir.kt | 9 + .../topLevelFun/headerWithoutImpl.fir.kt | 5 + .../implDeclarationWithoutBody.fir.kt | 12 + .../topLevelFun/implWithoutHeader.fir.kt | 5 + .../topLevelFun/inlineFun.fir.kt | 18 + .../topLevelFun/simpleHeaderFun.fir.kt | 12 + .../valueParameterModifiers.fir.kt | 27 ++ .../differentKindsOfProperties.fir.kt | 40 ++ .../topLevelProperty/simpleHeaderVar.fir.kt | 12 + .../allowForJavaAnnotation.fir.kt | 12 + .../ambiguousNamedArguments1.fir.kt | 27 ++ .../ambiguousNamedArguments2.fir.kt | 24 ++ ...mbiguousNamedArgumentsWithGenerics1.fir.kt | 15 + ...mbiguousNamedArgumentsWithGenerics2.fir.kt | 15 + ...mbiguousNamedArgumentsWithGenerics3.fir.kt | 15 + .../disallowForJavaConstructor.fir.kt | 9 + .../disallowForJavaMethods.fir.kt | 27 ++ .../disallowForSamAdapterConstructor.fir.kt | 17 + .../disallowForSamAdapterFunction.fir.kt | 17 + .../mixedNamedPosition/defaults.fir.kt | 28 ++ .../mixedNamedPosition/disabledFeature.fir.kt | 20 + .../mixedNamedPosition/oldInference.fir.kt | 20 + .../mixedNamedPosition/simple.fir.kt | 20 + .../mixedNamedPosition/varargs.fir.kt | 57 +++ .../namedArgumentsAndDefaultValues.fir.kt | 27 ++ .../namedArgumentsInOverloads.fir.kt | 14 + .../namedArgumentsInOverrides.fir.kt | 22 ++ .../AssertNotNull.fir.kt | 39 ++ .../InfixCallNullability.fir.kt | 41 ++ .../NullableNothingIsExactlyNull.fir.kt | 8 + .../PreferExtensionsOnNullableReceiver.fir.kt | 9 + .../QualifiedExpressionNullability.fir.kt | 30 ++ .../ReceiverNullability.fir.kt | 44 +++ .../SenselessNullInWhen.fir.kt | 10 + .../dataFlowInfoAfterExclExcl.fir.kt | 8 + .../equalityUnderNotNullCheck.fir.kt | 5 + .../funcLiteralArgsInsideAmbiguity.fir.kt | 14 + ...LiteralArgsInsideUnresolvedFunction.fir.kt | 10 + .../nullabilityAndSmartCasts/kt1270.fir.kt | 13 + .../nullabilityAndSmartCasts/kt1680.fir.kt | 14 + .../nullabilityAndSmartCasts/kt1778.fir.kt | 12 + .../nullabilityAndSmartCasts/kt2109.fir.kt | 20 + .../nullabilityAndSmartCasts/kt2125.fir.kt | 12 + .../nullabilityAndSmartCasts/kt2146.fir.kt | 55 +++ .../nullabilityAndSmartCasts/kt2164.fir.kt | 39 ++ .../nullabilityAndSmartCasts/kt2176.fir.kt | 29 ++ .../nullabilityAndSmartCasts/kt2195.fir.kt | 8 + .../nullabilityAndSmartCasts/kt2212.fir.kt | 8 + .../nullabilityAndSmartCasts/kt2216.fir.kt | 22 ++ .../nullabilityAndSmartCasts/kt2223.fir.kt | 8 + .../nullabilityAndSmartCasts/kt2234.fir.kt | 23 ++ .../nullabilityAndSmartCasts/kt2336.fir.kt | 11 + .../nullabilityAndSmartCasts/kt244.fir.kt | 33 ++ .../nullabilityAndSmartCasts/kt30734.fir.kt | 16 + .../nullabilityAndSmartCasts/kt362.fir.kt | 29 ++ .../noSenselessNullOnNullableType.fir.kt | 21 + ...ecessaryNotNullAssertionOnErrorType.fir.kt | 7 + .../notnullTypesFromJavaWithSmartcast.fir.kt | 20 + ...ullableReceiverWithOverloadedMethod.fir.kt | 29 ++ ...sComparisonWithNullOnTypeParameters.fir.kt | 16 + .../smartCastReceiverWithGenerics.fir.kt | 7 + .../smartCastsAndBooleanExpressions.fir.kt | 8 + .../unnecessaryNotNullAssertion.fir.kt | 24 ++ ...rtcastWhenOpenGetterWithOverloading.fir.kt | 15 + ...leSmartcastWithOverloadedExtensions.fir.kt | 14 + .../baseWithNullableUpperBound.fir.kt | 13 + .../tests/nullableTypes/elvisOnUnit.fir.kt | 11 + ...lAssertOnTypeWithNullableUpperBound.fir.kt | 15 + .../nullableArgumentForIn.fir.kt | 3 + ...eArgumentToNonNullParameterPlatform.fir.kt | 18 + ...bleArgumentToNonNullParameterSimple.fir.kt | 13 + .../nullableTypes/redundantNullable.fir.kt | 9 + .../redundantNullableInSupertype.fir.kt | 9 + .../nullableTypes/safeAccessOnUnit.fir.kt | 7 + ...afeCallOnTypeWithNullableUpperBound.fir.kt | 14 + .../nullableTypes/safeCallWithInvoke.fir.kt | 12 + .../tests/nullableTypes/uselessElvis.fir.kt | 48 +++ .../numbers/characterIsNotANumber.fir.kt | 12 + .../numbers/doublesInSimpleConstraints.fir.kt | 23 ++ .../tests/numbers/intValuesOutOfRange.fir.kt | 17 + .../numberAsUnionAndIntersection.fir.kt | 22 ++ .../numbers/numbersInSimpleConstraints.fir.kt | 78 ++++ .../diagnostics/tests/objects/Objects.fir.kt | 29 ++ .../tests/objects/ObjectsInheritance.fir.kt | 5 + .../tests/objects/ObjectsLocal.fir.kt | 25 ++ .../tests/objects/ObjectsNested.fir.kt | 29 ++ .../tests/objects/OpenInObject.fir.kt | 9 + .../tests/objects/invokeOnInnerObject.fir.kt | 12 + .../kt21515/annotationConstructor.fir.kt | 13 + ...ReferenceComplexCasesWithImportsOld.fir.kt | 74 ++++ ...cesComplexCasesWithQualificationOld.fir.kt | 69 ++++ .../kt21515/callableReferencesNew.fir.kt | 142 +++++++ .../kt21515/callableReferencesOld.fir.kt | 142 +++++++ .../callableReferencesOldComplexCases.fir.kt | 69 ++++ ...lableReferencesWithQualificationNew.fir.kt | 142 +++++++ ...lableReferencesWithQualificationOld.fir.kt | 142 +++++++ .../classifierFromCompanionObjectNew.fir.kt | 99 +++++ .../classifierFromCompanionObjectOld.fir.kt | 98 +++++ ...CompanionObjectWithQualificationNew.fir.kt | 99 +++++ ...CompanionObjectWithQualificationOld.fir.kt | 98 +++++ .../classifierIsVisibleByTwoPaths.fir.kt | 17 + .../kt21515/inheritedFromDeprecatedNew.fir.kt | 100 +++++ .../kt21515/inheritedFromDeprecatedOld.fir.kt | 100 +++++ ...dFromDeprecatedWithQualificationNew.fir.kt | 100 +++++ ...dFromDeprecatedWithQualificationOld.fir.kt | 100 +++++ .../objects/kt21515/staticsFromJavaNew.fir.kt | 48 +++ .../objects/kt21515/staticsFromJavaOld.fir.kt | 48 +++ ...staticsFromJavaWithQualificationNew.fir.kt | 53 +++ ...staticsFromJavaWithQualificationOld.fir.kt | 53 +++ .../useDeprecatedConstructorNew.fir.kt | 100 +++++ .../useDeprecatedConstructorOld.fir.kt | 99 +++++ ...atedConstructorWithQualificationNew.fir.kt | 100 +++++ ...atedConstructorWithQualificationOld.fir.kt | 100 +++++ .../diagnostics/tests/objects/kt2240.fir.kt | 13 + .../diagnostics/tests/objects/kt5527.fir.kt | 20 + .../objects/localObjectInsideObject.fir.kt | 11 + .../tests/objects/localObjects.fir.kt | 15 + .../nestedClassInAnonymousObject.fir.kt | 11 + .../tests/objects/objectInsideFun.fir.kt | 11 + ...objectLiteralExpressionTypeMismatch.fir.kt | 9 + .../tests/objects/upperBoundViolated.fir.kt | 9 + ...recatedModAssignOperatorConventions.fir.kt | 43 ++ .../DeprecatedModOperatorConventions.fir.kt | 37 ++ .../deprecatedModConvention.fir.kt | 38 ++ .../doNotResolveToInapplicableRem.fir.kt | 14 + .../operatorRem/errorOnExplicitModCall.fir.kt | 3 + .../forbiddenModOperatorConvention.fir.kt | 32 ++ .../tests/operatorRem/modWithRemAssign.fir.kt | 17 + ...precatedModConventionWithoutFeature.fir.kt | 38 ++ .../operatorRem/noOperatorRemFeature.fir.kt | 36 ++ ...gForModFromBuiltinsWhenApi1_0_after.fir.kt | 48 +++ ...ForModFromBuiltinsWhenApi1_0_before.fir.kt | 48 +++ .../operatorRem/numberRemConversions.fir.kt | 15 + .../tests/operatorRem/operatorRem.fir.kt | 15 + .../preferRemAsExtentionOverMod.fir.kt | 13 + .../preferRemAsMemberOverMod.fir.kt | 13 + ...preferRemFromCompanionObjectOverRem.fir.kt | 16 + .../preferRemOverModInLocalFunctions.fir.kt | 30 ++ .../preferRemWithImplicitReceivers.fir.kt | 20 + .../prefereRemAsExtensionOverMemberMod.fir.kt | 15 + .../remAndRemAssignAmbiguity.fir.kt | 12 + .../operatorRem/remWithModAndModAssign.fir.kt | 17 + .../tests/operatorRem/remWithModAssign.fir.kt | 12 + .../resolveModIfRemIsHidden.fir.kt | 15 + ...esolveToModWhenNoOperatorRemFeature.fir.kt | 39 ++ .../warningOnExplicitModCall1_1.fir.kt | 5 + .../warningOnExplicitModCall1_2.fir.kt | 5 + .../AssignOperatorAmbiguity.fir.kt | 17 + .../AssignmentOperations.fir.kt | 40 ++ .../InconsistentGetSet.fir.kt | 45 +++ .../IteratorAmbiguity.fir.kt | 27 ++ ...assignmentOperationsCheckReturnType.fir.kt | 48 +++ .../compareToNullable.fir.kt | 12 + .../tests/operatorsOverloading/kt1028.fir.kt | 35 ++ .../tests/operatorsOverloading/kt11300.fir.kt | 13 + .../tests/operatorsOverloading/kt13330.fir.kt | 4 + .../tests/operatorsOverloading/kt13349.fir.kt | 7 + .../tests/operatorsOverloading/kt3450.fir.kt | 23 ++ .../plusAssignOnArray.fir.kt | 20 + .../plusAssignOnLocal.fir.kt | 13 + .../plusAssignOnProperty.fir.kt | 19 + ...nflictingOlverloadsGenericFunctions.fir.kt | 34 ++ ...OverloadsFunsDifferentReturnInClass.fir.kt | 6 + ...erloadsFunsDifferentReturnInPackage.fir.kt | 7 + ...gOverloadsIdenticalExtFunsInPackage.fir.kt | 5 + ...ictingOverloadsIdenticalFunsInClass.fir.kt | 7 + ...tingOverloadsIdenticalFunsTPInClass.fir.kt | 4 + ...ictingOverloadsIdenticalValsInClass.fir.kt | 4 + ...ngOverloadsValsDifferentTypeInClass.fir.kt | 4 + .../overload/ConstructorVsFunOverload.fir.kt | 29 ++ .../overload/EmptyArgumentListInLambda.fir.kt | 8 + .../overload/ExtFunDifferentReceiver.fir.kt | 3 + .../FunNoConflictInDifferentPackages.fir.kt | 13 + .../tests/overload/LocalFunctions.fir.kt | 213 ++++++++++ .../overload/OverloadFunRegularAndExt.fir.kt | 7 + .../overload/OverloadVarAndFunInClass.fir.kt | 4 + .../overload/SyntheticAndNotSynthetic.fir.kt | 7 + .../TypeParameterMultipleBounds.fir.kt | 15 + .../overload/UnsubstitutedJavaGenetics.fir.kt | 17 + .../tests/overload/defaultParameters.fir.kt | 59 +++ .../diagnostics/tests/overload/kt10939.fir.kt | 28 ++ .../diagnostics/tests/overload/kt1998.fir.kt | 14 + .../diagnostics/tests/overload/kt2493.fir.kt | 20 + .../diagnostics/tests/overload/kt7068.fir.kt | 17 + .../tests/overload/kt7068_2.fir.kt | 17 + .../diagnostics/tests/overload/kt7440.fir.kt | 17 + .../onlyPrivateOverloadsDiagnostic.fir.kt | 12 + .../override/AbstractFunImplemented.fir.kt | 7 + .../override/AbstractFunNotImplemented.fir.kt | 6 + .../override/AbstractValImplemented.fir.kt | 7 + .../override/AbstractValNotImplemented.fir.kt | 6 + .../override/AbstractVarImplemented.fir.kt | 7 + .../override/AbstractVarNotImplemented.fir.kt | 6 + .../override/AllPrivateFromSuperTypes.fir.kt | 14 + .../override/ComplexValRedeclaration.fir.kt | 10 + ...tingFunctionSignatureFromSuperclass.fir.kt | 7 + ...tingPropertySignatureFromSuperclass.fir.kt | 8 + .../DefaultParameterValueInOverride.fir.kt | 13 + ...rrorsWhenInheritingFromOneTypeTwice.fir.kt | 15 + .../tests/override/Delegation.fir.kt | 49 +++ .../tests/override/DelegationFun.fir.kt | 7 + .../tests/override/DelegationVal.fir.kt | 7 + .../tests/override/DelegationVar.fir.kt | 7 + .../tests/override/DuplicateMethod.fir.kt | 8 + .../EqualityOfIntersectionTypes.fir.kt | 15 + .../tests/override/ExtendFunctionClass.fir.kt | 9 + ...keOverrideAbstractAndNonAbstractFun.fir.kt | 9 + ...rrideDifferentDeclarationSignatures.fir.kt | 11 + .../override/FakeOverrideModality1.fir.kt | 14 + .../override/FakeOverrideModality2.fir.kt | 18 + .../override/FakeOverrideModality3.fir.kt | 16 + .../tests/override/Generics.fir.kt | 60 +++ .../InvisiblePotentialOverride.fir.kt | 7 + .../tests/override/MissingDelegate.fir.kt | 3 + ...ltipleDefaultParametersInSupertypes.fir.kt | 15 + ...ultParametersInSupertypesNoOverride.fir.kt | 15 + ...ultipleDefaultsAndNamesInSupertypes.fir.kt | 14 + ...aultsInSupertypesNoExplicitOverride.fir.kt | 10 + .../tests/override/NonGenerics.fir.kt | 50 +++ .../override/ObjectDelegationManyImpl.fir.kt | 13 + .../tests/override/OverrideWithErrors.fir.kt | 9 + .../override/OverridingFinalMember.fir.kt | 7 + ...es-DefaultValueFromOnlyOneSupertype.fir.kt | 11 + .../ParentInheritsManyImplementations.fir.kt | 17 + .../override/PropertyInConstructor.fir.kt | 11 + .../ProtectedAndPrivateFromSupertypes.fir.kt | 17 + .../tests/override/SuspiciousCase1.fir.kt | 12 + .../ToAbstractMembersFromSuper-kt1996.fir.kt | 11 + .../covariantOverrides.fir.kt | 37 ++ .../flexibleReturnType.fir.kt | 27 ++ .../flexibleReturnTypeIn.fir.kt | 61 +++ .../flexibleReturnTypeList.fir.kt | 43 ++ .../genericWithUpperBound.fir.kt | 56 +++ .../clashesOnInheritance/kt13355.fir.kt | 13 + .../kt13355viaJava.fir.kt | 47 +++ .../clashesOnInheritance/kt9550.fir.kt | 13 + .../returnTypeMismatch.fir.kt | 29 ++ .../unrelatedInherited.fir.kt | 33 ++ .../valTypeMismatch.fir.kt | 29 ++ .../varTypeMismatch.fir.kt | 29 ++ .../tests/override/fakeEquals.fir.kt | 9 + .../diagnostics/tests/override/kt12358.fir.kt | 9 + .../diagnostics/tests/override/kt12467.fir.kt | 14 + .../diagnostics/tests/override/kt12482.fir.kt | 11 + .../diagnostics/tests/override/kt1862.fir.kt | 11 + .../diagnostics/tests/override/kt2052.fir.kt | 10 + .../diagnostics/tests/override/kt2491.fir.kt | 11 + .../diagnostics/tests/override/kt4763.fir.kt | 11 + .../tests/override/kt4763property.fir.kt | 11 + .../diagnostics/tests/override/kt4785.fir.kt | 11 + .../diagnostics/tests/override/kt6014.fir.kt | 17 + .../diagnostics/tests/override/kt880.fir.kt | 16 + .../diagnostics/tests/override/kt8990.fir.kt | 11 + .../overrideMemberFromFinalClass.fir.kt | 28 ++ .../changeOnOverrideDiagnostic.fir.kt | 13 + ...ifferentNamesInSupertypesDiagnostic.fir.kt | 15 + .../invokeInFunctionClass.fir.kt | 27 ++ .../parameterNames/jjkHierarchy.fir.kt | 16 + .../parameterNames/kjkHierarchy.fir.kt | 16 + .../kjkWithSeveralSupers.fir.kt | 51 +++ .../kotlinInheritsBothJavaAndKotlin.fir.kt | 13 + .../parameterNames/kotlinInheritsJava.fir.kt | 18 + .../classAndTwoInterfaceBounds.fir.kt | 31 ++ .../differentSetsOfBounds.fir.kt | 7 + .../override/typeParameters/kt9850.fir.kt | 8 + .../simpleVisitorTwoAccepts.fir.kt | 10 + ...tationsOnNullableParenthesizedTypes.fir.kt | 29 ++ .../annotationsOnParenthesizedTypes.fir.kt | 31 ++ .../splitModifierList.fir.kt | 16 + .../commonSupertype/collectionOrNull.fir.kt | 19 + .../commonSupertype/inferenceWithBound.fir.kt | 41 ++ .../commonSupertype/mixedElvis.fir.kt | 13 + .../commonSupertype/mixedIf.fir.kt | 21 + .../commonSupertype/recursiveGeneric.fir.kt | 35 ++ .../commonSupertype/stringOrNull.fir.kt | 19 + .../commonSupertype/typeOfElvis.fir.kt | 20 + .../commonSupertype/withNothing.fir.kt | 27 ++ .../delegateByComplexInheritance.fir.kt | 15 + .../tests/platformTypes/dereference.fir.kt | 30 ++ .../tests/platformTypes/elvis.fir.kt | 16 + .../explicitFlexibleNoPackage.fir.kt | 8 + .../explicitFlexibleWithPackage.fir.kt | 9 + .../listSuperType.fir.kt | 16 + .../genericVarianceViolation/rawTypes.fir.kt | 14 + .../genericVarianceViolation/simple.fir.kt | 67 ++++ .../genericVarianceViolation/smartCast.fir.kt | 16 + .../strangeVariance.fir.kt | 18 + .../userDefinedOut.fir.kt | 17 + .../valueFromJava.fir.kt | 14 + .../genericVarianceViolation/wildcards.fir.kt | 49 +++ .../platformTypes/getParentOfType.fir.kt | 36 ++ .../tests/platformTypes/inference.fir.kt | 25 ++ .../intVsIntegerAmbiguity.fir.kt | 37 ++ .../platformTypes/intersection/map.fir.kt | 12 + .../tests/platformTypes/javaEmptyList.fir.kt | 25 ++ .../platformTypes/methodCall/entrySet.fir.kt | 24 ++ .../methodCall/genericsAndArrays.fir.kt | 24 ++ .../tests/platformTypes/methodCall/int.fir.kt | 16 + .../platformTypes/methodCall/intArray.fir.kt | 16 + .../methodCall/javaCollectionToKotlin.fir.kt | 9 + .../methodCall/javaToJava.fir.kt | 20 + .../methodCall/javaToKotlin.fir.kt | 18 + .../methodCall/kotlinCollectionToJava.fir.kt | 7 + .../platformTypes/methodCall/kt27565.fir.kt | 21 + .../platformTypes/methodCall/list.fir.kt | 18 + .../methodCall/multipleExactBounds.fir.kt | 21 + .../multipleExactBoundsNullable.fir.kt | 39 ++ .../methodCall/objectArray.fir.kt | 23 ++ .../methodCall/overloadingForSubclass.fir.kt | 30 ++ .../tests/platformTypes/methodCall/sam.fir.kt | 26 ++ .../platformTypes/methodCall/singleton.fir.kt | 10 + .../platformTypes/methodCall/string.fir.kt | 16 + .../platformTypes/methodCall/visitor.fir.kt | 26 ++ .../methodTypeParameterDefaultBound.fir.kt | 25 ++ .../noAnnotationInClassPath.fir.kt | 17 + .../enhancementFromAnnotation.fir.kt | 28 ++ .../enhancementFromKotlin.fir.kt | 28 ++ .../methodTypeParameter.fir.kt | 19 + .../noInheritanceReturnType.fir.kt | 23 ++ .../noInheritanceValueParameter.fir.kt | 26 ++ .../onTypeProjection.fir.kt | 19 + .../substitutionInSuperType.fir.kt | 41 ++ .../nullabilityWarnings/arithmetic.fir.kt | 55 +++ .../nullabilityWarnings/array.fir.kt | 31 ++ .../nullabilityWarnings/assignToVar.fir.kt | 27 ++ .../nullabilityWarnings/conditions.fir.kt | 48 +++ .../nullabilityWarnings/dataFlowInfo.fir.kt | 32 ++ .../defaultParameters.fir.kt | 28 ++ .../delegatedProperties.fir.kt | 23 ++ .../nullabilityWarnings/delegation.fir.kt | 19 + .../derefenceExtension.fir.kt | 45 +++ .../derefenceMember.fir.kt | 40 ++ .../nullabilityWarnings/elvis.fir.kt | 67 ++++ .../nullabilityWarnings/expectedType.fir.kt | 32 ++ .../nullabilityWarnings/for.fir.kt | 28 ++ .../functionArguments.fir.kt | 27 ++ .../inferenceInConditionals.fir.kt | 27 ++ .../nullabilityWarnings/invoke.fir.kt | 24 ++ .../nullabilityWarnings/kt6829.fir.kt | 24 ++ .../multiDeclaration.fir.kt | 32 ++ .../noWarningOnDoubleElvis.fir.kt | 8 + .../notNullAfterSafeCall.fir.kt | 16 + .../notNullAssertion.fir.kt | 40 ++ .../notNullAssertionInCall.fir.kt | 27 ++ ...ullTypeMarkedWithNullableAnnotation.fir.kt | 22 ++ .../nullabilityWarnings/passToJava.fir.kt | 90 +++++ .../nullabilityWarnings/primitiveArray.fir.kt | 31 ++ .../nullabilityWarnings/safeCall.fir.kt | 43 ++ .../senselessComparisonEquals.fir.kt | 42 ++ .../senselessComparisonIdentityEquals.fir.kt | 40 ++ .../nullabilityWarnings/throw.fir.kt | 26 ++ .../uselessElvisInCall.fir.kt | 28 ++ .../uselessElvisRightIsNull.fir.kt | 39 ++ .../platformTypes/nullableTypeArgument.fir.kt | 9 + .../tests/platformTypes/override.fir.kt | 26 ++ .../tests/platformTypes/rawOverrides.fir.kt | 41 ++ .../platformTypes/rawSamOverrides.fir.kt | 41 ++ .../platformTypes/rawTypes/arrays.fir.kt | 44 +++ .../platformTypes/rawTypes/errorType.fir.kt | 12 + .../rawTypes/genericInnerClass.fir.kt | 34 ++ .../rawTypes/interClassesRecursion.fir.kt | 4 + .../rawTypes/nonGenericRawMember.fir.kt | 34 ++ .../rawTypes/nonTrivialErasure.fir.kt | 29 ++ .../rawTypes/rawEnhancment.fir.kt | 17 + .../rawTypes/rawSupertype.fir.kt | 36 ++ .../rawTypes/rawSupertypeOverride.fir.kt | 41 ++ .../rawTypes/rawTypeInUpperBound.fir.kt | 38 ++ .../rawTypes/rawWithInProjection.fir.kt | 11 + .../rawTypes/recursiveBound.fir.kt | 15 + .../platformTypes/rawTypes/samRaw.fir.kt | 28 ++ ...saveRawCapabilitiesAfterSubtitution.fir.kt | 20 + .../platformTypes/rawTypes/simple.fir.kt | 39 ++ .../rawTypes/starProjectionToRaw.fir.kt | 25 ++ .../rawTypes/typeEnhancement.fir.kt | 27 ++ .../tests/platformTypes/safeCall.fir.kt | 15 + .../samAdapterInConstructor.fir.kt | 14 + .../tests/platformTypes/samConstructor.fir.kt | 17 + .../supertypeArgumentsExplicit.fir.kt | 13 + .../supertypeTypeArguments.fir.kt | 3 + .../overriddenExtensions.fir.kt | 63 +++ .../saveAnnotationAfterSubstitution.fir.kt | 43 ++ ...ertypeDifferentParameterNullability.fir.kt | 33 ++ ...supertypeDifferentReturnNullability.fir.kt | 35 ++ .../tests/privateInFile/kt12429.fir.kt | 4 + .../topLevelAnnotationCall.fir.kt | 27 ++ .../tests/privateInFile/visibility.fir.kt | 54 +++ ...roperDefaultInitializationInTailrec.fir.kt | 39 ++ ...opertyMustHaveAccessorsOrBeAbstract.fir.kt | 25 ++ .../blockBodyGetter.fir.kt | 3 + .../cantBeInferred.fir.kt | 7 + .../explicitGetterType.fir.kt | 18 + .../inferenceFromGetters/members.fir.kt | 24 ++ .../inferenceFromGetters/nullAsNothing.fir.kt | 9 + .../objectExpression.fir.kt | 36 ++ .../inferenceFromGetters/overrides.fir.kt | 41 ++ .../primaryConstructorParameter.fir.kt | 23 ++ .../recursiveGetter.fir.kt | 20 + .../inferenceFromGetters/topLevel.fir.kt | 21 + .../unsupportedInferenceFromGetters.fir.kt | 71 ++++ .../inferenceFromGetters/vars.fir.kt | 21 + .../properties/lateinitOnTopLevel.fir.kt | 14 + .../diagnostics/tests/publishedApi.fir.kt | 71 ++++ .../GenericClassVsPackage.fir.kt | 76 ++++ .../qualifiedExpression/JavaQualifier.fir.kt | 9 + .../qualifiedExpression/PackageVsClass.fir.kt | 88 +++++ .../PackageVsClass2.fir.kt | 33 ++ .../PackageVsRootClass.fir.kt | 44 +++ .../qualifiedExpression/TypeWithError.fir.kt | 32 ++ .../calleeExpressionAsCallExpression.fir.kt | 2 + .../nullCalleeExpression.fir.kt | 4 + .../visibleClassVsQualifiedClass.fir.kt | 58 +++ .../tests/reassignment/afterfor.fir.kt | 10 + .../tests/reassignment/dowhile.fir.kt | 10 + .../tests/reassignment/else.fir.kt | 11 + .../tests/reassignment/foronly.fir.kt | 9 + .../diagnostics/tests/reassignment/if.fir.kt | 10 + .../tests/reassignment/ifelse.fir.kt | 13 + .../tests/reassignment/noifelse.fir.kt | 6 + .../tests/reassignment/when.fir.kt | 10 + .../tests/reassignment/whiletrue.fir.kt | 11 + .../tests/recovery/absentLeftHandSide.fir.kt | 16 + .../tests/recovery/emptyTypeArgs.fir.kt | 3 + .../tests/recovery/namelessInJava.fir.kt | 18 + .../tests/recovery/namelessMembers.fir.kt | 17 + .../namelessToplevelDeclarations.fir.kt | 26 ++ .../ClassRedeclarationInDifferentFiles.fir.kt | 11 + .../ConflictingExtensionProperties.fir.kt | 4 + ...plicateParameterNamesInFunctionType.fir.kt | 7 + .../tests/redeclarations/EnumName.fir.kt | 3 + .../FunVsCtorInDifferentFiles.fir.kt | 10 + .../MultiFilePackageRedeclaration.fir.kt | 7 + ...eclarationForClassesInDefaultObject.fir.kt | 12 + ...rEnumEntriesAndDefaultObjectMembers.fir.kt | 11 + .../PropertyAndFunInClass.fir.kt | 9 + .../PropertyAndInnerClass.fir.kt | 13 + .../RedeclarationInDefaultObject.fir.kt | 6 + .../RedeclarationInMultiFile.fir.kt | 9 + .../RedeclarationMainInFile.fir.kt | 4 + .../RedeclarationMainInMultiFile.fir.kt | 5 + .../RedeclarationParameterlessMain.fir.kt | 5 + ...declarationParameterlessMainInvalid.fir.kt | 7 + ...declarationParameterlessMain_before.fir.kt | 7 + ...RedeclarationSuspendMainInMultiFile.fir.kt | 5 + ...rationSuspendMainInMultiFile_before.fir.kt | 7 + .../redeclarations/Redeclarations.fir.kt | 15 + .../RedeclarationsInObjects.fir.kt | 9 + .../RedeclaredTypeParameters.fir.kt | 6 + .../RedeclaringPrivateToFile.fir.kt | 49 +++ .../SingletonAndFunctionSameName.fir.kt | 21 + .../TopLevelPropertyVsClassifier.fir.kt | 13 + .../redeclarations/TypeAliasCtorVsFun.fir.kt | 14 + .../redeclarations/TypeAliasVsClass.fir.kt | 18 + .../redeclarations/TypeAliasVsProperty.fir.kt | 16 + .../interfaceTypeParameters.fir.kt | 6 + .../tests/redeclarations/kt2418.fir.kt | 27 ++ .../tests/redeclarations/kt2438.fir.kt | 22 ++ .../tests/redeclarations/kt470.fir.kt | 37 ++ ...nFunShadowedByInnerClassConstructor.fir.kt | 31 ++ .../extensionFunShadowedByMemberFun.fir.kt | 32 ++ ...nShadowedByMemberPropertyWithInvoke.fir.kt | 18 + ...onFunShadowedBySynthesizedMemberFun.fir.kt | 5 + .../extensionFunVsMemberExtensionFun.fir.kt | 5 + .../extensionOnErrorType.fir.kt | 7 + .../extensionOnNullableReceiver.fir.kt | 7 + ...ionPropertyShadowedByMemberProperty.fir.kt | 22 ++ .../extensionShadowedByDelegatedMember.fir.kt | 16 + .../extensionVsNonPublicMember.fir.kt | 47 +++ .../infixExtensionVsNonInfixMember.fir.kt | 7 + .../localExtensionShadowedByMember.fir.kt | 7 + .../memberExtensionShadowedByMember.fir.kt | 9 + ...peratorExtensionVsNonOperatorMember.fir.kt | 7 + .../typeParameterWithTwoBounds.fir.kt | 8 + .../reflection/noReflectionInClassPath.fir.kt | 62 +++ .../AmbiguityOnLazyTypeComputation.fir.kt | 12 + .../AssignmentsUnderOperators.fir.kt | 6 + .../tests/regressions/CoercionToUnit.fir.kt | 9 + .../tests/regressions/DoubleDefine.fir.kt | 65 +++ ...rorsOnIbjectExpressionsAsParameters.fir.kt | 5 + .../tests/regressions/Jet11.fir.kt | 4 + .../tests/regressions/Jet121.fir.kt | 14 + .../tests/regressions/Jet124.fir.kt | 8 + .../tests/regressions/Jet169.fir.kt | 8 + .../tests/regressions/Jet17.fir.kt | 6 + .../tests/regressions/Jet183-1.fir.kt | 21 + .../tests/regressions/Jet183.fir.kt | 15 + .../tests/regressions/Jet53.fir.kt | 5 + .../tests/regressions/Jet67.fir.kt | 4 + .../tests/regressions/Jet68.fir.kt | 11 + .../tests/regressions/Jet69.fir.kt | 10 + .../tests/regressions/Jet72.fir.kt | 18 + .../tests/regressions/Jet81.fir.kt | 29 ++ .../regressions/OrphanStarProjection.fir.kt | 3 + .../tests/regressions/OutProjections.fir.kt | 22 ++ .../regressions/OverrideResolution.fir.kt | 16 + .../regressions/SpecififcityByReceiver.fir.kt | 9 + .../TypeMismatchOnUnaryOperations.fir.kt | 16 + .../TypeParameterAsASupertype.fir.kt | 1 + .../UnavaliableQualifiedThis.fir.kt | 13 + .../WrongTraceInCallResolver.fir.kt | 9 + ...tResultSubstitutorForErrorCandidate.fir.kt | 10 + .../regressions/delegationWithReceiver.fir.kt | 10 + .../tests/regressions/ea40964.fir.kt | 8 + .../tests/regressions/ea43298.fir.kt | 3 + .../tests/regressions/ea53340.fir.kt | 7 + .../tests/regressions/ea65509.fir.kt | 5 + .../tests/regressions/ea66984.fir.kt | 2 + .../tests/regressions/ea69735.fir.kt | 5 + .../tests/regressions/ea72837.fir.kt | 10 + .../tests/regressions/ea76264.fir.kt | 4 + .../tests/regressions/intchar.fir.kt | 1 + .../regressions/itselfAsUpperBound.fir.kt | 3 + .../itselfAsUpperBoundInClass.fir.kt | 1 + .../itselfAsUpperBoundInClassNotNull.fir.kt | 1 + .../itselfAsUpperBoundLocal.fir.kt | 5 + .../itselfAsUpperBoundMember.fir.kt | 5 + .../itselfAsUpperBoundNotNull.fir.kt | 3 + .../tests/regressions/kt10243.fir.kt | 17 + .../tests/regressions/kt10243a.fir.kt | 11 + .../tests/regressions/kt10633.fir.kt | 19 + .../tests/regressions/kt10824.fir.kt | 52 +++ .../tests/regressions/kt10843.fir.kt | 8 + .../tests/regressions/kt127.fir.kt | 18 + .../tests/regressions/kt128.fir.kt | 12 + .../tests/regressions/kt13685.fir.kt | 7 + .../tests/regressions/kt13954.fir.kt | 26 ++ .../tests/regressions/kt14740.fir.kt | 20 + .../tests/regressions/kt1489_1728.fir.kt | 31 ++ .../tests/regressions/kt1550.fir.kt | 12 + .../tests/regressions/kt16086.fir.kt | 21 + .../tests/regressions/kt16086_2.fir.kt | 13 + .../tests/regressions/kt1639-JFrame.fir.kt | 12 + .../tests/regressions/kt1647.fir.kt | 11 + .../tests/regressions/kt1736.fir.kt | 10 + .../tests/regressions/kt174.fir.kt | 7 + .../tests/regressions/kt201.fir.kt | 8 + .../tests/regressions/kt235.fir.kt | 49 +++ .../tests/regressions/kt2376.fir.kt | 10 + .../tests/regressions/kt24488.fir.kt | 15 + .../tests/regressions/kt251.fir.kt | 34 ++ .../tests/regressions/kt258.fir.kt | 10 + .../tests/regressions/kt26-1.fir.kt | 9 + .../diagnostics/tests/regressions/kt26.fir.kt | 12 + .../tests/regressions/kt26303.fir.kt | 17 + .../tests/regressions/kt2768.fir.kt | 20 + .../tests/regressions/kt28001.fir.kt | 32 ++ .../tests/regressions/kt282.fir.kt | 19 + .../tests/regressions/kt287.fir.kt | 12 + .../tests/regressions/kt2956.fir.kt | 1 + .../tests/regressions/kt302.fir.kt | 13 + .../tests/regressions/kt306.fir.kt | 23 ++ .../tests/regressions/kt307.fir.kt | 11 + .../tests/regressions/kt312.fir.kt | 10 + .../tests/regressions/kt313.fir.kt | 11 + .../tests/regressions/kt316.fir.kt | 10 + .../tests/regressions/kt31975.fir.kt | 18 + .../tests/regressions/kt32205.fir.kt | 12 + .../tests/regressions/kt328.fir.kt | 29 ++ .../tests/regressions/kt32836.fir.kt | 17 + .../tests/regressions/kt334.fir.kt | 8 + .../tests/regressions/kt335.336.fir.kt | 13 + .../tests/regressions/kt337.fir.kt | 14 + .../tests/regressions/kt352.fir.kt | 29 ++ .../tests/regressions/kt353.fir.kt | 33 ++ .../tests/regressions/kt3535.fir.kt | 9 + .../tests/regressions/kt3647.fir.kt | 9 + .../tests/regressions/kt3731.fir.kt | 17 + .../tests/regressions/kt3810.fir.kt | 5 + .../tests/regressions/kt385.109.441.fir.kt | 33 ++ .../tests/regressions/kt394.fir.kt | 11 + .../tests/regressions/kt398.fir.kt | 11 + .../tests/regressions/kt399.fir.kt | 11 + .../tests/regressions/kt402.fir.kt | 8 + .../diagnostics/tests/regressions/kt41.fir.kt | 11 + .../tests/regressions/kt411.fir.kt | 69 ++++ .../tests/regressions/kt439.fir.kt | 5 + .../tests/regressions/kt442.fir.kt | 31 ++ .../tests/regressions/kt443.fir.kt | 14 + .../tests/regressions/kt455.fir.kt | 10 + .../tests/regressions/kt456.fir.kt | 30 ++ .../tests/regressions/kt459.fir.kt | 8 + .../tests/regressions/kt469.fir.kt | 28 ++ .../tests/regressions/kt4693.fir.kt | 8 + .../tests/regressions/kt4827.fir.kt | 16 + .../tests/regressions/kt498.fir.kt | 8 + .../tests/regressions/kt524.fir.kt | 14 + ...kt526UnresolvedReferenceInnerStatic.fir.kt | 15 + .../tests/regressions/kt5326.fir.kt | 11 + .../tests/regressions/kt5362.fir.kt | 31 ++ .../tests/regressions/kt549.fir.kt | 17 + .../tests/regressions/kt557.fir.kt | 12 + .../tests/regressions/kt571.fir.kt | 3 + .../tests/regressions/kt575.fir.kt | 32 ++ .../diagnostics/tests/regressions/kt58.fir.kt | 91 +++++ .../tests/regressions/kt580.fir.kt | 22 ++ .../tests/regressions/kt588.fir.kt | 14 + .../tests/regressions/kt597.fir.kt | 19 + .../tests/regressions/kt600.fir.kt | 8 + .../tests/regressions/kt604.fir.kt | 20 + .../tests/regressions/kt618.fir.kt | 28 ++ .../tests/regressions/kt629.fir.kt | 23 ++ .../tests/regressions/kt630.fir.kt | 6 + .../tests/regressions/kt6508.fir.kt | 24 ++ .../tests/regressions/kt688.fir.kt | 14 + .../tests/regressions/kt691.fir.kt | 2 + .../tests/regressions/kt701.fir.kt | 17 + .../tests/regressions/kt716.fir.kt | 16 + .../tests/regressions/kt743.fir.kt | 7 + .../tests/regressions/kt750.fir.kt | 10 + .../tests/regressions/kt7585/base.fir.kt | 20 + .../tests/regressions/kt7585/java.fir.kt | 30 ++ .../regressions/kt7585/twoparents.fir.kt | 16 + .../tests/regressions/kt762.fir.kt | 4 + .../tests/regressions/kt7804.fir.kt | 65 +++ .../tests/regressions/kt847.fir.kt | 4 + .../tests/regressions/kt860.fir.kt | 14 + .../tests/regressions/kt9384.fir.kt | 11 + .../tests/regressions/kt9620.fir.kt | 14 + .../tests/regressions/kt9633.fir.kt | 2 + .../tests/regressions/kt9682.fir.kt | 28 ++ .../tests/regressions/kt9808.fir.kt | 8 + .../tests/regressions/noThis.fir.kt | 10 + .../propertyWithExtensionTypeInvoke.fir.kt | 7 + .../regressions/resolveSubclassOfList.fir.kt | 7 + .../tests/resolve/CycleInTypeArgs.fir.kt | 3 + .../tests/resolve/HiddenDeclarations.fir.kt | 74 ++++ ...yOnPropertiesWithTheSamePackageName.fir.kt | 30 ++ ...tyWithTwoCorrespondingFunctionTypes.fir.kt | 11 + .../anonymousObjectFromTopLevelMember.fir.kt | 24 ++ .../resolve/callableReferenceInCST.fir.kt | 36 ++ .../capturedTypesInLambdaParameter.fir.kt | 42 ++ .../resolve/constructorVsCompanion.fir.kt | 23 ++ .../dslMarker/annotatedFunctionType.fir.kt | 57 +++ .../annotatedFunctionType_1_4.fir.kt | 58 +++ .../dslMarker/annotatedTypeArgument.fir.kt | 26 ++ .../dslMarker/dslMarkerOnTypealias.fir.kt | 28 ++ .../dslMarkerWithTypealiasRecursion.fir.kt | 24 ++ .../resolve/dslMarker/inheritedMarker.fir.kt | 30 ++ .../dslMarker/insideTopLevelExtension.fir.kt | 23 ++ ...nsideTopLevelExtensionAnnotatedType.fir.kt | 22 ++ .../tests/resolve/dslMarker/kt29948.fir.kt | 19 + .../tests/resolve/dslMarker/kt31360.fir.kt | 25 ++ ...kedReceiverWithCapturedTypeArgument.fir.kt | 11 + .../dslMarker/markersIntersection.fir.kt | 93 +++++ .../dslMarker/nestedWithSameReceiver.fir.kt | 40 ++ .../tests/resolve/dslMarker/properties.fir.kt | 62 +++ .../dslMarker/simpleAnnotatedClasses.fir.kt | 27 ++ .../dslMarker/simpleAnnotatedTypes.fir.kt | 26 ++ ...substitutedReceiverAnnotatedClasses.fir.kt | 27 ++ .../substitutedReceiverAnnotatedType.fir.kt | 27 ++ .../dslMarker/threeImplicitReceivers.fir.kt | 111 ++++++ .../dslMarker/threeImplicitReceivers2.fir.kt | 106 +++++ .../dslMarker/twoImplicitReceivers.fir.kt | 102 +++++ .../resolve/dslMarker/twoLanguages.fir.kt | 104 +++++ .../dslMarker/unsupportedFeature.fir.kt | 28 ++ .../resolve/dslMarker/useOfExtensions.fir.kt | 27 ++ .../tests/resolve/dslMarker/usingWith.fir.kt | 24 ++ .../resolve/dslMarker/usingWithThis.fir.kt | 30 ++ .../resolve/implicitReceiverProperty.fir.kt | 33 ++ .../incompleteConstructorInvocation.fir.kt | 10 + .../resolve/inferenceInLinkedLambdas.fir.kt | 8 + ...inkedLambdasDependentOnExpectedType.fir.kt | 7 + .../tests/resolve/invoke/KT-4372.fir.kt | 22 ++ .../invoke/errors/ambiguityForInvoke.fir.kt | 11 + .../invoke/errors/invisibleInvoke.fir.kt | 10 + .../receiverPresenceErrorForInvoke.fir.kt | 11 + .../errors/typeInferenceErrorForInvoke.fir.kt | 14 + .../invoke/errors/unresolvedInvoke.fir.kt | 5 + .../invoke/errors/unsafeCallWithInvoke.fir.kt | 10 + .../wrongReceiverForInvokeOnExpression.fir.kt | 17 + .../errors/wrongReceiverTypeForInvoke.fir.kt | 10 + .../extensionValueAsNonExtension.fir.kt | 23 ++ ...tionExpectedWhenSeveralInvokesExist.fir.kt | 14 + .../resolve/invoke/implicitInvoke.fir.kt | 33 ++ .../resolve/invoke/invokeAndSmartCast.fir.kt | 22 ++ .../resolve/invoke/invokeAsExtension.fir.kt | 61 +++ .../resolve/invoke/invokeAsMember.fir.kt | 60 +++ .../invoke/invokeAsMemberExtension.fir.kt | 123 ++++++ ...AsMemberExtensionToExplicitReceiver.fir.kt | 12 + .../invokeNonExtensionLambdaInContext.fir.kt | 7 + ...OnVariableWithExtensionFunctionType.fir.kt | 84 ++++ .../tests/resolve/invoke/kt3772.fir.kt | 27 ++ .../kt3833-invokeInsideNestedClass.fir.kt | 35 ++ ...kt4204-completeNestedCallsForInvoke.fir.kt | 24 ++ .../resolve/invoke/kt4321InvokeOnEnum.fir.kt | 35 ++ .../tests/resolve/invoke/kt9517.fir.kt | 16 + .../tests/resolve/invoke/kt9805.fir.kt | 17 + ...tFunctionExpectedWhenOneInvokeExist.fir.kt | 13 + .../resolve/invoke/valNamedInvoke.fir.kt | 9 + .../invoke/wrongInvokeExtension.fir.kt | 18 + .../tests/resolve/localObject.fir.kt | 4 + ...analyzeArgsInFreeExpressionPosition.fir.kt | 12 + .../analyzeUnmappedArguments.fir.kt | 9 + .../nestedCalls/argumentsInParentheses.fir.kt | 20 + ...eInferenceForNestedInNoneApplicable.fir.kt | 11 + .../completeUnmappedArguments.fir.kt | 14 + .../nestedCalls/kt5971NestedSafeCall.fir.kt | 9 + .../tests/resolve/nestedCalls/kt7597.fir.kt | 8 + ...nyInapplicableCandidatesWithLambdas.fir.kt | 53 +++ .../nestedCalls/twoTypeParameters.fir.kt | 17 + .../tests/resolve/newLineLambda.fir.kt | 118 ++++++ .../tests/resolve/noCandidates/kt2787.fir.kt | 6 + .../noCandidates/resolvedToClassifier.fir.kt | 19 + .../resolvedToClassifierWithReceiver.fir.kt | 39 ++ .../resolve/objectLiteralAsArgument.fir.kt | 36 ++ .../overloadConflicts/allLambdas.fir.kt | 10 + .../extensionReceiverAndVarargs.fir.kt | 12 + .../overloadConflicts/genericClash.fir.kt | 20 + .../genericWithProjection.fir.kt | 11 + .../resolve/overloadConflicts/kt10472.fir.kt | 13 + .../resolve/overloadConflicts/kt10640.fir.kt | 10 + .../resolve/overloadConflicts/kt31670.fir.kt | 16 + .../overloadConflicts/kt31670_compat.fir.kt | 16 + .../resolve/overloadConflicts/kt31758.fir.kt | 26 ++ .../overloadConflicts/kt31758_compat.fir.kt | 26 ++ .../overloadConflicts/numberOfDefaults.fir.kt | 10 + .../overloadConflicts/originalExamples.fir.kt | 21 + ...ionOnNullableContravariantParameter.fir.kt | 24 ++ ...llableContravariantParameter_compat.fir.kt | 24 ++ .../varargWithMoreSpecificSignature.fir.kt | 9 + .../resolve/overloadConflicts/varargs.fir.kt | 11 + .../varargsInDifferentPositions.fir.kt | 13 + .../overloadConflicts/varargsMixed.fir.kt | 13 + .../varargsWithRecursiveGenerics.fir.kt | 21 + .../overloadConflicts/withVariance.fir.kt | 10 + ...ameterAsDefaultValueInLocalFunction.fir.kt | 6 + .../priority/invokeExtensionVsOther.fir.kt | 18 + .../priority/invokeExtensionVsOther2.fir.kt | 13 + .../tests/resolve/priority/kt10219.fir.kt | 22 ++ .../tests/resolve/priority/kt10510.fir.kt | 13 + .../tests/resolve/priority/kt9810.fir.kt | 12 + .../tests/resolve/priority/kt9965.fir.kt | 20 + .../priority/localExtVsNonLocalExt.fir.kt | 16 + .../resolve/priority/memberVsLocalExt.fir.kt | 18 + .../staticVsImplicitReceiverMember.fir.kt | 19 + .../synthesizedMembersVsExtension.fir.kt | 10 + .../syntheticPropertiesVsExtensions.fir.kt | 29 ++ .../syntheticPropertiesVsMembers.fir.kt | 36 ++ .../resolveAnnotatedLambdaArgument.fir.kt | 12 + .../resolveTypeArgsForUnresolvedCall.fir.kt | 4 + .../resolveWithFunctionLiteralWithId.fir.kt | 32 ++ .../resolveWithFunctionLiterals.fir.kt | 30 ++ ...resolveWithFunctionLiteralsOverload.fir.kt | 31 ++ .../tests/resolve/resolveWithGenerics.fir.kt | 21 + .../resolveWithRedeclarationError.fir.kt | 34 ++ ...eWithSpecifiedFunctionLiteralWithId.fir.kt | 36 ++ .../resolve/resolveWithoutGenerics.fir.kt | 20 + .../specialConstructions/constantsInIf.fir.kt | 14 + .../specialConstructions/elvisAsCall.fir.kt | 37 ++ .../exclExclAsCall.fir.kt | 29 ++ .../inferenceForElvis.fir.kt | 8 + .../multipleSuperClasses.fir.kt | 29 ++ .../reportTypeMismatchDeeplyOnBranches.fir.kt | 28 ++ ...ameterInDefaultValueInLocalFunction.fir.kt | 7 + .../resolve/wrongNumberOfTypeArguments.fir.kt | 15 + .../tests/resolve/wrongReceiver.fir.kt | 21 + .../diagnostics/tests/safeCall.fir.kt | 15 + .../samConversions/DisabledForKTSimple.fir.kt | 20 + .../samConversions/GenericSubstitution.fir.kt | 29 ++ .../GenericSubstitutionKT.fir.kt | 27 ++ .../samConversions/OverloadPriority.fir.kt | 31 ++ .../samConversions/OverloadPriorityKT.fir.kt | 30 ++ .../SAMAfterSubstitution.fir.kt | 18 + .../SAMAfterSubstitutionKT.fir.kt | 17 + .../tests/samConversions/SimpleCorrect.fir.kt | 34 ++ .../samConversions/SimpleCorrectKT.fir.kt | 31 ++ ...kSamConversionsAreDisabledByDefault.fir.kt | 31 ++ .../AmbiguityBetweenRootAndPackage.fir.kt | 12 + .../scopes/AmbiguousNonExtensions.fir.kt | 18 + .../NoAmbiguityBetweenRootAndPackage.fir.kt | 12 + .../scopes/VisibilityInClassObject.fir.kt | 33 ++ .../scopes/VisibilityInheritModifier.fir.kt | 85 ++++ .../classHeader/annotationOnClass.fir.kt | 51 +++ .../annotationOnConstructors.fir.kt | 65 +++ .../classHeader/classGenericParameters.fir.kt | 20 + .../scopes/classHeader/classParents.fir.kt | 12 + .../classHeader/companionObjectParents.fir.kt | 25 ++ ...nionObjectSuperConstructorArguments.fir.kt | 19 + .../scopes/classHeader/constructors.fir.kt | 65 +++ .../scopes/classHeader/delegation.fir.kt | 50 +++ .../scopes/classHeader/objectParents.fir.kt | 11 + .../objectSuperConstructorArguments.fir.kt | 8 + .../classHeader/simpleDelegation.fir.kt | 10 + .../superConstructorArguments.fir.kt | 48 +++ ...ctorArgumentsInSecondaryConstructor.fir.kt | 50 +++ .../tests/scopes/genericVsNested.fir.kt | 57 +++ .../implicitReceiverMemberVsParameter.fir.kt | 5 + .../scopes/inheritance/companionObject.fir.kt | 41 ++ .../companionObjectAfterJava.fir.kt | 52 +++ .../inheritance/companionObjectsOrder.fir.kt | 37 ++ .../scopes/inheritance/innerClasses.fir.kt | 66 ++++ .../tests/scopes/inheritance/kt3856.fir.kt | 33 ++ .../scopes/inheritance/methodsPriority.fir.kt | 34 ++ .../nestedClassesFromInterface.fir.kt | 27 ++ .../inheritance/nestedCompanionClass.fir.kt | 39 ++ .../nestedCompanionClassVsNested.fir.kt | 95 +++++ .../nestedCompanionClassVsNestedJava.fir.kt | 47 +++ .../scopes/inheritance/nestedFromJava.fir.kt | 90 +++++ .../nestedFromJavaAfterKotlin.fir.kt | 82 ++++ .../inheritance/nestedVsToplevelClass.fir.kt | 38 ++ .../inheritance/severalCompanions.fir.kt | 22 ++ ...StaticMembersOfParentClassJKJ_after.fir.kt | 55 +++ ...taticMembersOfParentClassJKJ_before.fir.kt | 55 +++ ...sToStaticMembersOfParentClass_after.fir.kt | 46 +++ ...ToStaticMembersOfParentClass_before.fir.kt | 46 +++ .../inheritFromContainingClass_after.fir.kt | 54 +++ .../inheritFromContainingClass_before.fir.kt | 54 +++ .../inheritFromJavaAfterKotlin_after.fir.kt | 50 +++ .../inheritFromJavaAfterKotlin_before.fir.kt | 50 +++ .../inheritFromJava_after.fir.kt | 39 ++ .../inheritFromJava_before.fir.kt | 39 ++ .../statics/hidePrivateByPublic.fir.kt | 36 ++ .../scopes/inheritance/statics/jjkj.fir.kt | 43 ++ .../scopes/inheritance/statics/kjk.fir.kt | 37 ++ .../inheritance/statics/localVsStatic.fir.kt | 27 ++ .../inheritance/statics/nameClash0.fir.kt | 32 ++ .../inheritance/statics/nameClash1.fir.kt | 32 ++ .../inheritance/statics/nameClash2.fir.kt | 66 ++++ .../statics/oneInterfaceManyTimes.fir.kt | 55 +++ .../inheritance/statics/overloadStatic.fir.kt | 20 + .../statics/staticFunVsImport.fir.kt | 50 +++ .../statics/staticPropertyVsImport.fir.kt | 59 +++ .../statics/staticVsCompanion.fir.kt | 36 ++ .../inheritance/statics/staticVsMember.fir.kt | 69 ++++ .../inheritance/statics/staticVsOuter.fir.kt | 19 + .../statics/staticsFromjava.fir.kt | 51 +++ .../statics/staticsFromjavaAfterKotlin.fir.kt | 27 ++ ...initializerScopeOfExtensionProperty.fir.kt | 31 ++ .../tests/scopes/invisibleSetter.fir.kt | 9 + .../diagnostics/tests/scopes/kt1078.fir.kt | 16 + .../diagnostics/tests/scopes/kt1080.fir.kt | 19 + .../diagnostics/tests/scopes/kt1244.fir.kt | 13 + .../diagnostics/tests/scopes/kt1248.fir.kt | 12 + .../diagnostics/tests/scopes/kt151.fir.kt | 40 ++ .../diagnostics/tests/scopes/kt1579.fir.kt | 10 + .../tests/scopes/kt1579_map_entry.fir.kt | 19 + .../diagnostics/tests/scopes/kt1580.fir.kt | 15 + .../diagnostics/tests/scopes/kt1642.fir.kt | 9 + .../diagnostics/tests/scopes/kt1738.fir.kt | 11 + .../diagnostics/tests/scopes/kt1805.fir.kt | 20 + .../diagnostics/tests/scopes/kt1806.fir.kt | 24 ++ .../diagnostics/tests/scopes/kt1822.fir.kt | 30 ++ .../diagnostics/tests/scopes/kt1942.fir.kt | 19 + .../diagnostics/tests/scopes/kt2262.fir.kt | 16 + .../tests/scopes/kt250.617.10.fir.kt | 49 +++ .../diagnostics/tests/scopes/kt323.fir.kt | 18 + .../diagnostics/tests/scopes/kt37.fir.kt | 16 + .../diagnostics/tests/scopes/kt587.fir.kt | 11 + .../diagnostics/tests/scopes/kt900-1.fir.kt | 24 ++ .../diagnostics/tests/scopes/kt900-2.fir.kt | 33 ++ .../diagnostics/tests/scopes/kt900.fir.kt | 69 ++++ .../diagnostics/tests/scopes/kt939.fir.kt | 18 + .../diagnostics/tests/scopes/kt9430.fir.kt | 16 + .../complexCompanion.fir.kt | 18 + .../protectedVisibility/constructors.fir.kt | 22 ++ .../constructorsInner.fir.kt | 19 + .../innerClassInJava.fir.kt | 24 ++ .../innerProtectedClass.fir.kt | 13 + .../javaInheritedInKotlin.fir.kt | 58 +++ .../scopes/protectedVisibility/kt7971.fir.kt | 22 ++ .../nonSuperCallConstructor.fir.kt | 27 ++ ...CallConstructorJavaDifferentPackage.fir.kt | 32 ++ ...SuperCallConstructorJavaSamePackage.fir.kt | 30 ++ .../protectedCallOnSubClass.fir.kt | 15 + .../smartcastOnExtensionReceiver.fir.kt | 9 + .../syntheticPropertyExtensions.fir.kt | 45 +++ .../syntheticSAMExtensions.fir.kt | 31 ++ .../unstableSmartCast.fir.kt | 19 + .../protectedVisibility/withSmartcast.fir.kt | 30 ++ .../tests/scopes/sameClassNameResolve.fir.kt | 10 + .../scopes/stopResolutionOnAmbiguity.fir.kt | 20 + .../tests/scopes/visibility.fir.kt | 95 +++++ .../tests/scopes/visibility2.fir.kt | 49 +++ .../tests/scopes/visibility3.fir.kt | 47 +++ .../tests/sealed/DerivedTopLevel.fir.kt | 10 + .../tests/sealed/DoubleInner.fir.kt | 9 + .../tests/sealed/ExhaustiveOnRoot.fir.kt | 23 ++ .../tests/sealed/ExhaustiveOnTree.fir.kt | 34 ++ .../sealed/ExhaustiveOnTriangleStar.fir.kt | 24 ++ .../tests/sealed/ExhaustiveWhen.fir.kt | 16 + .../sealed/ExhaustiveWhenDoubleInner.fir.kt | 16 + .../sealed/ExhaustiveWhenMultipleInner.fir.kt | 47 +++ .../tests/sealed/ExhaustiveWhenNegated.fir.kt | 16 + .../sealed/ExhaustiveWhenNegatedTwice.fir.kt | 17 + .../ExhaustiveWhenOnNestedSealed.fir.kt | 20 + .../sealed/ExhaustiveWhenOnNullable.fir.kt | 17 + .../ExhaustiveWhenWithAdditionalMember.fir.kt | 18 + .../sealed/ExhaustiveWhenWithElse.fir.kt | 15 + .../diagnostics/tests/sealed/Local.fir.kt | 13 + .../tests/sealed/LocalSealed.fir.kt | 3 + .../tests/sealed/NestedSealed.fir.kt | 45 +++ .../tests/sealed/NeverConstructed.fir.kt | 3 + .../sealed/NeverDerivedFromNested.fir.kt | 9 + .../diagnostics/tests/sealed/NeverEnum.fir.kt | 6 + .../tests/sealed/NeverFinal.fir.kt | 3 + .../tests/sealed/NeverInterface.fir.kt | 3 + .../tests/sealed/NeverObject.fir.kt | 3 + .../diagnostics/tests/sealed/NeverOpen.fir.kt | 3 + .../tests/sealed/NonExhaustiveWhen.fir.kt | 14 + .../sealed/NonExhaustiveWhenNegated.fir.kt | 14 + ...NonExhaustiveWhenWithAdditionalCase.fir.kt | 22 ++ .../NonExhaustiveWhenWithAnyCase.fir.kt | 15 + .../tests/sealed/NonPrivateConstructor.fir.kt | 7 + .../diagnostics/tests/sealed/NotFinal.fir.kt | 10 + .../tests/sealed/OperationWhen.fir.kt | 20 + .../tests/sealed/RedundantAbstract.fir.kt | 3 + .../diagnostics/tests/sealed/TreeWhen.fir.kt | 13 + .../tests/sealed/TreeWhenFunctional.fir.kt | 11 + .../sealed/TreeWhenFunctionalNoIs.fir.kt | 23 ++ .../tests/sealed/WhenOnEmptySealed.fir.kt | 11 + .../tests/sealed/WithInterface.fir.kt | 10 + ...mentsResolveInBodyAndDelegationCall.fir.kt | 25 ++ .../classInitializersWithoutPrimary.fir.kt | 4 + .../companionObjectScope.fir.kt | 17 + .../constructorCallType.fir.kt | 28 ++ .../constructorInObject.fir.kt | 20 + .../constructorInTrait.fir.kt | 3 + .../ctrsAnnotationResolve.fir.kt | 12 + .../cyclicDelegationCalls.fir.kt | 39 ++ .../secondaryConstructors/dataClasses.fir.kt | 14 + .../dataFlowInDelegationCall.fir.kt | 7 + .../delegationByWithoutPrimary.fir.kt | 6 + .../tests/secondaryConstructors/enums.fir.kt | 40 ++ .../errorsOnEmptyDelegationCall.fir.kt | 42 ++ .../expectedPrimaryConstructorCall.fir.kt | 8 + .../secondaryConstructors/generics.fir.kt | 21 + .../secondaryConstructors/generics2.fir.kt | 27 ++ .../secondaryConstructors/generics3.fir.kt | 16 + ...seGenericFromInnerExtendingSameBase.fir.kt | 12 + ...eGenericFromInnerExtendingSameBase2.fir.kt | 13 + .../accessBaseWithSameExtension.fir.kt | 12 + .../accessGenericBaseWithSameExtension.fir.kt | 13 + .../innerInstanceCreation.fir.kt | 11 + .../headerCallChecker/lambdaAsArgument.fir.kt | 15 + .../headerCallChecker/memberFunAccess.fir.kt | 7 + .../objectLiteralAsArgument.fir.kt | 12 + ...bjectLiteralAsDefaultValueParameter.fir.kt | 11 + .../headerCallChecker/operatorCall.fir.kt | 13 + .../headerCallChecker/passingInstance.fir.kt | 8 + .../headerCallChecker/propertyAccess.fir.kt | 7 + .../propertyAccessUnitialized.fir.kt | 7 + .../headerCallChecker/superFunAccess.fir.kt | 8 + .../superFunAccessOverriden.fir.kt | 9 + .../superPropertyAccess.fir.kt | 6 + .../thisAsExtensionReceiver.fir.kt | 15 + .../usingOuterInstance.fir.kt | 8 + .../usingOuterProperty.fir.kt | 8 + .../headerSupertypeInitialization.fir.kt | 5 + .../implicitSuperCallErrorsIfPrimary.fir.kt | 7 + .../initializationFromOtherInstance.fir.kt | 15 + .../tests/secondaryConstructors/kt6992.fir.kt | 3 + .../tests/secondaryConstructors/kt6993.fir.kt | 5 + .../tests/secondaryConstructors/kt6994.fir.kt | 4 + .../lambdaInDelegation.fir.kt | 5 + .../nestedExtendsInner.fir.kt | 7 + .../noDefaultIfEmptySecondary.fir.kt | 4 + .../noPrimaryConstructor.fir.kt | 6 + ...ertypeInitWithSecondaryConstructors.fir.kt | 6 + .../propertyInitializationWithPrimary.fir.kt | 33 ++ ...ropertyInitializationWithoutPrimary.fir.kt | 39 ++ .../redeclarations.fir.kt | 27 ++ ...redeclarationsOfConstructorsIgnored.fir.kt | 11 + ...reportResolutionErrorOnImplicitOnce.fir.kt | 6 + ...vePropertyInitializerWithoutPrimary.fir.kt | 4 + .../tests/secondaryConstructors/return.fir.kt | 17 + .../superAnyNonEmpty.fir.kt | 4 + .../superSecondaryNonExisting.fir.kt | 10 + .../thisNonExisting.fir.kt | 8 + .../unreachableCode.fir.kt | 38 ++ .../useOfPropertiesWithPrimary.fir.kt | 30 ++ .../useOfPropertiesWithoutPrimary.fir.kt | 46 +++ .../valOrValAndModifiersInCtr.fir.kt | 7 + .../varargsInDelegationCallToPrimary.fir.kt | 12 + .../varargsInDelegationCallToSecondary.fir.kt | 17 + .../senselessComparison/noExplicitType.fir.kt | 15 + .../senselessComparison/parenthesized.fir.kt | 23 ++ .../shadowing/ShadowLambdaParameter.fir.kt | 13 + ...dowMultiDeclarationWithFunParameter.fir.kt | 14 + .../ShadowParameterInFunctionBody.fir.kt | 4 + .../ShadowParameterInNestedBlockInFor.fir.kt | 7 + .../shadowing/ShadowPropertyInClosure.fir.kt | 3 + .../shadowing/ShadowPropertyInFor.fir.kt | 11 + .../shadowing/ShadowPropertyInFunction.fir.kt | 10 + .../shadowing/ShadowVariableInFor.fir.kt | 6 + .../ShadowVariableInNestedBlock.fir.kt | 7 + .../ShadowVariableInNestedClosure.fir.kt | 5 + .../ShadowVariableInNestedClosureParam.fir.kt | 5 + .../noNameShadowingForSimpleParameters.fir.kt | 24 ++ .../tests/smartCasts/afterBinaryExpr.fir.kt | 14 + .../tests/smartCasts/alwaysNull.fir.kt | 23 ++ .../smartCasts/alwaysNullWithJava.fir.kt | 17 + .../smartCasts/castchecks/basicOff.fir.kt | 36 ++ .../smartCasts/castchecks/basicOn.fir.kt | 36 ++ .../smartCasts/castchecks/impossible.fir.kt | 25 ++ .../smartCasts/castchecks/insideCall.fir.kt | 13 + ...fNullableExpressionWithExpectedType.fir.kt | 9 + .../smartCasts/castchecks/variables.fir.kt | 68 ++++ .../tests/smartCasts/classObjectMember.fir.kt | 22 ++ .../combineWithNoSelectorInfo.fir.kt | 13 + .../smartCasts/comparisonUnderAnd.fir.kt | 39 ++ .../tests/smartCasts/complexComparison.fir.kt | 23 ++ .../complexConditionsWithExcl.fir.kt | 55 +++ .../dataFlowInfoForArguments.fir.kt | 7 + .../smartCasts/doubleLambdaArgument.fir.kt | 10 + .../tests/smartCasts/elvis/basicOff.fir.kt | 50 +++ .../tests/smartCasts/elvis/basicOn.fir.kt | 50 +++ .../tests/smartCasts/elvis/impossible.fir.kt | 41 ++ .../tests/smartCasts/elvisExclExcl.fir.kt | 9 + .../smartCasts/elvisExclExclMerge.fir.kt | 6 + .../smartCasts/elvisExclExclPlatform.fir.kt | 27 ++ .../tests/smartCasts/elvisExprNotNull.fir.kt | 37 ++ .../tests/smartCasts/elvisNothingRHS.fir.kt | 11 + .../tests/smartCasts/elvisRHS.fir.kt | 10 + .../smartCasts/enumEntryMembers_after.fir.kt | 19 + .../smartCasts/enumEntryMembers_before.fir.kt | 19 + .../tests/smartCasts/equals.fir.kt | 25 ++ .../tests/smartCasts/exclUnderAnd.fir.kt | 13 + .../smartCasts/explicitDefaultGetter.fir.kt | 12 + .../tests/smartCasts/extensionSafeCall.fir.kt | 13 + .../smartCasts/fakeSmartCastOnEquality.fir.kt | 95 +++++ .../smartCasts/falseReceiverSmartCast.fir.kt | 15 + .../smartCasts/falseUnnecessaryCall.fir.kt | 11 + .../tests/smartCasts/fieldExclExcl.fir.kt | 12 + .../tests/smartCasts/fieldInGetter.fir.kt | 5 + .../tests/smartCasts/fieldPlus.fir.kt | 14 + .../smartCasts/genericIntersection.fir.kt | 7 + .../tests/smartCasts/genericSet.fir.kt | 7 + .../smartCasts/ifCascadeExprNotNull.fir.kt | 14 + .../ifExprInConditionNonNull.fir.kt | 11 + .../ifExprInWhenSubjectNonNull.fir.kt | 11 + .../tests/smartCasts/ifExprNonNull.fir.kt | 19 + .../tests/smartCasts/ifWhenExprNonNull.fir.kt | 13 + .../tests/smartCasts/implicitReceiver.fir.kt | 29 ++ .../smartCasts/implicitToGrandSon.fir.kt | 11 + .../tests/smartCasts/incDecToNull.fir.kt | 10 + .../inference/dependentOnPrevArg.fir.kt | 7 + .../inference/intersectionTypes.fir.kt | 61 +++ .../tests/smartCasts/inference/kt1275.fir.kt | 11 + .../tests/smartCasts/inference/kt1355.fir.kt | 40 ++ .../tests/smartCasts/inference/kt25432.fir.kt | 11 + .../tests/smartCasts/inference/kt2746.fir.kt | 18 + .../tests/smartCasts/inference/kt2851.fir.kt | 20 + .../tests/smartCasts/inference/kt29767.fir.kt | 11 + .../tests/smartCasts/inference/kt4009.fir.kt | 22 ++ .../tests/smartCasts/inference/kt4403.fir.kt | 11 + .../tests/smartCasts/inference/kt4415.fir.kt | 17 + .../tests/smartCasts/inference/kt6242.fir.kt | 12 + .../inference/smartCastOnReceiver.fir.kt | 13 + .../conflictTypeParameters.fir.kt | 13 + .../conflictingReturnType.fir.kt | 15 + .../intersectionScope/flexibleTypes.fir.kt | 53 +++ .../moreSpecificSetter.fir.kt | 15 + .../moreSpecificVisibility.fir.kt | 16 + .../intersectionScope/mostSpecific.fir.kt | 19 + .../mostSpecificIrrelevant.fir.kt | 15 + .../intersectionScope/properties.fir.kt | 21 + .../propertiesConflict.fir.kt | 20 + .../intersectionScope/refineReturnType.fir.kt | 16 + .../intersectionScope/simple.fir.kt | 12 + .../unstableSmartCast.fir.kt | 38 ++ .../validTypeParameters.fir.kt | 15 + .../validTypeParametersNoSmartCast.fir.kt | 15 + .../tests/smartCasts/kt10232.fir.kt | 15 + .../tests/smartCasts/kt10444.fir.kt | 35 ++ .../tests/smartCasts/kt10483.fir.kt | 17 + .../tests/smartCasts/kt1461.fir.kt | 18 + .../tests/smartCasts/kt2422.fir.kt | 23 ++ .../tests/smartCasts/kt27221.fir.kt | 28 ++ .../tests/smartCasts/kt27221_2.fir.kt | 36 ++ .../kt27221_irrelevantClasses.fir.kt | 28 ++ .../tests/smartCasts/kt2865.fir.kt | 12 + .../tests/smartCasts/kt30826.fir.kt | 19 + .../tests/smartCasts/kt30927.fir.kt | 51 +++ .../tests/smartCasts/kt3224.fir.kt | 8 + .../tests/smartCasts/kt3244.fir.kt | 12 + .../tests/smartCasts/kt3572.fir.kt | 17 + .../tests/smartCasts/kt3711.fir.kt | 9 + .../tests/smartCasts/kt3899.fir.kt | 13 + .../tests/smartCasts/kt3993.fir.kt | 10 + .../tests/smartCasts/kt5427.fir.kt | 5 + .../tests/smartCasts/kt5455.fir.kt | 28 ++ .../tests/smartCasts/kt6819.fir.kt | 7 + .../tests/smartCasts/kt7561.fir.kt | 15 + .../tests/smartCasts/lambdaAndArgument.fir.kt | 14 + .../smartCasts/lambdaAndArgumentFun.fir.kt | 14 + .../lambdaArgumentNoSubstitutedReturn.fir.kt | 19 + .../lambdaArgumentWithBoundWithoutType.fir.kt | 26 ++ ...mbdaArgumentWithExpectedGenericType.fir.kt | 8 + .../lambdaArgumentWithoutType.fir.kt | 20 + .../lambdaArgumentWithoutTypeIf.fir.kt | 13 + .../lambdaArgumentWithoutTypeIfMerge.fir.kt | 14 + .../lambdaArgumentWithoutTypeWhen.fir.kt | 13 + .../tests/smartCasts/lambdaCall.fir.kt | 6 + .../smartCasts/lambdaCallAnnotated.fir.kt | 11 + .../lambdaDeclaresAndModifies.fir.kt | 8 + .../lambdaDeclaresAndModifiesInLoop.fir.kt | 10 + ...ambdaDeclaresAndModifiesInSecondary.fir.kt | 10 + ...mbdaDeclaresAndModifiesWithDirectEq.fir.kt | 20 + .../smartCasts/lambdaUsesOwnerModifies.fir.kt | 10 + .../tests/smartCasts/level_1_0.fir.kt | 52 +++ .../tests/smartCasts/localClassChanges.fir.kt | 15 + .../localDelegatedPropertyAfter.fir.kt | 15 + .../localDelegatedPropertyBefore.fir.kt | 15 + .../tests/smartCasts/localFunBetween.fir.kt | 15 + .../tests/smartCasts/localFunChanges.fir.kt | 15 + .../smartCasts/localObjectChanges.fir.kt | 15 + .../WhileTrueWithBreakInIfCondition.fir.kt | 13 + .../assignElvisIfBreakInsideWhileTrue.fir.kt | 11 + .../loops/assignWhenInsideWhileTrue.fir.kt | 17 + .../callBreakBetweenInsideDoWhile.fir.kt | 16 + .../loops/callBreakFirstInsideDoWhile.fir.kt | 13 + .../loops/callBreakInsideDoWhile.fir.kt | 14 + .../loops/callBreakSecondInsideDoWhile.fir.kt | 13 + .../loops/callBreakThirdInsideDoWhile.fir.kt | 16 + .../tests/smartCasts/loops/doWhile.fir.kt | 11 + .../smartCasts/loops/doWhileBreak.fir.kt | 11 + .../smartCasts/loops/doWhileContinue.fir.kt | 11 + .../smartCasts/loops/doWhileEarlyBreak.fir.kt | 13 + .../loops/doWhileEarlyContinue.fir.kt | 13 + .../loops/doWhileInCondition.fir.kt | 5 + .../loops/doWhileInConditionWithBreak.fir.kt | 9 + .../smartCasts/loops/doWhileLiteral.fir.kt | 10 + .../loops/doWhileNotNullBreak.fir.kt | 10 + .../tests/smartCasts/loops/doWhileNull.fir.kt | 5 + .../loops/doWhileNullWithBreak.fir.kt | 9 + .../loops/elvisBreakInsideDoWhile.fir.kt | 10 + .../loops/elvisIfBreakInsideWhileTrue.fir.kt | 9 + .../loops/elvisInsideDoWhile.fir.kt | 9 + .../elvisLeftBreakInsideWhileTrue.fir.kt | 9 + .../loops/ifBlockInsideDoWhile.fir.kt | 12 + .../loops/ifBreakAssignInsideDoWhile.fir.kt | 14 + .../loops/ifBreakAssignInsideWhileTrue.fir.kt | 10 + .../loops/ifBreakExprInsideWhileTrue.fir.kt | 10 + .../loops/ifElseBlockInsideDoWhile.fir.kt | 15 + .../smartCasts/loops/ifInsideDoWhile.fir.kt | 9 + .../leftElvisBreakInsideWhileTrue.fir.kt | 11 + .../smartCasts/loops/nestedDoWhile.fir.kt | 13 + .../nestedDoWhileWithLongContinue.fir.kt | 14 + .../tests/smartCasts/loops/nestedLoops.fir.kt | 17 + .../smartCasts/loops/nestedLoopsShort.fir.kt | 15 + .../loops/nestedLoopsWithBreak.fir.kt | 18 + .../loops/nestedLoopsWithLongBreak.fir.kt | 20 + .../loops/nestedLoopsWithLongContinue.fir.kt | 19 + .../loops/plusAssignWhenInsideDoWhile.fir.kt | 22 ++ .../loops/safeCallBreakInsideDoWhile.fir.kt | 14 + .../loops/safeCallInsideDoWhile.fir.kt | 12 + .../smartCasts/loops/useInsideDoWhile.fir.kt | 9 + .../loops/whenInsideWhileTrue.fir.kt | 12 + .../loops/whenReturnInsideWhileTrue.fir.kt | 13 + .../smartCasts/loops/whileInCondition.fir.kt | 6 + .../loops/whileInConditionWithBreak.fir.kt | 9 + .../tests/smartCasts/loops/whileNull.fir.kt | 5 + .../loops/whileNullAssignToSomething.fir.kt | 9 + .../loops/whileNullWithBreak.fir.kt | 9 + .../tests/smartCasts/loops/whileSimple.fir.kt | 10 + .../smartCasts/loops/whileTrivial.fir.kt | 11 + .../tests/smartCasts/loops/whileTrue.fir.kt | 12 + .../loops/whileTrueBreakReturn.fir.kt | 12 + .../loops/whileTrueEarlyBreak.fir.kt | 11 + .../smartCasts/loops/whileTrueReturn.fir.kt | 13 + ...eWithAssertInConditionAndBreakAfter.fir.kt | 23 ++ ...WithAssertInConditionAndBreakBefore.fir.kt | 21 + .../smartCasts/multipleResolvedCalls.fir.kt | 19 + .../noErrorCheckForPackageLevelVal.fir.kt | 25 ++ .../noUnnecessarySmartCastForReceiver.fir.kt | 7 + .../tests/smartCasts/notNullorNotNull.fir.kt | 6 + .../objectLiterals/assignment.fir.kt | 19 + .../smartCasts/objectLiterals/base.fir.kt | 19 + .../smartCasts/objectLiterals/captured.fir.kt | 23 ++ .../smartCasts/objectLiterals/exclexcl.fir.kt | 22 ++ .../objectLiterals/exclexclArgument.fir.kt | 17 + .../objectLiterals/exclexclTwoArgument.fir.kt | 21 + .../smartCasts/objectLiterals/kt7110.fir.kt | 11 + .../smartCasts/objectLiterals/receiver.fir.kt | 16 + .../tests/smartCasts/openInSealed.fir.kt | 8 + .../ownerDeclaresBothModifies.fir.kt | 13 + .../smartCasts/propertyAsCondition.fir.kt | 30 ++ .../tests/smartCasts/propertyToNotNull.fir.kt | 14 + .../smartCasts/publicVals/customGetter.fir.kt | 13 + .../smartCasts/publicVals/delegate.fir.kt | 24 ++ .../tests/smartCasts/publicVals/kt4409.fir.kt | 13 + .../tests/smartCasts/publicVals/kt5502.fir.kt | 16 + .../tests/smartCasts/publicVals/open.fir.kt | 11 + .../smartCasts/publicVals/otherModule.fir.kt | 35 ++ .../smartCasts/publicVals/protected.fir.kt | 17 + .../tests/smartCasts/publicVals/simple.fir.kt | 12 + .../tests/smartCasts/publicVals/var.fir.kt | 15 + .../tests/smartCasts/safeAs.fir.kt | 17 + .../smartCasts/safecalls/anotherVal.fir.kt | 8 + .../smartCasts/safecalls/argument.fir.kt | 6 + .../smartCasts/safecalls/chainAndUse.fir.kt | 6 + .../smartCasts/safecalls/chainInChain.fir.kt | 6 + .../safecalls/chainMixedUnsafe.fir.kt | 5 + .../smartCasts/safecalls/doubleCall.fir.kt | 6 + .../smartCasts/safecalls/extension.fir.kt | 6 + .../smartCasts/safecalls/extensionCall.fir.kt | 6 + .../smartCasts/safecalls/falseArgument.fir.kt | 7 + .../smartCasts/safecalls/falseChain.fir.kt | 4 + .../safecalls/falseExtension.fir.kt | 7 + .../safecalls/falseSecondArgument.fir.kt | 7 + .../smartCasts/safecalls/innerReceiver.fir.kt | 8 + .../smartCasts/safecalls/insideCall.fir.kt | 8 + .../smartCasts/safecalls/insideIfExpr.fir.kt | 43 ++ .../smartCasts/safecalls/longChain.fir.kt | 6 + .../safecalls/nullableReceiver.fir.kt | 13 + .../nullableReceiverInLongChain.fir.kt | 42 ++ .../nullableReceiverWithExclExcl.fir.kt | 11 + .../nullableReceiverWithFlexible.fir.kt | 25 ++ .../smartCasts/safecalls/property.fir.kt | 6 + .../smartCasts/safecalls/propertyChain.fir.kt | 14 + .../smartCasts/safecalls/receiver.fir.kt | 8 + .../safecalls/receiverAndChain.fir.kt | 8 + .../safecalls/receiverAndChainFalse.fir.kt | 10 + .../safeAccessReceiverNotNull.fir.kt | 136 +++++++ .../tests/smartCasts/safecalls/simple.fir.kt | 6 + .../safecalls/simpleNullableReceiver.fir.kt | 6 + .../tests/smartCasts/safecalls/twoArgs.fir.kt | 6 + .../severalSmartCastsOnReified.fir.kt | 11 + .../smartCasts/shortIfExprNotNull.fir.kt | 9 + .../smartCastAndArgumentApproximation.fir.kt | 8 + .../tests/smartCasts/smartCastOnElvis.fir.kt | 15 + .../tests/smartCasts/smartCastOnIf.fir.kt | 10 + .../tests/smartCasts/smartCastOnWhen.fir.kt | 20 + ...castOnSameFieldOfDifferentInstances.fir.kt | 11 + .../tests/smartCasts/thisWithLabel.fir.kt | 36 ++ .../thisWithLabelAsReceiverPart.fir.kt | 39 ++ .../smartCasts/threeImplicitReceivers.fir.kt | 27 ++ .../smartCasts/twoImplicitReceivers.fir.kt | 18 + .../tests/smartCasts/typeDegradation.fir.kt | 17 + .../tests/smartCasts/typeInComparison.fir.kt | 9 + .../tests/smartCasts/unstableToStable.fir.kt | 18 + .../smartCasts/unstableToStableTypes.fir.kt | 22 ++ .../smartCasts/varChangedInInitializer.fir.kt | 7 + .../varChangedInLocalInitializer.fir.kt | 10 + .../tests/smartCasts/varInAccessor.fir.kt | 17 + .../smartCasts/varInInitNoPrimary.fir.kt | 22 ++ .../tests/smartCasts/varInInitializer.fir.kt | 12 + .../varInSecondaryConstructor.fir.kt | 10 + .../tests/smartCasts/varInsideLocalFun.fir.kt | 17 + .../variables/accessorAndFunction.fir.kt | 23 ++ .../smartCasts/variables/assignment.fir.kt | 10 + .../variables/assignmentConversion.fir.kt | 35 ++ .../variables/doWhileWithMiddleBreak.fir.kt | 12 + .../variables/ifElseBlockInsideDoWhile.fir.kt | 15 + .../ifElseBlockInsideDoWhileWithBreak.fir.kt | 16 + .../variables/ifNullAssignment.fir.kt | 73 ++++ .../tests/smartCasts/variables/ifVarIs.fir.kt | 9 + .../smartCasts/variables/ifVarIsAnd.fir.kt | 13 + .../variables/ifVarIsChanged.fir.kt | 11 + .../smartCasts/variables/inPropertySam.fir.kt | 18 + .../tests/smartCasts/variables/infix.fir.kt | 11 + .../variables/initialization.fir.kt | 8 + .../tests/smartCasts/variables/kt7599.fir.kt | 23 ++ .../variables/lambdaBetweenArguments.fir.kt | 10 + .../smartCasts/variables/property.fir.kt | 11 + .../variables/propertyNotNeeded.fir.kt | 10 + .../variables/propertySubtype.fir.kt | 10 + .../variables/propertySubtypeInMember.fir.kt | 10 + .../propertySubtypeInMemberCheck.fir.kt | 13 + .../smartCasts/variables/varAsUse.fir.kt | 9 + .../variables/varChangedInLoop.fir.kt | 9 + .../variables/varNotChangedInLoop.fir.kt | 8 + .../smartCasts/variables/whileTrue.fir.kt | 13 + .../variables/whileWithBreak.fir.kt | 17 + .../varnotnull/assignNestedWhile.fir.kt | 28 ++ .../smartCasts/varnotnull/assignment.fir.kt | 11 + .../varnotnull/boundInitializer.fir.kt | 20 + .../varnotnull/boundInitializerWrong.fir.kt | 46 +++ .../capturedInClosureModifiedBefore.fir.kt | 60 +++ .../varnotnull/capturedInClosureOff.fir.kt | 15 + .../varnotnull/doWhileWithBreak.fir.kt | 21 + .../varnotnull/doWhileWithMiddleBreak.fir.kt | 12 + .../smartCasts/varnotnull/forEach.fir.kt | 17 + .../varnotnull/forEachWithBreak.fir.kt | 18 + .../varnotnull/forEachWithContinue.fir.kt | 18 + .../smartCasts/varnotnull/ifVarNotNull.fir.kt | 9 + .../varnotnull/ifVarNotNullAnd.fir.kt | 13 + .../varnotnull/ifVarNullElse.fir.kt | 12 + .../varnotnull/ifVarNullReturn.fir.kt | 11 + .../smartCasts/varnotnull/inference.fir.kt | 21 + .../varnotnull/infiniteWhileWithBreak.fir.kt | 20 + .../tests/smartCasts/varnotnull/infix.fir.kt | 11 + .../varnotnull/initInTryReturnInCatch.fir.kt | 80 ++++ .../varnotnull/initialization.fir.kt | 8 + .../smartCasts/varnotnull/iterations.fir.kt | 14 + .../varnotnull/nestedDoWhile.fir.kt | 15 + .../smartCasts/varnotnull/nestedLoops.fir.kt | 19 + .../smartCasts/varnotnull/nestedWhile.fir.kt | 27 ++ .../varnotnull/plusplusMinusminus.fir.kt | 21 + .../postfixNotnullClassIncrement.fir.kt | 13 + .../postfixNullableClassIncrement.fir.kt | 12 + .../postfixNullableIncrement.fir.kt | 8 + .../prefixNotnullClassIncrement.fir.kt | 13 + .../prefixNullableClassIncrement.fir.kt | 13 + .../varnotnull/prefixNullableIncrement.fir.kt | 8 + .../varnotnull/setNotNullInTry.fir.kt | 14 + .../smartCasts/varnotnull/setNullInTry.fir.kt | 10 + .../varnotnull/setNullInTryFinally.fir.kt | 16 + .../varnotnull/setNullInTryUnsound.fir.kt | 10 + .../smartCasts/varnotnull/setSameInTry.fir.kt | 11 + .../varnotnull/toFlexibleType.fir.kt | 16 + .../smartCasts/varnotnull/unnecessary.fir.kt | 12 + .../varnotnull/unnecessaryWithBranch.fir.kt | 12 + .../varnotnull/unnecessaryWithMap.fir.kt | 20 + .../varnotnull/varCapturedInClosure.fir.kt | 17 + .../varCapturedInInlineClosure.fir.kt | 16 + .../varCapturedInSafeClosure.fir.kt | 15 + .../varnotnull/varChangedInLoop.fir.kt | 9 + .../smartCasts/varnotnull/varCheck.fir.kt | 9 + .../smartCasts/varnotnull/varIntNull.fir.kt | 6 + .../varnotnull/varNotChangedInLoop.fir.kt | 8 + .../smartCasts/varnotnull/varNull.fir.kt | 6 + .../smartCasts/varnotnull/whileTrue.fir.kt | 13 + .../varnotnull/whileTrueWithBracketSet.fir.kt | 13 + .../varnotnull/whileTrueWithBrackets.fir.kt | 13 + .../varnotnull/whileWithBreak.fir.kt | 17 + .../tests/smartCasts/whenExprNonNull.fir.kt | 18 + .../tests/smartCasts/whenIfExprNonNull.fir.kt | 13 + .../smartCasts/whenSubjectImpossible.fir.kt | 10 + .../whenSubjectImpossibleJava.fir.kt | 11 + .../apiVersion/annotations.fir.kt | 11 + .../apiVersion/classesAndConstructors.fir.kt | 23 ++ .../apiVersion/overriddenMembers.fir.kt | 34 ++ .../apiVersion/propertyAccessors.fir.kt | 48 +++ .../apiVersion/simpleMembers.fir.kt | 19 + .../apiVersion/sinceOldVersionIsOK.fir.kt | 18 + .../typealiasesAsCompanionObjects.fir.kt | 15 + .../typealiasesAsConstructors.fir.kt | 20 + .../apiVersion/typealiasesAsObjects.fir.kt | 11 + .../apiVersion/typealiasesAsTypes.fir.kt | 21 + .../apiVersion/typealiasesOnImport.fir.kt | 18 + .../inlineFunctionAlways.fir.kt | 16 + .../noBigFunctionTypes.fir.kt | 20 + .../boundCallableReference.fir.kt | 25 ++ .../boundClassLiteral.fir.kt | 18 + ...edJavaClassLiteralInKClassExtension.fir.kt | 11 + ...JavaClassReferenceInKClassExtension.fir.kt | 10 + .../noCallableReferencesWithEmptyLHS.fir.kt | 28 ++ .../noDataClassInheritance.fir.kt | 23 ++ .../noInlineProperty.fir.kt | 11 + .../noLocalDelegatedProperty.fir.kt | 21 + .../noMultiplatformProjects.fir.kt | 7 + .../noTopLevelSealedInheritance.fir.kt | 5 + .../tests/substitutions/kt1558-short.fir.kt | 5 + .../tests/substitutions/kt4887.fir.kt | 8 + .../substitutions/starProjections.fir.kt | 25 ++ ...nForOverloadResolutionWithAmbiguity.fir.kt | 19 + ...ForOverloadResolutionWithErrorTypes.fir.kt | 9 + .../extFunctionTypeAsSuperType.fir.kt | 24 ++ .../findClosestCorrespondingSupertype.fir.kt | 10 + .../subtyping/functionTypeAsSuperType.fir.kt | 45 +++ ...tForTypeParameterWithMultipleBounds.fir.kt | 18 + .../subtyping/javaAndKotlinSuperType.fir.kt | 42 ++ .../tests/subtyping/kt-1457.fir.kt | 12 + .../diagnostics/tests/subtyping/kt2069.fir.kt | 14 + .../diagnostics/tests/subtyping/kt2744.fir.kt | 3 + .../diagnostics/tests/subtyping/kt304.fir.kt | 7 + .../diagnostics/tests/subtyping/kt3159.fir.kt | 9 + .../subtyping/localAnonymousObjects.fir.kt | 5 + .../tests/subtyping/localClasses.fir.kt | 19 + .../subtyping/memberAnonymousObjects.fir.kt | 6 + .../subtyping/nestedIntoLocalClasses.fir.kt | 23 ++ .../tests/subtyping/nestedLocalClasses.fir.kt | 23 ++ .../subtyping/topLevelAnonymousObjects.fir.kt | 5 + .../subtyping/unresolvedSupertype.fir.kt | 7 + ...WarningsOnAnonymousObjectInVariable.fir.kt | 4 + .../suppressWarningsOnClass.fir.kt | 7 + .../suppressWarningsOnClassObject.fir.kt | 6 + .../suppressWarningsOnExpression.fir.kt | 4 + .../allWarnings/suppressWarningsOnFile.fir.kt | 7 + .../suppressWarningsOnFunction.fir.kt | 4 + .../suppressWarningsOnObject.fir.kt | 4 + .../suppressWarningsOnParameter.fir.kt | 3 + .../suppressWarningsOnProperty.fir.kt | 4 + .../suppressWarningsOnPropertyAccessor.fir.kt | 5 + .../tests/suppress/manyWarnings/mixed.fir.kt | 5 + .../suppress/manyWarnings/onClass.fir.kt | 4 + .../manyWarnings/onClassObject.fir.kt | 6 + .../suppress/manyWarnings/onExpression.fir.kt | 4 + .../suppress/manyWarnings/onFunction.fir.kt | 4 + .../suppress/manyWarnings/onObject.fir.kt | 4 + .../suppress/manyWarnings/onParameter.fir.kt | 3 + .../suppress/manyWarnings/onProperty.fir.kt | 4 + .../manyWarnings/onPropertyAccessor.fir.kt | 5 + .../oneWarning/onBlockStatement.fir.kt | 60 +++ .../onBlockStatementSameLine.fir.kt | 19 + .../tests/suppress/oneWarning/onClass.fir.kt | 4 + .../suppress/oneWarning/onClassObject.fir.kt | 6 + .../suppress/oneWarning/onExpression.fir.kt | 4 + .../suppress/oneWarning/onFunction.fir.kt | 4 + .../oneWarning/onLocalVariable.fir.kt | 7 + .../tests/suppress/oneWarning/onObject.fir.kt | 4 + .../suppress/oneWarning/onParameter.fir.kt | 3 + .../suppress/oneWarning/onProperty.fir.kt | 4 + .../oneWarning/onPropertyAccessor.fir.kt | 5 + .../javaProperties/AbbreviationName.fir.kt | 20 + .../javaProperties/Bases.fir.kt | 31 ++ .../javaProperties/CompiledClass.fir.kt | 6 + .../javaProperties/Deprecated.fir.kt | 48 +++ .../javaProperties/FalseGetters.fir.kt | 21 + .../javaProperties/FalseSetters.fir.kt | 26 ++ .../javaProperties/FromTwoBases.fir.kt | 19 + .../javaProperties/GenericClass.fir.kt | 10 + .../javaProperties/GetA.fir.kt | 10 + .../javaProperties/Getter.fir.kt | 20 + .../javaProperties/GetterAndSetter.fir.kt | 14 + .../javaProperties/ImplicitReceiver.fir.kt | 12 + .../javaProperties/IsNaming.fir.kt | 37 ++ .../javaProperties/JavaOverridesKotlin.fir.kt | 29 ++ .../javaProperties/KotlinOverridesJava.fir.kt | 52 +++ .../KotlinOverridesJava2.fir.kt | 25 ++ .../KotlinOverridesJava3.fir.kt | 25 ++ .../KotlinOverridesJava4.fir.kt | 28 ++ .../KotlinOverridesJava5.fir.kt | 29 ++ .../javaProperties/OnlyAscii.fir.kt | 22 ++ .../javaProperties/OnlyPublic.fir.kt | 22 ++ .../javaProperties/OverrideGetterOnly.fir.kt | 22 ++ .../SetterHasHigherAccess.fir.kt | 16 + .../javaProperties/SetterOnly.fir.kt | 9 + .../javaProperties/SmartCast.fir.kt | 28 ++ .../SmartCastImplicitReceiver.fir.kt | 23 ++ .../SyntheticJavaPropertyReference.fir.kt | 9 + .../javaProperties/TypeAnnotation.fir.kt | 13 + .../TypeParameterReceiver.fir.kt | 16 + .../samAdapters/Deprecated.fir.kt | 22 ++ .../samAdapters/GenericClass.fir.kt | 14 + .../samAdapters/GenericMethod.fir.kt | 14 + .../GenericMethodInGenericClass.fir.kt | 16 + .../samAdapters/InnerClassInGeneric.fir.kt | 17 + .../samAdapters/NoNamedArgsAllowed.fir.kt | 14 + .../samAdapters/PackageLocal.fir.kt | 18 + .../ParameterTypeAnnotation.fir.kt | 13 + .../samAdapters/PassNull.fir.kt | 10 + .../samAdapters/Private.fir.kt | 10 + .../samAdapters/Protected.fir.kt | 24 ++ .../samAdapters/ReturnTypeAnnotation.fir.kt | 18 + .../samAdapters/Simple.fir.kt | 30 ++ .../samAdapters/overloadResolution.fir.kt | 36 ++ .../overloadResolutionStatic.fir.kt | 36 ++ ...dResolutionStaticWithoutRefinedSams.fir.kt | 37 ++ ...verloadResolutionWithoutRefinedSams.fir.kt | 37 ++ .../tests/tailRecOnVirtualMember.fir.kt | 171 ++++++++ .../tests/tailRecOnVirtualMemberError.fir.kt | 170 ++++++++ .../tests/tailRecOverridden.fir.kt | 32 ++ .../tests/tailRecursionComplex.fir.kt | 16 + .../backwardCompatibility/basic.fir.kt | 18 + .../backwardCompatibility/delegation.fir.kt | 32 ++ .../derivedInterfaces.fir.kt | 13 + .../derivedInterfacesWithKotlinFun.fir.kt | 15 + .../fillInStackTrace.fir.kt | 4 + .../backwardCompatibility/finalize.fir.kt | 10 + .../hashMapGetOrDefault.fir.kt | 6 + .../concurrentMapRemove.fir.kt | 22 ++ .../forEachRemainingNullability.fir.kt | 41 ++ .../targetedBuiltIns/getOrDefault.fir.kt | 20 + .../targetedBuiltIns/mutableMapRemove.fir.kt | 31 ++ .../tests/targetedBuiltIns/removeIf.fir.kt | 12 + .../tests/targetedBuiltIns/stream.fir.kt | 13 + .../tests/thisAndSuper/QualifiedThis.fir.kt | 12 + .../tests/thisAndSuper/Super.fir.kt | 64 +++ .../thisAndSuper/ambigousLabelOnThis.fir.kt | 5 + .../genericQualifiedSuperOverridden.fir.kt | 19 + .../thisAndSuper/implicitInvokeOnSuper.fir.kt | 15 + .../notAccessibleSuperInTrait.fir.kt | 10 + .../qualifiedSuperOverridden.fir.kt | 29 ++ .../superInExtensionFunction.fir.kt | 4 + .../superInExtensionFunctionCall.fir.kt | 9 + .../superInToplevelFunction.fir.kt | 5 + .../superIsNotAnExpression.fir.kt | 12 + .../thisInFunctionLiterals.fir.kt | 18 + .../thisAndSuper/thisInInnerClasses.fir.kt | 11 + .../thisInPropertyInitializer.fir.kt | 8 + .../thisInToplevelFunction.fir.kt | 4 + .../tests/thisAndSuper/traitSuperCall.fir.kt | 24 ++ .../ambiguousSuperWithGenerics.fir.kt | 38 ++ .../unqualifiedSuper/unqualifiedSuper.fir.kt | 57 +++ ...unqualifiedSuperWithAbstractMembers.fir.kt | 39 ++ ...nqualifiedSuperWithCallableProperty.fir.kt | 21 + ...qualifiedSuperWithDeeperHierarchies.fir.kt | 51 +++ .../unqualifiedSuperWithGenerics.fir.kt | 22 ++ .../unqualifiedSuperWithInnerClass.fir.kt | 33 ++ .../unqualifiedSuperWithInterfaces.fir.kt | 28 ++ .../unqualifiedSuperWithLocalClass.fir.kt | 21 + .../unqualifiedSuperWithUnresolvedBase.fir.kt | 53 +++ ...withMethodOfAnyOverridenInInterface.fir.kt | 8 + ...hMethodOverriddenInAnotherSupertype.fir.kt | 29 ++ .../unqualifiedSuper/withMethodsOfAny.fir.kt | 10 + .../traitWithRequired/traitRequiresAny.fir.kt | 5 + .../traitSupertypeList.fir.kt | 10 + .../cannotHaveManyClassUpperBounds.fir.kt | 18 + .../typeParameters/deprecatedSyntax.fir.kt | 3 + .../extFunctionTypeAsUpperBound.fir.kt | 7 + .../functionTypeAsUpperBound.fir.kt | 7 + .../implicitNothingAsTypeParameter.fir.kt | 103 +++++ .../implicitNothingOnDelegates.fir.kt | 23 ++ .../misplacedConstraints.fir.kt | 13 + .../propertyTypeParameters.fir.kt | 44 +++ ...opertyTypeParametersWithUpperBounds.fir.kt | 28 ++ .../tests/typeParameters/repeatedBound.fir.kt | 7 + .../upperBoundCannotBeArray.fir.kt | 18 + .../tests/typealias/aliasesOnly.fir.kt | 8 + .../typealias/annotationsOnTypeAliases.fir.kt | 15 + ...oundViolationInTypeAliasConstructor.fir.kt | 18 + ...dsViolationInDeepTypeAliasExpansion.fir.kt | 17 + ...boundsViolationInTypeAliasExpansion.fir.kt | 30 ++ .../boundsViolationInTypeAliasRHS.fir.kt | 20 + ...pturingTypeParametersFromOuterClass.fir.kt | 29 ++ .../tests/typealias/classReference.fir.kt | 3 + .../typealias/conflictingProjections.fir.kt | 16 + .../constructorCallThroughPrivateAlias.fir.kt | 29 ++ .../cyclicInheritanceViaTypeAlias.fir.kt | 7 + .../tests/typealias/enumEntryQualifier.fir.kt | 6 + .../typealias/exposedExpandedType.fir.kt | 45 +++ .../typealias/functionTypeInTypeAlias.fir.kt | 3 + .../genericTypeAliasConstructor.fir.kt | 10 + .../typealias/genericTypeAliasObject.fir.kt | 25 ++ .../illegalTypeInTypeAliasExpansion.fir.kt | 12 + .../diagnostics/tests/typealias/import.fir.kt | 25 ++ .../typealias/importForTypealiasObject.fir.kt | 18 + .../importFromTypeAliasObject.fir.kt | 15 + .../importMemberFromJavaViaAlias.fir.kt | 28 ++ .../tests/typealias/inGenerics.fir.kt | 12 + .../tests/typealias/inSupertypesList.fir.kt | 6 + .../typealias/inheritedNestedTypeAlias.fir.kt | 20 + ...tedTypeAliasQualifiedByDerivedClass.fir.kt | 13 + .../innerClassTypeAliasConstructor.fir.kt | 24 ++ ...assTypeAliasConstructorInSupertypes.fir.kt | 40 ++ .../typealias/innerTypeAliasAsType.fir.kt | 34 ++ .../typealias/innerTypeAliasAsType2.fir.kt | 24 ++ .../innerTypeAliasConstructor.fir.kt | 24 ++ .../tests/typealias/isAsWithTypeAlias.fir.kt | 5 + .../javaStaticMembersViaTypeAlias.fir.kt | 46 +++ .../tests/typealias/kt14498.fir.kt | 17 + .../tests/typealias/kt14498a.fir.kt | 11 + .../tests/typealias/kt14518.fir.kt | 10 + .../tests/typealias/kt14641.fir.kt | 11 + .../tests/typealias/kt15734.fir.kt | 19 + .../tests/typealias/kt19601.fir.kt | 11 + .../tests/typealias/localTypeAlias.fir.kt | 19 + .../localTypeAliasConstructor.fir.kt | 11 + .../typealias/localTypeAliasModifiers.fir.kt | 5 + .../typealias/localTypeAliasRecursive.fir.kt | 7 + .../tests/typealias/methodReference.fir.kt | 7 + .../diagnostics/tests/typealias/nested.fir.kt | 24 ++ .../nestedCapturingTypeParameters.fir.kt | 23 ++ .../tests/typealias/nestedSubstituted.fir.kt | 9 + ...tionInTypeAliasArgumentSubstitution.fir.kt | 17 + .../diagnostics/tests/typealias/noRHS.fir.kt | 6 + .../typealias/parameterRestrictions.fir.kt | 9 + .../typealias/parameterSubstitution.fir.kt | 8 + .../tests/typealias/privateInFile.fir.kt | 22 ++ .../projectionsInTypeAliasConstructor.fir.kt | 6 + .../tests/typealias/recursive.fir.kt | 11 + ...eNothingShouldBeSpecifiedExplicitly.fir.kt | 5 + .../tests/typealias/simpleTypeAlias.fir.kt | 8 + .../typealias/starImportOnTypeAlias.fir.kt | 30 ++ .../tests/typealias/starProjection.fir.kt | 15 + .../starProjectionInTypeAliasArgument.fir.kt | 6 + .../typealias/substitutionVariance.fir.kt | 67 ++++ .../tests/typealias/throwJLException.fir.kt | 7 + .../typealias/topLevelTypeAliasesOnly.fir.kt | 19 + ...typeAliasArgumentsInCompanionObject.fir.kt | 10 + .../typeAliasArgumentsInConstructor.fir.kt | 11 + .../typealias/typeAliasAsBareType.fir.kt | 35 ++ .../typealias/typeAliasAsQualifier.fir.kt | 21 + .../typeAliasAsSuperQualifier.fir.kt | 41 ++ .../typealias/typeAliasConstructor.fir.kt | 24 ++ ...ypeAliasConstructorCrazyProjections.fir.kt | 16 + .../typeAliasConstructorForInterface.fir.kt | 6 + .../typeAliasConstructorForProjection.fir.kt | 15 + ...onstructorForProjectionInSupertypes.fir.kt | 17 + .../typeAliasConstructorInSuperCall.fir.kt | 14 + ...onstructorInferenceInSupertypesList.fir.kt | 7 + .../typeAliasConstructorReturnType.fir.kt | 18 + ...asConstructorTypeArgumentsInference.fir.kt | 33 ++ ...peArgumentsInferenceWithNestedCalls.fir.kt | 8 + ...eArgumentsInferenceWithNestedCalls2.fir.kt | 41 ++ ...eArgumentsInferenceWithPhantomTypes.fir.kt | 17 + .../typeAliasConstructorVsFunction.fir.kt | 14 + .../typeAliasConstructorWrongClass.fir.kt | 34 ++ ...typeAliasConstructorWrongVisibility.fir.kt | 29 ++ ...peAliasExpansionRepeatedAnnotations.fir.kt | 16 + ...AliasForProjectionInSuperInterfaces.fir.kt | 32 ++ .../typeAliasInAnonymousObjectType.fir.kt | 5 + .../typealias/typeAliasInvisibleObject.fir.kt | 8 + .../tests/typealias/typeAliasNotNull.fir.kt | 6 + .../tests/typealias/typeAliasObject.fir.kt | 32 ++ .../typeAliasObjectWithInvoke.fir.kt | 24 ++ .../typeAliasShouldExpandToClass.fir.kt | 16 + .../typeAliasesInImportDirectives.fir.kt | 47 +++ .../typealias/typeAliasesInQualifiers.fir.kt | 75 ++++ .../typealias/typealiasRhsAnnotations.fir.kt | 16 + .../typealiasRhsAnnotationsInArguments.fir.kt | 11 + ...iasRhsRepeatedAnnotationInArguments.fir.kt | 6 + .../typealiasRhsRepeatedAnnotations.fir.kt | 4 + .../typealias/unsupportedTypeAlias.fir.kt | 14 + .../typealias/unusedTypeAliasParameter.fir.kt | 2 + ...erOfArgumentsInTypeAliasConstructor.fir.kt | 42 ++ .../illegalUnderscores.fir.kt | 17 + .../noUnderscores.fir.kt | 9 + .../tests/unit/nullableUnit.fir.kt | 5 + ...roperDefaultInitializationInTailrec.fir.kt | 39 ++ .../tests/varargs/AmbiguousVararg.fir.kt | 6 + .../MoreSpecificVarargsOfEqualLength.fir.kt | 9 + .../MostSepcificVarargsWithJava.fir.kt | 19 + .../tests/varargs/NilaryVsVararg.fir.kt | 10 + .../NullableTypeForVarargArgument.fir.kt | 66 ++++ .../tests/varargs/UnaryVsVararg.fir.kt | 9 + ...gleArrayElementAsVarargInAnnotation.fir.kt | 26 ++ ...rayElementAsVarargInAnnotationError.fir.kt | 26 ++ ...signingArraysToVarargsInAnnotations.fir.kt | 46 +++ ...entsInNamedFormAnnDeprecation_after.fir.kt | 30 ++ ...ntsInNamedFormAnnDeprecation_before.fir.kt | 30 ++ ...entsInNamedFormFunDeprecation_after.fir.kt | 60 +++ ...ntsInNamedFormFunDeprecation_before.fir.kt | 60 +++ .../diagnostics/tests/varargs/kt1781.fir.kt | 13 + .../diagnostics/tests/varargs/kt1835.fir.kt | 12 + .../tests/varargs/kt1838-param.fir.kt | 5 + .../tests/varargs/kt1838-val.fir.kt | 5 + .../diagnostics/tests/varargs/kt2163.fir.kt | 7 + .../diagnostics/tests/varargs/kt422.fir.kt | 17 + .../noAssigningArraysToVarargsFeature.fir.kt | 49 +++ ...tAssigningSingleElementsInNamedForm.fir.kt | 20 + .../tests/varargs/varargInSetter.fir.kt | 6 + .../tests/varargs/varargIterator.fir.kt | 5 + .../tests/varargs/varargOfNothing.fir.kt | 15 + .../tests/varargs/varargViewedAsArray.fir.kt | 29 ++ .../varargs/varargsAndFunctionLiterals.fir.kt | 13 + .../tests/varargs/varargsAndOut1.fir.kt | 13 + .../tests/varargs/varargsAndOut2.fir.kt | 9 + .../tests/varargs/varargsAndPair.fir.kt | 10 + .../diagnostics/tests/variance/Class.fir.kt | 23 ++ .../tests/variance/Function.fir.kt | 34 ++ .../tests/variance/FunctionTypes.fir.kt | 12 + .../tests/variance/InPosition.fir.kt | 48 +++ .../tests/variance/InvariantPosition.fir.kt | 45 +++ .../tests/variance/NullableTypes.fir.kt | 16 + .../tests/variance/OutPosition.fir.kt | 40 ++ .../tests/variance/PrimaryConstructor.fir.kt | 25 ++ .../tests/variance/ValProperty.fir.kt | 50 +++ .../tests/variance/VarProperty.fir.kt | 50 +++ .../tests/variance/Visibility.fir.kt | 20 + .../tests/variance/ea1337846.fir.kt | 21 + .../variance/privateToThis/Abstract.fir.kt | 7 + .../privateToThis/FunctionCall.fir.kt | 37 ++ .../variance/privateToThis/GetVal.fir.kt | 37 ++ .../variance/privateToThis/SetVar.fir.kt | 37 ++ .../privateToThis/ValReassigned.fir.kt | 20 + .../abstractInvisibleMemberFromJava.fir.kt | 21 + .../abstractInvisibleMemberFromKotlin.fir.kt | 47 +++ ...actInvisibleMemberFromKotlinWarning.fir.kt | 22 ++ .../tests/when/AnnotatedWhenStatement.fir.kt | 8 + .../tests/when/BranchBypassVal.fir.kt | 12 + .../tests/when/BranchBypassVar.fir.kt | 12 + .../tests/when/BranchFalseBypass.fir.kt | 12 + .../tests/when/BranchFalseBypassElse.fir.kt | 12 + ...CommaInWhenConditionWithoutArgument.fir.kt | 11 + .../tests/when/DuplicatedLabels.fir.kt | 51 +++ .../tests/when/ElseOnNullableEnum.fir.kt | 46 +++ .../ElseOnNullableEnumWithSmartCast.fir.kt | 11 + .../when/EmptyConditionWithExpression.fir.kt | 8 + .../EmptyConditionWithExpressionEnum.fir.kt | 9 + .../tests/when/ExhaustiveBoolean.fir.kt | 8 + .../when/ExhaustiveBooleanBrackets.fir.kt | 7 + .../when/ExhaustiveBooleanComplex.fir.kt | 8 + .../when/ExhaustiveBooleanNullable.fir.kt | 9 + .../tests/when/ExhaustiveBreakContinue.fir.kt | 14 + .../tests/when/ExhaustiveEnumIs.fir.kt | 11 + .../tests/when/ExhaustiveEnumMixed.fir.kt | 11 + .../when/ExhaustiveInitialization.fir.kt | 15 + .../when/ExhaustiveNoInitialization.fir.kt | 11 + .../tests/when/ExhaustiveNullable.fir.kt | 14 + .../tests/when/ExhaustivePlatformEnum.fir.kt | 21 + .../ExhaustivePlatformEnumAnnotated.fir.kt | 23 ++ .../when/ExhaustivePlatformEnumElse.fir.kt | 21 + .../when/ExhaustivePlatformEnumNull.fir.kt | 22 ++ .../ExhaustivePlatformEnumStatement.fir.kt | 20 + .../tests/when/ExhaustiveReturn.fir.kt | 13 + .../tests/when/ExhaustiveReturnThrow.fir.kt | 14 + .../ExhaustiveValOverConditionalInit.fir.kt | 22 ++ .../ExhaustiveVarOverConditionalInit.fir.kt | 22 ++ .../ExhaustiveWithNullabilityCheck.fir.kt | 14 + ...xhaustiveWithNullabilityCheckBefore.fir.kt | 12 + ...haustiveWithNullabilityCheckBoolean.fir.kt | 13 + .../ExhaustiveWithNullabilityCheckElse.fir.kt | 14 + .../tests/when/NoElseExpectedUnit.fir.kt | 7 + .../tests/when/NoElseNoExpectedType.fir.kt | 6 + .../when/NoElseReturnedCoercionToUnit.fir.kt | 11 + ...NoElseReturnedFromLambdaExpectedInt.fir.kt | 11 + .../tests/when/NoElseReturnedNonUnit.fir.kt | 5 + .../tests/when/NoElseReturnedUnit.fir.kt | 6 + .../tests/when/NoElseWhenStatement.fir.kt | 6 + .../when/NonExhaustiveBooleanNullable.fir.kt | 8 + .../when/NonExhaustivePlatformEnum.fir.kt | 20 + .../tests/when/NonExhaustiveWarning.fir.kt | 11 + .../when/NonExhaustiveWarningElse.fir.kt | 12 + .../when/NonExhaustiveWarningFalse.fir.kt | 13 + .../NonExhaustiveWarningForSealedClass.fir.kt | 16 + .../when/NonExhaustiveWarningNull.fir.kt | 14 + .../NonExhaustiveWithNullabilityCheck.fir.kt | 12 + .../tests/when/PropertyNotInitialized.fir.kt | 16 + .../tests/when/RedundantElse.fir.kt | 68 ++++ .../tests/when/ReservedExhaustiveWhen.fir.kt | 37 ++ .../tests/when/TopLevelSealed.fir.kt | 22 ++ .../diagnostics/tests/when/When.fir.kt | 46 +++ .../tests/when/WhenTypeDisjunctions.fir.kt | 21 + .../diagnostics/tests/when/kt10439.fir.kt | 13 + .../diagnostics/tests/when/kt10809.fir.kt | 52 +++ .../diagnostics/tests/when/kt10811.fir.kt | 24 ++ .../diagnostics/tests/when/kt4434.fir.kt | 27 ++ .../diagnostics/tests/when/kt9929.fir.kt | 10 + .../diagnostics/tests/when/kt9972.fir.kt | 18 + .../when/whenAndLambdaWithExpectedType.fir.kt | 25 ++ .../when/whenWithNothingAndLambdas.fir.kt | 39 ++ .../capturingInInitializer.fir.kt | 37 ++ .../invisibleOutsideOfWhen.fir.kt | 14 + .../jumpoutInInitializer.fir.kt | 43 ++ .../nestedWhenWithSubject.fir.kt | 41 ++ .../noSubjectVariableName.fir.kt | 10 + .../reassignmentToWhenSubjectVariable.fir.kt | 10 + .../shadowingOtherVariable.fir.kt | 27 ++ ...rtCastOnValueBoundToSubjectVariable.fir.kt | 49 +++ .../smartCastsOnSubjectVariable.fir.kt | 8 + .../smartcastToEnum.fir.kt | 18 + .../smartcastToSealed.fir.kt | 20 + .../softModifierName.fir.kt | 7 + .../subjectVariableInIsPattern.fir.kt | 8 + .../unsupportedFeature.fir.kt | 16 + ...edVariableDeclarationsInWhenSubject.fir.kt | 29 ++ .../unusedWhenSubjectVariable.fir.kt | 8 + .../testsWithStdLib/ArrayOfNothing.fir.kt | 55 +++ .../CallCompanionProtectedNonStatic.fir.kt | 93 +++++ .../CallToMainRedeclaredInMultiFile.fir.kt | 8 + .../InaccessibleInternalClass.fir.kt | 15 + .../PropertyDelegateWithPrivateSet.fir.kt | 12 + .../RedeclarationMainInMultiFileClass.fir.kt | 11 + .../RenameOnImportHidesDefaultImport.fir.kt | 9 + .../testsWithStdLib/addAllProjection.fir.kt | 15 + .../ClassObjectAnnotatedWithItsKClass.fir.kt | 12 + .../annotations/JvmSyntheticOnDelegate.fir.kt | 10 + .../annotations/Synchronized.fir.kt | 31 ++ ...chronizedOnInterfaceCompanionMember.fir.kt | 23 ++ .../annotations/TransientOnDelegate.fir.kt | 5 + .../annotations/Volatile.fir.kt | 13 + .../annotationsOnUseSiteTargets.fir.kt | 13 + .../illegalPlatformName.fir.kt | 12 + .../annotationApplicability/jvmName.fir.kt | 95 +++++ .../jvmNameOnMangledNames.fir.kt | 13 + .../multifileClassPart.fir.kt | 19 + ...ultifileClassPartWithJavaAnnotation.fir.kt | 40 ++ .../suppressOnFunctionReference.fir.kt | 4 + .../array.fir.kt | 24 ++ .../simple.fir.kt | 30 ++ .../useOfNonConstVal.fir.kt | 16 + .../vararg.fir.kt | 27 ++ .../annotationParameters/kt10136.fir.kt | 8 + .../nonConstValAsArgument.fir.kt | 34 ++ .../orderWithValue.fir.kt | 9 + .../orderWithoutValue.fir.kt | 8 + .../annotationParameters/valueArray.fir.kt | 23 ++ .../valueArrayAndOtherDefault.fir.kt | 27 ++ .../valueArrayOnly.fir.kt | 15 + .../valueArrayWithDefault.fir.kt | 15 + .../javaAnnotationWithVarargArgument.fir.kt | 11 + .../kotlinAnnotationWithVarargArgument.fir.kt | 7 + ...notationsTargetingLateinitAccessors.fir.kt | 14 + ...tationsTargetingNonExistentAccessor.fir.kt | 114 ++++++ .../defaultValueMustBeConstant.fir.kt | 22 ++ .../annotations/explicitMetadata.fir.kt | 9 + .../annotationAsArgument.fir.kt | 19 + .../arg.fir.kt | 7 + .../argAndOtherDefault.fir.kt | 9 + .../argArray.fir.kt | 7 + .../argWithDefault.fir.kt | 8 + .../argWithDefaultAndOther.fir.kt | 9 + .../twoArgs.fir.kt | 8 + .../value.fir.kt | 8 + .../valueAndOtherDefault.fir.kt | 12 + .../valueArray.fir.kt | 9 + .../valueWithDefault.fir.kt | 9 + .../valueWithDefaultAndOther.fir.kt | 10 + .../annotations/jvmDefault/generic.fir.kt | 60 +++ .../jvmDefault/javaOverride.fir.kt | 72 ++++ .../jvmDefault/jvmDefaultInInheritance.fir.kt | 36 ++ .../annotations/jvmDefault/jvmDefaults.fir.kt | 322 +++++++++++++++ .../jvmDefault/jvmDefaultsWithJava.fir.kt | 162 ++++++++ .../jvmDefault/noJvmDefaultFlag.fir.kt | 29 ++ .../jvmDefault/notInterface.fir.kt | 22 ++ .../jvmDefault/propertyAccessor.fir.kt | 14 + .../jvmDefault/simpleOverride.fir.kt | 31 ++ .../jvmDefault/simplePropertyOverride.fir.kt | 32 ++ .../annotations/jvmDefault/superCall.fir.kt | 62 +++ .../jvmDefault/superCallAmbiguity.fir.kt | 32 ++ .../jvmDefault/superCallAmbiguity2.fir.kt | 32 ++ .../jvmDefault/superCallAmbiguity3.fir.kt | 31 ++ .../annotations/jvmDefault/target6.fir.kt | 29 ++ .../annotations/jvmDefault/target8.fir.kt | 30 ++ .../clashWithCompanionObjectField.fir.kt | 8 + .../jvmField/inMultiFileFacade.fir.kt | 13 + .../jvmField/inSingleFileFacade.fir.kt | 12 + .../annotations/jvmField/interface13.fir.kt | 59 +++ .../jvmField/jvmFieldApplicability.fir.kt | 143 +++++++ .../JvmOverloadWithNoDefaults.fir.kt | 7 + .../jvmOverloadsOnAbstractMethods.fir.kt | 11 + ...adsOnAnnotationClassConstructor_1_3.fir.kt | 4 + ...adsOnAnnotationClassConstructor_1_4.fir.kt | 4 + .../jvmOverloads/jvmOverloadsOnPrivate.fir.kt | 23 ++ .../incorrectJvmPackageName.fir.kt | 27 ++ ...piVersionIsAtLeastHasConstArguments.fir.kt | 23 ++ .../jvmStatic/constOrJvmFieldProperty.fir.kt | 18 + .../jvmStatic/constructorProperty.fir.kt | 4 + .../jvmStatic/constructorProperty_LL13.fir.kt | 4 + .../annotations/jvmStatic/constructors.fir.kt | 8 + .../jvmStatic/finalAndAbstract.fir.kt | 33 ++ .../annotations/jvmStatic/functions.fir.kt | 53 +++ .../jvmStatic/functions_LL13.fir.kt | 53 +++ .../jvmStatic/interfaceCompanion_LL12.fir.kt | 54 +++ .../interfaceCompanion_LL13_16.fir.kt | 55 +++ .../interfaceCompanion_LL13_18.fir.kt | 56 +++ .../annotations/jvmStatic/localFun.fir.kt | 7 + .../jvmStatic/localFun_LL13.fir.kt | 7 + .../annotations/jvmStatic/property.fir.kt | 45 +++ .../jvmStatic/property_LL13.fir.kt | 45 +++ .../kClassArrayInAnnotationsInVariance.fir.kt | 29 ++ ...kClassArrayInAnnotationsOutVariance.fir.kt | 29 ++ .../kClass/kClassInAnnotation.fir.kt | 20 + .../kClassInAnnotationsInVariance.fir.kt | 27 ++ .../kClassInAnnotationsOutVariance.fir.kt | 27 ++ .../kClass/kClassInvariantTP.fir.kt | 23 ++ ...assOutArrayInAnnotationsOutVariance.fir.kt | 7 + .../kotlinAnnotation.fir.kt | 5 + .../tooManyArgs.fir.kt | 11 + .../typeMismatch.fir.kt | 13 + .../withValue.fir.kt | 17 + .../withoutValue.fir.kt | 17 + .../annotations/qualifiedCallValue.fir.kt | 27 ++ .../annotations/strictfpOnClass.fir.kt | 17 + .../annotations/targetuse.fir.kt | 21 + .../testsWithStdLib/assert/cast.fir.kt | 21 + .../testsWithStdLib/assert/safeCall.fir.kt | 38 ++ .../builtins/arraysAreCloneable.fir.kt | 25 ++ .../testsWithStdLib/cast/AsInsideIn.fir.kt | 21 + .../testsWithStdLib/cast/IsArray.fir.kt | 5 + .../testsWithStdLib/cast/IsReified.fir.kt | 1 + .../testsWithStdLib/commonCollections.fir.kt | 30 ++ .../breakContinuesInInlinedLambda.fir.kt | 51 +++ .../flowInlining/expressionBody.fir.kt | 18 + .../implicitCastToAnyInReturnType.fir.kt | 20 + .../inlinedLambdaAlwaysThrows.fir.kt | 17 + .../irrelevantUnknownClosure.fir.kt | 23 ++ .../flowInlining/labeledReturns.fir.kt | 86 ++++ .../flowInlining/nestedTryCatchFinally.fir.kt | 98 +++++ .../flowInlining/nestedTryCatchs.fir.kt | 47 +++ .../flowInlining/nonLocalReturn.fir.kt | 18 + .../nonReturningInlinedLambda.fir.kt | 34 ++ .../safeCallAndInPlaceReturn.fir.kt | 23 ++ .../severalJumpOutsFromInlinedLambda.fir.kt | 79 ++++ .../flowInlining/throwIfNotCalled.fir.kt | 48 +++ .../controlflow/flowInlining/tryCatch.fir.kt | 58 +++ .../flowInlining/tryCatchFinally.fir.kt | 34 ++ .../flowInlining/typeMismatch.fir.kt | 19 + .../flowInlining/unreachableCode.fir.kt | 17 + .../valDefiniteReassignment.fir.kt | 75 ++++ .../varDefiniteInitialization.fir.kt | 31 ++ .../varIndefiniteIntialization.fir.kt | 29 ++ .../valDefiniteInitialization.fir.kt | 92 +++++ .../valDefiniteReassignment.fir.kt | 28 ++ .../valIndefiniteInitialization.fir.kt | 68 ++++ .../varDefiniteInitalization.fir.kt | 42 ++ .../varIndefiniteInitialization.fir.kt | 51 +++ .../exactlyOnce/withReceiver.fir.kt | 28 ++ .../unknown/unknownInvocations.fir.kt | 18 + .../dsl/callUsualContractFunction.fir.kt | 42 ++ .../dsl/errors/booleanComparisons.fir.kt | 23 ++ .../errors/callInContractDescription.fir.kt | 14 + .../dsl/errors/contractCallSites.fir.kt | 86 ++++ .../contracts/dsl/errors/emptyContract.fir.kt | 9 + .../illegalConstructionInContractBlock.fir.kt | 55 +++ .../dsl/errors/illegalEqualsCondition.fir.kt | 30 ++ .../errors/nestedConditionalEffects.fir.kt | 11 + .../errors/nonLambdaLiteralAsArgument.fir.kt | 15 + .../dsl/errors/notFirstStatement.fir.kt | 76 ++++ .../dsl/errors/recursiveContract.fir.kt | 25 ++ ...rsiveContractCustomContractFunction.fir.kt | 39 ++ .../dsl/errors/referenceToProperty.fir.kt | 14 + .../dsl/errors/typeReferences.fir.kt | 53 +++ .../dsl/errors/unlabeledReceiver.fir.kt | 12 + .../contracts/dsl/fqnContractFunction.fir.kt | 20 + .../dsl/rewriteAtSliceFunctor.fir.kt | 10 + .../contracts/dsl/useBeforeDeclaration.fir.kt | 20 + .../contracts/fromStdlib/check.fir.kt | 33 ++ .../fromStdlib/fromStandardKt.fir.kt | 110 ++++++ .../contracts/fromStdlib/isNullOrBlank.fir.kt | 20 + .../contracts/fromStdlib/isNullOrEmpty.fir.kt | 20 + .../contracts/fromStdlib/require.fir.kt | 27 ++ .../contracts/fromStdlib/synchronize.fir.kt | 11 + .../smartcasts/callWithDefaultValue.fir.kt | 17 + .../smartcasts/catchExceptionSpilling.fir.kt | 21 + .../contracts/smartcasts/compositions.fir.kt | 70 ++++ .../contracts/smartcasts/deeplyNested.fir.kt | 104 +++++ .../smartcasts/extensionReceiver.fir.kt | 38 ++ .../smartcasts/extensionReceiver_after.fir.kt | 38 ++ .../smartcasts/intersectingInfo.fir.kt | 61 +++ .../smartcasts/intersectionTypes.fir.kt | 45 +++ .../smartcasts/multieffect/implicitIff.fir.kt | 87 ++++ .../multieffect/returnsAndCalls.fir.kt | 68 ++++ ...nullabilitySmartcastWhenNullability.fir.kt | 57 +++ .../operatorsTests/andOperator.fir.kt | 81 ++++ .../andOperatorWithConstant.fir.kt | 60 +++ .../andOperatorWithUnknown.fir.kt | 60 +++ .../operatorsTests/equalsOperator.fir.kt | 47 +++ .../equalsWithNullableBoolean.fir.kt | 69 ++++ .../operatorsTests/isInstanceOperator.fir.kt | 60 +++ .../operatorsTests/orOperator.fir.kt | 78 ++++ .../orOperatorWithConstant.fir.kt | 57 +++ .../orOperatorWithUnknown.fir.kt | 60 +++ .../smartcasts/partiallyIncorrect.fir.kt | 21 + .../contracts/smartcasts/receiver.fir.kt | 36 ++ .../smartcasts/safecallAndReturnsNull.fir.kt | 17 + .../contracts/smartcasts/throwsEffect.fir.kt | 66 ++++ .../typeSmartcastWhenNullability.fir.kt | 59 +++ .../smartcasts/unreachableBranches.fir.kt | 32 ++ .../valueOfContractedFunctionIngored.fir.kt | 11 + .../smartcasts/when/withSubject.fir.kt | 36 ++ .../when/withSubjectNullableBoolean.fir.kt | 56 +++ .../smartcasts/when/withoutSubject.fir.kt | 31 ++ .../deprecated/deprecationOnReadBytes.fir.kt | 7 + .../noDeprecationOnReadBytes.fir.kt | 9 + .../delegatedProperty.fir.kt | 7 + .../duplicateJvmSignature/jvmNames.fir.kt | 22 ++ .../jvmNamesDuplicate.fir.kt | 53 +++ .../duplicateJvmSignature/jvmOverloads.fir.kt | 8 + .../jvmStaticInClassObject.fir.kt | 9 + .../jvmStaticInObject.fir.kt | 8 + .../duplicateJvmSignature/statics/jjk.fir.kt | 31 ++ .../duplicateJvmSignature/statics/jk.fir.kt | 21 + .../duplicateJvmSignature/statics/jkjk.fir.kt | 36 ++ ...otlinMembersVsJavaNonVisibleStatics.fir.kt | 22 ++ .../testsWithStdLib/elvisOnJavaList.fir.kt | 19 + .../testsWithStdLib/elvisOnUnitInLet.fir.kt | 9 + .../experimental/annotation.fir.kt | 136 +++++++ .../experimental/bodyUsages.fir.kt | 30 ++ .../experimental/bodyUsagesAndInline.fir.kt | 83 ++++ .../experimental/classMembers.fir.kt | 88 +++++ .../classMembersOverlyExperimental.fir.kt | 36 ++ .../experimental/constVal.fir.kt | 43 ++ .../experimental/deeplyNestedClass.fir.kt | 57 +++ .../experimental/errors.fir.kt | 26 ++ .../experimentalIsNotEnabled.fir.kt | 23 ++ .../experimentalOnWholeModule.fir.kt | 23 ++ .../experimentalUnsignedLiterals.fir.kt | 33 ++ .../experimental/fullFqNameUsage.fir.kt | 12 + .../experimental/importStatement.fir.kt | 27 ++ ...ectTargetsForExperimentalAnnotation.fir.kt | 25 ++ .../incorrectUseExperimental.fir.kt | 9 + .../experimental/override.fir.kt | 44 +++ .../overrideDifferentExperimentalities.fir.kt | 35 ++ .../experimental/topLevel.fir.kt | 78 ++++ .../experimental/typealias.fir.kt | 13 + .../experimental/usageNotAsAnnotation.fir.kt | 77 ++++ .../experimental/useExperimentalOnFile.fir.kt | 37 ++ ...talOnFileWithVeryExperimentalMarker.fir.kt | 30 ++ .../useExperimentalOnWholeModule.fir.kt | 22 ++ .../useExperimentalTargets.fir.kt | 57 +++ ...eExperimentalWithSeveralAnnotations.fir.kt | 52 +++ .../experimental/wasExperimental.fir.kt | 59 +++ ...uredRangeVariableAssignmentBefore13.fir.kt | 103 +++++ ...forInFieldUpdatedInLoopBodyBefore13.fir.kt | 15 + ...DelegatedPropertyAssignmentBefore13.fir.kt | 16 + .../rangeVariableAssignment13.fir.kt | 19 + .../rangeVariableAssignmentBefore13.fir.kt | 39 ++ .../pseudocodeMemoryOverhead.fir.kt | 371 ++++++++++++++++++ .../hugeUnresolvedKotlinxHtml.fir.kt | 60 +++ .../testsWithStdLib/ifElseJavaList.fir.kt | 16 + .../testsWithStdLib/implicitCastToAny.fir.kt | 34 ++ .../exactAnnotation.fir.kt | 12 + ...xplicitTypeArgumentAsValidInputType.fir.kt | 12 + .../internalAnnotationsOnTypes.fir.kt | 30 ++ .../annotationsForResolve/kt26698.fir.kt | 22 ++ .../annotationsForResolve/kt29307.fir.kt | 31 ++ .../noInferAndLowPriority.fir.kt | 16 + .../noInferAnnotation.fir.kt | 33 ++ .../notNullAnnotation.fir.kt | 26 ++ .../onlyInputTypes.fir.kt | 47 +++ .../onlyInputTypesAndLowPriority.fir.kt | 26 ++ ...yInputTypesAndTopLevelCapturedTypes.fir.kt | 73 ++++ ...putTypesAnnotationWithPlatformTypes.fir.kt | 19 + .../onlyInputTypesCaptured.fir.kt | 113 ++++++ .../onlyInputTypesWithVarargs.fir.kt | 26 ++ .../propagationOfNoInferAnnotation.fir.kt | 25 ++ ...resolveWithOnlyInputTypesAnnotation.fir.kt | 25 ++ .../inference/arrayConstructor.fir.kt | 14 + .../inference/integerLiterals.fir.kt | 24 ++ .../inference/intersectionInputType.fir.kt | 12 + .../testsWithStdLib/inference/kt11266.fir.kt | 4 + .../testsWithStdLib/inference/kt12008.fir.kt | 12 + .../testsWithStdLib/inference/kt1558.fir.kt | 26 ++ .../testsWithStdLib/inference/kt27772.fir.kt | 9 + .../testsWithStdLib/inference/kt30292.fir.kt | 5 + .../testsWithStdLib/inference/kt32345.fir.kt | 49 +++ .../testsWithStdLib/inference/kt3458.fir.kt | 9 + .../testsWithStdLib/inference/kt4975.fir.kt | 10 + ...inlineOnlySuppressesNothingToInline.fir.kt | 31 ++ .../inline/synchronizedOnInline.fir.kt | 16 + .../diagnostics/testsWithStdLib/instar.fir.kt | 11 + .../java/concurrentHashMapContains.fir.kt | 79 ++++ .../concurrentHashMapContainsError.fir.kt | 80 ++++ .../testsWithStdLib/java/functionN.fir.kt | 58 +++ .../java/inheritedFunctionN.fir.kt | 16 + .../patternCompileCallableReference.fir.kt | 8 + .../javaClassOnCompanion.fir.kt | 32 ++ .../testsWithStdLib/javaForKClass.fir.kt | 28 ++ .../testsWithStdLib/kt7585/delegate.fir.kt | 76 ++++ .../diagnostics/testsWithStdLib/kt8050.fir.kt | 11 + .../diagnostics/testsWithStdLib/kt9078.fir.kt | 12 + .../diagnostics/testsWithStdLib/kt9985.fir.kt | 3 + .../lateinit/isInitialized.fir.kt | 87 ++++ .../multiplatform/jvmOverloads.fir.kt | 11 + .../testsWithStdLib/native/abstract.fir.kt | 11 + .../testsWithStdLib/native/body.fir.kt | 25 ++ .../testsWithStdLib/native/constructor.fir.kt | 10 + .../testsWithStdLib/native/inline.fir.kt | 11 + .../testsWithStdLib/native/noBody.fir.kt | 25 ++ .../testsWithStdLib/native/nonFunction.fir.kt | 9 + .../testsWithStdLib/native/override.fir.kt | 9 + .../testsWithStdLib/native/reified.fir.kt | 4 + .../testsWithStdLib/native/trait.fir.kt | 11 + .../testsWithStdLib/outstar.fir.kt | 11 + .../overrideWithFunctionalType.fir.kt | 17 + .../testsWithStdLib/pureReifiable.fir.kt | 12 + .../pureReifiableArrayOperations.fir.kt | 18 + .../arrayList.fir.kt | 23 ++ .../arrayListNullable.fir.kt | 23 ++ .../customClassMutableCollection.fir.kt | 33 ++ .../customClassMutableList.fir.kt | 41 ++ .../invalidFqName.fir.kt | 28 ++ .../purelyImplementedCollection/maps.fir.kt | 81 ++++ .../mapsWithNullableKey.fir.kt | 57 +++ .../mapsWithNullableValues.fir.kt | 56 +++ .../purelyImplementedCollection/sets.fir.kt | 49 +++ .../wrongTypeParametersCount.fir.kt | 40 ++ .../typeOfWithNonReifiedParameter.fir.kt | 35 ++ .../testsWithStdLib/regression/ea63992.fir.kt | 7 + .../testsWithStdLib/regression/ea65206.fir.kt | 9 + .../ea66827_dataClassWrongToString.fir.kt | 7 + .../ea70485_functionTypeInheritor.fir.kt | 17 + .../regression/ea70880_illegalJvmName.fir.kt | 8 + .../testsWithStdLib/regression/kt10001.fir.kt | 9 + .../testsWithStdLib/regression/kt2082.fir.kt | 10 + .../testsWithStdLib/regression/kt26806.fir.kt | 9 + .../testsWithStdLib/regression/kt34391.fir.kt | 19 + .../testsWithStdLib/regression/kt9345.fir.kt | 3 + .../kt9820_javaFunctionTypeInheritor.fir.kt | 16 + .../reified/arrayConstruction.fir.kt | 18 + .../reified/arrayOfNullsReified.fir.kt | 14 + .../testsWithStdLib/reified/kt11881.fir.kt | 9 + .../reified/nonCallableReiefied.fir.kt | 11 + .../reified/reifiedNothingSubstitution.fir.kt | 17 + .../resolve/hidesMembers.fir.kt | 52 +++ .../resolve/hidesMembers2.fir.kt | 42 ++ .../resolve/javaPackageMembers.fir.kt | 9 + .../resolve/javaStaticMembers.fir.kt | 12 + .../testsWithStdLib/resolve/kt10103.fir.kt | 1 + .../testsWithStdLib/resolve/kt10732a.fir.kt | 10 + .../testsWithStdLib/resolve/kt4711.fir.kt | 21 + .../resolve/samAgainstFunctionalType.fir.kt | 30 ++ .../resolve/samConstructorVsFun.fir.kt | 30 ++ .../resolve/samOverloadsWithGenerics.fir.kt | 25 ++ ...loadsWithGenericsWithoutRefinedSams.fir.kt | 26 ++ .../resolve/samOverloadsWithKtFunction.fir.kt | 20 + ...adsWithKtFunctionWithoutRefinedSams.fir.kt | 22 ++ .../shadowingInDestructuring.fir.kt | 10 + .../smartcasts/forEachSafe.fir.kt | 12 + .../smartcasts/forEachUnsafe.fir.kt | 14 + .../testsWithStdLib/smartcasts/kt10463.fir.kt | 6 + .../smartcasts/lazyDeclaresAndModifies.fir.kt | 11 + .../letAlwaysChangesToNotNull.fir.kt | 7 + .../smartcasts/letChangesToNotNull.fir.kt | 7 + .../smartcasts/letChangesToNull.fir.kt | 9 + .../smartcasts/letChangesToNullComplex.fir.kt | 11 + .../smartcasts/letMergeNotNull.fir.kt | 9 + .../smartcasts/letStable.fir.kt | 10 + .../smartcasts/letUsesOwnReceiver.fir.kt | 7 + .../smartcasts/listOfGeneric.fir.kt | 8 + .../smartcasts/withChangesToNull.fir.kt | 10 + .../noDefaultImportOfKotlinComparisons.fir.kt | 3 + .../testsWithStdLib/streams.fir.kt | 9 + .../targetedBuiltIns/blackListed.fir.kt | 22 ++ .../unsupportedFeature.fir.kt | 66 ++++ ...iableDeclarationWithDisabledFeature.fir.kt | 19 + ...riableDeclarationWithEnabledFeature.fir.kt | 20 + .../trailingComma/noDisambiguation.fir.kt | 10 + .../typeArgumentsWithDisabledFeature.fir.kt | 28 ++ .../typeArgumentsWithEnabledFeature.fir.kt | 28 ++ .../typeParametersWithDisabledFeature.fir.kt | 48 +++ .../typeParametersWithEnabledFeature.fir.kt | 51 +++ .../valueArgumentsWithDisabledFeature.fir.kt | 73 ++++ .../valueArgumentsWithEnabledFeature.fir.kt | 69 ++++ .../valueParametersWithDisabledFeature.fir.kt | 120 ++++++ .../valueParametersWithEnabledFeature.fir.kt | 104 +++++ .../whenEntryWithDisabledFeature.fir.kt | 49 +++ .../whenEntryWithEnabledFeature.fir.kt | 50 +++ .../testsWithStdLib/tryCatch/assignTry.fir.kt | 111 ++++++ .../tryCatch/boundedSmartcasts.fir.kt | 101 +++++ .../tryCatch/catchRedeclaration.fir.kt | 54 +++ .../tryCatch/correctSmartcasts.fir.kt | 88 +++++ .../tryCatch/correctSmartcasts_after.fir.kt | 89 +++++ .../tryCatch/falseNegativeSmartcasts.fir.kt | 19 + .../falseNegativeSmartcasts_after.fir.kt | 20 + .../tryCatch/falsePositiveSmartcasts.fir.kt | 106 +++++ .../falsePositiveSmartcasts_after.fir.kt | 108 +++++ .../tryCatch/tryExpression.fir.kt | 35 ++ .../typealias/exceptionTypeAliases.fir.kt | 3 + ...peAliasesInvisibleWithApiVersion1_0.fir.kt | 5 + ...nTypeAliasesInvisibleWithoutFeature.fir.kt | 4 + .../typealias/hashMapTypeAlias.fir.kt | 20 + .../typeAliasSamAdapterConstructors.fir.kt | 8 + .../typeAliasSamAdapterConstructors2.fir.kt | 27 ++ .../testsWithStdLib/varargs/kt3213.fir.kt | 7 + .../testsWithStdLib/varargs/kt4172j.fir.kt | 9 + .../testsWithStdLib/varargs/kt5534.fir.kt | 6 + .../testsWithStdLib/when/kt10192.fir.kt | 20 + .../testsWithStdLib/when/kt10807.fir.kt | 17 + .../when/noTypeArgumentsInConstructor.fir.kt | 43 ++ 4578 files changed, 104067 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/Abstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AbstractAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AbstractInAbstractClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AbstractInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AbstractInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AnonymousInitializers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AssignToArrayElement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/AutoCreatedIt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/BacktickNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Basic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Bounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/BreakContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/BreakContinueInWhen_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Builders.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Casts.fir.kt create mode 100644 compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/CompareToWithErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Constants.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Constructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ConstructorsOfPrimitives.fir.kt create mode 100644 compiler/testData/diagnostics/tests/CovariantOverrideType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DefaultValuesCheckWithoutBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DefaultValuesTypechecking.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DeferredTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DiamondFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DiamondFunctionGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/DiamondProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Dollar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ExternalAccessors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ExternalAndAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ForRangeConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/GenericArgumentConsistency.fir.kt create mode 100644 compiler/testData/diagnostics/tests/GenericFunctionIsLessSpecific.fir.kt create mode 100644 compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt create mode 100644 compiler/testData/diagnostics/tests/IncDec.fir.kt create mode 100644 compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/InferNullabilityInThenBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Infix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/InfixModifierApplicability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/InvokeAndRecursiveResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/IsExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/LValueAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/LiteralAsResult.fir.kt create mode 100644 compiler/testData/diagnostics/tests/LocalClassAndShortSubpackageNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/MultilineStringTemplates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/MultipleBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Nullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OperatorChecks.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Operators.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OperatorsWithWrongNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OverrideFunctionWithParamDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OverridenFunctionAndSpecifiedTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/OverridingVarByVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PackageInTypePosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PackageQualified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PrimaryConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PrivateFromOuterPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PrivateSetterForOverridden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ProcessingEmptyImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ProjectionOnFunctionArgumentErrror.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ProjectionsInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Properties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/QualifiedExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/RecursiveResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/RecursiveTypeInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ReserveYield.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ReserveYield2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ResolveOfJavaGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ResolveToJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Return.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ReturnInFunctionWithoutBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SafeCallInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SafeCallNonNullReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SafeCallNonNullReceiverReturnNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SafeCallOnFakePackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Serializable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SetterVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ShiftFunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SingleUnderscoreUnsupported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/StarsInFunctionCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/StringTemplates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SupertypeListChecks.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlighting.fir.kt create mode 100644 compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlightingEof.fir.kt create mode 100644 compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/TypeInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Underscore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnderscoreUsageInAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnderscoreUsageInCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnderscoreUsageInCallableRefTypeLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnderscoreUsageInType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnitByDefaultForFunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnitValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Unresolved.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnusedInDestructuring.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnusedParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnusedParametersVersion10.fir.kt create mode 100644 compiler/testData/diagnostics/tests/UnusedVariables.fir.kt create mode 100644 compiler/testData/diagnostics/tests/ValAndFunOverrideCompatibilityClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/VarargTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Varargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/Variance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationAsDefaultParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationForObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationOnObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/BasicAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/ConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/DanglingMixed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/DanglingNoBrackets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/DanglingWithBrackets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/Deprecated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/MultiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedFunctionParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterWithAt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/UnresolvedAnnotationOnObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/WrongAnnotationArgsOnObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotatedExpressionInsideAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/annotationConstructorDefaultParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/booleanLocalVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/compareAndEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/javaProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/kotlinProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/standaloneInExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/strings.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/deprecatedRepeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/extensionFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithoutError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/functionalTypes/parenthesizedAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/illegalRequireKotlinValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/illegalSinceKotlinValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/javaRepeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/javaRepeatableRetention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/javaUnrepeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/kt1860-positive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/missingValOnParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/nestedClassesInAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/noNameProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onFunctionParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onLoops.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onLoopsUnreachable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/onMultiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/annotationAsArg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/annotationAsArgComplex.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/documented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/forParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/functionExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/functions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/javaDocumented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/javaKotlinTargetRetention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/javaretention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/multiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/objectLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/prefix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/repeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/retention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/setterParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/target.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/accessors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/expr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/field.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/file.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/init.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/nested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/suppress.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/type.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/options/unrepeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/conflictingOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/differentNamesForParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/memberProjectedOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/multipleInheritedDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/notImplementedMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/tooManyArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchDueToTypeProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverrideJavaNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/rendering/unusedValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/typeAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/DelegateAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FieldAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FileAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/GetterAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ParamAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/PropertyAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ReceiverAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SetterAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SparamAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/repeatable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/CustomGetSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/CustomGetVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/CustomGetValGlobal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/CustomGetVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/CustomSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/ExtensionProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldAsProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldDerived.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldInInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldInLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldOnVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldOnVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldReassignment_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldReassignment_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/FieldShadow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/InitCustomSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/InitOpenSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/SetterWithExplicitType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/backingField/kt782packageLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/companionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/controlFlow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/dataFlow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/expectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/expressionWithNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/functionCallWithoutArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/innerNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/kt12843.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/object.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/privateToThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/referenceToStaticMethodOnInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/syntheticExtensionOnLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/valueOfTypeParameterType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/classVsPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/emptyLhs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/expectedTypeAsSubtypeOfFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/abstractClassConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/annotationClassConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/classMemberVsConstructorLikeFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtensionInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorOfNestedClassInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/differentPackageTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/empty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/extensionToSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/fakeOverrideType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/javaStaticMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromExtensionInLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localNamedFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromExtensionInLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityLocalVsTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/privateStaticAndPublicMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/topLevelFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtensionInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/topLevelFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/unresolved.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/expectedFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/genericExtensionFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/kt10968.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/kt11075.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/kt12286.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/kt7470.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/nestedCallWithOverload.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/noInferenceFeatureForCallableReferences.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/resolutionGenericCallableWithNullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/resolutionWithGenericCallable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt25433.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt31981.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt32256.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/memberExtensionsImportedFromObjectsUnsupported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/packageInLhs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/classFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/extensionPropertyOnNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/genericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/kt7564.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/protectedVarFromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/propertyOfNestedGenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/applicableCallableReferenceFromDistantScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byValType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/chooseMostSpecificCandidateUsingCandidateDescriptorNotReflectionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/chooseOuterCallBySingleCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/commonSupertypeFromReturnTypesOfCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/constructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/eagerResolveOfSingleCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/innerClassConstructorOnOuterClassInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt10036_bound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt12338.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt12751.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/kt9601.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificAmbiguousExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificSimple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/multipleOutersAndMultipleCallableReferences.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/noAmbiguityBetweenTopLevelAndMemberProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/overloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/overloadsBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/overloadsMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/postponedResolveOfManyCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/resolveCallableReferencesAfterAllSimpleArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/resolveEqualsOperatorWithAnyExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/sam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/typealiases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unused.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/whitespacesInExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsErasedError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsErasedFine.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsErasedStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsErasedWarning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsInBlockWithReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsInExpressionBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsInPropertyAndPropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/DowncastMap.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/ExtensionAsNonExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/FlexibleTargetType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForOverridenVarianceWithProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithIrrelevantMixin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithTwoSameTypeSubstitutions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithoutTypeArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowParameterSubtype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowSameClassParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedAllowSameParameterParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowDifferentArgInvariantPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowForOverridenVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowForTypeWithConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromIn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithFirstInvalid.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithSecondInvalid.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedNonGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedNullableTasT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedTasT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedToErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsForTypeWithComplexUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsRecursionSustainable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsTraits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/IsWithCycleUpperBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/StableTypeForUselessCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/WhenErasedDisallowFromAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/WhenWithExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/AsNestedBare.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/AsNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/AsNullableNotEnough.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/EitherAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/EitherIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/EitherNotIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/EitherSafeAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/EitherWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/NullableAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/NullableAsNotEnough.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/NullableAsNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/NullableAsNullableNotEnough.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/RedundantNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/ToErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/UnrelatedAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/bare/UnrelatedIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/checkCastToNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/constants.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/isErasedAnyAndStarred.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/isErasedTAndStarred.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/kt15161.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/kt614.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedDirect.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedSubtypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsRelated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsUnrelated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cast/nothingAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/arrayAccessSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/arrayAccessSetTooManyArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/booleanExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/kt1940.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkArguments/twoLambdasFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/checkType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/arrays.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/classAndObjectLiteralType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/classLiteralType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/expressionWithNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/genericArrays.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/genericClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments_noTypeParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/integerValueType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/qualifiedClassLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/simpleClassLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/smartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/typealiases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classLiteral/unresolvedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/ClassObjectCannotAccessClassFields.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/ClassObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/builtInClassObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/classObjectHeader.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/classObjectInLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/classObjectRedeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/importClassInClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/kt3866.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/noCollectionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/collectionLiterals/resolveToFunctionFromBuiltIns.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/afterInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/aliencall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/backing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/basic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/companion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/comparison.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/delegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/derived.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/derivedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/getset.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/init.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/initwithgetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/inspection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/lambdaInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/lateInit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/localObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/nobacking.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/open.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/openProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/outer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/property.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/propertyAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/breakContinueInTryFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/breakInsideLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/checkPropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/constructorPropertyInterdependence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeFromDifferentSources.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInArrayAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInBinaryExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInDeadCode.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLocalDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLoops.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInWhileFromBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt3162tryAsInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/ReturnFromFunctionInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt3444_ReturnFromLocalFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt4034.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/simpleClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/delegatedPropertyEarlyAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileNotDefined.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/enumCompanionInterdependence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/infiniteLoops.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1027.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1066.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10805.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10823.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1156.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1185enums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1191.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1219.1301.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1977.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2166_kt2103.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2226.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2334.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2960.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3444.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3501.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4126.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt607.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt609.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt610.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt6788.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt776.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt843.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/localObjectInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithWarningOnUnusedParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithoutWarningOnUnusedParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/nestedTryFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnWithFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/privateSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceThisLabel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesOrderInPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/repeatUnitializedErrorOnlyForLocalVars.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/tryWithAssignmentUsedInCatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/uninitializedInLocalDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unmappedArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitRecursiveInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithErroneousDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithInit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructorsAndDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPlusAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPrimaryConstructorAndConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinitWithTwoConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlFlowAnalysis/varInitializationInIfInCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ForLoopWithExtensionIteratorOnNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/catchGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics_deprecation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/catchWithDefault.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/catchingLocalClassesCapturingTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/emptyIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/forWithNullableIterator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ifInResultOfLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/jumpAcrossFunctionBoundary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt10322.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt10706.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt1075.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt30406.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt4310.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt786.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt799.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/specialConstructsWithNullableExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/tryReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/typeInferenceForExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/when.fir.kt234.fir.kt973.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/whenInResultOfLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/whenToAnyDiscriminatingUsages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/callableReference/invokeOutideSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/classIndirectlyInheritsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/classInheritsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicAndUsualTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/cyclicHierarchy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/javaKotlinJavaCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/kt303.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/nestedClassInSuperClassParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/objectInheritsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/twoClassesWithNestedCycle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/typeIsLowEnough.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withoutTypeReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/componentNamedComponent1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/conflictingCopyOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/conflictingOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/copyOfPrivateClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyNoDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyWithDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassNoName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassNotOverridingCopy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv12.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv13.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataClassVarargParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/emptyConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/errorTypesInDataClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/extensionComponentsOnNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/finalMembersInBaseClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasComponent1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasFinalComponent1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/innerDataClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/innerOuterDataClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/multiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/multiDeclarationFor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/noConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/notADataClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/oneValParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/sealedDataClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/strange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/twoValParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataClasses/twoVarParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/CalleeExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/EmptyIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/IsExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/WhenSubject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/assignment/assignToNewVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/assignment/kt6118.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValIsCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/assignment/when.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassBase.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDefaultParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegatedProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalClassProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlow/local/kt2835.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentInInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentOperation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentToArrayElement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionBooleanOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionCompareToConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionContainsConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionEqualsConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionIdentifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionPlusConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Condition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ContinueOuterLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhileCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ForLoopRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfStatement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/MultiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/StringTemplate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenIn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenSubject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhileCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt4332WhenBranches.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5155WhenBranches.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5182WhenBranches.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/ConflictingAndRedundantProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/DataFlowInMultiDeclInFor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/DataFlowInfoInMultiDecl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/LocalVariableWithNoTypeInformation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/VarianceOnFunctionAndPropertyTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/DoubleDeclForLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionMissing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopMissingLoopParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopWithExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForWithExplicitTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/RedeclarationInForLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/SingleDeclForLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationAssignedUnresolved.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationMissingInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/kt2829.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/underscore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithTwoTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/JavaSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/illegalModifiersOnClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt1141.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt1193.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt2096.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt2142.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt2397.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt2631_MultipleDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt2643MultiDeclInControlFlow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/kt559.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/localDeclarationModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/localFunctionNoInheritVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/PureKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/packageDeclarationModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/propertyInPackageHasNoInheritVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/sealedOnMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/declarationChecks/valVarFunctionParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt create mode 100644 compiler/testData/diagnostics/tests/defaultArguments/superCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/abstractDelegatedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/backingField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/defaultSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTraitTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/disallowImplInTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/genericGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/getterWithSubtype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/callableReferenceArgumentInDelegatedExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionGet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedTypeForVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/localVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/localWithSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/commonCaseForInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/genericProvideDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/localDelegatedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/simpleProvideDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/setterWithSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/severalReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/thisOfAnyType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/wrongSetterReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/covariantOverrides/irrelevant.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/covariantOverrides/kt13952.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/covariantOverrides/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/kt8154.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/abstractOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverrideProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/diamond.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/explicitOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/fakeOverrideInTheMiddle.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/generic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/severalDelegates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleNoOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleProp.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/multiParenthesizedSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deparenthesize/parenthesizedSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/annotationUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/classWithCompanionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/componentUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/functionUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/imports.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/iteratorUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/javaDeprecated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/propertyUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/propertyUseSiteTargetedAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/thisUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/typeUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/typealiasForDeprecatedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/warningOnConstructorErrorOnClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/accidentalOverrideFromGrandparent.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyNoGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classPropertyOverriddenByFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/defaultFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/delegatedFunctionOverriddenByProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/genericClassFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/privateClassFunctionOverriddenByProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/require.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByPropertyNoImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunctionNoImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/class.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/fakeOverrideTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/trait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/caseInProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/clashFromInterfaceAndSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/collections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/extensionProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/genericType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/inheritFromTwoTraits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/kotlinAndJavaCollections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/nullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/twoTraitsAndOwnFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeMappedToJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBoundsInWhere.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/enumMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/waitNotifyGetClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/class.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classPropertyInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionFunctionAndNormalFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionPropertyAndFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClassInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/nestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/object.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpressionInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/privateClassPropertyNoClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelDifferentFiles.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/trait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/withErrorTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedFieldObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/dataClassCopy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/defaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/delegationBy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/enum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/innerClassField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/instance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/propertyMetadataCache.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/jkjk.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClassExtendsJavaClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterfaceExtendsJavaInteface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/synthesized/enumValuesValueOf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/oneTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitFunctionOverriddenByPropertyInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitPropertyOverriddenByFunctionInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/twoTraits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/duplicateJvmSignature/vararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dynamicTypes/delegationBy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dynamicTypes/unsupported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/dynamicTypes/withInvisibleSynthesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/AbstractEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/AbstractInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/AbstractOverrideInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/ConstructorCallFromOutside.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/ExplicitConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/InsideEntryConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/InsideSecondaryConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/SecondaryConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/classObjectInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/commonSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/compareTwoDifferentEnums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/constructorWithDefaultParametersOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/emptyConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/entryShouldBeOfEnumType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumEntryCannotHaveClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumEntryInAbstractEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumImplementingTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumIsAssignableToBuiltInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMissingName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumStarImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumWithAnnotationKeyword.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumWithEmptyName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/extendingEnumDirectly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/extensionNamedAsEnumEntry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/ifEnumEntry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/importEnumFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/incompatibleEnums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/incompatibleEnums_1_4.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inheritanceFromEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/existingClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/insideTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/twoEnums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/interfaceWithEnumKeyword.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/isEnumEntry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumValueOfMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumValuesMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumWithAbstractFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumWithFuns.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumWithNameClashing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/javaEnumWithProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/kt2834.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/kt8972_cloneNotAllowed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/localEnums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/modifiersOnEnumEntry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/multipleConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/openMemberInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/overrideFinalEnumMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/starImportNestedClassAndEntries.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/typeParametersInEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/valuesValueOfAndEntriesAccessibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/binaryMinusIndepWoExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/divisionByZero.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/float.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/floatLiteralOutOfRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/infixFunOverBuiltinMemberInConst.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/intOverflow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/intOverflowWithJavaProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/integer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/logicWithNumber.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/longOverflow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/noOverflowWithZero.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/otherOverflow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/qualifiedExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/unaryMinusIndepWoExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/unaryMinusIndependentExpType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/evaluate/wrongLongSuffix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/delegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/exceptionOnFakeInvisible.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/functional.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/implements.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/inaccessibleType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/internal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/internalAndProtected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/internalFromLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/local.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/localFromInternal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/localFromPrivate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/localInFunReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/localInMemberType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/localInPropertyType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/nested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/object.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/packagePrivate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/privateFromLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/privatePropertyInPrivateConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/propertyInConstructorOfPrivateClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/propertyInPrivateConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/propertyInSimpleConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedInProtected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/protectedSameWay.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/ExtensionsCalledOnSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/GenericIterator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/GenericIterator2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/classObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/extensionPropertyVsParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/kt1875.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/kt2317.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/kt3470.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/kt3563.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/kt819ExtensionProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/noClassObjectsInJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/object.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/fileDependencyRecursion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/Common.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/DifficultInferenceForParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/ForbiddenNonLocalReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/NoOverloadError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/Parameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/ReturnAndLabels.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/ScopeCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/extensionComponents.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/modifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/shadowing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/functionExpressionAsLastExpressionInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/functionLiteralAsArgumentForFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/functionLiteralInIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt2906.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt3343.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt4529.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt6541_extensionForExtensionFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt6869.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt7383_starProjectedFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabels.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabelsNonLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/IfInReturnedExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalAndNonLocalReturnInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelNoParens.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnHasTypeNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNoCoercionToUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitAndDontCareType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitWithBodyExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExplicitUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/MixedReturnsFromLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/NoCommonSystem.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/SmartCastWithExplicitType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/returnNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/returnNullWithReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/InconsistentTypeParameterBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/Projections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/PseudoRawTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/RawTypeInIsExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/RawTypeInIsPattern.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundWithTwoArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/TypeParameterBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/TypeParametersInTypeParameterBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/argumentsForT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/captured.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/localClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/localWithTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/objectLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/cyclicBounds/functions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/cyclicBounds/inClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/doNotCaptureSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/finalUpperBoundWithOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/genericsInType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/bareTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/checkBoundsOuter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/inStaticScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/secondLevelDepth.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/importedInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCallSecondary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/innerUncheckedCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/innerVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/iterator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/j+k.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/j+k_complex.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/kt3357.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/kt408.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/kt6325.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/outerArgumentsRequired.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/parameterShadowing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedOuter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedTypesResolution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/simpleIn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/simpleOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/simpleOutUseSite.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/innerClasses/substitutedMemberScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt1575-Class.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt1575-Function.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt30590.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt5508.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt9203.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt9203_1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/kt9985.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/conflictingReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/flexibleTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/mostSpecific.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/propertiesConflict.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/validTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/declarationsBoundsViolation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/expressionsBoundsViolation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/functionalBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/inferNotNullTypeFromIntersectionOfNullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/kt25182.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/smartCastRefinedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/smartCastsOnThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/smartCastsValueArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/tpInBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/useAsReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/nullability/useAsValueArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/MLOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/approximateDispatchReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/extensionResultSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/inValueParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/iterateOnExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/kt7296.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/kt8647.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/lambdaArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/leakedApproximatedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/multipleArgumentProjectedOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/platformSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStarOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/starNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/starNullabilityRecursive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/superClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/protectedSuperCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/recursive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/resolveGenericBoundsBeforeSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/sameTypeParameterUse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/starProjections/checkBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/starProjections/collectionInheritedFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/starProjections/invalid.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/suppressVarianceConflict.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/ClassDereference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgumentWarning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/GenericAsReifiedArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/InConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/InProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/InType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/InlineableReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/LocalFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/NotInlineableReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/tpAsReified/ReifiedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutPlusAssignDefined.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/wildcardInValueParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/implicitIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/implicitNestedIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/implicitNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/AllUnderImportsAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/AllUnderImportsLessPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/CheckVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClashStarImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassImportsConflicting.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/CurrentPackageAndAllUnderImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/CurrentPackageAndExplicitImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/DefaultImportsPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ExplicitImportsAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ExplicitImportsUnambiguityForFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportClassClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportFromCompanionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportFromObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportFromRootPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportHidingDefinitionInTheSameFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportNestedWithDifferentName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportObjectAndUseAsSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportObjectHidesCurrentPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportOverloadFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportProtectedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportTwoTimes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportTwoTimesStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/Imports.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ImportsConflicting.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/InaccessiblePrivateClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/JavaPackageLocalClassNotImported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/MalformedImports.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/OperatorRenameOnImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PackageVsClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/RenameOnImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/StarImportFromObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/SyntaxError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/WrongImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImportAfterNamedImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/invisibleFakeReferenceInImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/kt13112.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/propertyClassFileDependencyRecursion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/imports/twoImportLists.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/NoSenselessComparisonForErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/SupertypeOfErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/arrayExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/completeFunctionArgumentsOfNestedCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterDotSelectorExpected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterIncompleteElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteEnumReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameBeforeNextDeclarationWithModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameInBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/illegalSelectorCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/inExpr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/kt1955.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/kt2014.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/kt4866UnresolvedArrayAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/plusOnTheRight.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/pseudocodeTraverseNextInstructions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/senselessComparisonWithNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/typeParameterOnLhsOfDot.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/unresolvedArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/variableDeclarationInSelector.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/cannotCompleteResolveAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoneApplicable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureForNullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromSubtyping.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeAndApproximation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/expectedTypeMismatchWithInVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/invokeCallWithCapturedReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/kt25302.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/kt2570.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/noCaptureTypeErrorForNonTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForOutCaptured.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/propagateNullailityOnSupertypesWhenCaptureTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/starProjectionRegression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/topLevelCapturingInsideReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForLastLambdaInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/indirectCoercionWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/noCoercion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/fixVariablesInRightOrder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/kt30300.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/kt31969.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/kt32818.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/kt33197.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/kt3372toCollection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation_ni.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/manyArgumentsForVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/outProjectedTypeToOutProjected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation_ni.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/selectFromTwoIncompatibleTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/selectIntegerValueTypeFromIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/theSameFunctionInArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/conflictingSubstitutions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInvariantPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/earlyCompletionForCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/fixTypeVariableWithNothingConstraintEarlierThanComplexVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/kt6320.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/kt7351ConstraintFromUnitExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/kt7433.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/operationsOnIntegerValueTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/remainConstraintContainingTypeWithoutProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/dependOnExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/dependantOnVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeDoubleReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeFromCastComplexExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/findViewById.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/immutableArrayList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/inferInFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/inferInFunctionLiteralsWithReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt11963.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt12399.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt1293.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt28598.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt28654.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt30405.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt3184.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt32415.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt32434.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt6175.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt619.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/listConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/mapFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/arrayAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsForArraySetExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedForVariableAsFunctionCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/externalTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/inferenceForNestedBinaryCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/kt3395.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/kt3461checkTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/noInformationForParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/complexDependancyOnVariableWithTrivialConstraint.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/kt24490.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/kt32051.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/kt32081.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/kt32207.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/kt32388.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/nestedLambdaInferenceWithIncorporationOfVariables.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nullableTypeArgumentWithNotNullUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/nullableUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/opposite.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/localFactorial.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/recursiveTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/compareBy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1029.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1031.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1127.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1145.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1358.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1410.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1718.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt1944.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2057.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2179.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2200.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2283.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2294.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2320.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2324.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2407.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2445.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2459.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2484.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2505.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2514.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2588.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2741.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2754.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2841.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2842.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2883.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3007.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3038.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3150.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3174.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3301.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3344.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt34029.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt34282.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3496.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt3559.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt4420.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt702.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt731.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt742.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt8132.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt832.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt943.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt9461.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportAboutUnresolvedReferenceAsUnresolved.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/inferTypeFromUnresolvedArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnComponentN.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnIteratorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/delegationAndInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitutionOldInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/kt6081SubstituteIntoClassCorrectly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/simpleSubstitutionCheckTypeArgumentsNotTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoAnonymousClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/typeConstructorMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/typeParameterAsUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/useFunctionLiteralsToInferType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.fir.kt create mode 100644 compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/anonymousObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/andOr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/arrayAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/comparison.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/componentAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/mathOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/capture.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/constructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/default.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/defaultLambdaInlineDisable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/defaultLambdaInlineSuspend.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/defaultLambdaInlining.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/extensionOnFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/functions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameterDisabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/inlineReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/invoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/isCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/kt15410.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/kt19679.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/kt4869.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/labeled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/lambdaCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/localFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/messagesForUnsupportedInInline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/explicitReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/fromOnlyLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/inlineLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/labeledReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaWithGlobalReturnsInsideOnlyLocalOne.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/localFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/nestedNonLocals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/nonInlinedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambdaBinaryExpr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/propertyAccessorsAndConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonLocalReturns/toOnlyLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/inPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/inPublicClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/kt14887.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/localFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonPublicMember/publishedApi.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nothingToInline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nullabilityOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/nullableFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/overrideWithInline.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/privateClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/propagation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/property/invoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/property/propertyWithBackingField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/property/unsupportedConstruction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/property/virtualProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/protectedCallDepecation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/protectedCallError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/publishedApi.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/recursion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/regressions/kt4341.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/returns.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/sam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/stringTemplate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/vararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/when.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inline/wrongUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclarationDisabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/constructorsJvmSignaturesClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/delegatedPropertyInInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesConflictOnInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassConstructorParameterWithDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassImplementsCollection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassWithForbiddenUnderlyingType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/inlineClassesInsideAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/lateinitInlineClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/presenceOfInitializerBlockInsideInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/presenceOfPublicPrimaryConstructorForInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/propertiesWithBackingFieldsInsideInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/recursiveInlineClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/reservedMembersAndConstructsInsideInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/unsignedLiteralsWithoutArtifactOnClasspath.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inlineClasses/varargsOnParametersOfInlineClassType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/InnerClassNameClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/accessingToJavaNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/accessingToKotlinNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/deepInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/enumEntries.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/extensionFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/extensionLambdaInsideNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/illegalModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/illegalModifier_lv12.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClassMemberResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerClassesInStaticParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/kt5854.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/kt6026.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/localClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/localClassInsideNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/localThisSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/modality.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassAccessedViaInstanceReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuterGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/outerGenericParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/outerProtectedMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/outerSuperClassMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/classObjectOfNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/dataLocalVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/enumConstant.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/genericNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/importNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedClassInPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedEnumConstant.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/qualifiedExpression/typePosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/resolvePackageClassInObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/selfAnnotationForClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/traits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inner/visibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/InheritedGenericFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/InnerClassFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/KJKInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/OverrideVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/Simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/StaticMembersFromSuperclasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-SpecialTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/UnboxingNulls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/accessClassObjectFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/annotationsInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/arrayOfStarParametrized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/brokenCode/classDuplicates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/brokenCode/fieldDuplicates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/callableReferencesStaticMemberClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/charBuffer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/collectionStringImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/commonCollections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/contains.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAll.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAndOverload.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/getCharSequence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantCharAtAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequenceKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableListKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantMapGetAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/mapGetOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/overridesBuiltinNoMagic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/collectorInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/computeIfAbsentConcurrent.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/contravariantIterable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/deprecations/forFakeOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/deprecations/forMixedOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/deprecations/forOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/differentFilename.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/enumGetOrdinal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/exceptionMessage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/fieldOverridesField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/fieldOverridesFieldOfDifferentType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/finalCollectionSize.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/flexibleNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/recursive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/selfTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/superCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructor/withClassTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/genericConstructorWithMultipleBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/inheritAbstractSamAdapter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/inheritanceStaticMethodFromInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/invisiblePackagePrivateInheritedMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/javaStaticImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt1402.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt1431.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt1730_implementCharSequence.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2152.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2394.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2606.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2619.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2641.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt2890.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt3307.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt3311.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt6720_abstractProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/kt7523.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/matchers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/mutableIterator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/nullForOptionalOrElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/overrideRawType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/overrideWithSamAndTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/packagePrivateClassStaticMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/packageVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/primitiveOverridesWithInlineClass/inlineClassErasedToPrimitiveInt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/interface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/isName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/val.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/var.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/protectedStaticSamePackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/recursionWithJavaSyntheticProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/fakeOverrideFunctionForStaticSam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/inheritedStaticSam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/staticSamFromImportWithStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/staticSamWithExplicitImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/sam/withDefaultMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInValueParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericSuperWildcard.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samByProjectedType/starProjectionComplexUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/samWithConsumer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/selectMoreSpecific.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/serializable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/shadowingPrimitiveStaticField.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultLongLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNullAndParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/emptyParameterName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/notNullVarargOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/nullableVarargOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesParameterName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/reorderedParameterNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/sameParameterName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/specialCharsParameterName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/stableParameterName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/signatureAnnotations/staticMethodWithDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/specialBridges.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/specialBuiltIns/securityProvider.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/staticMethodInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/types/arrayList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/types/returnCollection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPositionGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/types/typeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/abstractBaseClassMemberNotImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/abstractVsAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/defaultVsAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/hidingMethodOfAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/implementingMethodOfAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/notAMethodOfAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyDiamond.fir.kt create mode 100644 compiler/testData/diagnostics/tests/java8Overrides/singleRelevantDefault.fir.kt create mode 100644 compiler/testData/diagnostics/tests/kt13401.fir.kt create mode 100644 compiler/testData/diagnostics/tests/kt310.fir.kt create mode 100644 compiler/testData/diagnostics/tests/kt435.fir.kt create mode 100644 compiler/testData/diagnostics/tests/kt53.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt1703.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt361.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt3920.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt3988.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt4247.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt4586.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt4603.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/kt591.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/local/inapplicableLateinitModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/local/localLateinit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/local/uninitialized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/modifierApplicability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/modifierApplicability_lv12.fir.kt create mode 100644 compiler/testData/diagnostics/tests/lateinit/setter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/library/Collections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/library/kt828.fir.kt create mode 100644 compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/localInterfaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/annotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/constInteraction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/fromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/kt12248.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/kt15913.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/noDivisionByZeroFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/types.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/defaultModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/incompatibleVarianceModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/inlineParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/internalInInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/openInInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingBrackets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingKeyword.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/privateInInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/protected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/redundantTargets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/repeatedModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/collectionMethodStub.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArgumentsReversed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateNestedClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsageNoTypeAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/members.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameClassNameDifferentPackages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameGenericArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsBoundMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsIndexMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsNameMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classVsFunctionGenericsInParamsMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/covariantReturnTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differenceInParamNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentGenericsInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentNumberOfParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentReturnTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/extensionMatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsBoundsMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsEqNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsNotIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnFooT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/incompleteCodeNoNoneApplicable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noGenericsInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sameGenericsInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sinceKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateMethod/substitutedGenericInParams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateSuper/differentSuperTraits.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/internal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/kt14249.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/packagePrivate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/publishedApiInternal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/redundantElseInWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/varargConflict.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationArgumentEquality.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/constructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedDeclaresDefaultArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedInheritsDefaultArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedVsNonExpectedWithDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/deprecated/header.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/additionalEntriesInImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/differentEntryOrder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/generic/functionTypeParameterBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/generic/genericMemberBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/generic/membersInGenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/generic/typeParameterBoundsDifferentOrderActualMissing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDifferentConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/baseExpectClassWithoutConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/classKinds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/dontOverrideMethodsFromInterfaceInCommonCode.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithExplicitAbstractMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/expectFinalActualOpen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/explicitConstructorDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithAbstractMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithoutExplicitOverrideOfMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/extraHeaderOnMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassWithFunctionBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/implDataClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/implOpenClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/inheritanceByDelegationInExpectClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActual.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActualViaTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClassesWithErrors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/noImplKeywordOnMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/privateMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/simpleHeaderClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/smartCastOnExpectClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerClass/superClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/headerFunInNonHeaderClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/implDelegatedMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/implDynamic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/implFakeOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/inlineClasses/expectActualInlineClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/sealedTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/sealedTypeAliasTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callHeaderFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingImplDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/functionModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerAndImplInDIfferentPackages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerDeclarationWithBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerWithoutImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implDeclarationWithoutBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implWithoutHeader.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/inlineFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/simpleHeaderFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelFun/valueParameterModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simpleHeaderVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/allowForJavaAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/disallowForJavaConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/defaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/disabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/oldInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/varargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/InfixCallNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/PreferExtensionsOnNullableReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/ReceiverNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/SenselessNullInWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/dataFlowInfoAfterExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/equalityUnderNotNullCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideUnresolvedFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1270.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1680.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2109.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2125.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2195.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2223.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noSenselessNullOnNullableType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noUnnecessaryNotNullAssertionOnErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/nullableReceiverWithOverloadedMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/senslessComparisonWithNullOnTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastReceiverWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastsAndBooleanExpressions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWhenOpenGetterWithOverloading.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWithOverloadedExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentForIn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterPlatform.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterSimple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/safeAccessOnUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/safeCallWithInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/characterIsNotANumber.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/doublesInSimpleConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/numberAsUnionAndIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/Objects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/ObjectsInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/ObjectsLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/ObjectsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/OpenInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/invokeOnInnerObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferenceComplexCasesWithImportsOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesComplexCasesWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOldComplexCases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/classifierIsVisibleByTwoPaths.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationNew.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationOld.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt2240.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/kt5527.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/localObjectInsideObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/localObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/nestedClassInAnonymousObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/objectInsideFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/objectLiteralExpressionTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/objects/upperBoundViolated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/DeprecatedModAssignOperatorConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/DeprecatedModOperatorConventions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/deprecatedModConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/doNotResolveToInapplicableRem.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/errorOnExplicitModCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/forbiddenModOperatorConvention.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/modWithRemAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/noDeprecatedModConventionWithoutFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/noOperatorRemFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/operatorRem.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/preferRemAsExtentionOverMod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/preferRemAsMemberOverMod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/preferRemFromCompanionObjectOverRem.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/preferRemOverModInLocalFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/preferRemWithImplicitReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/prefereRemAsExtensionOverMemberMod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/remWithModAndModAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/remWithModAssign.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/resolveModIfRemIsHidden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/resolveToModWhenNoOperatorRemFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/AssignmentOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/InconsistentGetSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/IteratorAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/kt1028.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/kt13330.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/kt13349.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/kt3450.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOlverloadsGenericFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalExtFunsInPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsTPInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalValsInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConflictingOverloadsValsDifferentTypeInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ConstructorVsFunOverload.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/EmptyArgumentListInLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/ExtFunDifferentReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/FunNoConflictInDifferentPackages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/LocalFunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/OverloadFunRegularAndExt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/OverloadVarAndFunInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/TypeParameterMultipleBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/UnsubstitutedJavaGenetics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/defaultParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt10939.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt1998.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt2493.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt7068.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt7068_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt7440.fir.kt create mode 100644 compiler/testData/diagnostics/tests/overload/onlyPrivateOverloadsDiagnostic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractFunImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractFunNotImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractValImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractValNotImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractVarImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AbstractVarNotImplemented.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/AllPrivateFromSuperTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ConflictingFunctionSignatureFromSuperclass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DefaultParameterValueInOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DefaultParameterValues-NoErrorsWhenInheritingFromOneTypeTwice.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/Delegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DelegationFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DelegationVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DelegationVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/DuplicateMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ExtendFunctionClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideDifferentDeclarationSignatures.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideModality1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideModality2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideModality3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/Generics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/InvisiblePotentialOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/MissingDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/MultipleDefaultsAndNamesInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/MultipleDefaultsInSupertypesNoExplicitOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/OverrideWithErrors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/OverridingFinalMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ParameterDefaultValues-DefaultValueFromOnlyOneSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ParentInheritsManyImplementations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/PropertyInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ProtectedAndPrivateFromSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/SuspiciousCase1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/ToAbstractMembersFromSuper-kt1996.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/covariantOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/genericWithUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355viaJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt9550.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/returnTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/unrelatedInherited.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/valTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/clashesOnInheritance/varTypeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/fakeEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt12358.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt12467.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt12482.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt1862.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt2052.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt2491.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt4763.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt4763property.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt4785.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt6014.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt880.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/kt8990.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/overrideMemberFromFinalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/changeOnOverrideDiagnostic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/differentNamesInSupertypesDiagnostic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/invokeInFunctionClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/jjkHierarchy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/kjkHierarchy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/kjkWithSeveralSupers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsBothJavaAndKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/typeParameters/classAndTwoInterfaceBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/typeParameters/kt9850.fir.kt create mode 100644 compiler/testData/diagnostics/tests/override/typeParameters/simpleVisitorTwoAccepts.fir.kt create mode 100644 compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnNullableParenthesizedTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnParenthesizedTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/parenthesizedTypes/splitModifierList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/collectionOrNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/inferenceWithBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/stringOrNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/typeOfElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/delegateByComplexInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/dereference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/elvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/listSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/rawTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/strangeVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/userDefinedOut.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/valueFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/wildcards.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/getParentOfType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/inference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/intVsIntegerAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/intersection/map.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/javaEmptyList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/genericsAndArrays.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/intArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/javaCollectionToKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/kotlinCollectionToJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/kt27565.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/list.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBoundsNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/objectArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/overloadingForSubclass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/string.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodCall/visitor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/methodTypeParameterDefaultBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/methodTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/onTypeProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/arithmetic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/array.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/assignToVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/conditions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/defaultParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/expectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/for.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/functionArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/inferenceInConditionals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/invoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/multiDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/noWarningOnDoubleElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAfterSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/primitiveArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/safeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/throw.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisInCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullableTypeArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/override.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/errorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/genericInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/interClassesRecursion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonGenericRawMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawEnhancment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawWithInProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/recursiveBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/samRaw.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/saveRawCapabilitiesAfterSubtitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/safeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/samConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/supertypeArgumentsExplicit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/supertypeTypeArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/privateInFile/kt12429.fir.kt create mode 100644 compiler/testData/diagnostics/tests/privateInFile/topLevelAnnotationCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properDefaultInitializationInTailrec.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/blockBodyGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/cantBeInferred.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/explicitGetterType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/members.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/objectExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/overrides.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/primaryConstructorParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/topLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/unsupportedInferenceFromGetters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/inferenceFromGetters/vars.fir.kt create mode 100644 compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/publishedApi.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/GenericClassVsPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/JavaQualifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsRootClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/calleeExpressionAsCallExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/nullCalleeExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/qualifiedExpression/visibleClassVsQualifiedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/afterfor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/dowhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/else.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/foronly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/if.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/ifelse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/noifelse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/when.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reassignment/whiletrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/recovery/absentLeftHandSide.fir.kt create mode 100644 compiler/testData/diagnostics/tests/recovery/emptyTypeArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/recovery/namelessInJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/recovery/namelessMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/ConflictingExtensionProperties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/DuplicateParameterNamesInFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/EnumName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForClassesInDefaultObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForEnumEntriesAndDefaultObjectMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/PropertyAndFunInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/PropertyAndInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationInDefaultObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationInMultiFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInMultiFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMainInvalid.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/Redeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclarationsInObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/interfaceTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/kt2418.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/kt2438.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/kt470.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByInnerClassConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberPropertyWithInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedBySynthesizedMemberFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunVsMemberExtensionFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnErrorType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnNullableReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionPropertyShadowedByMemberProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionShadowedByDelegatedMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionVsNonPublicMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/infixExtensionVsNonInfixMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/localExtensionShadowedByMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/memberExtensionShadowedByMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/operatorExtensionVsNonOperatorMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/redeclarations/typeParameterWithTwoBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/reflection/noReflectionInClassPath.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/AmbiguityOnLazyTypeComputation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/AssignmentsUnderOperators.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/CoercionToUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/DoubleDefine.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet11.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet121.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet124.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet169.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet17.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet183-1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet183.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet53.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet67.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet68.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet69.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet72.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/Jet81.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/OverrideResolution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/TypeParameterAsASupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/WrongTraceInCallResolver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/delegationWithReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea40964.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea43298.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea53340.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea65509.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea66984.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea69735.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea72837.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/ea76264.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/intchar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClassNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt10243.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt10243a.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt10824.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt127.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt128.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt13685.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt13954.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt14740.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt1489_1728.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt1550.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt16086.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt16086_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt1647.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt1736.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt174.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt201.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt235.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt2376.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt251.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt258.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt26-1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt26.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt26303.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt2768.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt28001.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt282.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt287.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt2956.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt302.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt306.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt307.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt312.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt313.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt316.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt32205.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt328.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt334.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt335.336.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt337.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt352.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt353.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt3535.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt3647.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt3731.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt3810.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt385.109.441.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt394.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt398.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt399.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt402.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt41.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt411.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt439.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt442.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt443.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt455.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt456.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt459.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt469.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt4693.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt498.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt524.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt526UnresolvedReferenceInnerStatic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt5326.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt549.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt557.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt571.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt575.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt58.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt580.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt588.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt597.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt600.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt604.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt618.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt629.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt630.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt6508.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt688.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt691.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt701.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt716.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt743.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt750.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt7585/base.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt7585/java.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt7585/twoparents.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt762.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt7804.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt847.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt860.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt9384.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt9633.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt9808.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/noThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/CycleInTypeArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/ambiguityOnPropertiesWithTheSamePackageName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/constructorVsCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType_1_4.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedTypeArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerOnTypealias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerWithTypealiasRecursion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/inheritedMarker.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/nestedWithSameReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/properties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/twoImplicitReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/twoLanguages.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/unsupportedFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/useOfExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/usingWith.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/dslMarker/usingWithThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/KT-4372.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/invisibleInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/unresolvedInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/unsafeCallWithInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverTypeForInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt3772.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt3833-invokeInsideNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt4321InvokeOnEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt9517.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/kt9805.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/valNamedInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/localObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeArgsInFreeExpressionPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeUnmappedArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/completeUnmappedArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/kt7597.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/manyInapplicableCandidatesWithLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/objectLiteralAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/allLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/extensionReceiverAndVarargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericClash.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericWithProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10472.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsInDifferentPositions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsMixed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsWithRecursiveGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/withVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/parameterAsDefaultValueInLocalFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/kt10219.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/kt10510.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/kt9810.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/kt9965.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/localExtVsNonLocalExt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/staticVsImplicitReceiverMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/synthesizedMembersVsExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveTypeArgsForUnresolvedCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralsOverload.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithRedeclarationError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/inferenceForElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/multipleSuperClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/wrongReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/safeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/OverloadPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.fir.kt create mode 100644 compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/NoAmbiguityBetweenRootAndPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classParents.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectParents.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectSuperConstructorArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/objectParents.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/objectSuperConstructorArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/genericVsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/implicitReceiverMemberVsParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/companionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectAfterJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectsOrder.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/kt3856.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/methodsPriority.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedClassesFromInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNestedJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/nestedVsToplevelClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/severalCompanions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/hidePrivateByPublic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/jjkj.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/kjk.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/localVsStatic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash0.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/oneInterfaceManyTimes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/overloadStatic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticFunVsImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticPropertyVsImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsOuter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjavaAfterKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/invisibleSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1078.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1244.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1248.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt151.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1579.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1579_map_entry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1580.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1642.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1738.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1805.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1806.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1822.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt1942.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt2262.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt323.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt37.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt587.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt900-1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt900-2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt900.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt939.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/kt9430.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/complexCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructorsInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerClassInJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerProtectedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/javaInheritedInKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/kt7971.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaDifferentPackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaSamePackage.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/smartcastOnExtensionReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticPropertyExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/unstableSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/protectedVisibility/withSmartcast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/sameClassNameResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/visibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/DerivedTopLevel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/DoubleInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTree.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTriangleStar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenDoubleInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenMultipleInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNestedSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithAdditionalMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/Local.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/LocalSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NestedSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverConstructed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverDerivedFromNested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverFinal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NeverOpen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenNegated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAdditionalCase.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/NotFinal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/OperationWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/RedundantAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/TreeWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/TreeWhenFunctional.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/TreeWhenFunctionalNoIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/WhenOnEmptySealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sealed/WithInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/argumentsResolveInBodyAndDelegationCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/classInitializersWithoutPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/companionObjectScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/ctrsAnnotationResolve.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/dataClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/dataFlowInDelegationCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/delegationByWithoutPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/enums.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/generics3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/initializationFromOtherInstance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/lambdaInDelegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/noDefaultIfEmptySecondary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/noPrimaryConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/noSupertypeInitWithSecondaryConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithoutPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/reportResolutionErrorOnImplicitOnce.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/resolvePropertyInitializerWithoutPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/thisNonExisting.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/unreachableCode.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithoutPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/valOrValAndModifiersInCtr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToSecondary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowMultiDeclarationWithFunParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInClosure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowVariableInFor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/afterBinaryExpr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOff.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/impossible.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/insideCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/classObjectMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/complexComparison.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/doubleLambdaArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvis/basicOff.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisExclExclMerge.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisExclExclPlatform.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisExprNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisRHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/exclUnderAnd.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/explicitDefaultGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/extensionSafeCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/fakeSmartCastOnEquality.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/falseReceiverSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/falseUnnecessaryCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/fieldInGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/fieldPlus.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/genericIntersection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/genericSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ifCascadeExprNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ifExprInConditionNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ifExprInWhenSubjectNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ifExprNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ifWhenExprNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/implicitToGrandSon.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/incDecToNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/dependentOnPrevArg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt25432.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt2746.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt29767.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt4403.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt4415.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/kt6242.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/refineReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParametersNoSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt10232.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt10444.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt10483.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt1461.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt2422.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt27221.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt27221_2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt30826.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt30927.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3224.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3244.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3572.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3711.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3899.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt3993.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt5427.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt5455.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt6819.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt7561.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgumentFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentNoSubstitutedReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithBoundWithoutType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithExpectedGenericType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIfMerge.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaCallAnnotated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifies.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInSecondary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesWithDirectEq.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/lambdaUsesOwnerModifies.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/level_1_0.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localClassChanges.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyAfter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyBefore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localFunBetween.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localFunChanges.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/localObjectChanges.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/WhileTrueWithBreakInIfCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/assignElvisIfBreakInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/assignWhenInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/callBreakBetweenInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/callBreakFirstInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/callBreakInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/callBreakSecondInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/callBreakThirdInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInConditionWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNotNullBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNullWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/elvisBreakInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/elvisIfBreakInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/elvisInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/elvisLeftBreakInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifBlockInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakExprInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifElseBlockInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/ifInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/leftElvisBreakInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhileWithLongContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoops.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsShort.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/plusAssignWhenInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/safeCallBreakInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/safeCallInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/useInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whenInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whenReturnInsideWhileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileInCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileInConditionWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileNullAssignToSomething.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileNullWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileSimple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileTrivial.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueBreakReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueEarlyBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakAfter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakBefore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/multipleResolvedCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/base.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/captured.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclTwoArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/kt7110.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/objectLiterals/receiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/openInSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/ownerDeclaresBothModifies.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/propertyAsCondition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/propertyToNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/customGetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/kt4409.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/kt5502.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/open.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/protected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVals/var.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safeAs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/anotherVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/chainAndUse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/chainInChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/doubleCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/extension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/extensionCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/falseChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/falseExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/falseSecondArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/innerReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/insideCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/insideIfExpr.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/longChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverInLongChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithExclExcl.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithFlexible.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/property.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/receiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChain.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChainFalse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/simpleNullableReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/safecalls/twoArgs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartCastOnIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartcastOnSameFieldOfDifferentInstances.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/thisWithLabelAsReceiverPart.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/twoImplicitReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/typeDegradation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/typeInComparison.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/unstableToStable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/unstableToStableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varChangedInInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varChangedInLocalInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varInAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varInInitNoPrimary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varInInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varInSecondaryConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varInsideLocalFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/accessorAndFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/assignmentConversion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhileWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsAnd.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsChanged.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/inPropertySam.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/infix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/initialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/kt7599.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/property.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/propertyNotNeeded.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMemberCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/varAsUse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/varChangedInLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/varNotChangedInLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/whileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/variables/whileWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializerWrong.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureOff.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/infiniteWhileWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/initInTryReturnInCatch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedDoWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedLoops.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedWhile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/plusplusMinusminus.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableClassIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableClassIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableIncrement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNotNullInTry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryFinally.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryUnsound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/setSameInTry.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithBranch.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithMap.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInClosure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInSafeClosure.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNotChangedInLoop.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBracketSet.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBrackets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileWithBreak.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/whenExprNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/whenIfExprNonNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossible.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossibleJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/overriddenMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/simpleMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/sinceOldVersionIsOK.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsCompanionObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/inlineFunctionAlways.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noBigFunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundClassLiteral.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassLiteralInKClassExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassReferenceInKClassExtension.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noInlineProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noTopLevelSealedInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/substitutions/kt1558-short.fir.kt create mode 100644 compiler/testData/diagnostics/tests/substitutions/kt4887.fir.kt create mode 100644 compiler/testData/diagnostics/tests/substitutions/starProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithErrorTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/findClosestCorrespondingSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/functionTypeAsSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/invariantArgumentForTypeParameterWithMultipleBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/javaAndKotlinSuperType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/kt-1457.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/kt2069.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/kt2744.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/kt304.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/localAnonymousObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/localClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/nestedIntoLocalClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/topLevelAnonymousObjects.fir.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/unresolvedSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnAnonymousObjectInVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnPropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/mixed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/manyWarnings/onPropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onLocalVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onPropertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/AbbreviationName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/CompiledClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseGetters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseSetters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetA.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetterAndSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/ImplicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/IsNaming.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/JavaOverridesKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava4.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava5.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyAscii.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyPublic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCastImplicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeParameterReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethod.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethodInGenericClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/InnerClassInGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/NoNamedArgsAllowed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PackageLocal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PassNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Private.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Protected.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ReturnTypeAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Simple.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStatic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStaticWithoutRefinedSams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionWithoutRefinedSams.fir.kt create mode 100644 compiler/testData/diagnostics/tests/tailRecOnVirtualMember.fir.kt create mode 100644 compiler/testData/diagnostics/tests/tailRecOnVirtualMemberError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/tailRecOverridden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/tailRecursionComplex.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/basic.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/delegation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfacesWithKotlinFun.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/fillInStackTrace.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/finalize.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/hashMapGetOrDefault.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/concurrentMapRemove.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/getOrDefault.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/removeIf.fir.kt create mode 100644 compiler/testData/diagnostics/tests/targetedBuiltIns/stream.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/Super.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInInnerClasses.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOfAnyOverridenInInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOverriddenInAnotherSupertype.fir.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodsOfAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/traitWithRequired/traitRequiresAny.fir.kt create mode 100644 compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/cannotHaveManyClassUpperBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/propertyTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/propertyTypeParametersWithUpperBounds.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/repeatedBound.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/upperBoundCannotBeArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/aliasesOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/annotationsOnTypeAliases.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/boundViolationInTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/classReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/conflictingProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/constructorCallThroughPrivateAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/cyclicInheritanceViaTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/enumEntryQualifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/exposedExpandedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/functionTypeInTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/genericTypeAliasObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/illegalTypeInTypeAliasExpansion.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/import.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/importForTypealiasObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/inGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructorInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/javaStaticMembersViaTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt14498.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt14498a.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt14518.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt14641.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt15734.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/kt19601.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/methodReference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/nested.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/nestedSubstituted.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/noRHS.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/parameterRestrictions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/parameterSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/privateInFile.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/projectionsInTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/recursive.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/returnTypeNothingShouldBeSpecifiedExplicitly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/starProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/starProjectionInTypeAliasArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/substitutionVariance.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjectionInSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInSuperCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInferenceInSupertypesList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithPhantomTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorVsFunction.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongVisibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasExpansionRepeatedAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasForProjectionInSuperInterfaces.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasInAnonymousObjectType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasObject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasesInImportDirectives.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasesInQualifiers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotationsInArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotationInArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/unsupportedTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/unusedTypeAliasParameter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/wrongNumberOfArgumentsInTypeAliasConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/underscoresInNumericLiterals/illegalUnderscores.fir.kt create mode 100644 compiler/testData/diagnostics/tests/underscoresInNumericLiterals/noUnderscores.fir.kt create mode 100644 compiler/testData/diagnostics/tests/unit/nullableUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/unproperDefaultInitializationInTailrec.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/AmbiguousVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/MoreSpecificVarargsOfEqualLength.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/MostSepcificVarargsWithJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/NilaryVsVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/UnaryVsVararg.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotationError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_after.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_before.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt1781.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt1835.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt1838-param.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt1838-val.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt2163.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/kt422.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/prohibitAssigningSingleElementsInNamedForm.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargInSetter.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargIterator.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargOfNothing.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargsAndOut1.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargsAndOut2.fir.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/varargsAndPair.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/Class.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/Function.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/FunctionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/InPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/InvariantPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/NullableTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/OutPosition.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/PrimaryConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/ValProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/VarProperty.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/Visibility.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/ea1337846.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/Abstract.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.fir.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromJava.fir.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlinWarning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/AnnotatedWhenStatement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/BranchBypassVal.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/BranchBypassVar.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/BranchFalseBypass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/BranchFalseBypassElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/CommaInWhenConditionWithoutArgument.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/DuplicatedLabels.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ElseOnNullableEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/EmptyConditionWithExpression.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/EmptyConditionWithExpressionEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveBooleanBrackets.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveBooleanComplex.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveBooleanNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveBreakContinue.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveEnumIs.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveEnumMixed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveNoInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumAnnotated.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumStatement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveReturn.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveReturnThrow.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveValOverConditionalInit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveVarOverConditionalInit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBefore.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBoolean.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseExpectedUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseNoExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseReturnedFromLambdaExpectedInt.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseReturnedNonUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseReturnedUnit.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NoElseWhenStatement.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveBooleanNullable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustivePlatformEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWarning.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWarningElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWarningFalse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWarningForSealedClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWarningNull.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/NonExhaustiveWithNullabilityCheck.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/PropertyNotInitialized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/RedundantElse.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/ReservedExhaustiveWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/TopLevelSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/When.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/WhenTypeDisjunctions.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt10439.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt10809.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt10811.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt4434.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt9929.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/kt9972.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/capturingInInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/invisibleOutsideOfWhen.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/jumpoutInInitializer.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/nestedWhenWithSubject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/noSubjectVariableName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/reassignmentToWhenSubjectVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/shadowingOtherVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToEnum.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToSealed.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/softModifierName.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/subjectVariableInIsPattern.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt create mode 100644 compiler/testData/diagnostics/tests/when/withSubjectVariable/unusedWhenSubjectVariable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/CallCompanionProtectedNonStatic.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/CallToMainRedeclaredInMultiFile.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/InaccessibleInternalClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/RedeclarationMainInMultiFileClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/RenameOnImportHidesDefaultImport.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/addAllProjection.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/ClassObjectAnnotatedWithItsKClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/Synchronized.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/SynchronizedOnInterfaceCompanionMember.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/TransientOnDelegate.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/annotationsOnUseSiteTargets.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/illegalPlatformName.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmName.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmNameOnMangledNames.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPart.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPartWithJavaAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/suppressOnFunctionReference.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/simple.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/useOfNonConstVal.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/kt10136.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/nonConstValAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithoutValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArray.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayAndOtherDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayOnly.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayWithDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingLateinitAccessors.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingNonExistentAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/annotationAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/arg.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argAndOtherDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argArray.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefaultAndOther.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/twoArgs.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/value.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueAndOtherDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueArray.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefault.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefaultAndOther.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/clashWithCompanionObjectField.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inMultiFileFacade.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inSingleFileFacade.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/interface13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/jvmFieldApplicability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/JvmOverloadWithNoDefaults.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAbstractMethods.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_3.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_4.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnPrivate.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmSpecialFunctions/apiVersionIsAtLeastHasConstArguments.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constOrJvmFieldProperty.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty_LL13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructors.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/finalAndAbstract.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun_LL13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property_LL13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsInVariance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsOutVariance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInvariantTP.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassOutArrayInAnnotationsOutVariance.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/kotlinAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/typeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/strictfpOnClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/targetuse.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/assert/cast.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builtins/arraysAreCloneable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/cast/AsInsideIn.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/cast/IsReified.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/commonCollections.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/breakContinuesInInlinedLambda.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/expressionBody.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/implicitCastToAnyInReturnType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/inlinedLambdaAlwaysThrows.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/irrelevantUnknownClosure.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchFinally.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonLocalReturn.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonReturningInlinedLambda.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/safeCallAndInPlaceReturn.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/severalJumpOutsFromInlinedLambda.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatchFinally.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/typeMismatch.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/unreachableCode.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/valDefiniteReassignment.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varDefiniteInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varIndefiniteIntialization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteReassignment.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valIndefiniteInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varDefiniteInitalization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varIndefiniteInitialization.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/withReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/unknown/unknownInvocations.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/callUsualContractFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/booleanComparisons.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/emptyContract.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalEqualsCondition.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nestedConditionalEffects.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nonLambdaLiteralAsArgument.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/notFirstStatement.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContract.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/unlabeledReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/fqnContractFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/rewriteAtSliceFunctor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/useBeforeDeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/callWithDefaultValue.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/catchExceptionSpilling.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectionTypes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/implicitIff.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/returnsAndCalls.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/nullabilitySmartcastWhenNullability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperator.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithConstant.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithUnknown.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsOperator.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsWithNullableBoolean.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/isInstanceOperator.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperator.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithConstant.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithUnknown.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/partiallyIncorrect.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/typeSmartcastWhenNullability.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/unreachableBranches.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/valueOfContractedFunctionIngored.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubject.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubjectNullableBoolean.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withoutSubject.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNames.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNamesDuplicate.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInClassObject.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInObject.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jjk.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jk.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jkjk.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/elvisOnUnitInLet.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsagesAndInline.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/errors.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalUnsignedLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/fullFqNameUsage.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/importStatement.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/override.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/usageNotAsAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/forInFieldUpdatedInLoopBodyBefore13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/hugeUnresolvedKotlinxHtml.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/explicitTypeArgumentAsValidInputType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt26698.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/notNullAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndLowPriority.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndTopLevelCapturedTypes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCaptured.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesWithVarargs.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt12008.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt32345.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/instar.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContains.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContainsError.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/java/inheritedFunctionN.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/java/patternCompileCallableReference.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/javaClassOnCompanion.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/javaForKClass.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/kt8050.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/kt9078.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/kt9985.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/lateinit/isInitialized.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/multiplatform/jvmOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/abstract.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/body.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/constructor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/inline.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/noBody.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/override.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/reified.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/native/trait.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/outstar.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/overrideWithFunctionalType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/pureReifiable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/pureReifiableArrayOperations.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayListNullable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableCollection.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/maps.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableKey.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableValues.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/sets.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reflection/typeOfWithNonReifiedParameter.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/ea63992.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/ea65206.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/ea66827_dataClassWrongToString.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/ea70880_illegalJvmName.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt26806.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reified/arrayOfNullsReified.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reified/kt11881.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reified/nonCallableReiefied.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/javaPackageMembers.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/javaStaticMembers.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/kt10103.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/kt10732a.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samAgainstFunctionalType.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samConstructorVsFun.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenerics.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenericsWithoutRefinedSams.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunction.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunctionWithoutRefinedSams.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/shadowingInDestructuring.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachSafe.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachUnsafe.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/kt10463.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/lazyDeclaresAndModifies.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letAlwaysChangesToNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNullComplex.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letMergeNotNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letStable.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/letUsesOwnReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/listOfGeneric.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/smartcasts/withChangesToNull.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/sourceCompatibility/noDefaultImportOfKotlinComparisons.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/streams.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/unsupportedFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/noDisambiguation.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithDisabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/boundedSmartcasts.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/catchRedeclaration.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts_after.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts_after.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts_after.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliases.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithApiVersion1_0.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithoutFeature.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/hashMapTypeAlias.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/varargs/kt3213.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/varargs/kt4172j.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/varargs/kt5534.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/when/kt10192.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/when/kt10807.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt diff --git a/compiler/testData/diagnostics/tests/Abstract.fir.kt b/compiler/testData/diagnostics/tests/Abstract.fir.kt new file mode 100644 index 00000000000..fa1c36427a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Abstract.fir.kt @@ -0,0 +1,61 @@ +// FILE: b.kt +package MyPackage + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { field = v } + var c1: Int = 0; set(v: Int) { field = v } + abstract var c2: Int set(v: Int) { field = v } + abstract var c3: Int = 0; set(v: Int) { field = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} + +// FILE: c.kt +//creating an instance +abstract class B1( + val i: Int, + val s: String +) { +} + +class B2() : B1(1, "r") {} + +abstract class B3(i: Int) { +} + +fun foo(c: B3) { + val a = B3(1) + val b = B1(2, "s") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractAccessor.fir.kt b/compiler/testData/diagnostics/tests/AbstractAccessor.fir.kt new file mode 100644 index 00000000000..3bfbc333f51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/AbstractAccessor.fir.kt @@ -0,0 +1,21 @@ +abstract class My { + abstract var x: Int + public get + private set + + abstract val y: Int + protected get + + abstract protected var z: Int + internal get + private set + + abstract internal val w: Int + protected get + + abstract var u: Int + protected set + + open var t: Int = 0 + private set +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInAbstractClass.fir.kt b/compiler/testData/diagnostics/tests/AbstractInAbstractClass.fir.kt new file mode 100644 index 00000000000..5fa3158c3ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/AbstractInAbstractClass.fir.kt @@ -0,0 +1,45 @@ +package abstract + +abstract class MyAbstractClass() { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { field = v } + var c1: Int = 0; set(v: Int) { field = v } + abstract var c2: Int set(v: Int) { field = v } + abstract var c3: Int = 0; set(v: Int) { field = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInClass.fir.kt b/compiler/testData/diagnostics/tests/AbstractInClass.fir.kt new file mode 100644 index 00000000000..ca2612d35bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/AbstractInClass.fir.kt @@ -0,0 +1,45 @@ +package abstract + +class MyClass() { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { field = v } + var c1: Int = 0; set(v: Int) { field = v } + abstract var c2: Int set(v: Int) { field = v } + abstract var c3: Int = 0; set(v: Int) { field = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInTrait.fir.kt b/compiler/testData/diagnostics/tests/AbstractInTrait.fir.kt new file mode 100644 index 00000000000..2560ef10b9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/AbstractInTrait.fir.kt @@ -0,0 +1,45 @@ +package abstract + +interface MyTrait { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { field = v } + var c1: Int = 0; set(v: Int) { field = v } + abstract var c2: Int set(v: Int) { field = v } + abstract var c3: Int = 0; set(v: Int) { field = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.fir.kt b/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.fir.kt new file mode 100644 index 00000000000..65e6d55d878 --- /dev/null +++ b/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.fir.kt @@ -0,0 +1,10 @@ +// http://youtrack.jetbrains.net/issue/KT-419 + +class A(w: Int) { + var c = w + + init { + c = 81 + } +} + diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializers.fir.kt b/compiler/testData/diagnostics/tests/AnonymousInitializers.fir.kt new file mode 100644 index 00000000000..f066a44ab9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/AnonymousInitializers.fir.kt @@ -0,0 +1,26 @@ +interface NoC { + init { + + } + + val a : Int get() = 1 + + init { + + } +} + +class WithC() { + val x : Int = 1 + init { + val b = x + + } + + val a : Int get() = 1 + + init { + val z = b + val zz = x + } +} diff --git a/compiler/testData/diagnostics/tests/AssignToArrayElement.fir.kt b/compiler/testData/diagnostics/tests/AssignToArrayElement.fir.kt new file mode 100644 index 00000000000..43f8284a476 --- /dev/null +++ b/compiler/testData/diagnostics/tests/AssignToArrayElement.fir.kt @@ -0,0 +1,10 @@ +fun getArray(): Array = throw Exception() +fun getList(): MutableList = throw Exception() +fun fn() { + getArray()[1] = 2 + getList()[1] = 2 + getArray()[1]++ + getList()[1]++ + getArray()[1] += 2 + getList()[1] += 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AutoCreatedIt.fir.kt b/compiler/testData/diagnostics/tests/AutoCreatedIt.fir.kt new file mode 100644 index 00000000000..52f3a1f0369 --- /dev/null +++ b/compiler/testData/diagnostics/tests/AutoCreatedIt.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +fun text() { + "direct:a" to "mock:a" + "direct:a" on {it.body == ""} to "mock:a" + "direct:a" on {it -> it.body == ""} to "mock:a" + bar {1} + bar {it + 1} + bar {it, it1 -> it} + + bar1 {1} + bar1 {it + 1} + + bar2 {} + bar2 {1} + bar2 {it} + bar2 {it -> it} +} + +fun bar(f : (Int, Int) -> Int) {} +fun bar1(f : (Int) -> Int) {} +fun bar2(f : () -> Int) {} + +infix fun String.to(dest : String) { + +} + +infix fun String.on(predicate : (s : URI) -> Boolean) : URI { + return URI(this) +} + +class URI(val body : Any) { + infix fun to(dest : String) {} +} diff --git a/compiler/testData/diagnostics/tests/BacktickNames.fir.kt b/compiler/testData/diagnostics/tests/BacktickNames.fir.kt new file mode 100644 index 00000000000..a1f1b49f01c --- /dev/null +++ b/compiler/testData/diagnostics/tests/BacktickNames.fir.kt @@ -0,0 +1,94 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +// TODO Uncomment all the examples when there will be no problems with light classes +//package `foo.bar` + +// TODO: Uncomment after fixing KT-9416 +//import kotlin.Deprecated as `deprecate\entity` + +//@`deprecate\entity`("") data class Pair(val x: Int, val y: Int) + +// Names should not contains characters: '.', ';', '[', ']', '/', '<', '>', ':', '\\' +//class `class.name` +class `class;name` +class `class[name` +class `class]name` +//class `class/name` +class `classname` +class `class:name` +class `class\name` + +class ` ` {} +class ` ` + +//val `val.X` = 10 +val `val;X` = 10 +val `val[X` = 10 +val `val]X` = 10 +//val `val/X` = 10 +val `valX` = 10 +val `val:X` = 10 +val `val\X` = 10 + +val `;` = 1 +val `[` = 2 +val `]` = 3 +val `<` = 4 + +val `>` = 5 +val `:` = 6 +val `\` = 7 +val `<>` = 8 + +val `[]` = 9 +val `[;]` = 10 + +// TODO Uncomment when there will be no problems with light classes (Error: Invalid formal type parameter (must be a valid Java identifier)) +//class AWithTypeParameter<`T:K`> {} +//fun <`T/K`> genericFun(x: `T/K`) {} + +class B(val `a:b`: Int, val `c:d`: Int) + +val ff: (`x:X`: Int) -> Unit = {} +val fg: ((`x:X`: Int) -> Unit) -> Unit = {} +val fh: ((Int) -> ((`x:X`: Int) -> Unit) -> Unit) = {{}} + +fun f(x: Int, g: (Int) -> Unit) = g(x) + +data class Data(val x: Int, val y: Int) + +class A() { + init { + val `a:b` = 10 + } + + fun g(`x:y`: Int) { + val `s:` = 30 + } +} + +fun `foo:bar`(`\arg`: Int): Int { + val (`a:b`, c) = Data(10, 20) + val `a\b` = 10 + + fun localFun() {} + + for (`x/y` in 0..10) { + } + + f(10) { + `x:z`: Int -> localFun() + } + + f(20, fun(`x:z`: Int): Unit {}) + + try { + val `a:` = 10 + } + catch (`e:a`: Exception) { + val `b:` = 20 + } + + return `\arg` +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Basic.fir.kt b/compiler/testData/diagnostics/tests/Basic.fir.kt new file mode 100644 index 00000000000..6da1912608e --- /dev/null +++ b/compiler/testData/diagnostics/tests/Basic.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +fun foo(u : Unit) : Int = 1 + +fun test() : Int { + foo(1) + val a : () -> Unit = { + foo(1) + } + return 1 - "1" +} + +class A() { + val x : Int = foo1(xx) +} + +fun foo1() {} diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt new file mode 100644 index 00000000000..2d3b17bca8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +class A() { + override fun equals(other : Any?) : Boolean = false +} + +fun f(): Unit { + var x: Int? = 1 + x = null + x + 1 + x plus 1 + x < 1 + x += 1 + + x == 1 + x != 1 + + A() == 1 + + x === "1" + x !== "1" + + x === 1 + x !== 1 + + x..2 + x in 1..2 + + val y : Boolean? = true + false || y + y && true + y && 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Bounds.fir.kt b/compiler/testData/diagnostics/tests/Bounds.fir.kt new file mode 100644 index 00000000000..7f4547bc671 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Bounds.fir.kt @@ -0,0 +1,43 @@ +// !WITH_NEW_INFERENCE +// FILE: a.kt +package boundsWithSubstitutors + open class A + class B>() + + class C : A() + + val a = B() + val a1 = B() + + class X() + + val b = X, C>>() + val b0 = X() + val b1 = X, String>>() + +// FILE: b.kt + open class A {} + open class B() + + class Pair + + abstract class C, X : (B) -> Pair, B>>() : B() { // 2 errors + val a = B() // error + + abstract val x : (B) -> B + } + + +fun test() { + foo() + foo() + bar() + bar() + bar() + bar() + 1.buzz() +} + +fun foo() {} +fun bar() {} +fun Int.buzz() : Unit {} diff --git a/compiler/testData/diagnostics/tests/BreakContinue.fir.kt b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt new file mode 100644 index 00000000000..9ed9dad5de2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt @@ -0,0 +1,96 @@ +class C { + + fun f (a : Boolean, b : Boolean) { + b@ while (true) + a@ { + break@f + break + break@b + break@a + } + + continue + + b@ while (true) + a@ { + continue@f + continue + continue@b + continue@a + } + + break + + continue@f + break@f + } + + fun containsBreak(a: String?, b: String?) { + while (a == null) { + break; + } + a.compareTo("2") + } + + fun notContainsBreak(a: String?, b: String?) { + while (a == null) { + while (b == null) { + break; + } + } + a.compareTo("2") + } + + fun containsBreakWithLabel(a: String?) { + loop@ while(a == null) { + break@loop + } + a?.compareTo("2") + } + + fun containsIllegalBreak(a: String?) { + loop@ while(a == null) { + break@label + } + a.compareTo("2") + } + + fun containsBreakToOuterLoop(a: String?, b: String?) { + loop@ while(b == null) { + while(a == null) { + break@loop + } + a.compareTo("2") + } + } + + fun containsBreakInsideLoopWithLabel(a: String?, array: Array) { + l@ while(a == null) { + for (el in array) { + break@l + } + } + a.compareTo("2") + } + + fun unresolvedBreak(a: String?, array: Array) { + while(a == null) { + l@ for (el in array) { + break + } + if (true) break else break@l + } + a.compareTo("2") + } + + fun twoLabelsOnLoop() { + label1@ label2@ for (i in 1..100) { + if (i > 0) { + break@label1 + } + else { + break@label2 + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt b/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt new file mode 100644 index 00000000000..0d72e61d39f --- /dev/null +++ b/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt @@ -0,0 +1,92 @@ +// !LANGUAGE: +AllowBreakAndContinueInsideWhen + +fun breakContinueInWhen(i: Int) { + for (y in 0..10) { + when(i) { + 0 -> continue + 1 -> break + 2 -> { + for(z in 0..10) { + break + } + for(w in 0..10) { + continue + } + } + } + } +} + + +fun breakContinueInWhenWithWhile(i: Int, j: Int) { + while (i > 0) { + when (i) { + 0 -> continue + 1 -> break + 2 -> { + while (j > 0) { + break + } + } + } + } +} + +fun breakContinueInWhenWithDoWhile(i: Int, j: Int) { + do { + when (i) { + 0 -> continue + 1 -> break + 2 -> { + do { + if (j == 5) break + if (j == 10) continue + } while (j > 0) + } + } + } while (i > 0) +} + +fun labeledBreakContinue(i: Int) { + outer@ for (y in 0..10) { + when (i) { + 0 -> continue@outer + 1 -> break@outer + } + } +} + +fun testBreakContinueInWhenInWhileCondition() { + var i = 0 + while ( + when (i) { + 1 -> break + 2 -> continue + else -> true + } + ) { + ++i + } +} + +fun testBreakContinueInWhenInDoWhileCondition() { + var i = 0 + do { + ++i + } while ( + when (i) { + 1 -> break + 2 -> continue + else -> true + } + ) +} + +fun testBreakContinueInWhenInForIteratorExpression(xs: List, i: Int) { + for (x in when (i) { + 1 -> break + 2 -> continue + else -> xs + }) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/BreakContinueInWhen_before.fir.kt b/compiler/testData/diagnostics/tests/BreakContinueInWhen_before.fir.kt new file mode 100644 index 00000000000..8d32c2adfce --- /dev/null +++ b/compiler/testData/diagnostics/tests/BreakContinueInWhen_before.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: -AllowBreakAndContinueInsideWhen + +fun breakContinueInWhen(i: Int) { + for (y in 0..10) { + when(i) { + 0 -> continue + 1 -> break + 2 -> { + for(z in 0..10) { + break + } + for(w in 0..10) { + continue + } + } + } + } +} + + +fun breakContinueInWhenWithWhile(i: Int, j: Int) { + while (i > 0) { + when (i) { + 0 -> continue + 1 -> break + 2 -> { + while (j > 0) { + break + } + } + } + } +} + +fun breakContinueInWhenWithDoWhile(i: Int, j: Int) { + do { + when (i) { + 0 -> continue + 1 -> break + 2 -> { + do { + if (j == 5) break + if (j == 10) continue + } while (j > 0) + } + } + } while (i > 0) +} + +fun labeledBreakContinue(i: Int) { + outer@ for (y in 0..10) { + when (i) { + 0 -> continue@outer + 1 -> break@outer + } + } +} diff --git a/compiler/testData/diagnostics/tests/Builders.fir.kt b/compiler/testData/diagnostics/tests/Builders.fir.kt new file mode 100644 index 00000000000..dd611744660 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Builders.fir.kt @@ -0,0 +1,159 @@ +// FILE: a.kt + +/** + * This is an example of a Type-Safe Groovy-style Builder + * + * Builders are good for declaratively describing data in your code. + * In this example we show how to describe an HTML page in Kotlin. + * + * See this page for details: + * http://confluence.jetbrains.net/display/Kotlin/Type-safe+Groovy-style+builders + */ +package html + +import java.util.* + +fun main(args : Array) { + val result = + html { + head { + title {+"XML encoding with Kotlin"} + } + body { + h1 {+"XML encoding with Kotlin"} + p {+"this format can be used as an alternative markup to XML"} + + // an element with attributes and text content + a(href = "https://jetbrains.com/kotlin") {+"Kotlin"} + + // mixed content + p { + +"This is some" + b {+"mixed"} + +"text. For more see the" + a(href = "https://jetbrains.com/kotlin") {+"Kotlin"} + +"project" + } + p {+"some text"} + + // content generated from command-line arguments + p { + +"Command line arguments were:" + ul { + for (arg in args) + li {+arg} + } + } + } + } + println(result) +} + +abstract class Element { + abstract fun render(builder : StringBuilder, indent : String) + + override fun toString() : String { + val builder = StringBuilder() + render(builder, "") + return builder.toString() + } +} + +class TextElement(val text : String) : Element() { + override fun render(builder : StringBuilder, indent : String) { + builder.append("$indent$text\n") + } +} + +abstract class Tag(val name : String) : Element() { + val children = ArrayList() + val attributes = HashMap() + + protected fun initTag(tag : T, init : T.() -> Unit) : T { + tag.init() + children.add(tag) + return tag + } + + override fun render(builder : StringBuilder, indent : String) { + builder.append("$indent<$name${renderAttributes()}>\n") + for (c in children) { + c.render(builder, indent + " ") + } + builder.append("$indent\n") + } + + private fun renderAttributes() : String? { + val builder = StringBuilder() + for (a in attributes.keys) { + builder.append(" $a=\"${attributes[a]}\"") + } + return builder.toString() + } +} + +abstract class TagWithText(name : String) : Tag(name) { + operator fun String.unaryPlus() { + children.add(TextElement(this)) + } +} + +class HTML() : TagWithText("html") { + fun head(init : Head.() -> Unit) = initTag(Head(), init) + + fun body(init : Body.() -> Unit) = initTag(Body(), init) +} + +class Head() : TagWithText("head") { + fun title(init : Title.() -> Unit) = initTag(Title(), init) +} + +class Title() : TagWithText("title") + +abstract class BodyTag(name : String) : TagWithText(name) { + fun b(init : B.() -> Unit) = initTag(B(), init) + fun p(init : P.() -> Unit) = initTag(P(), init) + fun h1(init : H1.() -> Unit) = initTag(H1(), init) + fun ul(init : UL.() -> Unit) = initTag(UL(), init) + fun a(href : String, init : A.() -> Unit) { + val a = initTag(A(), init) + a.href = href + } +} + +class Body() : BodyTag("body") +class UL() : BodyTag("ul") { + fun li(init : LI.() -> Unit) = initTag(LI(), init) +} + +class B() : BodyTag("b") +class LI() : BodyTag("li") +class P() : BodyTag("p") +class H1() : BodyTag("h1") +class A() : BodyTag("a") { + public var href : String? + get() = attributes["href"] + set(value) { + if (value != null) { + attributes.put("href", value) +// attributes["href"] = value //doesn't work: KT-1355 + } + } +} + +fun html(init : HTML.() -> Unit) : HTML { + val html = HTML() + html.init() + return html +} + +// An excerpt from the Standard Library +operator fun MutableMap.set(key : K, value : V) = this.put(key, value) + +fun println(message : Any?) { + System.out.println(message) +} + +fun print(message : Any?) { + System.out.print(message) +} diff --git a/compiler/testData/diagnostics/tests/Casts.fir.kt b/compiler/testData/diagnostics/tests/Casts.fir.kt new file mode 100644 index 00000000000..54d6ee2d330 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Casts.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +fun test() : Unit { + var x : Int? = 0 + var y : Int = 0 + + checkSubtype(x) + checkSubtype(y) + checkSubtype(x as Int) + checkSubtype(y as Int) + checkSubtype(x as Int?) + checkSubtype(y as Int?) + checkSubtype(x as? Int) + checkSubtype(y as? Int) + checkSubtype(x as? Int?) + checkSubtype(y as? Int?) + + val s = "" as Any + ("" as String?)?.length + (data@("" as String?))?.length + (@MustBeDocumented()( "" as String?))?.length + Unit +} diff --git a/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt b/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt new file mode 100644 index 00000000000..fc9280d4f3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt @@ -0,0 +1,13 @@ +fun test(c : Char) { + test('') + test('a') + test('aa') + test('a) + test(' + test(0' + test('\n') + test('\\') + test('''') + test('\'') + test('\"') +} diff --git a/compiler/testData/diagnostics/tests/CompareToWithErrorType.fir.kt b/compiler/testData/diagnostics/tests/CompareToWithErrorType.fir.kt new file mode 100644 index 00000000000..de38f681f4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/CompareToWithErrorType.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +fun test() { + if (x > 0) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Constants.fir.kt b/compiler/testData/diagnostics/tests/Constants.fir.kt new file mode 100644 index 00000000000..fd7b1e0f60c --- /dev/null +++ b/compiler/testData/diagnostics/tests/Constants.fir.kt @@ -0,0 +1,53 @@ +// !CHECK_TYPE + +fun varargByte(vararg v: Byte) = v + +fun varargShort(vararg v: Short) = v + +fun varargInt(vararg v: Int) = v + +fun varargLong(vararg v: Long) = v + +fun varargFloat(vararg v: Float) = v + +fun varargDouble(vararg v: Double) = v + +fun testFun(p: T) {} + +fun test() { + checkSubtype(1) + checkSubtype(1) + checkSubtype(1) + checkSubtype(1) + + checkSubtype(0x001) + checkSubtype(0b001) + + checkSubtype(0.1) + checkSubtype(0.1.toFloat()) + + checkSubtype(1e5) + checkSubtype(1e-5.toFloat()) + + checkSubtype(1) + checkSubtype(1) + + 1 as Byte + 1 as Int + 0xff as Long + + 1.1 as Int + checkSubtype(1.1) + + varargByte(0x77, 1, 3, 200, 0b111) + varargShort(0x777, 1, 2, 3, 200000, 0b111) + varargInt(0x77777777, 0x7777777777, 1, 2, 3, 2000000000, 0b111) + varargLong(0x777777777777, 1, 2, 3, 200000, 0b111) + varargFloat(1, 1.0, -0.1, 1e4, 1e-4, -1e4) + varargDouble(1, 1.0, -0.1, 1e4, 1e-4, -1e4) + + testFun(1.0) + testFun(1.0) + testFun(1.0.toFloat()) + testFun(1.0.toFloat()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Constructors.fir.kt b/compiler/testData/diagnostics/tests/Constructors.fir.kt new file mode 100644 index 00000000000..b891906c1c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Constructors.fir.kt @@ -0,0 +1,35 @@ +open class NoC +class NoC1 : NoC + +class WithC0() : NoC() +open class WithC1() : NoC +class NoC2 : WithC1 +class NoC3 : WithC1() +class WithC2() : WithC1 + +class WithPC0() { +} + +class WithPC1(a : Int) { +} + + +class Foo() : WithPC0, this() { + +} + +class WithCPI_Dup(x : Int) { + var x : Int +} + +class WithCPI(x : Int) { + val a = 1 + val xy : Int = x +} + +class NoCPI { + val a = 1 + var ab = 1 + get() = 1 + set(v) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ConstructorsOfPrimitives.fir.kt b/compiler/testData/diagnostics/tests/ConstructorsOfPrimitives.fir.kt new file mode 100644 index 00000000000..da6e15df17d --- /dev/null +++ b/compiler/testData/diagnostics/tests/ConstructorsOfPrimitives.fir.kt @@ -0,0 +1,10 @@ +fun test() { + Double() + Float() + Long() + Int() + Short() + Byte() + Char() + Boolean() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/CovariantOverrideType.fir.kt b/compiler/testData/diagnostics/tests/CovariantOverrideType.fir.kt new file mode 100644 index 00000000000..bbfd7ba22a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/CovariantOverrideType.fir.kt @@ -0,0 +1,26 @@ +interface A { + fun foo() : Int = 1 + fun foo2() : Int = 1 + fun foo1() : Int = 1 + val a : Int + val a1 : Int + val g : Iterator + + fun g() : T + fun g1() : T +} + +abstract class B() : A { + override fun foo() { + } + override fun foo2() : Unit { + } + + override val a : Double = 1.toDouble() + override val a1 = 1.toDouble() + + abstract override fun g() : Int + abstract override fun g1() : List + + abstract override val g : Iterator +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.fir.kt b/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.fir.kt new file mode 100644 index 00000000000..41c7b8eedbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun f(x: Int = 0) {} + +val inVal: (x: Int = 0)->Unit = {} + +fun inParam(fn: (x: Int = 0)->Unit) {} + +fun inParamNested(fn1: (fn2: (n: Int = 0)->Unit)->Unit) {} + +fun inReturn(): (x: Int = 0)->Unit = {} + +class A : (Int)->Unit { + override fun invoke(p1: Int) { + var lambda: (x: Int = 0)->Unit = {} + } + + val prop: (x: Int = 0)->Unit + get(): (x: Int = 0)->Unit = {} +} diff --git a/compiler/testData/diagnostics/tests/DefaultValuesCheckWithoutBody.fir.kt b/compiler/testData/diagnostics/tests/DefaultValuesCheckWithoutBody.fir.kt new file mode 100644 index 00000000000..635ae083091 --- /dev/null +++ b/compiler/testData/diagnostics/tests/DefaultValuesCheckWithoutBody.fir.kt @@ -0,0 +1,9 @@ +interface Inter { + fun foo(x: Int = y, y: Int = x) +} + +abstract class Abst { + abstract fun foo(x: Int = y, y: Int = x) +} + +fun extraDiagnostics(x: Int = y, y: Int) diff --git a/compiler/testData/diagnostics/tests/DefaultValuesTypechecking.fir.kt b/compiler/testData/diagnostics/tests/DefaultValuesTypechecking.fir.kt new file mode 100644 index 00000000000..5ea18909bba --- /dev/null +++ b/compiler/testData/diagnostics/tests/DefaultValuesTypechecking.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +val x = "" + +fun bar(x : Int = "", y : Int = x, z : String = y) { + +} + +// KT-371 Resolve default parameters for constructors + +class A(x : Int = y, y : Int = x) { // None of the references is resolved, no types checked + fun foo(bool: Boolean, a: Int = b, b: String = a) {} +} + +val z = 3 + +fun foo(x: Int = y, y: Int = x, i : Int = z): Int = x + y diff --git a/compiler/testData/diagnostics/tests/DeferredTypes.fir.kt b/compiler/testData/diagnostics/tests/DeferredTypes.fir.kt new file mode 100644 index 00000000000..e2b364f0e11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/DeferredTypes.fir.kt @@ -0,0 +1,5 @@ +// NI_EXPECTED_FILE + +interface T { + val a = Foo.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt new file mode 100644 index 00000000000..009457f0ff9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt @@ -0,0 +1,53 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class CustomDelegate { + operator fun get(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +class OkDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +class CustomDelegate2 { + operator fun get(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {} + + operator fun getValue(thisRef: Any?, prop: KProperty<*>): Int = 5 + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: Int) {} +} + +class CustomDelegate3 { + operator fun get(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +operator fun OkDelegate.get(thisRef: Any?, prop: KProperty<*>): Int = 4 +operator fun OkDelegate.set(thisRef: Any?, prop: KProperty<*>, value: Int) {} + +operator fun CustomDelegate3.getValue(thisRef: Any?, prop: KProperty<*>): Int = 4 +operator fun CustomDelegate3.setValue(thisRef: Any?, prop: KProperty<*>, value: Int) {} + +class Example { + + var a by CustomDelegate() + val aval by CustomDelegate() + var b by OkDelegate() + var c by CustomDelegate2() + var d by CustomDelegate3() + + fun test() { + requireString(a) + requireString(aval) + requireString(b) + requireInt(c) + requireInt(d) + } + + fun requireString(s: String) {} + fun requireInt(n: Int) {} + +} diff --git a/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.fir.kt b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.fir.kt new file mode 100644 index 00000000000..36926e1421d --- /dev/null +++ b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Example { + operator fun plus(): String = "" + operator fun unaryPlus(): Int = 0 +} + +class ExampleDeprecated { + operator fun plus(): String = "" +} + +operator fun String.plus(): String = this +operator fun String.unaryPlus(): Int = 0 + +fun test() { + requireInt(+ "") + requireInt(+ Example()) + requireString(+ ExampleDeprecated()) +} + +fun requireInt(n: Int) {} +fun requireString(s: String) {} + +class Example2 { + operator fun plus() = this + operator fun minus() = this + + fun test() { + +this + -this + } +} diff --git a/compiler/testData/diagnostics/tests/DiamondFunction.fir.kt b/compiler/testData/diagnostics/tests/DiamondFunction.fir.kt new file mode 100644 index 00000000000..0d8b9a77755 --- /dev/null +++ b/compiler/testData/diagnostics/tests/DiamondFunction.fir.kt @@ -0,0 +1,9 @@ +interface Base { + fun f() = 1 +} + +open class Left() : Base + +interface Right : Base + +class Diamond() : Left(), Right diff --git a/compiler/testData/diagnostics/tests/DiamondFunctionGeneric.fir.kt b/compiler/testData/diagnostics/tests/DiamondFunctionGeneric.fir.kt new file mode 100644 index 00000000000..d84e34a40a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/DiamondFunctionGeneric.fir.kt @@ -0,0 +1,9 @@ +interface Base

{ + fun f() = 1 +} + +open class Left

() : Base

+ +interface Right

: Base

+ +class Diamond

() : Left

(), Right

diff --git a/compiler/testData/diagnostics/tests/DiamondProperty.fir.kt b/compiler/testData/diagnostics/tests/DiamondProperty.fir.kt new file mode 100644 index 00000000000..5a93ad88daa --- /dev/null +++ b/compiler/testData/diagnostics/tests/DiamondProperty.fir.kt @@ -0,0 +1,11 @@ +interface Base { + var v : Int + get() = 1 + set(v) {} +} + +open class Left() : Base + +interface Right : Base + +class Diamond() : Left(), Right diff --git a/compiler/testData/diagnostics/tests/Dollar.fir.kt b/compiler/testData/diagnostics/tests/Dollar.fir.kt new file mode 100644 index 00000000000..ca13dc9c9d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Dollar.fir.kt @@ -0,0 +1,12 @@ +package dollar + +open class `$$$$$`() { +} +open class `$`() { +} +open class `$$`(`$$$$` : `$$$$$`?) : `$`() { + val `$$$` : `$$$$$`? = `$$$$` + open public fun `$$$$$$`() : `$$$$$`? { + return `$$$` + } +} diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt new file mode 100644 index 00000000000..cf9bf545942 --- /dev/null +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt @@ -0,0 +1,55 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +enum class Color { + RED { + fun simpleName(): RED = null!! + } +} + +class MyColor(val x: Color.RED, y: Color.RED) : Color.RED { + + var z: Color.RED = Color.RED + set(arg: Color.RED) { z = arg } + + fun foo(arg: Color.RED): Color.RED = arg + + fun bar(): Color.RED { + class Local : Color.RED + fun local(arg: Color.RED): Color.RED = arg + val temp: Color.RED = Color.RED + temp as? Color.RED + if (temp is Color.RED) { + return temp as Color.RED + } + val obj = object : Color.RED {} + if (obj is Color.RED) { + return obj + } + return Color.RED + } +} + +fun create(): Array? = null + +interface Your + +class His : Your + +fun otherCreate(): Array? = null + +typealias RedAlias = Color.RED + +typealias ArrayOfEnumEntry = Array + +typealias ArrayOfEnumEntryAlias = Array + +fun bar(a: Any): T = a as T + +fun foo() { + foo() + foo() + bar(Color.RED) +} + +fun Array.foo(entries: Array): Array = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt b/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt new file mode 100644 index 00000000000..a4092148fba --- /dev/null +++ b/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt @@ -0,0 +1,7 @@ +fun bar(doIt: Int.() -> Int) { + 1.doIt() + 1?.doIt() + val i: Int? = 1 + i.doIt() + i?.doIt() +} diff --git a/compiler/testData/diagnostics/tests/ExternalAccessors.fir.kt b/compiler/testData/diagnostics/tests/ExternalAccessors.fir.kt new file mode 100644 index 00000000000..55bea112b91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ExternalAccessors.fir.kt @@ -0,0 +1,19 @@ +// See KT-13997 + +class Foo { + var bar: Int // Ok + external get + external set +} + +class Bar { + val foo: Int // Ok + external get + + var baz: Int + external get + + var gav: Int + external set +} + diff --git a/compiler/testData/diagnostics/tests/ExternalAndAbstract.fir.kt b/compiler/testData/diagnostics/tests/ExternalAndAbstract.fir.kt new file mode 100644 index 00000000000..fa3f698fe67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ExternalAndAbstract.fir.kt @@ -0,0 +1,9 @@ +abstract class A { + abstract val x : Int + external get +} + +interface B { + val x: Int + external get +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ForRangeConventions.fir.kt b/compiler/testData/diagnostics/tests/ForRangeConventions.fir.kt new file mode 100644 index 00000000000..87cad73a5f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ForRangeConventions.fir.kt @@ -0,0 +1,93 @@ +// !CHECK_TYPE + +import java.util.*; + +class NotRange1() { + +} + +abstract class NotRange2() { + abstract operator fun iterator() : Unit +} + +abstract class ImproperIterator1 { + abstract operator fun hasNext() : Boolean +} + +abstract class NotRange3() { + abstract operator fun iterator() : ImproperIterator1 +} + +abstract class ImproperIterator2 { + abstract operator fun next() : Boolean +} + +abstract class NotRange4() { + abstract operator fun iterator() : ImproperIterator2 +} + +abstract class ImproperIterator3 { + abstract operator fun hasNext() : Int + abstract operator fun next() : Int +} + +abstract class NotRange5() { + abstract operator fun iterator() : ImproperIterator3 +} + +abstract class AmbiguousHasNextIterator { + abstract operator fun hasNext() : Boolean + val hasNext : Boolean get() = false + abstract operator fun next() : Int +} + +abstract class NotRange6() { + abstract operator fun iterator() : AmbiguousHasNextIterator +} + +abstract class ImproperIterator4 { + val hasNext : Int get() = 1 + abstract operator fun next() : Int +} + +abstract class NotRange7() { + abstract operator fun iterator() : ImproperIterator3 +} + +abstract class GoodIterator { + abstract operator fun hasNext() : Boolean + abstract operator fun next() : Int +} + +abstract class Range0() { + abstract operator fun iterator() : GoodIterator +} + +abstract class Range1() { + abstract operator fun iterator() : Iterator +} + +abstract class ImproperIterator5 { + abstract val String.hasNext : Boolean + abstract operator fun next() : Int +} + +abstract class NotRange8() { + abstract operator fun iterator() : ImproperIterator5 +} + + +fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRange4: NotRange4, notRange5: NotRange5, notRange6: NotRange6, notRange7: NotRange7, notRange8: NotRange8, range0: Range0, range1: Range1) { + for (i in notRange1); + for (i in notRange2); + for (i in notRange3); + for (i in notRange4); + for (i in notRange5); + for (i in notRange6); + for (i in notRange7); + for (i in notRange8); + for (i in range0); + for (i in range1); + + for (i in (checkSubtype>(ArrayList()))); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt new file mode 100644 index 00000000000..22b2715d38f --- /dev/null +++ b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt @@ -0,0 +1,13 @@ +fun foo(a: (String) -> Unit) { + "".a() +} + + + +interface A : (String) -> Unit {} + +fun foo(a: @ExtensionFunctionType A) { + // @Extension annotation on an unrelated type shouldn't have any effect on this diagnostic. + // Only kotlin.Function{n} type annotated with @Extension should + "".a() +} diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt new file mode 100644 index 00000000000..ba26cc68507 --- /dev/null +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt @@ -0,0 +1,84 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package foo + +fun Any.foo() : () -> Unit { + return {} +} + +fun Any.foo1() : (i : Int) -> Unit { + return {} +} + +fun foo2() : (i : () -> Unit) -> Unit { + return {} +} + +fun fooT1(t : T) : () -> T { + return {t} +} + +fun fooT2() : (t : T) -> T { + return {it} +} + +fun main(args : Array) { + args.foo()() + args.foo1()() + a.foo1()() + a.foo1()(a) + + args.foo1()(1) + args.foo1()("1") + a.foo1()("1") + a.foo1()(a) + + foo2()({}) + foo2(){} + (foo2()){} + (foo2()){x -> } + foo2()({x -> }) + + val a = fooT1(1)() + checkSubtype(a) + + val b = fooT2()(1) + checkSubtype(b) + fooT2()(1) // : Any? + + 1() + 1{} + 1(){} +} + +fun f() : Int.() -> Unit = {} + +fun main1() { + 1.(fun Int.() = 1)(); + {1}(); + (fun (x : Int) = x)(1) + 1.(fun Int.(x : Int) = x)(1); + l@{1}() + 1.((fun Int.() = 1))() + 1.(f())() + 1.if(true){f()}else{f()}() + 1.if(true)(fun Int.() {})else{f()}() + + 1."sdf"() + + 1."sdf" + 1.{} + 1.if (true) {} +} + +fun test() { + {x : Int -> 1}(); + (fun Int.() = 1)() + "sd".(fun Int.() = 1)() + val i : Int? = null + i.(fun Int.() = 1)(); + {}() + 1?.(fun Int.() = 1)() + 1.{}() +} diff --git a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt new file mode 100644 index 00000000000..770829cde47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +fun test(a) { + +} + +class A(a) + +val bar = fun(a){} + +val la = { a -> } +val las = { a: Int -> } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt new file mode 100644 index 00000000000..8d72e507236 --- /dev/null +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.fir.kt @@ -0,0 +1,209 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNREACHABLE_CODE + +fun none() {} + +fun unitEmptyInfer() {} +fun unitEmpty() : Unit {} +fun unitEmptyReturn() : Unit {return} +fun unitIntReturn() : Unit {return 1} +fun unitUnitReturn() : Unit {return Unit} +fun test1() : Any = {return} +fun test2() : Any = a@ {return@a 1} +fun test3() : Any { return } +fun test4(): ()-> Unit = { return@test4 } +fun test5(): Any = l@{ return@l } +fun test6(): Any = {return 1} + +fun bbb() { + return 1 +} + +fun foo(expr: StringBuilder): Int { + val c = 'a' + when(c) { + 0.toChar() -> throw Exception("zero") + else -> throw Exception("nonzero" + c) + } +} + + +fun unitShort() : Unit = Unit +fun unitShortConv() : Unit = 1 +fun unitShortNull() : Unit = null + +fun intEmpty() : Int {} +fun intShortInfer() = 1 +fun intShort() : Int = 1 +//fun intBlockInfer() {1} +fun intBlock() : Int {return 1} +fun intBlock1() : Int {1} + +fun intString(): Int = "s" +fun intFunctionLiteral(): Int = { 10 } + +fun blockReturnUnitMismatch() : Int {return} +fun blockReturnValueTypeMismatch() : Int {return 3.4} +fun blockReturnValueTypeMatch() : Int {return 1} +fun blockReturnValueTypeMismatchUnit() : Int {return Unit} + +fun blockAndAndMismatch() : Int { + true && false + } +fun blockAndAndMismatch1() : Int { + return true && false +} +fun blockAndAndMismatch2() : Int { + (return true) && (return false) +} + +fun blockAndAndMismatch3() : Int { + true || false + } +fun blockAndAndMismatch4() : Int { + return true || false +} +fun blockAndAndMismatch5() : Int { + (return true) || (return false) +} +fun blockReturnValueTypeMatch1() : Int { + return if (1 > 2) 1.0 else 2.0 +} +fun blockReturnValueTypeMatch2() : Int { + return if (1 > 2) 1 +} +fun blockReturnValueTypeMatch3() : Int { + return if (1 > 2) else 1 +} +fun blockReturnValueTypeMatch4() : Int { + if (1 > 2) + return 1.0 + else return 2.0 +} +fun blockReturnValueTypeMatch5() : Int { + if (1 > 2) + return 1.0 + return 2.0 +} +fun blockReturnValueTypeMatch6() : Int { + if (1 > 2) + else return 1.0 + return 2.0 +} +fun blockReturnValueTypeMatch7() : Int { + if (1 > 2) + 1.0 + else 2.0 + } +fun blockReturnValueTypeMatch8() : Int { + if (1 > 2) + 1.0 + else 2.0 + return 1 +} +fun blockReturnValueTypeMatch9() : Int { + if (1 > 2) + 1.0 + } +fun blockReturnValueTypeMatch10() : Int { + return if (1 > 2) + 1 +} +fun blockReturnValueTypeMatch11() : Int { + if (1 > 2) + else 1.0 + } +fun blockReturnValueTypeMatch12() : Int { + if (1 > 2) + return 1 + else return 1.0 +} +fun blockNoReturnIfValDeclaration(): Int { + val x = 1 + } +fun blockNoReturnIfEmptyIf(): Int { + if (1 < 2) {} else {} + } +fun blockNoReturnIfUnitInOneBranch(): Int { + if (1 < 2) { + return 1 + } else { + if (3 < 4) { + } else { + return 2 + } + } + } +fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) {} else {} +fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) {} else 2 + +val a = return 1 + +class A() { +} +fun illegalConstantBody(): Int = "s" +fun illegalConstantBlock(): String { + return 1 +} +fun illegalIfBody(): Int = + if (1 < 2) 'a' else { 1.0 } +fun illegalIfBlock(): Boolean { + if (1 < 2) + return false + else { return 1 } +} +fun illegalReturnIf(): Char { + return if (1 < 2) 'a' else { 1 } +} + +fun returnNothing(): Nothing { + throw 1 +} +fun f(): Int { + if (1 < 2) { return 1 } else returnNothing() +} + +fun f1(): Int = if (1 < 2) 1 else returnNothing() + +public fun f2() = 1 +class B() { + protected fun f() = "ss" +} + +fun testFunctionLiterals() { + val endsWithVarDeclaration : () -> Boolean = { + val x = 2 + } + + val endsWithAssignment: () -> Int = { + var x = 1 + x = 333 + } + + val endsWithReAssignment: () -> Int = { + var x = 1 + x += 333 + } + + val endsWithFunDeclaration : () -> String = { + var x = 1 + x = 333 + fun meow() : Unit {} + } + + val endsWithObjectDeclaration : () -> Int = { + var x = 1 + x = 333 + object A {} + } + + val expectedUnitReturnType1: () -> Unit = { + val x = 1 + } + + val expectedUnitReturnType2: () -> Unit = { + fun meow() : Unit {} + object A {} + } + +} diff --git a/compiler/testData/diagnostics/tests/GenericArgumentConsistency.fir.kt b/compiler/testData/diagnostics/tests/GenericArgumentConsistency.fir.kt new file mode 100644 index 00000000000..d5421d842e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/GenericArgumentConsistency.fir.kt @@ -0,0 +1,43 @@ +// FILE: b.kt +interface A {} +interface B : A {} +interface C : B, A {} +interface C1 : B, A {} +interface D : C, B{} + +interface A1 {} +interface B1 : A1 {} +interface B2 : A1, B1 {} + +interface BA1 {} +interface BB1 : BA1 {} +interface BB2 : BA1, BB1 {} + + +// FILE: b.kt +package x + interface AA1 {} + interface AB1 : AA1 {} + interface AB3 : AA1> {} + interface AB2 : AA1, AB1, AB3 {} + +// FILE: b.kt +package x2 + interface AA1 {} + interface AB1 : AA1 {} + interface AB3 : AA1> {} + interface AB2 : AA1, AB1, AB3 {} + +// FILE: b.kt +package x3 + interface AA1 {} + interface AB1 : AA1 {} + interface AB3 : AA1> {} + interface AB2 : AA1, AB1, AB3 {} + +// FILE: b.kt +package sx2 + interface AA1 {} + interface AB1 : AA1 {} + interface AB3 : AA1> {} + interface AB2 : AA1, AB1, AB3 {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/GenericFunctionIsLessSpecific.fir.kt b/compiler/testData/diagnostics/tests/GenericFunctionIsLessSpecific.fir.kt new file mode 100644 index 00000000000..67150ef3926 --- /dev/null +++ b/compiler/testData/diagnostics/tests/GenericFunctionIsLessSpecific.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +// A generic funciton is always less specific than a non-generic one +fun foo(t : T) : Unit {} +fun foo(i : Int) : Int = 1 + +fun test() { + checkSubtype(foo(1)) + checkSubtype(foo("s")) +} diff --git a/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt b/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt new file mode 100644 index 00000000000..6b1c6f1338a --- /dev/null +++ b/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt @@ -0,0 +1,81 @@ +val z: Boolean = true +val b: Byte = 0 +val s: Short = 0 +val i: Int = 0 +val j: Long = 0L +val f: Float = 0.0f +val d: Double = 0.0 +val c: Char = '0' + +val nz: Boolean? = true +val nb: Byte? = 0 +val ns: Short? = 0 +val ni: Int? = 0 +val nj: Long? = 0L +val nf: Float? = 0.0f +val nd: Double? = 0.0 +val nc: Char? = '0' + +val n: Number = 0 +val nn: Number? = 0 +val a: Any = 0 +val na: Any? = 0 + +// Identity for primitive values of same type +val test_zz = z === z || z !== z +val test_bb = b === b || b !== b +val test_ss = s === s || s !== s +val test_ii = i === i || i !== i +val test_jj = j === j || j !== j +val test_ff = f === f || f !== f +val test_dd = d === d || d !== d +val test_cc = c === c || c !== c + +// Identity for primitive values of different types (no extra error) +val test_zb = z === b || z !== b + +// Primitive vs nullable +val test_znz = z === nz || nz === z || z !== nz || nz !== z +val test_bnb = b === nb || nb === b || b !== nb || nb !== b +val test_sns = s === ns || ns === s || s !== ns || ns !== s +val test_ini = i === ni || ni === i || i !== ni || ni !== i +val test_jnj = j === nj || nj === j || j !== nj || nj !== j +val test_fnf = f === nf || nf === f || f !== nf || nf !== f +val test_dnd = d === nd || nd === d || d !== nd || nd !== d +val test_cnc = c === nc || nc === c || c !== nc || nc !== c + +// Primitive number vs Number +val test_bn = b === n || n === b || b !== n || n !== b +val test_sn = s === n || n === s || s !== n || n !== s +val test_in = i === n || n === i || i !== n || n !== i +val test_jn = j === n || n === j || j !== n || n !== j +val test_fn = f === n || n === f || f !== n || n !== f +val test_dn = d === n || n === d || d !== n || n !== d + +// Primitive number vs Number? +val test_bnn = b === nn || nn === b || b !== nn || nn !== b +val test_snn = s === nn || nn === s || s !== nn || nn !== s +val test_inn = i === nn || nn === i || i !== nn || nn !== i +val test_jnn = j === nn || nn === j || j !== nn || nn !== j +val test_fnn = f === nn || nn === f || f !== nn || nn !== f +val test_dnn = d === nn || nn === d || d !== nn || nn !== d + +// Primitive vs Any +val test_za = z === a || a === z || z !== a || a !== z +val test_ba = b === a || a === b || b !== a || a !== b +val test_sa = s === a || a === s || s !== a || a !== s +val test_ia = i === a || a === i || i !== a || a !== i +val test_ja = j === a || a === j || j !== a || a !== j +val test_fa = f === a || a === f || f !== a || a !== f +val test_da = d === a || a === d || d !== a || a !== d +val test_ca = c === a || a === c || c !== a || a !== c + +// Primitive vs Any? +val test_zna = z === na || na === z || z !== na || na !== z +val test_bna = b === na || na === b || b !== na || na !== b +val test_sna = s === na || na === s || s !== na || na !== s +val test_ina = i === na || na === i || i !== na || na !== i +val test_jna = j === na || na === j || j !== na || na !== j +val test_fna = f === na || na === f || f !== na || na !== f +val test_dna = d === na || na === d || d !== na || na !== d +val test_cna = c === na || na === c || c !== na || na !== c \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/IncDec.fir.kt b/compiler/testData/diagnostics/tests/IncDec.fir.kt new file mode 100644 index 00000000000..71ddec78514 --- /dev/null +++ b/compiler/testData/diagnostics/tests/IncDec.fir.kt @@ -0,0 +1,46 @@ +class IncDec() { + operator fun inc() : IncDec = this + operator fun dec() : IncDec = this +} + +fun testIncDec() { + var x = IncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x +} + +class WrongIncDec() { + operator fun inc() : Int = 1 + operator fun dec() : Int = 1 +} + +fun testWrongIncDec() { + var x = WrongIncDec() + x++ + ++x + x-- + --x +} + +class UnitIncDec() { + operator fun inc() : Unit {} + operator fun dec() : Unit {} +} + +fun testUnitIncDec() { + var x = UnitIncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt new file mode 100644 index 00000000000..ae99eb93871 --- /dev/null +++ b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt @@ -0,0 +1,37 @@ +// http://youtrack.jetbrains.net/issue/KT-451 +// KT-451 Incorrect character literals cause assertion failures + +fun ff() { + val b = '' + val c = '23' + val d = 'a + val e = 'ab + val f = '\' +} + +fun test() { + 'a' + '\n' + '\t' + '\b' + '\r' + '\"' + '\'' + '\\' + '\$' + '\x' + '\123' + '\ra' + '\000' + '\000' + '\u0000' + '\u000a' + '\u000A' + '\u' + '\u0' + '\u00' + '\u000' + '\u000z' + '\\u000' + '\' +} diff --git a/compiler/testData/diagnostics/tests/InferNullabilityInThenBlock.fir.kt b/compiler/testData/diagnostics/tests/InferNullabilityInThenBlock.fir.kt new file mode 100644 index 00000000000..81dbd493513 --- /dev/null +++ b/compiler/testData/diagnostics/tests/InferNullabilityInThenBlock.fir.kt @@ -0,0 +1,9 @@ +fun ff(a: String) = 1 + +fun gg() { + val a: String? = "" + + if (a != null) { + ff(a) + } +} diff --git a/compiler/testData/diagnostics/tests/Infix.fir.kt b/compiler/testData/diagnostics/tests/Infix.fir.kt new file mode 100644 index 00000000000..f852458c439 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Infix.fir.kt @@ -0,0 +1,38 @@ +class Pair(val first: A, val second: B) + +class Example { + infix fun to(other: Example) = Pair(this, other) + fun toNonInfix(other: Example) = Pair(this, other) +} + +infix fun Example.toExt(other: Example) = Pair(this, other) +fun Example.toExtNonInfix(other: Example) = Pair(this, other) + +infix fun Example.toExtWithExtraParams(other: Example, blah: Int = 0) = Pair(this, other) +fun Example.toExtNonInfixWithExtraParams(other: Example, blah: Int = 0) = Pair(this, other) + +infix fun Example.toExtDefaultValues(other: Example? = null, blah: Int = 0) = Pair(this, other) +fun Example.toExtNonInfixDefaultValues(other: Example? = null, blah: Int = 0) = Pair(this, other) + +fun Example.withLambda(f: () -> Unit) = Pair(this, f) + +fun test() { + Example() to Example() + Example() toNonInfix Example() + Example().toNonInfix(Example()) + + val a = Example() + val b = Example() + + a toExt b + a toExtNonInfix b + a.toExtNonInfix(b) + + a toExtWithExtraParams b + a toExtNonInfixWithExtraParams b + + a toExtDefaultValues b + a toExtNonInfixDefaultValues b + + a withLambda { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/InfixModifierApplicability.fir.kt b/compiler/testData/diagnostics/tests/InfixModifierApplicability.fir.kt new file mode 100644 index 00000000000..e276ad484b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/InfixModifierApplicability.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Pair(val a: A, val b: B) +infix fun A.to(that: B): Pair = Pair(this, that) + +// OK +infix fun String.ok1(o: String) {} +class OkTest { + infix fun ok2(o: String) {} + infix fun String.ok3(o: String) {} +} + +// Errors +infix fun String.e1(o: String, o2: String? = null) = o +infix fun String.e2(o: String = "", o2: String? = null) = o + +infix fun e3() {} +infix fun e4(s: String) {} +infix fun String.e5() {} +infix fun String.e6(a: Int, b: Int) {} +infix fun e7(a: Int, b: Int) {} + +class Example { + infix fun e8(s: String, a: Int = 0) {} + infix fun e9(s: String, a: Int) {} + infix fun e10() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/InvokeAndRecursiveResolve.fir.kt b/compiler/testData/diagnostics/tests/InvokeAndRecursiveResolve.fir.kt new file mode 100644 index 00000000000..1a8d787d47f --- /dev/null +++ b/compiler/testData/diagnostics/tests/InvokeAndRecursiveResolve.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +fun test() = 3 + +fun proxy(t: T) = t + +class A { + val test = test() +} + +class B { + val test = proxy(test()) +} + +class C { + val bar = test() + val test = bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/IsExpressions.fir.kt b/compiler/testData/diagnostics/tests/IsExpressions.fir.kt new file mode 100644 index 00000000000..a12b3ef9fe4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/IsExpressions.fir.kt @@ -0,0 +1,26 @@ +// FILE: KotlinFile.kt + +fun test() { + if (1 is Int) { + if (1 is Boolean) { + + } + } + + A.create() is A + A.create() is A? + + unresolved is A + unresolved is A? + + val x = foo() + x as String + x is String +} + +fun foo(): Any = "" + +// FILE: A.java +class A { + static A create() { return null; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt new file mode 100644 index 00000000000..89c5d1c5d1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt @@ -0,0 +1,143 @@ +package lvalue_assignment + +open class B() { + var b: Int = 2 + val c: Int = 34 +} + +class C() : B() { + var x = 4 + fun foo(c: C) { + this.x = 34 + this.b = 123 + super.b = 23 + this.c = 34 + super.c = 3535 //repeat for 'c' + + getInt() = 12 + } + + fun foo1(c: C) { + super.c = 34 + } + + fun bar(c: C) { + this = c //should be an error + } +} + +fun getInt() = 0 + +class D() { + inner class B() { + fun foo() { + this@D = D() + } + } +} + +fun foo(): Unit {} + +fun cannotBe() { + var i: Int = 5 + + z = 30; + "" = ""; + foo() = Unit; + + (i as Int) = 34 + (i is Int) = false + A() = A() + 5 = 34 +} + +fun canBe(i0: Int, j: Int) { + var i = i0 + (label@ i) = 34 + + (label@ j) = 34 //repeat for j + + val a = A() + (l@ a.a) = 3894 +} + +fun canBe2(j: Int) { + (label@ j) = 34 +} + +class A() { + var a: Int = 3 +} + +class Test() { + fun testIllegalValues() { + 1 += 23 + (l@ 1) += 23 + + getInt() += 343 + (f@ getInt()) += 343 + + 1++ + (r@ 1)++ + + getInt()++ + (m@ getInt())++ + + this++ + + var s : String = "r" + s += "ss" + s += this + s += (a@ 2) + } + + fun testIncompleteSyntax() { + val s = "s" + ++s. + } + + fun testVariables() { + var a: Int = 34 + val b: Int = 34 + + a += 34 + (l@ a) += 34 + + b += 34 + + a++ + (l@ a)++ + (a)++ + } + + fun testVariables1() { + val b: Int = 34 + + (l@ b) += 34 + //repeat for b + (b) += 3 + } + + fun testArrays(a: Array, ab: Ab) { + a[3] = 4 + a[4]++ + a[6] += 43 + + ab.getArray()[54] = 23 + ab.getArray()[54]++ + + (f@ a)[3] = 4 + + this[54] = 34 + } +} + +fun Array.checkThis() { + this[45] = 34 + this[352]++ + this[35] += 234 +} + +abstract class Ab { + abstract fun getArray() : Array +} diff --git a/compiler/testData/diagnostics/tests/LiteralAsResult.fir.kt b/compiler/testData/diagnostics/tests/LiteralAsResult.fir.kt new file mode 100644 index 00000000000..434e19277b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/LiteralAsResult.fir.kt @@ -0,0 +1,3 @@ +// Here we want just to check return type +// Should be () -> Int +fun foo() = { 42 } diff --git a/compiler/testData/diagnostics/tests/LocalClassAndShortSubpackageNames.fir.kt b/compiler/testData/diagnostics/tests/LocalClassAndShortSubpackageNames.fir.kt new file mode 100644 index 00000000000..cf97ae1f74a --- /dev/null +++ b/compiler/testData/diagnostics/tests/LocalClassAndShortSubpackageNames.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.kt +package foo.bar + +class X + +// FILE: B.kt + +package foo + +fun f() { + class Local1 { + fun g() : bar.X? = null + } + class Local2 { + fun g() : foo.bar.X? = null + } +} diff --git a/compiler/testData/diagnostics/tests/MultilineStringTemplates.fir.kt b/compiler/testData/diagnostics/tests/MultilineStringTemplates.fir.kt new file mode 100644 index 00000000000..715007c246c --- /dev/null +++ b/compiler/testData/diagnostics/tests/MultilineStringTemplates.fir.kt @@ -0,0 +1,43 @@ +fun box() : String { + val s = "abc" + val test1 = """$s""" + if (test1 != "abc") return "Fail 1: $test1" + + val test2 = """${s}""" + if (test2 != "abc") return "Fail 2: $test2" + + val test3 = """ "$s" """ + if (test3 != " \"abc\" ") return "Fail 3: $test3" + + val test4 = """ "${s}" """ + if (test4 != " \"abc\" ") return "Fail 4: $test4" + + val test5 = +""" + ${s.length} +""" + if (test5 != "\n 3\n") return "Fail 5: $test5" + + val test6 = """\n""" + if (test6 != "\\n") return "Fail 6: $test6" + + val test7 = """\${'$'}foo""" + if (test7 != "\\\$foo") return "Fail 7: $test7" + + val test8 = """$ foo""" + if (test8 != "$ foo") return "Fail 8: $test8" + + return "OK" +} + + +fun new() : String { + return """ + sdfasdf + ${a} + ds"asdfas + $b + asgfaf + """ + +} diff --git a/compiler/testData/diagnostics/tests/MultipleBounds.fir.kt b/compiler/testData/diagnostics/tests/MultipleBounds.fir.kt new file mode 100644 index 00000000000..966c8561ea9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/MultipleBounds.fir.kt @@ -0,0 +1,69 @@ +package Jet87 + +open class A() { + fun foo() : Int = 1 +} + +interface B { + fun bar() : Double = 1.0; +} + +interface G { + val boo: Double where X : A, X : B + val bal: Double where A : B + val bas: Double where Y : B, X : B +} + +class C() : A(), B + +class D() { + companion object : A(), B {} +} + +class Test1() + where + T : A, + T : B, + B : T // error + { + + fun test(t : T) { + T.foo() + T.bar() + t.foo() + t.bar() + } +} + +fun test() { + Test1() + Test1() + Test1() +} + +class Foo() {} + +class Bar + +class Buzz where T : Bar, T : nioho + +class X +class Y where T : Foo, T : Bar + +fun test2(t : T) + where + T : A, + T : B, + B : T +{ + T.foo() + T.bar() + t.foo() + t.bar() +} + +val t1 = test2(A()) +val t2 = test2(C()) +val t3 = test2(C()) + +val x : Int = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.fir.kt b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.fir.kt new file mode 100644 index 00000000000..76b787ffc75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.fir.kt @@ -0,0 +1,9 @@ +abstract class A : Function1 + +abstract class B : (Int)->Unit + +// Named parameter is prohibited because of possible inconsistency between +// type declaration and actual override +class C : (x: Int)->Unit { + override fun invoke(p1: Int): Unit {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Nullability.fir.kt b/compiler/testData/diagnostics/tests/Nullability.fir.kt new file mode 100644 index 00000000000..c71b2e98286 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Nullability.fir.kt @@ -0,0 +1,296 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +fun test() { + val a : Int? = 0 + if (a != null) { + a.plus(1) + } + else { + a?.plus(1) + } + + val out : java.io.PrintStream? = null + val ins : java.io.InputStream? = null + + out?.println() + ins?.read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins?.read(); + ins.read(); + out.println(); + } + + if (out == null || out.println(0) == Unit) { + out?.println(1) + out.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == Unit) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out.println() == Unit) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == Unit) { + out?.println(2); + out.println(2); + } + else { + out?.println(3) + out.println(3) + } + + out?.println() + ins?.read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins?.read(); + out.println(); + } + + if (out == null || out.println(0) == Unit) { + out?.println(1) + out.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == Unit) { + out.println(); + } + else { + out?.println(); + out.println(); + } + + if (out == null || out.println() == Unit) { + out?.println(); + out.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == Unit) { + out?.println(2); + out.println(2); + } + else { + out?.println(3) + out.println(3) + } + + if (1 > 2) { + if (out == null) return; + out.println(); + } + out?.println(); + + while (out != null) { + out.println(); + } + out?.println(); + + val out2 : java.io.PrintStream? = null + + while (out2 == null) { + out2?.println(); + out2.println(); + } + out2.println() + +} + + +fun f(out : String?) { + out?.get(0) + out.get(0) + if (out != null) else return; + out.get(0) +} + +fun f1(out : String?) { + out?.get(0) + if (out != null) else { + 1 + 2 + return; + } + out.get(0) +} + +fun f2(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + out.get(0) +} + +fun f3(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + else { + 1 + 2 + } + out.get(0) +} + +fun f4(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + s?.get(0) + } + s.get(0) +} + +fun f5(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + if (1 > 2) break + s?.get(0) + } + s?.get(0); +} + +fun f6(s : String?) { + s?.get(0) + do { + s?.get(0) + if (1 < 2) break; + } while (s == null) + s?.get(0) + do { + s?.get(0) + } while (s == null) + s.get(0) +} + +fun f7(s : String?, t : String?) { + s?.get(0) + if (!(s == null)) { + s.get(0) + } + s?.get(0) + if (!(s != null)) { + s?.get(0) + } + else { + s.get(0) + } + s?.get(0) + if (!!(s != null)) { + s.get(0) + } + else { + s?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null || t == null)) { + s.get(0) + t.get(0) + } + else { + s?.get(0) + t?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null)) { + s.get(0) + t?.get(0) + } + else { + s?.get(0) + t?.get(0) + } +} + +fun f8(b : String?, a : String) { + b?.get(0) + if (b == a) { + b.get(0); + } + b?.get(0) + if (a == b) { + b.get(0) + } + if (a != b) { + b?.get(0) + } + else { + b.get(0) + } +} + +fun f9(a : Int?) : Int { + if (a != null) + return a + return 1 +} diff --git a/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.fir.kt b/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.fir.kt new file mode 100644 index 00000000000..7301b10cf92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/NumberPrefixAndSuffix.fir.kt @@ -0,0 +1,54 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -USELESS_CAST + +infix fun Any?.foo(a: Any) {} +infix fun Any?.zoo(a: Any) {} +infix fun Any?.Loo(a: Any) {} +infix fun Any?.doo(a: Any) {} +infix fun Any?.ddoo(a: Any) {} +operator fun Any?.contains(a: Any): Boolean = true + +fun test(a: Any) { + 1foo a + 1ffoo a + 1doo a + 1ddoo a + 1contains a + + 1Lfoo a + 1Loo a + 1LLoo a + + 0b1foo a + 0b1Lfoo a + 0b1Loo a + 0b1LLoo a + + 0xfoo a + 0xffoo a + 0xfLLoo a + + 1.0foo a + 1.0ffoo a + 1.0doo a + 1.0ddoo a + + .0foo a + .0ffoo a + .0doo a + .0ddoo a + + 1in a + 1.0in a + 1.0fin a + 1.0din a + .0in a + .0fin a + .0din a + + 1is Any + 1as Any + 1as? Any + + 1!is Any + 1!in a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt new file mode 100644 index 00000000000..7ee1f433ccc --- /dev/null +++ b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt @@ -0,0 +1,24 @@ +object A1() { + constructor(x: Int = "", y: Int) : this() { + x + y + } +} + +object A2 public constructor(private val prop: Int) { + constructor(x: Int = "", y: Int) : this(x * y) { + x + y + } +} + +val x = object (val prop: Int) { + constructor() : this(1) { + val x = 1 + x * x + } +} + +class A3 { + companion object B(val prop: Int) { + public constructor() : this(2) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/OperatorChecks.fir.kt b/compiler/testData/diagnostics/tests/OperatorChecks.fir.kt new file mode 100644 index 00000000000..ac4f09e9adc --- /dev/null +++ b/compiler/testData/diagnostics/tests/OperatorChecks.fir.kt @@ -0,0 +1,219 @@ +// !DIAGNOSTICS: -EXTENSION_SHADOWED_BY_MEMBER + +import kotlin.reflect.KProperty + +interface Example { + operator fun plus(o: Example): Example + operator fun div(o: Example): Example + operator fun plus(o: Example, s: String = ""): Example + operator fun minus(vararg o: Example): Example + operator fun plus(): Example + operator fun minus(): Example + + operator fun unaryPlus(): Example + operator fun unaryMinus(): Example + + operator fun unaryPlus(s: String = ""): Example + operator fun unaryMinus(o: Example) + + operator fun inc(): Example + operator fun dec(): Example? + + operator fun plusAssign(n: Int) + operator fun minusAssign(n: Int): String + operator fun divAssign(n: Int, a: String = "") + operator fun modAssign(vararg n: Int) + + operator fun compareTo(other: Example): Int + + override operator fun equals(other: Any?): Boolean + operator fun equals(a: String): Boolean + + operator fun contains(n: Int): Boolean + operator fun contains(n: Int, s: String = ""): Boolean + + operator fun invoke() + + operator fun get(n: Int) + operator fun get(n: Int, n2: Int) + operator fun get() + + operator fun set(n: Int, v: Int) + operator fun set(n: Int, n2: Int, v: Int) + operator fun set(v: Int) + + operator fun rangeTo(o: Int) + operator fun rangeTo(o: Int, o2: Int) + operator fun rangeTo(vararg o: String) + + operator fun component1(): Int + operator fun component1(n: Int): Int + operator fun componentN(): Int + + operator fun iterator(): String + operator fun iterator(n: Int): String + + operator fun next(): String + operator fun next(n: Int): String + + operator fun hasNext(): Boolean + operator fun hasNext(n: Int): String + + infix fun i1(n: Int) + infix fun i1(n: Int, n2: Int) + infix fun i1(vararg n: Int) +} + +class OkDelegates { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = "" + operator fun setValue(thisRef: Any?, prop: KProperty<*>, s: String): String = "" + operator fun setValue(thisRef: Any?, prop: Any, n: Int) {} + operator fun setValue(thisRef: Any?, prop: Any?, s: String) {} +} + +class DelegatesWithErrors { + operator fun getValue(thisRef: Any?, prop: String): String = "" + operator fun setValue(thisRef: Any?, prop: String, value: String) {} + + operator fun setValue(thisRef: Any?, prop: KProperty<*>, vararg n: Int) {} + operator fun setValue(thisRef: Any?, prop: KProperty<*>, f: Float = 0.0f) {} + + operator fun getValue(prop: KProperty<*>): String = "" + operator fun setValue(prop: KProperty<*>, value: String) {} +} + +interface Example2 { + operator fun inc(s: String): Example + operator fun dec() + operator fun compareTo(vararg other: Example): Int + operator fun contains(vararg n: Int): Boolean + operator fun hasNext(): Int +} + +interface Example3 { + operator fun compareTo(other: Example, s: String = ""): Int + operator fun contains(n: Int) +} + + + + +operator fun Example.plus(o: Any): Example {} +operator fun Example.div(o: Example): Example {} +operator fun Example.plus(o: Example, s: String = ""): Example {} +operator fun Example.minus(vararg o: Example): Example {} +operator fun Example.plus(): Example {} +operator fun Example.minus(): Example {} + +operator fun Example.unaryPlus(): Example {} +operator fun Example.unaryMinus(): Example {} + +operator fun Example.unaryPlus(s: String = ""): Example {} +operator fun Example.unaryMinus(o: Example) {} + +operator fun Example.inc(): Example {} +operator fun Example.dec(): Example? {} + +operator fun Example.plusAssign(n: Int) {} +operator fun Example.minusAssign(n: Int): String {} +operator fun Example.divAssign(n: Int, a: String = "") {} +operator fun Example.modAssign(vararg n: Int) {} + +operator fun Example.compareTo(other: Example): Int {} + +operator fun Example.equals(a: String): Boolean {} + +operator fun Example.contains(n: Int): Boolean {} +operator fun Example.contains(n: Int, s: String = ""): Boolean {} + +operator fun Example.invoke() {} + +operator fun Example.get(n: Int) {} +operator fun Example.get(n: Int, n2: Int) {} +operator fun Example.get() {} + +operator fun Example.set(n: Int, v: Int) {} +operator fun Example.set(n: Int, n2: Int, v: Int) {} +operator fun Example.set(v: Int) {} + +operator fun Example.rangeTo(o: Int) {} +operator fun Example.rangeTo(o: Int, o2: Int) {} +operator fun Example.rangeTo(vararg o: String) {} + +operator fun Example.component1(): Int {} +operator fun Example.component1(n: Int): Int {} +operator fun Example.componentN(): Int {} + +operator fun Example.iterator(): String {} +operator fun Example.iterator(n: Int): String {} + +operator fun Example.next(): String {} +operator fun Example.next(n: Int): String {} + +operator fun Example.hasNext(): Boolean {} +operator fun Example.hasNext(n: Int): String {} + +infix fun Example.i1(n: Int) {} +infix fun Example.i1(n: Int, n2: Int) {} +infix fun Example.i1(vararg n: Int) {} + + + + + +operator fun plus(o: String): Example {} +operator fun div(o: Example): Example {} +operator fun plus(o: Example, s: String = ""): Example {} +operator fun minus(vararg o: Example): Example {} + +operator fun unaryPlus(): Example {} +operator fun unaryMinus(): Example {} + +operator fun unaryPlus(s: String = ""): Example {} +operator fun unaryMinus(o: Example) {} + +operator fun inc(): Example {} +operator fun dec(): Example? {} + +operator fun plusAssign(n: Int) {} +operator fun minusAssign(n: Int): String {} +operator fun divAssign(n: Int, a: String = "") {} +operator fun modAssign(vararg n: Int) {} + +operator fun compareTo(other: Example): Int {} + +operator fun equals(a: String): Boolean {} + +operator fun contains(n: Int): Boolean {} +operator fun contains(n: Int, s: String = ""): Boolean {} + +operator fun invoke() {} + +operator fun get(n: Int) {} +operator fun get(n: Int, n2: Int) {} +operator fun get() {} + +operator fun set(n: Int, v: Int) {} +operator fun set(n: Int, n2: Int, v: Int) {} +operator fun set(v: Int) {} + +operator fun rangeTo(o: Int) {} +operator fun rangeTo(o: Int, o2: Int) {} +operator fun rangeTo(vararg o: String) {} + +operator fun component1(): Int {} +operator fun component1(n: Int): Int {} +operator fun componentN(): Int {} + +operator fun iterator(): String {} +operator fun iterator(n: Int): String {} + +operator fun next(): String {} +operator fun next(n: Int): String {} + +operator fun hasNext(): Boolean {} +operator fun hasNext(n: Int): String {} + +infix fun i1(n: Int) {} +infix fun i1(n: Int, n2: Int) {} +infix fun i1(vararg n: Int) {} diff --git a/compiler/testData/diagnostics/tests/Operators.fir.kt b/compiler/testData/diagnostics/tests/Operators.fir.kt new file mode 100644 index 00000000000..4e99d4993d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Operators.fir.kt @@ -0,0 +1,114 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Example { + public fun plus(o: Example) = o + public operator fun minus(o: Example) = o + + public fun get(i: Int) = "" + public operator fun get(s: String) = "" + + public fun set(i: Int, v: String) {} + public operator fun set(s: String, v: String) {} + + public fun not() = false + + public fun rangeTo(o: Example) = o + public fun contains(o: Example) = false + public fun compareTo(o: Example) = 0 + + public fun inc() = this + public fun dec() = this + + public fun invoke() {} +} + +class Example2 { + public operator fun not() = true + + public fun plusAssign(o: Example2) {} + public operator fun minusAssign(o: Example2) {} + + public operator fun rangeTo(o: Example2) = o + public operator fun contains(o: Example2) = false + public operator fun compareTo(o: Example2) = 0 + + public operator fun inc() = this + public operator fun dec() = this + + public operator fun invoke() {} +} + +fun test() { + var a = Example() + var b = Example() + var c = Example2() + var d = Example2() + + Example() == Example() + + a == b + c != d + + Example() + Example() + + a + b + a - b + a[1] + a["str"] + + a[1] = "A" + a["str"] = "str" + + a.plus(b) + a.minus(b) + a.get(1) + a.get("str") + + c += d + c -= d + + a..b + c..d + + Example()..Example() + Example2()..Example2() + + a < b + a >= b + c > d + + a in b + c in d + + a++ + a-- + c++ + c-- + + !a + !c + + a() + c() + + Example()() + Example2()() +} + +abstract class Base { + abstract operator fun plus(o: Base): Base + abstract fun minus(o: Base): Base +} + +open class Anc : Base() { + override fun plus(o: Base) = o + override fun minus(o: Base) = o +} + +class Anc2 : Anc() + +fun test2() { + Anc() + Anc() + Anc() - Anc() + Anc2() + Anc2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/OperatorsWithWrongNames.fir.kt b/compiler/testData/diagnostics/tests/OperatorsWithWrongNames.fir.kt new file mode 100644 index 00000000000..16440292185 --- /dev/null +++ b/compiler/testData/diagnostics/tests/OperatorsWithWrongNames.fir.kt @@ -0,0 +1,11 @@ +class A { + operator fun A.minus(o: A) = o + + operator fun A.add(o: A) = o + operator fun A.get(o: A) = o + operator fun A.invokee() {} +} + +operator fun A.plus(o: A) = o +operator fun A.component1() = 1 +operator fun A.componentN() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/OverrideFunctionWithParamDefaultValue.fir.kt b/compiler/testData/diagnostics/tests/OverrideFunctionWithParamDefaultValue.fir.kt new file mode 100644 index 00000000000..df495e555ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/OverrideFunctionWithParamDefaultValue.fir.kt @@ -0,0 +1,11 @@ +abstract class B() { + abstract fun foo2(arg: Int = 239) : Int +} + +class C() : B() { + override fun foo2(arg: Int) : Int = arg +} + +fun invokeIt() { + C().foo2() +} diff --git a/compiler/testData/diagnostics/tests/OverridenFunctionAndSpecifiedTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/OverridenFunctionAndSpecifiedTypeParameter.fir.kt new file mode 100644 index 00000000000..95d4fdcc9c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/OverridenFunctionAndSpecifiedTypeParameter.fir.kt @@ -0,0 +1,13 @@ + +interface Aaa { + fun zzz(value: T): Unit +} + +class Bbb() : Aaa { + override fun zzz(value: T) { } +} + +fun foo() { + var a = Bbb() + a.zzz(10.0) +} diff --git a/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt b/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt new file mode 100644 index 00000000000..cbae506efc4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt @@ -0,0 +1,29 @@ +public interface ITest { + public var prop : Int + get() = 12 + set(value) {} +} + +abstract class ATest { + protected open var prop2 : Int + get() = 13 + set(value) {} +} + +class Test: ATest(), ITest { + override var prop : Int + get() = 12 + private set(value) {} + + override var prop2 : Int + get() = 14 + internal set(value) {} +} + +fun main() { + val test = Test() + test.prop = 12 + + val itest: ITest = test + itest.prop = 12 // No error here +} diff --git a/compiler/testData/diagnostics/tests/OverridingVarByVal.fir.kt b/compiler/testData/diagnostics/tests/OverridingVarByVal.fir.kt new file mode 100644 index 00000000000..6ad543c6d65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/OverridingVarByVal.fir.kt @@ -0,0 +1,15 @@ +open class Var() { + open var v : Int = 1 +} + +interface VarT { + var v : Int +} + +class Val() : Var(), VarT { + override val v : Int = 1 +} + +class Var2() : Var() { + override var v : Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt new file mode 100644 index 00000000000..81208da3b4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt @@ -0,0 +1,26 @@ +package foo + +class X {} + +val s = java +val ss = System +val sss = X +val x = "${System}" +val xs = java.lang +val xss = java.lang.System +val xsss = foo.X +val xssss = foo +val f = { System } + +fun main() { + java = null + System = null + System!! + java.lang.System = null + java.lang.System!! + System is Int + System() + (System) + foo@ System + null in System +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PackageInTypePosition.fir.kt b/compiler/testData/diagnostics/tests/PackageInTypePosition.fir.kt new file mode 100644 index 00000000000..4969f3b9ee1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PackageInTypePosition.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package foo + +// FILE: b.kt + +@foo fun bar(p: foo): foo = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PackageQualified.fir.kt b/compiler/testData/diagnostics/tests/PackageQualified.fir.kt new file mode 100644 index 00000000000..16faade22a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PackageQualified.fir.kt @@ -0,0 +1,71 @@ +// !WITH_NEW_INFERENCE +// FILE: b.kt + + +package foobar.a + import java.* + + val a : java.util.List? = null + val a2 : util.List? = null + val a3 : LinkedList? = null + +// FILE: b.kt +package foobar + +abstract class Foo() { + abstract val x : T +} + +// FILE: b.kt +package foobar.a + import java.util.* + + val b : List? = a + val b1 : util.List? = a + +// FILE: b.kt +package foobar +val x1 = a.a +val x2 = foobar.a.a + +val y1 = foobar.a.b + + +///////////////////////////////////////////////////////////////////////// + +fun done(result : O) : Iteratee = StrangeIterateeImpl(result) + +abstract class Iteratee { + abstract fun process(item : I) : Iteratee + abstract val isDone : Boolean + abstract val result : O + abstract fun done() : O +} + +class StrangeIterateeImpl(val obj: O) : Iteratee() { + override fun process(item: I): Iteratee = StrangeIterateeImpl(obj) + override val isDone = true + override val result = obj + override fun done() = obj +} + +abstract class Sum() : Iteratee() { + override fun process(item : Int) : Iteratee { + return foobar.done(item); + } + abstract override val isDone : Boolean + abstract override val result : Int + abstract override fun done() : Int +} + +abstract class Collection : Iterable { + fun iterate(iteratee : Iteratee) : O { + var current = iteratee + for (x in this) { + val it = current.process(x) + if (it.isDone) return it.result + current = it + } + return current.done() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PrimaryConstructors.fir.kt b/compiler/testData/diagnostics/tests/PrimaryConstructors.fir.kt new file mode 100644 index 00000000000..d576493f416 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PrimaryConstructors.fir.kt @@ -0,0 +1,29 @@ +class X { + val x : Int +} + +open class Y() { + val x : Int = 2 +} + +class Y1 { + val x : Int get() = 1 +} + +class Z : Y() { +} + +//KT-650 Prohibit creating class without constructor. + +class MyIterable : Iterable +{ + override fun iterator(): Iterator = MyIterator() + + inner class MyIterator : Iterator + { + override fun hasNext(): Boolean = false + override fun next(): T { + throw UnsupportedOperationException() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PrivateFromOuterPackage.fir.kt b/compiler/testData/diagnostics/tests/PrivateFromOuterPackage.fir.kt new file mode 100644 index 00000000000..7c63a2ef936 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PrivateFromOuterPackage.fir.kt @@ -0,0 +1,25 @@ +// FILE: a.kt +package outer + +private fun a() {} +private class B + +// FILE: b.kt +package outer.p1 + +import outer.a + +fun use() { + a() + outer.B() +} + +// FILE: c.kt +package outer.p1.p2 + +import outer.a + +fun use() { + a() + outer.B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PrivateSetterForOverridden.fir.kt b/compiler/testData/diagnostics/tests/PrivateSetterForOverridden.fir.kt new file mode 100644 index 00000000000..787940eac55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PrivateSetterForOverridden.fir.kt @@ -0,0 +1,70 @@ +// See KT-10325: private setters are allowed for overridden properties in final class + +interface A { + val a: Int + + var b: Int +} + +abstract class AA { + abstract val c: Int + + abstract var d: Int +} + +class B : A, AA() { + override var a: Int = 0 + // Ok + private set + + override var b: Int = 1 + private set + + override var c: Int = 2 + // Ok + private set + + override var d: Int = 3 + private set +} + +open class C : A, AA() { + override var a: Int = 0 + // Errors here and below + private set + + override var b: Int = 1 + private set + + override var c: Int = 2 + private set + + override var d: Int = 3 + private set +} + +abstract class D : A, AA() { + override var a: Int = 0 + // Errors here and below + private set + + override var b: Int = 1 + private set + + override var c: Int = 2 + private set + + override var d: Int = 3 + private set +} + +interface E : A { + override var a: Int + get() = 0 + // Errors here and below + private set(arg) {} + + override var b: Int + get() = 0 + private set(arg) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ProcessingEmptyImport.fir.kt b/compiler/testData/diagnostics/tests/ProcessingEmptyImport.fir.kt new file mode 100644 index 00000000000..35c39eae02b --- /dev/null +++ b/compiler/testData/diagnostics/tests/ProcessingEmptyImport.fir.kt @@ -0,0 +1,3 @@ +import + +fun firstFun() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ProjectionOnFunctionArgumentErrror.fir.kt b/compiler/testData/diagnostics/tests/ProjectionOnFunctionArgumentErrror.fir.kt new file mode 100644 index 00000000000..43c935eb9b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ProjectionOnFunctionArgumentErrror.fir.kt @@ -0,0 +1,4 @@ +fun test() { + fun foo(){} + foo() +} diff --git a/compiler/testData/diagnostics/tests/ProjectionsInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/ProjectionsInSupertypes.fir.kt new file mode 100644 index 00000000000..2e5805d7b18 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ProjectionsInSupertypes.fir.kt @@ -0,0 +1,6 @@ +interface A {} +interface B {} +interface C {} +interface D {} + +interface Test : A, B, C<*>???, D {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Properties.fir.kt b/compiler/testData/diagnostics/tests/Properties.fir.kt new file mode 100644 index 00000000000..ba5fcedde03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Properties.fir.kt @@ -0,0 +1,22 @@ +var x : Int = 1 + x + get() : Int = 1 + set(value : Long) { + field = value.toInt() + field = 1.toLong() + } + + val xx : Int = 1 + x + get() : Int = 1 + set(value : Long) {} + + val p : Int = 1 + get() = 1 + +class Test() { + var a : Int = 111 + var b : Int = 222 + get() = field + set(x) {a = x; field = x} + + public val i = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt b/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt new file mode 100644 index 00000000000..feecafe9145 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt @@ -0,0 +1,9 @@ +class Foo(val a: Int, b: Int) { + val c = a + b + + val d: Int + get() = a + + val e: Int + get() = b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/QualifiedExpressions.fir.kt b/compiler/testData/diagnostics/tests/QualifiedExpressions.fir.kt new file mode 100644 index 00000000000..d34cd8ec1cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/QualifiedExpressions.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +package qualified_expressions + +fun test(s: IntRange?) { + val a: Int = s?.start + val b: Int? = s?.start + val c: Int = s?.start ?: -11 + val d: Int = s?.start ?: "empty" + val e: String = s?.start ?: "empty" + val f: Int = s?.endInclusive ?: b ?: 1 + val g: Boolean? = e.startsWith("s")//?.length +} + +fun String.startsWith(s: String): Boolean = true diff --git a/compiler/testData/diagnostics/tests/RecursiveResolve.fir.kt b/compiler/testData/diagnostics/tests/RecursiveResolve.fir.kt new file mode 100644 index 00000000000..39c0000bfff --- /dev/null +++ b/compiler/testData/diagnostics/tests/RecursiveResolve.fir.kt @@ -0,0 +1,75 @@ +class Test(foo: Any?, bar: Any?) { + val foo = foo ?: this + private val bar = bar ?: this + private val bas = bas() + val bas2 = bas2() + + private fun bas(): Int = null!! + private fun bas2(): Int = null!! + + fun bar() = bar(1) + fun bar(i: Int) = 2 + private fun bar2() = bar2(1) + private fun bar2(i: Int) = 2 +} + +// KT-6413 Typechecker recursive problem when class have non-invariant generic parameters +class Test2(foo: Any?, bar: Any?) { + val foo = foo ?: this + private val bar = bar ?: this + private val bas = bas() + val bas2 = bas2() + + private fun bas(): Int = null!! + private fun bas2(): Int = null!! + + fun bar() = bar(1) + fun bar(i: Int) = 2 + private fun bar2() = bar2(1) + private fun bar2(i: Int) = 2 +} + +class Test3(foo: Any?, bar: Any?) { + val foo = foo ?: this + private val bar = bar ?: this + private val bas = bas() + val bas2 = bas2() + + private fun bas(): Int = null!! + private fun bas2(): Int = null!! + + fun bar() = bar(1) + fun bar(i: Int) = 2 + private fun bar2() = bar2(1) + private fun bar2(i: Int) = 2 +} + +class Test4(foo: Any?, bar: Any?) { + val foo = foo ?: this + private val bar = bar ?: this + private val bas = bas() + val bas2 = bas2() + + private fun bas(): Int = null!! + private fun bas2(): Int = null!! + + fun bar() = bar(1) + fun bar(i: Int) = 2 + private fun bar2() = bar2(1) + private fun bar2(i: Int) = 2 +} + +class Test5(foo: Any?, bar: Any?) { + val foo = foo ?: this + private val bar = bar ?: this + private val bas: Int = bas() + val bas2 = bas2() + + private fun bas(): Int = null!! + private fun bas2(): Int = null!! + + fun bar() = bar(1) + fun bar(i: Int) = 2 + private fun bar2(): Int = bar2(1) + private fun bar2(i: Int) = 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/RecursiveTypeInference.fir.kt b/compiler/testData/diagnostics/tests/RecursiveTypeInference.fir.kt new file mode 100644 index 00000000000..4c0c35b113a --- /dev/null +++ b/compiler/testData/diagnostics/tests/RecursiveTypeInference.fir.kt @@ -0,0 +1,43 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +// FILE: f.kt +package a + val foo = bar() + + fun bar() = foo + +// FILE: f.kt +package b + fun foo() = bar() + + fun bar() = foo() + +// FILE: f.kt +package c + fun bazz() = bar() + + fun foo() = bazz() + + fun bar() = foo() + +// FILE: f.kt + + package ok.a + val foo = bar() + + fun bar() : Int = foo + +// FILE: f.kt + package ok.b + fun foo() : Int = bar() + + fun bar() = foo() + +// FILE: f.kt + package ok.c + fun bazz() = bar() + + fun foo() : Int = bazz() + + fun bar() = foo() diff --git a/compiler/testData/diagnostics/tests/ReserveYield.fir.kt b/compiler/testData/diagnostics/tests/ReserveYield.fir.kt new file mode 100644 index 00000000000..314f4435d9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/ReserveYield.fir.kt @@ -0,0 +1,71 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE + +// FILE: 1.kt +package p1.yield + +import p1.yield.yield +import p1.yield.foo + +val yield = 5 +fun foo(){} + +fun bar(yield: Int = 4) {} + +fun yield(yield: Int) { + "$yield" + "${yield}" + + yield + val foo = yield + yield + val foo2 = yield + + bar(yield = 5) + + yield(4) + yield {} + + class yield> + + return@yield + return@yield Unit + + val foo5: yield<*> +} + +fun yield(i: (Int) -> Unit) {} + +// FILE: 2.kt + +package p2.yield + +import p2.yield.yield +import p2.yield.foo + +val yield = 5 +fun foo(){} + +fun bar(yield: Int = 4) {} + +fun yield(yield: Int) { + "$`yield`" + "${`yield`}" + + `yield` + val foo = `yield` + `yield` + val foo2 = `yield` + + bar(`yield` = 5) + + `yield`(4) + `yield` {} + + class `yield`> + + return@`yield` + return@`yield` Unit + + val foo5: `yield`<*> +} + +fun yield(i: (Int) -> Unit) {} diff --git a/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt b/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt new file mode 100644 index 00000000000..aab3b906def --- /dev/null +++ b/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt @@ -0,0 +1,54 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION + +// FILE: 1.kt + +annotation class yield + +fun bar(p: Int) { + yield@ p + `yield`@ p + + @yield() p + @`yield`() p + + for (yield in 1..5) { + + } + { yield: Int -> } + + val (yield) = listOf(4) + +} + +fun listOf(vararg e: T): List = null!! +operator fun List.component1() = get(0) + +// FILE: 2.kt +package p3 + +enum class yield { + yield +} + +fun f1(yield: Int, foo: Int = yield) {} + +fun f2(foo: yield) {} + +// FILE: 3.kt +package p4 + +typealias yield = Number + +fun f1() {} +fun f2() {} + +// FILE: 4.kt +object X { + fun yield() {} + + fun test3(yield: Int) { + X::yield + + yield::toInt + } +} diff --git a/compiler/testData/diagnostics/tests/ResolveOfJavaGenerics.fir.kt b/compiler/testData/diagnostics/tests/ResolveOfJavaGenerics.fir.kt new file mode 100644 index 00000000000..8391182a406 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ResolveOfJavaGenerics.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// Fixpoint generic in Java: Enum> +fun test(a : java.lang.annotation.RetentionPolicy) { + +} + +fun test() { + java.util.Collections.emptyList() + val a : Collection? = java.util.Collections.emptyList() +} + +fun test(a : java.lang.Comparable) { + +} + +fun test(a : java.util.ArrayList) { + +} + +fun test(a : java.lang.Class) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ResolveToJava.fir.kt b/compiler/testData/diagnostics/tests/ResolveToJava.fir.kt new file mode 100644 index 00000000000..223ad431198 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ResolveToJava.fir.kt @@ -0,0 +1,58 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// JAVAC_SKIP +// FULL_JDK + +// FILE: f.kt + +import java.* +import java.util.* +import utils.* + +import java.io.PrintStream +import java.lang.Comparable as Com + +val l : MutableList = ArrayList() + +fun test(l : java.util.List) { + val x : java.List + val y : java.util.List + val b : java.lang.Object + val z : java.utils.List + + val f : java.io.File? = null + + Collections.emptyList + Collections.emptyList + Collections.emptyList() + Collections.emptyList() + + checkSubtype?>(Collections.singleton(1)) + Collections.singleton(1.0) + + List + + + val o = "sdf" as Object + + try { + // ... + } + catch(e: Exception) { + System.out.println(e.message) + } + + PrintStream("sdf") + + val c : Com? = null + + checkSubtype?>(c) + +// Collections.sort(ArrayList()) + xxx.Class() +} + + +// FILE: f.kt +package xxx + import java.lang.Class; \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Return.fir.kt b/compiler/testData/diagnostics/tests/Return.fir.kt new file mode 100644 index 00000000000..747f383243e --- /dev/null +++ b/compiler/testData/diagnostics/tests/Return.fir.kt @@ -0,0 +1,17 @@ +package return + +class A { + fun outer() { + fun inner() { + if (1 < 2) + return@inner + else + return@outer + } + if (1 < 2) + return@A + else if (2 < 3) + return@inner + return@outer + } +} diff --git a/compiler/testData/diagnostics/tests/ReturnInFunctionWithoutBody.fir.kt b/compiler/testData/diagnostics/tests/ReturnInFunctionWithoutBody.fir.kt new file mode 100644 index 00000000000..d2a51a83105 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ReturnInFunctionWithoutBody.fir.kt @@ -0,0 +1,3 @@ +fun foo1(): () -> String = return { "some long expression "} +fun foo2(): () -> String = return@label { "some long expression "} +fun foo3(): () -> String = return@ { "some long expression "} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SafeCallInvoke.fir.kt b/compiler/testData/diagnostics/tests/SafeCallInvoke.fir.kt new file mode 100644 index 00000000000..b5366e9679c --- /dev/null +++ b/compiler/testData/diagnostics/tests/SafeCallInvoke.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +class Rule(val apply:() -> Unit) + +fun bar() {} + +fun foo() { + val rule: Rule? = Rule { bar() } + + // this compiles and works + val apply = rule?.apply + if (apply != null) apply() + + // this compiles and works + rule?.apply?.invoke() + + // this should be an error + rule?.apply() + + // these both also ok (with smart cast / unnecessary safe call) + if (rule != null) { + rule.apply() + rule?.apply() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SafeCallNonNullReceiver.fir.kt b/compiler/testData/diagnostics/tests/SafeCallNonNullReceiver.fir.kt new file mode 100644 index 00000000000..4e4765234c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/SafeCallNonNullReceiver.fir.kt @@ -0,0 +1,6 @@ +// http://youtrack.jetbrains.net/issue/KT-418 + +fun ff() { + val i: Int = 1 + val a: Int = i?.plus(2) +} diff --git a/compiler/testData/diagnostics/tests/SafeCallNonNullReceiverReturnNull.fir.kt b/compiler/testData/diagnostics/tests/SafeCallNonNullReceiverReturnNull.fir.kt new file mode 100644 index 00000000000..ccdd7aa33cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/SafeCallNonNullReceiverReturnNull.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +fun Int.gg() = null + +fun ff() { + val a: Int = 1 + val b: Int = a?.gg() +} diff --git a/compiler/testData/diagnostics/tests/SafeCallOnFakePackage.fir.kt b/compiler/testData/diagnostics/tests/SafeCallOnFakePackage.fir.kt new file mode 100644 index 00000000000..9750c5ecc86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/SafeCallOnFakePackage.fir.kt @@ -0,0 +1,16 @@ +// FILE: Test.java +public class Test { + public static final String FOO = "test"; +} + +// FILE: anotherTest.kt +package foo + +val s: String = "test" + +// FILE: test.kt +fun ff() { + val a = Test?.FOO + val b = foo?.s + System?.out.println(a + b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.fir.kt b/compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.fir.kt new file mode 100644 index 00000000000..0f1d94e9d7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.fir.kt @@ -0,0 +1,11 @@ +// http://youtrack.jetbrains.net/issue/KT-413 + +open class A { + fun f() {} +} + +class B : A() { + fun g() { + super?.f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Serializable.fir.kt b/compiler/testData/diagnostics/tests/Serializable.fir.kt new file mode 100644 index 00000000000..ee3ba199974 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Serializable.fir.kt @@ -0,0 +1,55 @@ +fun use(s: java.io.Serializable) { + +} + +fun useList(s: List) { + +} + +fun testPrimitives(b: Byte, ss: Short, i: Int, l: Long, d: Double, s: String, f: Float, bool: Boolean) { + use(b) + use(ss) + use(i) + use(l) + use(s) + use(f) + use(d) + use(bool) +} + +class N +class S: java.io.Serializable + +fun testArrays(ia: IntArray, ai: Array, an: Array, a: Array) { + use(ia) + use(ai) + use(an) + use(a) +} + +fun testLiterals() { + use(1) + use(1.0) + use(11111111111111) + use("Asdsd") + use(true) +} + +fun testNotSerializable(l: List) { + use(l) + use(N()) +} + +enum class C { + E, E2 +} + +fun testEnums(a: Enum<*>) { + use(C.E) + use(C.E2) + use(a) +} + +fun testLists(a: List) { + useList(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt b/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt new file mode 100644 index 00000000000..35e921407f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt @@ -0,0 +1,25 @@ +class My { + var x: Int = 0 + // Ok + private set + + private var y: Int = 1 + // Error: better + public set + + protected var z: Int = 2 + // Ok + private set + + protected var w: Int = 3 + // Error: incompatible + internal set + + internal var v: Int = 4 + // Error: incompatible + protected set + + internal var t: Int = 5 + // Error: better + public set +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ShiftFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/ShiftFunctionTypes.fir.kt new file mode 100644 index 00000000000..cfc6fb59656 --- /dev/null +++ b/compiler/testData/diagnostics/tests/ShiftFunctionTypes.fir.kt @@ -0,0 +1,52 @@ +// FILE: f.kt +class A { +} + +// FILE: f.kt +package n + class B +// FILE: f.kt +abstract class XXX() { + abstract val a : Int + abstract val a2 : n.B + abstract val a3 : (A) + abstract val a31 : (n.B) + abstract val a4 : A? + abstract val a5 : (A)? + abstract val a6 : (A?) + abstract val a7 : (A) -> n.B + abstract val a8 : (A, n.B) -> n.B + +//val a9 : (A, B) +//val a10 : (B)? -> B + + val a11 : ((Int) -> Int)? = null + val a12 : ((Int) -> (Int))? = null + abstract val a13 : Int.(Int) -> Int + abstract val a14 : n.B.(Int) -> Int + abstract val a15 : Int? .(Int) -> Int + abstract val a152 : (Int?).(Int) -> Int +// abstract val a151 : Int?.(Int) -> Int + abstract val a16 : (Int) -> (Int) -> Int + abstract val a17 : ((Int) -> Int).(Int) -> Int + abstract val a18 : (Int) -> ((Int) -> Int) + abstract val a19 : ((Int) -> Int) -> Int +} + +abstract class YYY() { + abstract val a7 : (a : A) -> n.B + abstract val a8 : (a : A, b : n.B) -> n.B +//val a9 : (A, B) +//val a10 : (B)? -> B + val a11 : ((a : Int) -> Int)? = null + val a12 : ((a : Int) -> (Int))? = null + abstract val a13 : Int.(a : Int) -> Int + abstract val a14 : n.B.(a : Int) -> Int + abstract val a15 : Int? .(a : Int) -> Int + abstract val a152 : (Int?).(a : Int) -> Int +//abstract val a151 : Int?.(a : Int) -> Int + abstract val a16 : (a : Int) -> (a : Int) -> Int + abstract val a17 : ((a : Int) -> Int).(a : Int) -> Int + abstract val a18 : (a : Int) -> ((a : Int) -> Int) + abstract val a19 : (b : (a : Int) -> Int) -> Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SingleUnderscoreUnsupported.fir.kt b/compiler/testData/diagnostics/tests/SingleUnderscoreUnsupported.fir.kt new file mode 100644 index 00000000000..691287f983b --- /dev/null +++ b/compiler/testData/diagnostics/tests/SingleUnderscoreUnsupported.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: -SingleUnderscoreForParameterName + +data class A(val x: Int, val y: Int) + +fun foo(a: Array) { + val (_, y) = A(1, 2) + y.hashCode() + + val q1: (Int, String) -> Unit = { + _, s -> s.hashCode() + } + q1(1, "") + + val q2: (Int, String) -> Unit = fun(_: Int, s: String) { + s.hashCode() + } + q2(1, "") + + val q3: (A) -> Unit = { + (_, y) -> y.hashCode() + } + q3(A(2, 3)) + + for ((_, z) in a) { + z.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/StarsInFunctionCalls.fir.kt b/compiler/testData/diagnostics/tests/StarsInFunctionCalls.fir.kt new file mode 100644 index 00000000000..bd8811ea0c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/StarsInFunctionCalls.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE + +fun getT() {} +fun getTT() {} +fun getTTT(x : Any) {} +fun foo(a : Any?) {} + +public fun main() { + getT<*>() + ggetT<*>() + getTT<*, *>() + getTT<*, Int>() + getTT() + foo(getTTT(1)) +} diff --git a/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt new file mode 100644 index 00000000000..f32edd2fe40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +infix fun Any?.foo(a: Any) {} +operator fun Any?.contains(a: Any): Boolean = true + +fun test(a: Any) { + + a foo"" + a foo"asd" + a foo"$a" + a foo"asd${a}sfsa" + a foo"""sdf""" + a foo'd' + a foo'' + + a foo""foo a + a foo"asd"foo a + a foo"$a"foo a + a foo"asd${a}sfsa"foo a + a foo"""sdf"""foo a + a foo'd'foo a + a foo''foo a + + a in"foo" + a in"""foo""" + a in's' + a in'' + + a !in"foo" + a !in"""foo""" + a !in's' + a !in'' + + if("s"is Any) {} + if("s"is Any) {} + test("s"as Any) + + a foo""1 + a foo""1.0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/StringTemplates.fir.kt b/compiler/testData/diagnostics/tests/StringTemplates.fir.kt new file mode 100644 index 00000000000..42ebed1181f --- /dev/null +++ b/compiler/testData/diagnostics/tests/StringTemplates.fir.kt @@ -0,0 +1,22 @@ +fun demo() { + val abc = 1 + val a = "" + val asd = 1 + val bar = 5 + fun map(f : () -> Any?) : Int = 1 + fun buzz(f : () -> Any?) : Int = 1 + val sdf = 1 + val foo = 3; + "$abc" + "$" + "$.$.asdf$\t" + "asd\$" + "asd$a\x" + "asd$a$asd$ $xxx" + "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" + "foo${bar + map {foo}}sdfsdf" + "foo${bar + map { "foo" }}sdfsdf" + "foo${bar + map { + "foo$sdf${ buzz{}}" }}sdfsdf" + "a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SupertypeListChecks.fir.kt b/compiler/testData/diagnostics/tests/SupertypeListChecks.fir.kt new file mode 100644 index 00000000000..bbc92ce0967 --- /dev/null +++ b/compiler/testData/diagnostics/tests/SupertypeListChecks.fir.kt @@ -0,0 +1,49 @@ +// KT-286 Check supertype lists + +/* +In a supertype list: + Same type should not be mentioned twice + Same type should not be indirectly mentioned with incoherent type arguments + Every interface's required dependencies should be satisfied + No final types should appear + Only one class is allowed +*/ + +class C1() + +open class OC1() + +open class C2 {} + +open class C3 {} + +interface T1 {} + +interface T2 {} + +interface Test() { +} + +interface Test1 : C2() {} + +interface Test2 : C2 {} + +interface Test3 : C2, C3 {} + +interface Test4 : T1 {} + +interface Test5 : T1, T1 {} + +interface Test6 : C1 {} + +class CTest1() : OC1() {} + +class CTest2 : C2 {} + +class CTest3 : C2, C3 {} + +class CTest4 : T1 {} + +class CTest5 : T1, T1 {} + +class CTest6 : C1 {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlighting.fir.kt b/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlighting.fir.kt new file mode 100644 index 00000000000..6698a262bcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlighting.fir.kt @@ -0,0 +1,5 @@ +// dummy test of syntax error highlighting in tests + +fun get() { + 1 + 2 2 3 4 +} diff --git a/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlightingEof.fir.kt b/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlightingEof.fir.kt new file mode 100644 index 00000000000..7114933f970 --- /dev/null +++ b/compiler/testData/diagnostics/tests/SyntaxErrorInTestHighlightingEof.fir.kt @@ -0,0 +1 @@ +fun f() { diff --git a/compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.fir.kt b/compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.fir.kt new file mode 100644 index 00000000000..2866cc8751a --- /dev/null +++ b/compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.fir.kt @@ -0,0 +1,6 @@ +// JAVAC_EXPECTED_FILE +interface MyTrait: Object { + override fun toString(): String + public override fun finalize() + public override fun wait() +} diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt new file mode 100644 index 00000000000..f4bc01edac2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -MISSING_CONSTRUCTOR_KEYWORD + +class C(val a: String) {} + +interface T1(val x: String) {} + +interface T2 constructor() {} + +interface T3 private constructor(a: Int) {} + +interface T4 { + constructor(a: Int) { + val b: Int = 1 + } +} + +interface T5 private () : T4 {} +interface T6 private : T5 {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/TypeInference.fir.kt b/compiler/testData/diagnostics/tests/TypeInference.fir.kt new file mode 100644 index 00000000000..b1f763b91b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/TypeInference.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +class C() { + fun foo() : T {} +} + +fun foo(c: C) {} +fun bar() : C {} + +fun main() { + val a : C = C(); + val x : C = C() + val y : C = C() + val z : C<*> = C() + + val ba : C = bar(); + val bx : C = bar() + val by : C = bar() + val bz : C<*> = bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.fir.kt b/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.fir.kt new file mode 100644 index 00000000000..79f4f16d1bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.fir.kt @@ -0,0 +1,9 @@ +abstract class A { + abstract var x: Int; + abstract fun foo() : Int; +} + +abstract class C : A() { + override abstract var x: String = ? + override abstract fun foo(): String = ? +} diff --git a/compiler/testData/diagnostics/tests/Underscore.fir.kt b/compiler/testData/diagnostics/tests/Underscore.fir.kt new file mode 100644 index 00000000000..1ab54eb4c44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Underscore.fir.kt @@ -0,0 +1,46 @@ +// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY + +import kotlin.Deprecated as ___ + +@___("") data class Pair(val x: Int, val y: Int) + +class _<________> +val ______ = _() + +fun __(___: Int, y: _?): Int { + val (_, z) = Pair(___ - 1, 42) + val (x, __________) = Pair(___ - 1, 42) + val ____ = x + // in backquotes: allowed + val `_` = __________ + + val q = fun(_: Int, __: Int) {} + q(1, 2) + + val _ = 56 + + fun localFun(_: String) = 1 + + __@ return if (y != null) __(____, y) else __(`_`, ______) +} + + +class A1(val _: String) +class A2(_: String) { + class B { + typealias _ = CharSequence + } + val _: Int = 1 + + fun _() {} + + fun foo(_: Double) {} +} + +// one underscore parameters for named function are still prohibited +fun oneUnderscore(_: Int) {} + +fun doIt(f: (Any?) -> Any?) = f(null) + +val something = doIt { __ -> __ } +val something2 = doIt { _ -> 1 } diff --git a/compiler/testData/diagnostics/tests/UnderscoreUsageInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/UnderscoreUsageInAnnotation.fir.kt new file mode 100644 index 00000000000..8259c0d577d --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnderscoreUsageInAnnotation.fir.kt @@ -0,0 +1,6 @@ +package test + +annotation class `__`(val value: String) + +@__("") class TestAnn +@`__`("") class TestAnn2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnderscoreUsageInCall.fir.kt b/compiler/testData/diagnostics/tests/UnderscoreUsageInCall.fir.kt new file mode 100644 index 00000000000..7c60cce7fc8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnderscoreUsageInCall.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY + +fun test(`_`: Int) { + _ + 1 + `_` + 1 +} + +fun `__`() {} + +fun testCall() { + __() + `__`() +} + +val testCallableRef = ::__ +val testCallableRef2 = ::`__` + + +object Host { + val `_` = 42 + object `__` { + val bar = 4 + } +} + +val testQualified = Host._ +val testQualified2 = Host.`_` + +object `___` { + val test = 42 +} + +val testQualifier = ___.test +val testQualifier2 = `___`.test +val testQualifier3 = Host.__.bar +val testQualifier4 = Host.`__`.bar + +fun testCallableRefLHSValue(`_`: Any) = _::toString +fun testCallableRefLHSValue2(`_`: Any) = `_`::toString + +val testCallableRefLHSObject = ___::toString +val testCallableRefLHSObject2 = `___`::toString diff --git a/compiler/testData/diagnostics/tests/UnderscoreUsageInCallableRefTypeLHS.fir.kt b/compiler/testData/diagnostics/tests/UnderscoreUsageInCallableRefTypeLHS.fir.kt new file mode 100644 index 00000000000..e97cd0f103f --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnderscoreUsageInCallableRefTypeLHS.fir.kt @@ -0,0 +1,11 @@ +class `___` { + class `____` +} + +val testCallableRefLHSType = ___::toString +val testCallableRefLHSType2 = `___`::toString + +val testClassLiteralLHSType = ___::class +val testClassLiteralLHSType2 = `___`::class + +val tesLHSTypeFQN = `___`.____::class \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnderscoreUsageInType.fir.kt b/compiler/testData/diagnostics/tests/UnderscoreUsageInType.fir.kt new file mode 100644 index 00000000000..181bc7a41cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnderscoreUsageInType.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY + +class `_`<`__`> { + fun testTypeArgument(x: List<__>) = x + fun testTypeArgument2(x: List<`__`>) = x +} + +fun _.testTypeConstructor() {} +fun `_`.testTypeConstructor2() {} + +val testConstructor = _() +val testConstructor2 = `_`() diff --git a/compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.fir.kt b/compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.fir.kt new file mode 100644 index 00000000000..84c1dc55f57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.fir.kt @@ -0,0 +1,6 @@ +object Host { + val `____` = { -> } + fun testFunTypeVal() { + ____() + } +} diff --git a/compiler/testData/diagnostics/tests/UnitByDefaultForFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/UnitByDefaultForFunctionTypes.fir.kt new file mode 100644 index 00000000000..bf866f26c3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnitByDefaultForFunctionTypes.fir.kt @@ -0,0 +1,3 @@ +fun foo(f : () -> Unit) { + val x : Unit = f() +} diff --git a/compiler/testData/diagnostics/tests/UnitValue.fir.kt b/compiler/testData/diagnostics/tests/UnitValue.fir.kt new file mode 100644 index 00000000000..b4d92bc704a --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnitValue.fir.kt @@ -0,0 +1,5 @@ +// !CHECK_TYPE + +fun test() { + return checkSubtype(Unit) +} diff --git a/compiler/testData/diagnostics/tests/Unresolved.fir.kt b/compiler/testData/diagnostics/tests/Unresolved.fir.kt new file mode 100644 index 00000000000..d4133613353 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Unresolved.fir.kt @@ -0,0 +1,32 @@ +package unresolved + +class Pair(val a: A, val b: B) + +fun testGenericArgumentsCount() { + val p1: Pair = Pair(2, 2) + val p2: Pair = Pair(2, 2) +} + +fun testUnresolved() { + if (a is String) { + val s = a + } + foo(a) + val s = "s" + foo(s) + foo1(i) + s.foo() + + when(a) { + is Int -> a + is String -> a + } + + for (j in collection) { + var i: Int = j + i += 1 + foo1(j) + } +} + +fun foo1(i: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnusedInDestructuring.fir.kt b/compiler/testData/diagnostics/tests/UnusedInDestructuring.fir.kt new file mode 100644 index 00000000000..ddf1ff5a0fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnusedInDestructuring.fir.kt @@ -0,0 +1,9 @@ +data class D(val x: Int, val y: Int, val z: Int) +fun foo(): Int { + val (x, y, z) = D(1, 2, 3) + return y + z // x is not used, but we cannot do anything with it +} +fun bar(): Int { + val (x, y, z) = D(1, 2, 3) + return y + x // z is not used +} diff --git a/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt b/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt new file mode 100644 index 00000000000..17eed4370af --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnusedParameters.fir.kt @@ -0,0 +1,43 @@ +import kotlin.reflect.KProperty + +class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { + init { + a + a + } + + val g = b + + init { + c + c + } +} + +fun f(a: Int, b: Int, c: Int = b) { + a + a +} + +fun Any.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" +fun Any.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { +} + +fun Any.provideDelegate(thisRef: Any?, prop: KProperty<*>) { +} + +operator fun Int.getValue(thisRef: Any?, prop: KProperty<*>): String = ":)" + +operator fun Int.setValue(thisRef: Any?, prop: KProperty<*>, value: String) { +} + +operator fun Int.provideDelegate(thisRef: Any?, prop: KProperty<*>) { +} + + +fun get(p: Any) { +} + +fun set(p: Any) { +} + +fun foo(s: String) { + s.xxx = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnusedParametersVersion10.fir.kt b/compiler/testData/diagnostics/tests/UnusedParametersVersion10.fir.kt new file mode 100644 index 00000000000..b3c56ab9bd4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnusedParametersVersion10.fir.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: -SingleUnderscoreForParameterName + +val x = 1.let { arg -> } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnusedVariables.fir.kt b/compiler/testData/diagnostics/tests/UnusedVariables.fir.kt new file mode 100644 index 00000000000..70f2c6d91cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/UnusedVariables.fir.kt @@ -0,0 +1,133 @@ +package unused_variables + +fun testSimpleCases() { + var i = 2 + i = 34 + i = 34 + doSmth(i) + i = 5 + + var j = 2 + j = j++ + j = j-- +} + +class IncDec() { + operator fun inc() : IncDec = this + operator fun dec() : IncDec = this +} + +class MyTest() { + fun testIncDec() { + var x = IncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x + } + + var a: String = "s" + set(v: String) { + var i: Int = 23 + doSmth(i) + i = 34 + field = v + } + + init { + a = "rr" + } + + fun testSimple() { + a = "rro" + + var i = 1; + i = 34; + i = 456; + } + + fun testWhile() { + var a : Any? = true + var b : Any? = 34 + while (a is Any) { + a = null + } + while (b != null) { + a = null + } + } + + fun testIf() { + var a : Any + if (1 < 2) { + a = 23 + } + else { + a = "ss" + doSmth(a) + } + doSmth(a) + + if (1 < 2) { + a = 23 + } + else { + a = "ss" + } + } + + fun testFor() { + for (i in 1..10) { + doSmth(i) + } + } + + fun doSmth(s: String) {} + fun doSmth(a: Any) {} +} + +fun testInnerFunctions() { + var y = 1 + fun foo() { + y = 1 + } + var z = 1 + fun bar() { + doSmth(z) + } +} + +fun testFunctionLiterals() { + var x = 1 + var fl = { + x + } + var y = 2 + var fl1 = { + doSmth(y) + } +} + +interface Trait { + fun foo() +} + +fun testObject() : Trait { + val x = 24 + val o = object : Trait { + val y : Int //in this case y should not be marked as unused + get() = 55 + + override fun foo() { + doSmth(x) + } + } + + return o +} + +fun doSmth(i : Int) {} diff --git a/compiler/testData/diagnostics/tests/ValAndFunOverrideCompatibilityClash.fir.kt b/compiler/testData/diagnostics/tests/ValAndFunOverrideCompatibilityClash.fir.kt new file mode 100644 index 00000000000..6331a7778ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/ValAndFunOverrideCompatibilityClash.fir.kt @@ -0,0 +1,9 @@ +// JAVAC_EXPECTED_FILE +class Foo1() : java.util.ArrayList() + +open class Bar() { + fun v() : Int = 1 + val v : Int = 1 +} + +class Barr() : Bar() {} diff --git a/compiler/testData/diagnostics/tests/VarargTypes.fir.kt b/compiler/testData/diagnostics/tests/VarargTypes.fir.kt new file mode 100644 index 00000000000..66e2f692ab9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/VarargTypes.fir.kt @@ -0,0 +1,26 @@ +// KT-389 Wrong type inference for varargs etc. + +import java.util.* + +fun foob(vararg a : Byte) : ByteArray = a +fun fooc(vararg a : Char) : CharArray = a +fun foos(vararg a : Short) : ShortArray = a +fun fooi(vararg a : Int) : IntArray = a +fun fool(vararg a : Long) : LongArray = a +fun food(vararg a : Double) : DoubleArray = a +fun foof(vararg a : Float) : FloatArray = a +fun foob(vararg a : Boolean) : BooleanArray = a +fun foos(vararg a : String) : Array = a + +fun test() { + Arrays.asList(1, 2, 3) + Arrays.asList(1, 2, 3) + + foob(1, 2, 3) + foos(1, 2, 3) + fooc('1', '2', '3') + fooi(1, 2, 3) + fool(1, 2, 3) + food(1.0, 2.0, 3.0) + foof(1.0.toFloat(), 2.0.toFloat(), 3.0.toFloat()) +} diff --git a/compiler/testData/diagnostics/tests/Varargs.fir.kt b/compiler/testData/diagnostics/tests/Varargs.fir.kt new file mode 100644 index 00000000000..a37f503f461 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Varargs.fir.kt @@ -0,0 +1,17 @@ +fun v(x : Int, y : String, vararg f : Long) {} +fun v1(vararg f : (Int) -> Unit) {} + +fun test() { + v(1, "") + v(1, "", 1) + v(1, "", 1, 1, 1) + v(1, "", 1, 1, 1) + + v1() + v1({}) + v1({}, {}) + v1({}, 1, {}) + v1({}, {}, {it}) + v1({}) {} + v1 {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Variance.fir.kt b/compiler/testData/diagnostics/tests/Variance.fir.kt new file mode 100644 index 00000000000..72753b660a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/Variance.fir.kt @@ -0,0 +1,41 @@ +// !WITH_NEW_INFERENCE +package variance + +abstract class Consumer {} + +abstract class Producer {} + +abstract class Usual {} + +fun foo(c: Consumer, p: Producer, u: Usual) { + val c1: Consumer = c + val c2: Consumer = c1 + + val p1: Producer = p + val p2: Producer = p1 + + val u1: Usual = u + val u2: Usual = u1 +} + +//Arrays copy example +class Array(val length : Int, val t : T) { + fun get(index : Int) : T { return t } + fun set(index : Int, value : T) { /* ... */ } +} + +fun copy1(from : Array, to : Array) {} + +fun copy2(from : Array, to : Array) {} + +fun copy3(from : Array, to : Array) {} + +fun copy4(from : Array, to : Array) {} + +fun f(ints: Array, any: Array, numbers: Array) { + copy1(ints, any) + copy2(ints, any) //ok + copy2(ints, numbers) + copy3(ints, numbers) + copy4(ints, numbers) //ok +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt new file mode 100644 index 00000000000..e2fb989be02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +import java.util.ArrayList + +@ArrayList(1, 1) fun b() {} +@Xoo(x) fun c() {} +@java.lang.Deprecated(x) fun a() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructor.fir.kt new file mode 100644 index 00000000000..32e92a33f72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructor.fir.kt @@ -0,0 +1,2 @@ +annotation class ann +class Annotated(@ann val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.fir.kt new file mode 100644 index 00000000000..f53a25d9ee4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.fir.kt @@ -0,0 +1,15 @@ +package a + +import java.lang.Deprecated as deprecated +import java.lang.SuppressWarnings as suppresswarnings + + +@deprecated @suppresswarnings val s: String = ""; + +@deprecated @suppresswarnings fun main() { + System.out.println("Hello, world!") +} + +class Test(@deprecated val s: String, + @suppresswarnings val x : Int) {} + diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectFun.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectFun.fir.kt new file mode 100644 index 00000000000..bdb7dca248a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectFun.fir.kt @@ -0,0 +1,8 @@ +annotation class My + +fun foo() { + val s = object { + @My fun bar() {} + } + s.bar() +} diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectProperty.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectProperty.fir.kt new file mode 100644 index 00000000000..1f95a8ea8ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedLocalObjectProperty.fir.kt @@ -0,0 +1,8 @@ +annotation class My + +fun foo(): Int { + val s = object { + @My val bar: Int = 0 + } + return s.bar +} diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedLoop.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedLoop.fir.kt new file mode 100644 index 00000000000..1d30d760f42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedLoop.fir.kt @@ -0,0 +1,8 @@ +@Target(AnnotationTarget.TYPE) +annotation class My + +fun foo() { + for (i: @My Int in 0..41) { + if (i == 13) return + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.fir.kt new file mode 100644 index 00000000000..af41d3d5944 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.fir.kt @@ -0,0 +1,5 @@ +// Result type can be annotated +@Target(AnnotationTarget.TYPE) +annotation class My(val x: Int) + +fun foo(): @My(42) Int = 24 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt new file mode 100644 index 00000000000..e98b5122708 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt @@ -0,0 +1,9 @@ +annotation class My + +fun foo(arg: Int): Int { + try { + return 1 / (arg - arg) + } catch (e: @My Exception) { + return -1 + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationAsDefaultParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationAsDefaultParameter.fir.kt new file mode 100644 index 00000000000..a1ef09e0da3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationAsDefaultParameter.fir.kt @@ -0,0 +1,5 @@ +annotation class Base(val x: Int) + +annotation class UseBase(val b: Base = Base(0)) + +@UseBase class My diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.fir.kt new file mode 100644 index 00000000000..dc3b6defedf --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.fir.kt @@ -0,0 +1,10 @@ +annotation class A1 +annotation class A2(val some: Int = 12) + +class TopLevelClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> { + class InnerClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> { + fun test() { + class InFun<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.fir.kt new file mode 100644 index 00000000000..45b6124e8c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.fir.kt @@ -0,0 +1,12 @@ +annotation class A1 +annotation class A2(val some: Int = 12) + +fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> topFun() = 12 + +class SomeClass { + fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> method() = 12 + + fun foo() { + fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> innerFun() = 12 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationForObject.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationForObject.fir.kt new file mode 100644 index 00000000000..d775c840fa8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationForObject.fir.kt @@ -0,0 +1,3 @@ +// Check that there won't be "Rewrite at slice ANNOTATION key" exception - EA-36935 +@someErrorAnnotation object Test { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt new file mode 100644 index 00000000000..57427f7f9ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt + +annotation class annotation + +// FILE: test/b.kt + +package test + +@test.annotation class annotation + +// FILE: other/c.kt + +package other + +annotation class My + +@test.annotation class Your + +@My class Our \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationOnObject.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationOnObject.fir.kt new file mode 100644 index 00000000000..bfc2133b520 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationOnObject.fir.kt @@ -0,0 +1,6 @@ +package test + +annotation class A(val a: Int = 12, val b: String = "Test", val c: String) + +@A(a = 12, c = "Hello") +object SomeObject diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.fir.kt new file mode 100644 index 00000000000..b33157d0892 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.fir.kt @@ -0,0 +1 @@ +annotation @java.lang.Deprecated class my diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.fir.kt new file mode 100644 index 00000000000..f5f40eedd69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.fir.kt @@ -0,0 +1,12 @@ +annotation class A1 +annotation class A2(val some: Int = 12) + +val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> T.topProp: Int get() = 12 + +class SomeClass { + val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> T.field: Int get() = 12 + + fun foo() { + val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> localVal = 12 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/BasicAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/BasicAnnotations.fir.kt new file mode 100644 index 00000000000..96404567511 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/BasicAnnotations.fir.kt @@ -0,0 +1,10 @@ +annotation class my +annotation class my1(val i : Int) +annotation class my2(val i : Int = 0) + +@my fun foo() {} +@my1 fun foo2() {} +@my1(2) fun foo3() {} +@my2() fun foo4() {} +@my2 fun foo41() {} +@my2(2) fun foo42() {} diff --git a/compiler/testData/diagnostics/tests/annotations/ConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/annotations/ConstructorCall.fir.kt new file mode 100644 index 00000000000..21188f702fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/ConstructorCall.fir.kt @@ -0,0 +1,35 @@ +annotation class Ann +annotation class Ann1(val a: Int) +annotation class Ann2(val a: Ann1) + +annotation class Ann3(val a: Ann1 = Ann1(1)) + +annotation class Ann4(val value: String) + +@Ann2(Ann1(1)) val a = 1 + +@Ann2(a = Ann1(1)) val c = 2 + +@Ann4("a") class MyClass + +fun foo() { + Ann() + val a = Ann() + + Ann1() + Ann1(1) + bar(Ann()) + bar(a = Ann()) + + val ann = javaClass().getAnnotation(javaClass()) + ann!!.value() +} + +fun bar(a: Ann = Ann()) { + if (a is Ann) {} +} + +operator fun String.invoke() {} + +// from stdlib +fun javaClass() : Class = null as Class diff --git a/compiler/testData/diagnostics/tests/annotations/DanglingMixed.fir.kt b/compiler/testData/diagnostics/tests/annotations/DanglingMixed.fir.kt new file mode 100644 index 00000000000..5e619361ce3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/DanglingMixed.fir.kt @@ -0,0 +1,22 @@ +annotation class Ann +annotation class Ann2 + +class C { + fun foo() { + class Local { + @Ann0 + @Ann @Ann3 + @Ann2(1) + @Ann4 + } + } + @Ann0 + @Ann @Ann3 + @Ann2(1) + @Ann4 +} + +@Ann0 +@Ann @Ann3 +@Ann2(1) +@Ann4 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/DanglingNoBrackets.fir.kt b/compiler/testData/diagnostics/tests/annotations/DanglingNoBrackets.fir.kt new file mode 100644 index 00000000000..fe2e95895bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/DanglingNoBrackets.fir.kt @@ -0,0 +1,13 @@ +annotation class Ann + +class C { + fun foo() { + class Local { + @Ann + } + } + + @Ann +} + +@Ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/DanglingWithBrackets.fir.kt b/compiler/testData/diagnostics/tests/annotations/DanglingWithBrackets.fir.kt new file mode 100644 index 00000000000..8a0f5e78d5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/DanglingWithBrackets.fir.kt @@ -0,0 +1,16 @@ +annotation class Ann + +class C { + fun test() { + @Ann + } + + fun foo() { + class Local { + @Ann + } + } + @Ann +} + +@Ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/Deprecated.fir.kt b/compiler/testData/diagnostics/tests/annotations/Deprecated.fir.kt new file mode 100644 index 00000000000..9032870147a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/Deprecated.fir.kt @@ -0,0 +1,5 @@ +import java.lang.Deprecated as deprecated + +@java.lang.Deprecated fun foo() {} + +@deprecated fun foo1() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.fir.kt b/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.fir.kt new file mode 100644 index 00000000000..0fa0d5677dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.fir.kt @@ -0,0 +1,10 @@ +import java.lang.annotation.Retention +import java.lang.annotation.Target +import java.lang.annotation.* + +@java.lang.annotation.Retention(RetentionPolicy.CLASS) +annotation class my + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR) +annotation class my1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/MultiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/annotations/MultiDeclaration.fir.kt new file mode 100644 index 00000000000..7ac8fbe9641 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/MultiDeclaration.fir.kt @@ -0,0 +1,9 @@ +annotation class Ann + +data class Pair(val x: Int, val y: Int) + +fun foo(): Int { + @Ann val (a, b) = Pair(12, 34) + @Err val (c, d) = Pair(56, 78) + return a + b + c + d +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.fir.kt b/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.fir.kt new file mode 100644 index 00000000000..6ea315c899a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.fir.kt @@ -0,0 +1,4 @@ +// Functions can be recursively annotated +annotation class ann(val x: Int) +@ann(bar()) fun foo() = 1 +@ann(foo()) fun bar() = 2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt b/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt new file mode 100644 index 00000000000..b606948ff6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt @@ -0,0 +1,3 @@ +class Foo + +@Foo class Bar \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotated.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotated.fir.kt new file mode 100644 index 00000000000..86351a434ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotated.fir.kt @@ -0,0 +1,3 @@ +// Class CAN be recursively annotated +@RecursivelyAnnotated(1) +annotation class RecursivelyAnnotated(val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedFunctionParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedFunctionParameter.fir.kt new file mode 100644 index 00000000000..1319481c187 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedFunctionParameter.fir.kt @@ -0,0 +1,3 @@ +// Function parameter CAN be recursively annotated +annotation class ann(val x: Int) +fun foo(@ann(foo(1)) x: Int): Int = x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalFunction.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalFunction.fir.kt new file mode 100644 index 00000000000..b99a231e627 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalFunction.fir.kt @@ -0,0 +1,3 @@ +// Functions can be recursively annotated +annotation class ann(val x: Int) +@ann(foo()) fun foo() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalProperty.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalProperty.fir.kt new file mode 100644 index 00000000000..638a1728975 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalProperty.fir.kt @@ -0,0 +1,3 @@ +// Properties can be recursively annotated +annotation class ann(val x: Int) +@ann(x) const val x: Int = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameter.fir.kt new file mode 100644 index 00000000000..e4277530222 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameter.fir.kt @@ -0,0 +1,2 @@ +// Class constructor parameter CAN be recursively annotated +annotation class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.fir.kt new file mode 100644 index 00000000000..f3227d7dccd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.fir.kt @@ -0,0 +1,3 @@ +// Class constructor parameter type CAN be recursively annotated +@Target(AnnotationTarget.TYPE) +annotation class RecursivelyAnnotated(val x: @RecursivelyAnnotated(1) Int) diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterWithAt.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterWithAt.fir.kt new file mode 100644 index 00000000000..e4277530222 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterWithAt.fir.kt @@ -0,0 +1,2 @@ +// Class constructor parameter CAN be recursively annotated +annotation class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedProperty.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedProperty.fir.kt new file mode 100644 index 00000000000..0f5f8a50c52 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedProperty.fir.kt @@ -0,0 +1,5 @@ +// Properties can be recursively annotated +annotation class ann(val x: Int) +class My { + @ann(x) val x: Int = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt new file mode 100644 index 00000000000..b7696796635 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt @@ -0,0 +1,2 @@ +// Class constructor parameter CAN be recursively annotated +class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_after.fir.kt new file mode 100644 index 00000000000..a20223575a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_after.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +RestrictRetentionForExpressionAnnotations + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class TestRetentionSource + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.BINARY) +annotation class TestRetentionBinary + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.RUNTIME) +annotation class TestRetentionRuntime \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_before.fir.kt new file mode 100644 index 00000000000..a3cfeb4173d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/RetentionsOfAnnotationWithExpressionTarget_before.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -RestrictRetentionForExpressionAnnotations + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class TestRetentionSource + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.BINARY) +annotation class TestRetentionBinary + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.RUNTIME) +annotation class TestRetentionRuntime \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/UnresolvedAnnotationOnObject.fir.kt b/compiler/testData/diagnostics/tests/annotations/UnresolvedAnnotationOnObject.fir.kt new file mode 100644 index 00000000000..6d25c741128 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/UnresolvedAnnotationOnObject.fir.kt @@ -0,0 +1,9 @@ +package test + +// Checks that there is no rewrite error at ANNOTATION slice because of resolving annotations for object in lazy resolve and resolving +// object as property (method tries to resolve annotations too). + +@BadAnnotation +object SomeObject + +val some = SomeObject \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/WrongAnnotationArgsOnObject.fir.kt b/compiler/testData/diagnostics/tests/annotations/WrongAnnotationArgsOnObject.fir.kt new file mode 100644 index 00000000000..3dc7d2d7bd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/WrongAnnotationArgsOnObject.fir.kt @@ -0,0 +1,8 @@ +package test + +@BadAnnotation(1) +object SomeObject + +val some = SomeObject + +annotation class BadAnnotation(val s: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotatedExpressionInsideAnnotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotatedExpressionInsideAnnotation.fir.kt new file mode 100644 index 00000000000..03e91388a2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotatedExpressionInsideAnnotation.fir.kt @@ -0,0 +1,11 @@ +// SKIP_ERRORS_BEFORE + +annotation class X(val value: Y, val y: Y) +annotation class Y() + +@X(@Y(), y = Y()) +fun foo1() { +} +@X(@Y(), y = @Y()) +fun foo2() { +} diff --git a/compiler/testData/diagnostics/tests/annotations/annotationInheritance.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationInheritance.fir.kt new file mode 100644 index 00000000000..dd3c7ea6d62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationInheritance.fir.kt @@ -0,0 +1,8 @@ +val a = object: T {} +open class C +interface T + +annotation class Ann: C() +annotation class Ann2: T +annotation class Ann3: T by a +annotation class Ann4: C(), T \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationModifier.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationModifier.fir.kt new file mode 100644 index 00000000000..a62a21476bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationModifier.fir.kt @@ -0,0 +1,15 @@ +annotation class B + +class A { + annotation companion object {} +} + +annotation object O {} + +annotation interface T {} + +annotation fun f() = 0 + +annotation val x = 0 + +annotation var y = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt new file mode 100644 index 00000000000..63606691a1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +annotation class Ann + +fun f(@Ann x: Int) {} + +val inVal: (@Ann x: Int)->Unit = {} + +fun inParam(fn: (@Ann x: Int)->Unit) {} + +fun inParamNested(fn1: (fn2: (@Ann n: Int)->Unit)->Unit) {} + +fun inReturn(): (@Ann x: Int)->Unit = {} + +class A : (@Ann Int)->Unit { + override fun invoke(p1: Int) { + var lambda: (@Ann x: Int)->Unit = {} + } + + val prop: (@Ann x: Int)->Unit + get(): (@Ann x: Int)->Unit = {} +} + +@Target(AnnotationTarget.TYPE) +annotation class TypeAnn + +val onType: (@TypeAnn A).(@Ann a: @TypeAnn A, @TypeAnn A)->@TypeAnn A? = { null } + +fun (@TypeAnn A).extFun(@Ann a: @TypeAnn A): @TypeAnn A? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/annotationConstructorDefaultParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/annotationConstructorDefaultParameter.fir.kt new file mode 100644 index 00000000000..2e0eb6f8ce1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/annotationConstructorDefaultParameter.fir.kt @@ -0,0 +1,12 @@ +const val iConst = 42 +val iVal = 42 +fun iFun() = 42 + +annotation class Ann(val x: Int) +annotation class Test1(val x: Int = 42) +annotation class Test2(val x: Int = iConst) +annotation class Test3(val x: Int = 1 + iConst + 1) +annotation class Test4(val x: Int = iVal) +annotation class Test5(val x: Int = 1 + iVal + 1) +annotation class Test6(val x: Int = iFun()) +annotation class Test7(val x: Int = 1 + iFun() + 1) diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/booleanLocalVal.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/booleanLocalVal.fir.kt new file mode 100644 index 00000000000..332422e5e47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/booleanLocalVal.fir.kt @@ -0,0 +1,6 @@ +annotation class Ann(vararg val i: Boolean) +fun foo() { + val bool1 = true + + @Ann(bool1) val a = bool1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/compareAndEquals.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/compareAndEquals.fir.kt new file mode 100644 index 00000000000..5156c7bbb89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/compareAndEquals.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +annotation class Ann(vararg val i: Boolean) +fun foo() { + val a1 = 1 > 2 + val a2 = 1 == 2 + val a3 = a1 == a2 + val a4 = a1 > a2 + + @Ann( + a1, + a2, + a3, + a1 > a2, + a1 == a2 + ) val b = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_after.fir.kt new file mode 100644 index 00000000000..e5cdcbffc91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_after.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ProhibitNonConstValuesAsVarargsInAnnotations + +annotation class AnnE(val i: MyEnum) + +@AnnE(e) +class Test + +val e: MyEnum = MyEnum.A + +enum class MyEnum { + A +} + +@AnnE(Test()) +class Test2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_before.fir.kt new file mode 100644 index 00000000000..35d43f1e3e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/enumConst_before.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitNonConstValuesAsVarargsInAnnotations + +annotation class AnnE(val i: MyEnum) + +@AnnE(e) +class Test + +val e: MyEnum = MyEnum.A + +enum class MyEnum { + A +} + +@AnnE(Test()) +class Test2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/javaProperties.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/javaProperties.fir.kt new file mode 100644 index 00000000000..9d6c13de8c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/javaProperties.fir.kt @@ -0,0 +1,25 @@ +// FILE: Test.java +public class Test { + public static int i1 = 1; + public static final int i2 = 1; + public static final int i3 = i1; + public static final int i4 = i2; + public static int i5 = i1; + public static int i6 = i2; + + public final int i7 = 1; +} + +// FILE: a.kt +annotation class Ann(vararg val i: Int) + +@Ann( + Test.i1, + Test.i2, + Test.i3, + Test.i4, + Test.i5, + Test.i6, + Test().i7 +) +class A diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/kotlinProperties.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/kotlinProperties.fir.kt new file mode 100644 index 00000000000..b580df33fee --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/kotlinProperties.fir.kt @@ -0,0 +1,18 @@ +annotation class Ann(vararg val i: Int) + +@Ann( + i1, + i2, + i3, + i4, + i5, + i6 +) +class Test + +var i1 = 1 // var +const val i2 = 1 // val +val i3 = i1 // val with var in initializer +const val i4 = i2 // val with val in initializer +var i5 = i1 // var with var in initializer +var i6 = i2 // var with val in initializer diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/standaloneInExpression.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/standaloneInExpression.fir.kt new file mode 100644 index 00000000000..5283fe5f70a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/standaloneInExpression.fir.kt @@ -0,0 +1,18 @@ +annotation class AnnE(val i: String) + +enum class MyEnum { + A +} + +@AnnE("1" + MyEnum.A) +class Test + +@AnnE("1" + MyEnum::class) +class Test2 + +@AnnE("1" + AnnE("23")) +class Test3 + +@AnnE("1" + arrayOf("23", "34")) +class Test4 + diff --git a/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/strings.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/strings.fir.kt new file mode 100644 index 00000000000..a90f4b533c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationParameterMustBeConstant/strings.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +annotation class Ann(vararg val i: String) + +const val topLevel = "topLevel" + +fun foo() { + val a1 = "a" + val a2 = "b" + val a3 = a1 + a2 + + val a4 = 1 + val a5 = 1.0 + + @Ann( + a1, + a2, + a3, + "$topLevel", + "$a1", + "$a1 $topLevel", + "$a4", + "$a5", + a1 + a2, + "a" + a2, + "a" + topLevel, + "a" + a4 + ) val b = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.fir.kt new file mode 100644 index 00000000000..42ba06bd17d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.fir.kt @@ -0,0 +1,26 @@ +// !RENDER_DIAGNOSTICS_MESSAGES +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER +// !WITH_NEW_INFERENCE + +fun f1(x: String) {} +fun f2(f: () -> Unit) {} +fun test1() = f2(::f1) + + +@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE) +annotation class Ann + +fun <@Ann R : @Ann Any> f3(a: Array<@Ann R>): Array<@Ann R?> = null!! + +fun test2(a: @Ann Array) { + val r: Array = f3(a) +} + + +var test3: Int = 0 + set(s: @Ann String) {} + + +fun f4(fn: (@Ann Int, @Ann Int) -> Unit) {} + +val test4 = f4 { single -> } diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.fir.kt new file mode 100644 index 00000000000..33f552e47e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.fir.kt @@ -0,0 +1,19 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann(val x: Int = 1) + +inline fun bar(block: () -> Int): Int = block() + +fun foo() { + bar() @Ann(1) @Ann(2) { 101 } + bar() @Ann(3) { 102 } + + bar @Ann l1@ { + return@l1 103 + } + + bar @Ann("") { + 104 + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt new file mode 100644 index 00000000000..840cb49a5de --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt @@ -0,0 +1,44 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + +@Target(AnnotationTarget.TYPE) +annotation class a + +@Target(AnnotationTarget.TYPE) +annotation class b(val i: Int) + +annotation class c + +fun foo(i: @a Int?) {} + +fun foo(l: List<@a Int?>) {} + +fun @a Int?.bar() {} + +val baz: @a Int? = 1 + + +fun foo1(i: @b(1) Int?) {} + +fun foo1(l: List<@b(1) Int?>) {} + +fun @b(1) Int?.bar1() {} + +val baz1: @b(1) Int? = 1 + + +fun foo2(i: @[a b(1)] Int?) {} + +fun foo2(l: List<@[a b(1)] Int?>) {} + +fun @[a b(1)] Int?.bar2() {} + +val baz2: @[a b(1)] Int? = 1 + + +fun foo3(i: @c Int?) {} + +fun foo3(l: List<@c Int?>) {} + +fun @c Int?.bar3() {} + +val baz3: @c Int? = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.fir.kt b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.fir.kt new file mode 100644 index 00000000000..b2e39f4b44a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS, + AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, + AnnotationTarget.EXPRESSION, AnnotationTarget.PROPERTY) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann(val x: Int = 6) + +@Ann(1) @Ann(2) @Ann(3) private class A @Ann constructor() { + @Ann(x = 5) fun foo() { + 1 + @Ann(1) 1 * @Ann("") 6 + + @Ann fun local() {} + } + + @Ann val x = 1 + + fun bar(x: @Ann(1) @Ann(2) @Ann(3) Int) {} +} diff --git a/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.fir.kt b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.fir.kt new file mode 100644 index 00000000000..467dbcb69f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/blockLevelOnTheSameLineWarning.fir.kt @@ -0,0 +1,62 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann1 + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann2(val x: String) + +fun bar() {} +fun bar(block: () -> Unit) {} + +fun foo(y: IntArray) { + @Ann1 bar() + @Ann1 bar() { } + @Ann1 bar { } + + @Ann2("") bar() + @Ann2("") bar() { } + @Ann2("") bar { } + + @Ann1 @Ann2("") bar() + + var x = 1 + + @Ann1 ++x + @Ann1 x++ + @Ann2("") ++x + @Ann2("") x++ + @Ann1 @Ann2("") ++x + @Ann1 @Ann2("") x++ + + @Ann1 y[0] + + @Ann1 { x: Int -> x } + @Ann1 { x: Int -> x }(1) + @Ann1 object { fun foo() = 1 } + @Ann1 object { fun foo() = 1 }.foo() + + @Ann1() (x * x) + var z = 1 + @Ann1 x + z + + @Ann1 x = x + 2 + @Ann1 x += z + 2 + + @Ann1 x + 6 * 2 > 0 + @Ann1 x * 6 + 2 > 0 + + @Ann1 object { operator fun plus(x: Int) = 1 } + 1 + @Ann1 object { operator fun plus(x: Int) = 1 } + 1 * 4 > 0 + + @Ann1 x foo z + 8 + + 1 + @Ann1 x + 1 + @Ann1 x * z + 8 + + x foo @Ann1 z + 8 +} + +infix fun Int.foo(other: Int) = 1 diff --git a/compiler/testData/diagnostics/tests/annotations/deprecatedRepeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/deprecatedRepeatable.fir.kt new file mode 100644 index 00000000000..df340589e70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/deprecatedRepeatable.fir.kt @@ -0,0 +1,11 @@ +// FULL_JDK + +import java.lang.annotation.Repeatable + +@java.lang.annotation.Repeatable(Annotations::class) annotation class RepAnn + +@Repeatable(OtherAnnotations::class) annotation class OtherAnn + +annotation class Annotations(vararg val value: RepAnn) + +annotation class OtherAnnotations(vararg val value: OtherAnn) diff --git a/compiler/testData/diagnostics/tests/annotations/extensionFunctionType.fir.kt b/compiler/testData/diagnostics/tests/annotations/extensionFunctionType.fir.kt new file mode 100644 index 00000000000..f034031bb3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/extensionFunctionType.fir.kt @@ -0,0 +1,11 @@ +// This test checks that annotations on extension function types are preserved. See the corresponding .txt file + +@Target(AnnotationTarget.TYPE) +annotation class ann + +interface Some { + fun f1(): String.() -> Int + fun f2(): @ExtensionFunctionType() (String.() -> Int) + fun f3(): @ann String.() -> Int + fun f4(): @ExtensionFunctionType @ann() (String.() -> Int) +} diff --git a/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.fir.kt b/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.fir.kt new file mode 100644 index 00000000000..fd63f5b0969 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.fir.kt @@ -0,0 +1,14 @@ +annotation class Ann(val x: Int) + +data class A(val x: Int, val y: Int) + +fun bar(): Array = null!! + +fun foo() { + for (@Ann(1) i in 1..100) {} + for (@Ann(2) i in 1..100) {} + + for (@Ann(3) (x, @Ann(4) y) in bar()) {} + + for (@Err() (x,y) in bar()) {} +} diff --git a/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithError.fir.kt b/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithError.fir.kt new file mode 100644 index 00000000000..9936973da17 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithError.fir.kt @@ -0,0 +1,70 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER +// SKIP_TXT +// Issue: KT-31734 + +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Foo + +fun foo1(x: @Foo () -> Unit) = x as Iterable<@Foo () -> Unit>? + +fun foo2() = null as @Foo () -> Unit + +fun foo3(x: Any?) { + if (x is (@Foo () -> Unit)?) { + + } +} + +fun foo4(x: Any) = x is @Foo () -> (() -> Unit?) + +fun foo5(x: Any): @Foo () -> Unit = x as @Foo() @[Foo Foo()] @Foo () -> Unit + +fun foo6() { + val x: @Foo() @[Foo Foo()] @Foo () -> Unit = {} +} + +fun foo7() { + val x: @Foo (@Foo () -> Unit) -> Unit = { x: @Foo () -> Unit -> } +} + +fun foo8(x: Any?) { + val x: (@Foo () -> Unit)? = {} +} + +fun foo9(x: (@Foo () -> Unit)?) = x as Iterable<(@Foo () -> Unit?)?>? + +fun foo10(x: @[Foo] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo11(x: @[Foo ] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo12(x: @[Foo/**/] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +val foo13: @Foo (x: @Foo Any) -> Unit get() = {} + +val foo14: @Foo (x: @Foo () -> Unit) -> Unit get() = {} + +val foo15: @Foo () @Foo () -> Unit get() = {} + +val foo16: @Foo @Foo () @Foo () -> Unit get() = {} + +val foo17: @Foo() @Foo () @Foo () -> Unit get() = {} + +val foo18: @Foo()@Foo () @Foo () -> Unit get() = {} + +val foo19: @Foo@Foo () @Foo () -> Unit get() = {} + +val foo20: @Foo@Foo () -> Unit get() = {} + +val foo21: @Foo()@Foo () -> Unit get() = {} + +val foo22: @Foo (x: @Foo () -> Unit) -> Unit get() = {} + +val foo23: @Foo (@Foo () -> Unit) -> Unit get() = {} + +val foo24: @Foo (@Foo () -> Unit, @Foo () -> Unit) -> Unit get() = {x, y -> } + +val foo25: @Foo (x: @Foo Any, @Foo Any) -> Unit get() = {x, y -> } + +val foo26: @Foo suspend () -> Unit = {} diff --git a/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithoutError.fir.kt b/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithoutError.fir.kt new file mode 100644 index 00000000000..87c031e3a6a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/functionalTypes/nonParenthesizedAnnotationsWithoutError.fir.kt @@ -0,0 +1,67 @@ +// !LANGUAGE: +NonParenthesizedAnnotationsOnFunctionalTypes +// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER +// SKIP_TXT +// Issue: KT-31734 + +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Foo + +class MyClass + +fun foo1(x: @Foo () -> Unit) = x as Iterable<@Foo () -> Unit>? + +fun foo2() = null as @Foo () -> Unit + +fun foo3(x: Any?) { + if (x is (@Foo () -> Unit)?) { + + } +} + +fun foo4(x: Any) = x is @Foo () -> (() -> Unit?) + +fun foo5(x: Any): @Foo () -> Unit = x as @Foo() @[Foo Foo()] @Foo () -> Unit + +fun foo6() { + val x: @Foo() @[Foo Foo()] @Foo () -> Unit = {} +} + +fun foo7() { + val x: @Foo (@Foo () -> Unit) -> Unit = { x: @Foo () -> Unit -> } +} + +fun foo10(x: @[Foo()] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo11(x: @[Foo] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo12(x: @[Foo ] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo13(x: @[Foo/**/] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +val foo14: @Foo (x: @Foo () -> Unit) -> Unit get() = {} + +val foo15: @Foo () @Foo () -> Unit get() = {} + +val foo16: @Foo @Foo () @Foo () -> Unit get() = {} + +val foo17: @Foo() @Foo () @Foo () -> Unit get() = {} + +val foo18: @Foo()@Foo () @Foo () -> Unit get() = {} + +val foo19: @Foo@Foo () @Foo () -> Unit get() = {} + +val foo20: @Foo@Foo () -> Unit get() = {} + +val foo21: @Foo()@Foo () -> Unit get() = {} + +val foo22: @Foo (x: @Foo () -> Unit) -> Unit get() = {} + +val foo23: @Foo (@Foo () -> Unit) -> Unit get() = {} + +val foo24: @Foo (@Foo () -> Unit, @Foo () -> Unit) -> Unit get() = {x, y -> } + +val foo25: @Foo (x: @Foo Any, @Foo Any) -> Unit get() = {x, y -> } + +val foo26: @Foo suspend () -> Unit = {} diff --git a/compiler/testData/diagnostics/tests/annotations/functionalTypes/parenthesizedAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/functionalTypes/parenthesizedAnnotations.fir.kt new file mode 100644 index 00000000000..89371321a75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/functionalTypes/parenthesizedAnnotations.fir.kt @@ -0,0 +1,46 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER +// SKIP_TXT +// Issue: KT-31734 + +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Foo + +fun foo1(x: @Foo() () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo2() = null as @Foo() () -> Unit + +fun foo3(x: Any?) { + if (x is (@Foo() () -> Unit)?) { + + } +} + +fun foo4(x: Any) = x is @Foo() () -> (() -> Unit?) + +fun foo5(x: Any): @Foo() () -> Unit = x as @Foo () @[Foo Foo ()] @Foo() () -> Unit + +fun foo6() { + val x: @Foo() @[Foo Foo()] @Foo() () -> Unit = {} +} + +fun foo7() { + val x: @Foo() (@Foo() () -> Unit) -> Unit = { x: @Foo() () -> Unit -> } +} + +fun foo8(x: @[Foo() ] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo9(x: @[Foo()] () -> Unit) = x as Iterable<@Foo() () -> Unit>? + +fun foo10() { + val x: @Foo () @Foo () () -> Unit = {} +} + +fun foo11() { + val x: @Foo @Foo () () -> Unit = {} +} + +fun foo12() { + val x: @Foo() @Foo () () -> Unit = {} +} diff --git a/compiler/testData/diagnostics/tests/annotations/illegalRequireKotlinValue.fir.kt b/compiler/testData/diagnostics/tests/annotations/illegalRequireKotlinValue.fir.kt new file mode 100644 index 00000000000..f253cd804d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/illegalRequireKotlinValue.fir.kt @@ -0,0 +1,38 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +package test + +import kotlin.internal.RequireKotlin + +@RequireKotlin("") +fun f01() {} + +@RequireKotlin("x") +fun f02() {} + +@RequireKotlin("1") +fun f03() {} + +@RequireKotlin("1.0-beta") +fun f04() {} + +@RequireKotlin("1.1.0-dev-1111") +fun f05() {} + +@RequireKotlin("1.5.3.7") +fun f06() {} + +@RequireKotlin("1..0") +fun f07() {} + +@RequireKotlin(" 1.0") +fun f08() {} + + +@RequireKotlin("1.1") +fun ok1() {} + +@RequireKotlin("1.1.0") +fun ok2() {} + +@RequireKotlin("0.0.0") +fun ok3() {} diff --git a/compiler/testData/diagnostics/tests/annotations/illegalSinceKotlinValue.fir.kt b/compiler/testData/diagnostics/tests/annotations/illegalSinceKotlinValue.fir.kt new file mode 100644 index 00000000000..e5b29c8b002 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/illegalSinceKotlinValue.fir.kt @@ -0,0 +1,74 @@ +@SinceKotlin("") +fun f01() {} + +@SinceKotlin("x") +fun f02() {} + +@SinceKotlin("1") +fun f03() {} + +@SinceKotlin("1,0") +fun f04() {} + +@SinceKotlin("1,0,1") +fun f05() {} + +@SinceKotlin("a.b") +fun f06() {} + +@SinceKotlin("1.a") +fun f07() {} + +@SinceKotlin("1.0.a") +fun f08() {} + +@SinceKotlin("1.0-beta") +fun f09() {} + +@SinceKotlin("1.1.0-dev-1111") +fun f10() {} + +@SinceKotlin("1.1.0+rc") +fun f11() {} + +@SinceKotlin("1.5.3.7") +fun f12() {} + +@SinceKotlin("01.1") +fun f13() {} + +@SinceKotlin("1.01") +fun f14() {} + +@SinceKotlin("-1.0") +fun f15() {} + +@SinceKotlin("1.-1.0") +fun f16() {} + +@SinceKotlin("0.00.1") +fun f17() {} + +@SinceKotlin("1..0") +fun f18() {} + +@SinceKotlin(" 1.0") +fun f19() {} + +@SinceKotlin("1.0 ") +fun f20() {} + + + + +@SinceKotlin("1.1") +fun ok1() {} + +@SinceKotlin("1.1.0") +fun ok2() {} + +@SinceKotlin("0.0.0") +fun ok3() {} + +@SinceKotlin("123456789012345678901234567890.123456789012345678901234567890.123456789012345678901234567890") +fun ok4() {} diff --git a/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass.fir.kt b/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass.fir.kt new file mode 100644 index 00000000000..17b9a770ad2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -FINAL_SUPERTYPE +// This error needs to be suppressed to cause light class generation + +class Foo : Target() diff --git a/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass2.fir.kt b/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass2.fir.kt new file mode 100644 index 00000000000..7a63ab0f4e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/inheritFromAnnotationClass2.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -SUPERTYPES_FOR_ANNOTATION_CLASS -VIRTUAL_MEMBER_HIDDEN -FINAL_SUPERTYPE -MISSING_DEPENDENCY_SUPERCLASS +// These errors need to be suppressed to cause light class generation +// FILE: test.kt + +annotation class Ann : Target() + +annotation class Ann2(vararg val allowedTargets: AnnotationTarget) : Target() + +interface I : J { + override fun foo(): List = throw Exception() +} +class C : I { + fun bar(): Set = throw Exception() +} +annotation class Ann3 : C() +annotation class Ann4 : I + +// FILE: J.java + +import java.util.Collection; +import kotlin.annotation.Target; + +public interface J extends Target { + Collection foo(); +} diff --git a/compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.fir.kt new file mode 100644 index 00000000000..73a5332afb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.fir.kt @@ -0,0 +1,76 @@ +package test + +import java.lang.annotation.RetentionPolicy + +// CORRECT +annotation class Ann1(val p1: Int, + val p2: Byte, + val p3: Short, + val p4: Long, + val p5: Double, + val p6: Float, + val p7: Char, + val p8: Boolean) + +annotation class Ann2(val p1: String) +annotation class Ann3(val p1: Ann1) +annotation class Ann4(val p1: IntArray, + val p2: ByteArray, + val p3: ShortArray, + val p4: LongArray, + val p5: DoubleArray, + val p6: FloatArray, + val p7: CharArray, + val p8: BooleanArray) + +annotation class Ann5(val p1: MyEnum) + +annotation class Ann6(val p: Class<*>) +annotation class Ann7(val p: RetentionPolicy) + +annotation class Ann8(val p1: Array, + val p2: Array>, + val p3: Array, + val p4: Array) + +annotation class Ann9( + val error: Unresolved = Unresolved.VALUE +) + + +// INCORRECT +annotation class InAnn1(val p1: Int?, + val p3: Short?, + val p4: Long?, + val p5: Double?, + val p6: Float?, + val p7: Char?, + val p8: Boolean?) + +annotation class InAnn4(val p1: Array, + val p2: Array?) + +annotation class InAnn6(val p: Class<*>?) +annotation class InAnn7(val p: RetentionPolicy?) +annotation class InAnn8(val p1: Array, + val p2: Array, + val p3: Array, + val p4: Array) + +annotation class InAnn9(val p: MyClass) + +annotation class InAnn10(val p1: String?) +annotation class InAnn11(val p1: Ann1?) +annotation class InAnn12(val p1: MyEnum?) + +annotation class InAnn13(vararg val p1: String, + vararg val p2: Class<*>, + vararg val p3: MyEnum, + vararg val p4: Ann1, + vararg val p5: Int) + +enum class MyEnum { + A +} + +class MyClass diff --git a/compiler/testData/diagnostics/tests/annotations/javaRepeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/javaRepeatable.fir.kt new file mode 100644 index 00000000000..4cee7b2a11a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/javaRepeatable.fir.kt @@ -0,0 +1,19 @@ +// FULL_JDK +// FILE: RepeatableAnnotation.java + +import java.lang.annotation.Repeatable; + +@Repeatable(RepeatableAnnotations.class) +public @interface RepeatableAnnotation { +} + +// FILE: RepeatableAnnotations.java + +public @interface RepeatableAnnotations { + RepeatableAnnotation[] value(); +} + +// FILE: RepeatableUse.kt + +// Error should be gone when Java 8 Target will be available +@RepeatableAnnotation @RepeatableAnnotation class My diff --git a/compiler/testData/diagnostics/tests/annotations/javaRepeatableRetention.fir.kt b/compiler/testData/diagnostics/tests/annotations/javaRepeatableRetention.fir.kt new file mode 100644 index 00000000000..7c63caeac1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/javaRepeatableRetention.fir.kt @@ -0,0 +1,20 @@ +// FULL_JDK +// FILE: RepeatableAnnotation.java + +import java.lang.annotation.*; + +@Repeatable(RepeatableAnnotations.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface RepeatableAnnotation { +} + +// FILE: RepeatableAnnotations.java + +public @interface RepeatableAnnotations { + RepeatableAnnotation[] value(); +} + +// FILE: RepeatableUse.kt + +// Error should be gone when Java 8 Target will be available +@RepeatableAnnotation @RepeatableAnnotation class My diff --git a/compiler/testData/diagnostics/tests/annotations/javaUnrepeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/javaUnrepeatable.fir.kt new file mode 100644 index 00000000000..204ca20c272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/javaUnrepeatable.fir.kt @@ -0,0 +1,9 @@ +// FILE: UnrepeatableAnnotation.java + +public @interface UnrepeatableAnnotation { + +} + +// FILE: UnrepeatableUse.kt + +@UnrepeatableAnnotation @UnrepeatableAnnotation class My \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt b/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt new file mode 100644 index 00000000000..e19143ff1bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +fun foo(@varargs f : Int) {} + +var bar : Int = 1 + set(@varargs v) {} + +val x : (Int) -> Int = {@varargs x : Int -> x} + +class Hello(@varargs args: Any) { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/kt1860-positive.fir.kt b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.fir.kt new file mode 100644 index 00000000000..ce6384ae9e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class test + +fun foo(@test f : Int) {} + +var bar : Int = 1 + set(@test v) {} + +val x : (Int) -> Int = {@test x : Int -> x} // todo fix parser annotation on lambda parameter + +class Hello(@test args: Any) { +} diff --git a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_after.fir.kt new file mode 100644 index 00000000000..db9574ebd15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_after.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +NestedClassesInAnnotations + +annotation class Annotation2() { + public val s: String = "" +} + +annotation class Annotation3() { + public fun foo() {} +} + +annotation class Annotation4() { + class Foo() {} +} + +annotation class Annotation5() { + companion object {} +} + +annotation class Annotation6() { + init {} +} + +annotation class Annotation1() {} + +annotation class Annotation7(val name: String) {} + +annotation class Annotation8(var name: String = "") {} + +annotation class Annotation9(val name: String) + +annotation class Annotation10 diff --git a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_before.fir.kt new file mode 100644 index 00000000000..4f8115d7162 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody_before.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: -NestedClassesInAnnotations + +annotation class Annotation2() { + public val s: String = "" +} + +annotation class Annotation3() { + public fun foo() {} +} + +annotation class Annotation4() { + class Foo() {} +} + +annotation class Annotation5() { + companion object {} +} + +annotation class Annotation6() { + init {} +} + +annotation class Annotation1() {} + +annotation class Annotation7(val name: String) {} + +annotation class Annotation8(var name: String = "") {} + +annotation class Annotation9(val name: String) + +annotation class Annotation10 diff --git a/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.fir.kt new file mode 100644 index 00000000000..41d19140eb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/missingValOnParameter.fir.kt @@ -0,0 +1,5 @@ +annotation class Ann( + val a: Int, + var b: Int, + c: String + ) diff --git a/compiler/testData/diagnostics/tests/annotations/nestedClassesInAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/nestedClassesInAnnotations.fir.kt new file mode 100644 index 00000000000..b347ffd50f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/nestedClassesInAnnotations.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +NestedClassesInAnnotations + +annotation class Foo { + class Nested + + inner class Inner + + enum class E { A, B } + object O + interface I + annotation class Anno(val e: E) + + companion object { + val x = 1 + const val y = "" + } + + + constructor(s: Int) {} + init {} + fun function() {} + val property get() = Unit +} diff --git a/compiler/testData/diagnostics/tests/annotations/noNameProperty.fir.kt b/compiler/testData/diagnostics/tests/annotations/noNameProperty.fir.kt new file mode 100644 index 00000000000..3fcd987d7ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/noNameProperty.fir.kt @@ -0,0 +1 @@ +annotation class Ann(val x: Int, val ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/onExpression.fir.kt b/compiler/testData/diagnostics/tests/annotations/onExpression.fir.kt new file mode 100644 index 00000000000..9ffd58eb14a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onExpression.fir.kt @@ -0,0 +1,5 @@ +fun foo() = @ann 1 + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.fir.kt new file mode 100644 index 00000000000..f0b2fcb1e1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.fir.kt @@ -0,0 +1,7 @@ +annotation class ann + +fun test(@ann p: Int) { + +} + +val bar = fun(@ann g: Int) {} diff --git a/compiler/testData/diagnostics/tests/annotations/onInitializer.fir.kt b/compiler/testData/diagnostics/tests/annotations/onInitializer.fir.kt new file mode 100644 index 00000000000..9cfe8761a65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onInitializer.fir.kt @@ -0,0 +1,11 @@ +class A { + @ann init {} + @aaa init {} +} + +interface T { + @ann init {} + @aaa init {} +} + +annotation class ann diff --git a/compiler/testData/diagnostics/tests/annotations/onLoops.fir.kt b/compiler/testData/diagnostics/tests/annotations/onLoops.fir.kt new file mode 100644 index 00000000000..2ec18eb93d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onLoops.fir.kt @@ -0,0 +1,12 @@ +fun test() { + @ann + while (2 < 1) {} + + @ann + do {} while (2 < 1) + + @ann + for (i in 1..2) {} +} + +annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/onLoopsUnreachable.fir.kt b/compiler/testData/diagnostics/tests/annotations/onLoopsUnreachable.fir.kt new file mode 100644 index 00000000000..2500c6f6f4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onLoopsUnreachable.fir.kt @@ -0,0 +1,12 @@ +fun test() { + @ann + while (2 > 1) {} + + @ann + do {} while (2 > 1) + + @ann + for (i in 1..2) {} +} + +annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/onMultiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/annotations/onMultiDeclaration.fir.kt new file mode 100644 index 00000000000..b9c8cf57036 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/onMultiDeclaration.fir.kt @@ -0,0 +1,7 @@ +fun test(): Any? { + @ann val (a, b) = P(1, 1) + return a + b +} + +annotation class ann +data class P(val a: Int, val b: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/annotationAsArg.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/annotationAsArg.fir.kt new file mode 100644 index 00000000000..5484366eef0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/annotationAsArg.fir.kt @@ -0,0 +1,14 @@ +class Annotation(val x: Int) { + fun baz() {} + fun bar() = x +} + +fun foo(annotation: Annotation): Int { + if (annotation.bar() == 0) { + annotation.baz() + return 0 + } + else { + return -1 + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/annotationAsArgComplex.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/annotationAsArgComplex.fir.kt new file mode 100644 index 00000000000..e2c064206da --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/annotationAsArgComplex.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +class Annotation { + fun setProblemGroup() {} + fun getQuickFixes() = 0 +} + +fun registerQuickFix(annotation: Annotation) { + annotation.setProblemGroup() + val fixes = annotation.getQuickFixes() +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/assignment.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/assignment.fir.kt new file mode 100644 index 00000000000..53727d0796c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/assignment.fir.kt @@ -0,0 +1,10 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class ExprAnn + +fun foo(): Int { + var a: Int + @ExprAnn a = 1 + @ExprAnn a += 1 + return a +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/documented.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/documented.fir.kt new file mode 100644 index 00000000000..6b97984be50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/documented.fir.kt @@ -0,0 +1,8 @@ +@MustBeDocumented +annotation class DocAnn + +annotation class NotDocAnn + +@DocAnn class My + +@NotDocAnn class Your diff --git a/compiler/testData/diagnostics/tests/annotations/options/forParam.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/forParam.fir.kt new file mode 100644 index 00000000000..f4416823d77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/forParam.fir.kt @@ -0,0 +1,10 @@ +// See KT-9145 + +@Target(AnnotationTarget.CLASS) +annotation class Ann + +fun foo() { + for (@Ann private x in 1..100) { + if (x == 1) return + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/functionExpression.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/functionExpression.fir.kt new file mode 100644 index 00000000000..7bd5906366e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/functionExpression.fir.kt @@ -0,0 +1,12 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class ExprAnn + +@Target(AnnotationTarget.FUNCTION) +annotation class FunAnn + +fun foo(): Int { + val x = @ExprAnn fun() = 1 + val y = @FunAnn fun() = 2 + return x() + y() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/functions.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/functions.fir.kt new file mode 100644 index 00000000000..e1caca0c43e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/functions.fir.kt @@ -0,0 +1,40 @@ +// !WITH_NEW_INFERENCE +@Target(AnnotationTarget.FUNCTION) +annotation class FunAnn + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +annotation class SourceAnn + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class ExprAnn + +fun bar(arg: () -> Int) = arg() + +inline fun fast(arg: () -> Int) = arg() + +inline fun fast2(x: Int, arg: () -> Int) = x + arg() + +@FunAnn fun gav() = 13 + +fun foo(arg: Int) { + // Literal is annotatable + bar @FunAnn { arg } + // Annotatable in principle but useless, fast is inline + fast @FunAnn { arg } + fast2(1, @FunAnn { arg }) + // Source annotation, ok + fast @SourceAnn { arg } + fast2(1, @SourceAnn { arg }) + // Expression annotation, ok + fast @ExprAnn { arg } + fast2(1, @ExprAnn { arg }) + // Function expression too + val f = @FunAnn fun(): Int { return 42 } + // But here, f and gav should be annotated instead + bar(@FunAnn f) + bar(@FunAnn ::gav) + // Function expression, ok + fast(f) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/javaDocumented.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/javaDocumented.fir.kt new file mode 100644 index 00000000000..3c50e6cf83b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/javaDocumented.fir.kt @@ -0,0 +1,20 @@ +// FILE: DocumentedAnnotations.java + +import java.lang.annotation.*; + +public class DocumentedAnnotations { + + @Documented public @interface DocAnn {}; + + public @interface NotDocAnn {}; + + @Documented @Retention(RetentionPolicy.RUNTIME) public @interface RunDocAnn {}; +} + +// FILE: DocumentedAnnotations.kt + +@DocumentedAnnotations.DocAnn class My + +@DocumentedAnnotations.NotDocAnn class Your + +@DocumentedAnnotations.RunDocAnn class His diff --git a/compiler/testData/diagnostics/tests/annotations/options/javaKotlinTargetRetention.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/javaKotlinTargetRetention.fir.kt new file mode 100644 index 00000000000..878fb7ad602 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/javaKotlinTargetRetention.fir.kt @@ -0,0 +1,9 @@ +import java.lang.annotation.* + +@java.lang.annotation.Target(ElementType.PACKAGE) +@Target(AnnotationTarget.CLASS) +annotation class my + +@java.lang.annotation.Retention(RetentionPolicy.SOURCE) +@Retention(AnnotationRetention.BINARY) +annotation class your diff --git a/compiler/testData/diagnostics/tests/annotations/options/javaretention.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/javaretention.fir.kt new file mode 100644 index 00000000000..9da8584e996 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/javaretention.fir.kt @@ -0,0 +1,35 @@ +// FILE: AnnotationRetentions.java + +import java.lang.annotation.*; + +public class AnnotationRetentions { + + public @interface BaseAnnotation { + + } + + @Retention(RetentionPolicy.SOURCE) + public @interface SourceAnnotation { + + } + + @Retention(RetentionPolicy.CLASS) + public @interface BinaryAnnotation { + + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface RuntimeAnnotation { + + } +} + +// FILE: AnnotationRetentions.kt + +@AnnotationRetentions.BaseAnnotation class BaseClass + +@AnnotationRetentions.SourceAnnotation class SourceClass + +@AnnotationRetentions.BinaryAnnotation class BinaryClass + +@AnnotationRetentions.RuntimeAnnotation class RuntimeClass diff --git a/compiler/testData/diagnostics/tests/annotations/options/multiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/multiDeclaration.fir.kt new file mode 100644 index 00000000000..80ffcfcb864 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/multiDeclaration.fir.kt @@ -0,0 +1,7 @@ +@Target(AnnotationTarget.CLASS) +annotation class My +data class Pair(val a: Int, val b: Int) +fun foo(): Int { + val (@My private a, @My public b) = Pair(12, 34) + return a + b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/objectLiteral.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/objectLiteral.fir.kt new file mode 100644 index 00000000000..4f9a6d917c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/objectLiteral.fir.kt @@ -0,0 +1,8 @@ +@Target(AnnotationTarget.CLASS) +annotation class Ann + +open class My + +fun foo(): My { + return (@Ann object: My() {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/prefix.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/prefix.fir.kt new file mode 100644 index 00000000000..8eb29e09ae3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/prefix.fir.kt @@ -0,0 +1,13 @@ +@Target(AnnotationTarget.FUNCTION) +annotation class FunAnn + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class ExprAnn + +fun foo(): Int { + var x = 5 + @FunAnn ++x + @ExprAnn ++x + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/repeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/repeatable.fir.kt new file mode 100644 index 00000000000..1b3c23a9272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/repeatable.fir.kt @@ -0,0 +1,31 @@ +@Repeatable +annotation class repann + +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class repann1(val x: Int) + +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class repann2(val f: Boolean) + +@Retention(AnnotationRetention.BINARY) +@Repeatable +annotation class binrepann + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class repexpr + +@repann @repann class DoubleAnnotated + +@repann1(1) @repann1(2) @repann1(3) class TripleAnnotated + +@repann2(true) @repann2(false) @repann2(false) @repann2(true) class FourTimesAnnotated + +@binrepann @binrepann class BinaryAnnotated + +@repann @repann fun foo(@repann @repann x: Int): Int { + @repexpr @repexpr return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/retention.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/retention.fir.kt new file mode 100644 index 00000000000..2ea2d384d69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/retention.fir.kt @@ -0,0 +1,4 @@ +@Retention(AnnotationRetention.SOURCE) +annotation class sourceann + +@sourceann class AnnotatedAtSource diff --git a/compiler/testData/diagnostics/tests/annotations/options/setterParam.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/setterParam.fir.kt new file mode 100644 index 00000000000..89d774979d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/setterParam.fir.kt @@ -0,0 +1,8 @@ +// KT-9145 + +@Target(AnnotationTarget.CLASS) +annotation class Ann + +var x: Int + get() = 1 + set(@Ann private x) { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/target.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/target.fir.kt new file mode 100644 index 00000000000..107ff9bb57f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/target.fir.kt @@ -0,0 +1,4 @@ +@Target(AnnotationTarget.CLASS) +annotation class base + +@base data class My(val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.fir.kt new file mode 100644 index 00000000000..47f5a243a6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.fir.kt @@ -0,0 +1,16 @@ +@Target(AnnotationTarget.PROPERTY_GETTER) +annotation class smartget + +@Target(AnnotationTarget.PROPERTY_SETTER) +annotation class smartset + +@Target(AnnotationTarget.FUNCTION) +annotation class base + +class My(x: Int) { + @smartget var y = x + @base @smartget @smartset get + @base @smartget @smartset set + + @base @smartget @smartset fun foo() = y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt new file mode 100644 index 00000000000..31b8e95d177 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt @@ -0,0 +1,20 @@ +@Target(AnnotationTarget.ANNOTATION_CLASS) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int) { + @base constructor(): this(0) +} + +@base enum class My { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt new file mode 100644 index 00000000000..fc66e1f59ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.CLASS) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int, @base w: @base Int) { + @base constructor(): this(0, 0) +} + +@base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt new file mode 100644 index 00000000000..294579bda78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt @@ -0,0 +1,20 @@ +@Target(AnnotationTarget.CONSTRUCTOR) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int) { + @base constructor(): this(0) +} + +@base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt new file mode 100644 index 00000000000..19674e7f39b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target() annotation class empty + +@empty annotation class derived + +@empty class correct(@empty val x: Int, @empty w: @empty Int) { + @empty constructor(): this(0, 0) +} + +@empty enum class My @empty constructor() { + @empty FIRST, + @empty SECOND +} + +@empty fun foo(@empty y: @empty Int): Int { + @empty fun bar(@empty z: @empty Int) = z + 1 + @empty val local = bar(y) + return local +} + +@empty val z = @empty 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/expr.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.fir.kt new file mode 100644 index 00000000000..0c3f82d9278 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.fir.kt @@ -0,0 +1,13 @@ +annotation class base + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class special + +fun transform(i: Int, tr: (Int) -> Int): Int = @base @special tr(@special i) + +@base @special fun foo(i: Int): Int { + val j = @base @special i + 1 + if (j == 1) return foo(@special @base 42) + return transform(@special j, @base @special { @special it * 2 }) +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/field.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/field.fir.kt new file mode 100644 index 00000000000..c1a3bdc1a65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/field.fir.kt @@ -0,0 +1,45 @@ +// !WITH_NEW_INFERENCE +@Target(AnnotationTarget.FIELD) +annotation class Field + +@Field +annotation class Another + +@Field +val x: Int = 42 + +@Field +val y: Int + get() = 13 + +@Field +abstract class My(@Field arg: Int, @Field val w: Int) { + @Field + val x: Int = arg + + @Field + val y: Int + get() = 0 + + @Field + abstract val z: Int + + @Field + fun foo() {} + + @Field + val v: Int by Delegates.lazy { 42 } +} + +enum class Your { + @Field FIRST +} + +interface His { + @Field + val x: Int + + @Field + val y: Int + get() = 42 +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/file.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/file.fir.kt new file mode 100644 index 00000000000..fff4469146c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/file.fir.kt @@ -0,0 +1,23 @@ +// FILE: annotation.kt + +package test + +@Target(AnnotationTarget.FILE) annotation class special + +annotation class common + +// FILE: other.kt + +@file:special + +package test + +@special class Incorrect + +// FILE: another.kt + +@file:common + +package test + +@common class Correct diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt new file mode 100644 index 00000000000..e64693a83d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt @@ -0,0 +1,22 @@ +@Target(AnnotationTarget.FUNCTION) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int) { + @base constructor(): this(0) + + @base public fun baz() {} +} + +@base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt new file mode 100644 index 00000000000..5374da7895c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt @@ -0,0 +1,14 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class special + +@Target(AnnotationTarget.TYPE) +annotation class base + +fun transform(i: Int, tr: (@special Int) -> Int): Int = @special tr(@special i) + +fun foo(i: Int): Int { + val j = @special i + 1 + if (j == 1) return foo(@special 42) + return transform(@special j, @special { i: @base Int -> @base i * 2 }) +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt new file mode 100644 index 00000000000..fe4219516fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.INIT) annotation class incorrect + +@incorrect annotation class derived + +@incorrect class correct(@incorrect val x: Int, @incorrect w: @incorrect Int) { + @incorrect constructor(): this(0, 0) +} + +@incorrect enum class My @incorrect constructor() { + @incorrect FIRST, + @incorrect SECOND +} + +@incorrect fun foo(@incorrect y: @incorrect Int): Int { + @incorrect fun bar(@incorrect z: @incorrect Int) = z + 1 + @incorrect val local = bar(y) + return local +} + +@incorrect val z = @incorrect 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/init.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/init.fir.kt new file mode 100644 index 00000000000..b69a5251d59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/init.fir.kt @@ -0,0 +1,6 @@ +annotation class base + +@base class My { + @base init { + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt new file mode 100644 index 00000000000..7d9b683f27e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt @@ -0,0 +1,82 @@ +// FILE: test/AnnotationTargets.java + +package test; + +import java.lang.annotation.*; + +public class AnnotationTargets { + + public @interface base { + + } + + @Target(ElementType.ANNOTATION_TYPE) + public @interface meta { + + } + + @Target(ElementType.CONSTRUCTOR) + public @interface konstructor { + + } + + @Target(ElementType.FIELD) + public @interface fieldann { + + } + + + @Target(ElementType.LOCAL_VARIABLE) + public @interface local { + + } + + @Target(ElementType.METHOD) + public @interface method { + + } + + @Target(ElementType.PARAMETER) + public @interface parameter { + + } + + + @Target(ElementType.TYPE) + public @interface type { + + } + + @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) + public @interface multiple { + + } +} + +// FILE: test/AnnotationTargets.kt + +@file:AnnotationTargets.type +package test + +import test.AnnotationTargets.* + +@base @meta @type @konstructor annotation class KMeta + +@base @meta @type @method @multiple class KClass( + @base @fieldann @parameter val y: + @base @type Int) { + + @base @multiple @fieldann @local val x = 0 + @method @konstructor @type get + + @base @method @multiple @konstructor + fun foo(@parameter @type i: + @base @multiple Int + ): @fieldann @parameter Int { + + @local @base @multiple @fieldann val j = i + 1 + @base @multiple return j + } + + @base @method @konstructor constructor(): this(0) +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt new file mode 100644 index 00000000000..a3b51770c7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt @@ -0,0 +1,20 @@ +@Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int) { + @base constructor(): this(0) +} + +@base enum class My { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/nested.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.fir.kt new file mode 100644 index 00000000000..a836dd98491 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.fir.kt @@ -0,0 +1,15 @@ +@Target(AnnotationTarget.CLASS) +annotation class base + +@Target(AnnotationTarget.ANNOTATION_CLASS) +annotation class meta + +@base class Outer { + @base @meta class Nested + + @base @meta annotation class Annotated + + fun foo() { + @base @meta class Local + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt new file mode 100644 index 00000000000..73fe69e8cda --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.PROPERTY) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int, @base w: Int) { + @base constructor(): this(0, 0) +} + +@base enum class My { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt new file mode 100644 index 00000000000..fc73f675e77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt @@ -0,0 +1,9 @@ +annotation class base + +@Target(AnnotationTarget.TYPE) +annotation class typed + +@base class My(val x: @base @typed Int, y: @base @typed Int) { + val z: @base @typed Int = y + fun foo(): @base @typed Int = z +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.fir.kt new file mode 100644 index 00000000000..a2bcb5cb48c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.fir.kt @@ -0,0 +1,5 @@ +@file:Suppress("abc") + +fun foo(): Int { + @Suppress("xyz") return 1 +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/type.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/type.fir.kt new file mode 100644 index 00000000000..fddebafe484 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/type.fir.kt @@ -0,0 +1,20 @@ +@Target(AnnotationTarget.TYPE) annotation class base + +@base annotation class derived + +@base class correct(@base val x: @base Int) { + @base constructor(): this(0) +} + +@base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt new file mode 100644 index 00000000000..bb4af67b25c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt @@ -0,0 +1,38 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + +@Target(AnnotationTarget.TYPE_PARAMETER) +annotation class A + +@Target(AnnotationTarget.TYPE_PARAMETER) +annotation class B(val i: Int = 12) + + +fun <@A @B(3) T> topFun() = 12 + +class Class1 { + fun <@A @B(3)T> method() = 12 + + fun foo() { + fun <@A @B(3) T> innerFun() = 12 + } +} + +val <@A @B(3) T> T.topProp: Int get() = 12 + +class Class2 { + val <@A @B(3) T> T.field: Int get() = 12 +} + + +@A fun foo() {} +@A class D +fun foo(i: @A Int) { + @A val i = 1 +} +fun test(t: @A T): T = t + + +@Target(AnnotationTarget.TYPE) +internal annotation class C + +fun <@C T> test2(t: T): T = t \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt new file mode 100644 index 00000000000..0ac291e9e92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt @@ -0,0 +1,10 @@ +annotation class base + +val x: List<@base String>? = null + +val y: List<@[base] String>? = null + +@Target(AnnotationTarget.TYPE) +annotation class typeAnn + +fun foo(list: List<@typeAnn Int>) = list \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt new file mode 100644 index 00000000000..89f1de3c26d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.VALUE_PARAMETER) annotation class base + +@base annotation class derived + +@base class correct(@base val x: Int, @base w: Int) { + @base constructor(): this(0, 0) +} + +@base enum class My { + @base FIRST, + @base SECOND +} + +@base fun foo(@base y: @base Int): Int { + @base fun bar(@base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/unrepeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/unrepeatable.fir.kt new file mode 100644 index 00000000000..ea3e981f159 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/unrepeatable.fir.kt @@ -0,0 +1,23 @@ +annotation class unrepann(val x: Int) + +annotation class ann(val y: Int) + +@unrepann(1) @unrepann(2) class DoubleAnnotated + +@ann(3) @ann(7) @ann(42) class TripleAnnotated + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class annexpr + +@ann(0) @ann(1) fun foo(@ann(7) @ann(2) x: Int): Int { + @annexpr @annexpr return x +} + +@unrepann(0) +@get:unrepann(1) +var annotated = 1 // No errors should be here + +@unrepann(0) +@property:unrepann(1) +var annotated2 = 2 diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt new file mode 100644 index 00000000000..ae412ba8eb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -INCOMPATIBLE_MODIFIERS +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS) +annotation class A + +@A +open class B1 { + @A + private open fun foo() {} +} + +class D1 : B1() { + override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/conflictingOverloads.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/conflictingOverloads.fir.kt new file mode 100644 index 00000000000..fdd2776bba6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/conflictingOverloads.fir.kt @@ -0,0 +1,10 @@ +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) +annotation class An + +@An +data class A(@An val x: @An Int) { + @An + fun copy(@An x: @An Int) = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/differentNamesForParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/differentNamesForParameter.fir.kt new file mode 100644 index 00000000000..322233012fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/differentNamesForParameter.fir.kt @@ -0,0 +1,18 @@ +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) +annotation class An + +@An +interface A { + @An + fun foo(@An a : @An Int) +} + +@An +interface B { + @An + fun foo(@An b : @An Int) +} + +interface C : A, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/memberProjectedOut.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/memberProjectedOut.fir.kt new file mode 100644 index 00000000000..fbbaba7fb47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/memberProjectedOut.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS) +annotation class A + +@A +class C { + @A + operator fun set(x: @A Int, y: @A T) {} +} + +fun test(a: C) { + a[1] = 25 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/multipleInheritedDefaults.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/multipleInheritedDefaults.fir.kt new file mode 100644 index 00000000000..646f648ff0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/multipleInheritedDefaults.fir.kt @@ -0,0 +1,26 @@ +// !RENDER_DIAGNOSTICS_MESSAGES +// !DIAGNOSTICS: -ABSTRACT_MEMBER_NOT_IMPLEMENTED + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY, AnnotationTarget.EXPRESSION) +@Retention( AnnotationRetention.SOURCE) +annotation class An + +@An +interface A { + @An + fun foo(@An a: @An Int = @An 1) +} + +@An +interface B { + @An + fun foo(@An a: @An Int = @An 2) +} + +class AB1 : A, B + +@An +class AB2 : A, B { + @An + override fun foo(@An a: @An Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/notImplementedMembers.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/notImplementedMembers.fir.kt new file mode 100644 index 00000000000..081c2838d5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/notImplementedMembers.fir.kt @@ -0,0 +1,48 @@ +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY) +annotation class An + +@An +interface A { + @An + fun a(@An arg: @An Int) +} + +@An +interface B { + @An + fun a(@An arg: @An Int) +} + +interface C : A, B + +@An +abstract class D { + @An + abstract val d: @An Int +} + +class E : D(), A +class F : A + +@An +interface G { + @An + fun a(@An arg: @An Int) +} + +@An +interface AI : A { + @An + override fun a(@An arg: @An Int) {} +} + +@An +interface GI : G { + @An + override fun a(@An arg: @An Int) {} +} + +class AG1(val a: A, val g: G) : A by a, G by g +class AG2() : AI, GI \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/tooManyArguments.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/tooManyArguments.fir.kt new file mode 100644 index 00000000000..b59d761bfba --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/tooManyArguments.fir.kt @@ -0,0 +1,11 @@ +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS) +annotation class Ann(val s: String = "") + +@Ann("s") +fun foo() {} + +val bar = foo( + 15 +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchDueToTypeProjections.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchDueToTypeProjections.fir.kt new file mode 100644 index 00000000000..79b90d1f64c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchDueToTypeProjections.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !RENDER_DIAGNOSTICS_MESSAGES +// !WITH_NEW_INFERENCE + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS) +annotation class A + +@A +class C { + @A + operator fun plus(x: Out<@A T>): @A C<@A T> = this +} + +class Out + +fun test(a: C, y: Out) { + a + y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverride.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverride.fir.kt new file mode 100644 index 00000000000..2a3d5566e23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverride.fir.kt @@ -0,0 +1,26 @@ +// !RENDER_DIAGNOSTICS_MESSAGES + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) +annotation class An + +@An +interface A { + @An + val p1: @An String + @An + var p2: @An String + @An + fun test(@An arg: @An String): @An String +} + +@An +interface B : A { + override val p1: Int + @An + override val p2: @An String + override fun test(arg: String): Int +} + +interface C : A { + override var p2: Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverrideJavaNullable.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverrideJavaNullable.fir.kt new file mode 100644 index 00000000000..e34b5de84f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/typeMismatchOnOverrideJavaNullable.fir.kt @@ -0,0 +1,42 @@ +// !RENDER_DIAGNOSTICS_MESSAGES +// JAVAC_SKIP + +// FILE: A.java + +import org.jetbrains.annotations.NotNull; +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@javax.annotation.meta.TypeQualifier +public @interface MyTypeQualifier {} + +@An +public interface A { + @NotNull + @An + @MyTypeQualifier + String foo(); +} + +// FILE: k.kt + +import org.jetbrains.annotations.NotNull; + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) +annotation class An + +class B : A { + override fun foo(): String? = null +} + +@An +public interface C { + @NotNull + @An + fun foo(): String +} + +class D : C { + override fun foo(): String? = null +} diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/unusedValue.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/unusedValue.fir.kt new file mode 100644 index 00000000000..42e57965221 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/rendering/unusedValue.fir.kt @@ -0,0 +1,12 @@ +// !RENDER_DIAGNOSTICS_MESSAGES +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.TYPE, AnnotationTarget.LOCAL_VARIABLE) +annotation class A + +@A +fun test() { + @A + var b: @A Int = 0 + b = 15 +} diff --git a/compiler/testData/diagnostics/tests/annotations/typeAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeAnnotations.fir.kt new file mode 100644 index 00000000000..d0e22f7c574 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/typeAnnotations.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER +class A + +@Target(AnnotationTarget.TYPE) +annotation class x + +fun @x A.foo(a: @x Int) { + val v: @x Int = 1 +} + +fun @x List<@x T>.foo(l: List<@x T>): @x List<@x T> = throw Exception() + +fun List<@x T>.firstTyped(): U = throw Exception() + +val @x List<@x T>.f: Int get() = 42 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt new file mode 100644 index 00000000000..cedd6de950f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt @@ -0,0 +1,9 @@ +class Foo { + @T + fun foo() = 0 +} + +class Bar { + @T + fun foo() = 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt new file mode 100644 index 00000000000..9ef01c335a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt @@ -0,0 +1,5 @@ +@Ann class A +@Ann class B +@Ann(1) class C +@kotlin.Ann(1) class D +@kotlin.annotation.Ann(1) class E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/DelegateAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/DelegateAnnotations.fir.kt new file mode 100644 index 00000000000..930f962015f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/DelegateAnnotations.fir.kt @@ -0,0 +1,33 @@ +import kotlin.reflect.KProperty + +@Target(AnnotationTarget.FIELD) annotation class Field + +@Target(AnnotationTarget.PROPERTY) annotation class Prop + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +@delegate:Field +class SomeClass { + + @delegate:Field + constructor() + + @delegate:Field @delegate:Prop + protected val simpleProperty: String = "text" + + @delegate:Field @delegate:Prop + protected val delegatedProperty: String by CustomDelegate() + + @delegate:Field @delegate:Prop + val propertyWithCustomGetter: Int + get() = 5 + +} + +class WithPrimaryConstructor(@delegate:Field @delegate:Prop val a: String, + @param:Field @param:Prop val b: String) + +fun foo(@delegate:Field @delegate:Prop x: Int) = x + diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FieldAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FieldAnnotations.fir.kt new file mode 100644 index 00000000000..006381feb39 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FieldAnnotations.fir.kt @@ -0,0 +1,36 @@ +import kotlin.reflect.KProperty + +annotation class Ann + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +@field:Ann +class SomeClass { + + @field:Ann + constructor() + + @field:Ann + protected val simpleProperty: String = "text" + + @field:[Ann] + protected val simplePropertyWithAnnotationList: String = "text" + + @field:Ann + protected val delegatedProperty: String by CustomDelegate() + + @field:Ann + val propertyWithCustomGetter: Int + get() = 5 + + @field:Ann + fun anotherFun(@field:Ann s: String) { + @field:Ann + val localVariable = 5 + } + +} + +class WithPrimaryConstructor(@field:Ann val a: String) diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FileAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FileAnnotations.fir.kt new file mode 100644 index 00000000000..1092884e7f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FileAnnotations.fir.kt @@ -0,0 +1,12 @@ +// FILE: annotations.kt +@Target(AnnotationTarget.CLASS) +public annotation class ClassAnn + +@Target(AnnotationTarget.FILE) +public annotation class FileAnn + +// FILE: 1.kt +@file:ClassAnn + +// FILE: 2.kt +@file:FileAnn \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/GetterAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/GetterAnnotations.fir.kt new file mode 100644 index 00000000000..343a6ccde0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/GetterAnnotations.fir.kt @@ -0,0 +1,39 @@ +import kotlin.reflect.KProperty + +annotation class Ann + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +@get:Ann +class SomeClass { + + @get:Ann + constructor() + + @get:Ann + protected val simpleProperty: String = "text" + + @get:Ann + protected var mutableProperty: String = "text" + + @get:[Ann] + protected val simplePropertyWithAnnotationList: String = "text" + + @get:Ann + protected val delegatedProperty: String by CustomDelegate() + + @get:Ann + val propertyWithCustomGetter: Int + get() = 5 + + @get:Ann + fun annotationOnFunction(a: Int) = a + 5 + + fun anotherFun() { + @get:Ann + val localVariable = 5 + } + +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ParamAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ParamAnnotations.fir.kt new file mode 100644 index 00000000000..f0f7b9c9442 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ParamAnnotations.fir.kt @@ -0,0 +1,24 @@ +annotation class Ann +annotation class Second + +@param:Ann +class SomeClass { + + @param:Ann + constructor(@param:Ann a: String) + + @param:Ann + protected val simpleProperty: String = "text" + + @param:Ann + fun anotherFun() { + @param:Ann + val localVariable = 5 + } + +} + +class PrimaryConstructorClass( + @param:Ann a: String, +@param:[Ann Second] b: String, +@param:Ann val c: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/PropertyAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/PropertyAnnotations.fir.kt new file mode 100644 index 00000000000..9142c89dbb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/PropertyAnnotations.fir.kt @@ -0,0 +1,39 @@ +import kotlin.reflect.KProperty + +annotation class Ann +annotation class Second + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +@property:Ann +class SomeClass { + + @property:Ann + constructor(s: String) + + @property:Ann + protected val p1: String = "" + + @property:[Ann Second] + protected val p2: String = "" + + @property:Ann + protected var p3: String = "" + + @property:Ann + protected val p4: String by CustomDelegate() + + @property:Ann + var propertyWithCustomSetter: Int + get() = 5 + set(v) {} + + @property:Ann + fun anotherFun() { + @property:Ann + val localVariable = 5 + } + +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ReceiverAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ReceiverAnnotations.fir.kt new file mode 100644 index 00000000000..74ccbb4be01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/ReceiverAnnotations.fir.kt @@ -0,0 +1,25 @@ +annotation class Ann + +@receiver:Ann +class SomeClass { + + @receiver:Ann + constructor(@receiver:Ann a: String) + + @receiver:Ann + protected val simpleProperty: String = "text" + + @receiver:Ann + fun anotherFun() { + @receiver:Ann + val localVariable = 5 + } + + val @receiver:Ann String.extensionProperty2: String + get() = "A" +} + +fun @receiver:Ann String.length2() = length + +val @receiver:Ann String.extensionProperty: String + get() = "A" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SetterAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SetterAnnotations.fir.kt new file mode 100644 index 00000000000..ddde82164fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SetterAnnotations.fir.kt @@ -0,0 +1,38 @@ +import kotlin.reflect.KProperty + +annotation class Ann + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +@set:Ann +class SomeClass { + + @set:Ann + protected val simpleProperty: String = "text" + + @set:Ann + protected var mutableProperty: String = "text" + + @set:[Ann] + protected var mutablePropertyWithAnnotationList: String = "text" + + @set:Ann + protected var delegatedProperty: String by CustomDelegate() + + @set:Ann + var propertyWithCustomSetter: Int + get() = 5 + set(v) {} + + @set:Ann + fun annotationOnFunction(a: Int) = a + 5 + + fun anotherFun() { + @set:Ann + val localVariable = 5 + } + +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SparamAnnotations.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SparamAnnotations.fir.kt new file mode 100644 index 00000000000..9279aa0120a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/SparamAnnotations.fir.kt @@ -0,0 +1,39 @@ +import kotlin.reflect.KProperty + +annotation class Ann + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +@setparam:Ann +class SomeClass { + + @setparam:Ann + constructor() + + @setparam:Ann + protected val simpleProperty: String = "text" + + @setparam:Ann + protected var mutableProperty: String = "text" + + @setparam:[Ann] + protected var mutablePropertyWithAnnotationList: String = "text" + + @setparam:Ann + protected var delegatedProperty: String by CustomDelegate() + + @setparam:Ann + var propertyWithCustomSetter: Int + get() = 5 + set(v) {} + + @setparam:Ann + fun anotherFun() { + @setparam:Ann + val localVariable = 5 + } + +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.fir.kt new file mode 100644 index 00000000000..91147c0b82d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.fir.kt @@ -0,0 +1,20 @@ +package bar + +@file:foo +val prop + +@file:[bar baz] +fun func() {} + +@file:[baz] +class C + +@file: +interface T + +@file:[] +interface T + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.fir.kt new file mode 100644 index 00000000000..026f57fa379 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.fir.kt @@ -0,0 +1,8 @@ +@file:foo +@foo @bar +@file:[baz] +fun test() {} + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.fir.kt new file mode 100644 index 00000000000..ab22f55f577 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.fir.kt @@ -0,0 +1,8 @@ +@file:foo +@foo @bar +@file: baz +fun test() {} + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt new file mode 100644 index 00000000000..0ea7436b026 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_after.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(@file Suppress("") x: Int) {} + +@file @Suppress("") +fun test2() {} + +class OnType(x: @file Suppress("") Int) + +fun @file : Suppress("") Int.test3() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt new file mode 100644 index 00000000000..b67f6f53f0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon_before.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: -RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(@file Suppress("") x: Int) {} + +@file @Suppress("") +fun test2() {} + +class OnType(x: @file Suppress("") Int) + +fun @file : Suppress("") Int.test3() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt new file mode 100644 index 00000000000..2164ebed7f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -ProhibitUseSiteTargetAnnotationsOnSuperTypes + +interface Foo + +annotation class Ann + +class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo + +interface G : @Ann Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt new file mode 100644 index 00000000000..d85a79c1c5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes + +interface Foo + +annotation class Ann + +class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo + +interface G : @Ann Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638.fir.kt new file mode 100644 index 00000000000..e9e29f0434f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: -ProhibitRepeatedUseSiteTargetAnnotations + +// Ann is not repeatable +annotation class Ann(val x: Int) + +@get:Ann(10) +val a: String + @Ann(20) get() = "foo" + +@set:Ann(10) +var b: String = "" + @Ann(20) set(value) { field = value } + +@setparam:Ann(10) +var c = " " + set(@Ann(20) x) {} + +@get:Ann(10) +@get:Ann(20) +val d: String + @Ann(30) @Ann(40) get() = "foo" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638_after.fir.kt new file mode 100644 index 00000000000..138bab0c129 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt26638_after.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +ProhibitRepeatedUseSiteTargetAnnotations + +// Ann is not repeatable +annotation class Ann(val x: Int) + +@get:Ann(10) +val a: String + @Ann(20) get() = "foo" + +@set:Ann(10) +var b: String = "" + @Ann(20) set(value) { field = value } + +@setparam:Ann(10) +var c = " " + set(@Ann(20) x) {} + +@get:Ann(10) +@get:Ann(20) +val d: String + @Ann(30) @Ann(40) get() = "foo" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_after.fir.kt new file mode 100644 index 00000000000..6fc63f57ceb --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_after.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes + +@Target(AnnotationTarget.VALUE_PARAMETER) +annotation class Fancy + +fun @receiver:Fancy String.myExtension() { } +val @receiver:Fancy Int.asVal get() = 0 + +fun ((@receiver:Fancy Int) -> Unit).complexReceiver1() {} +fun ((Int) -> @receiver:Fancy Unit).complexReceiver2() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_before.fir.kt new file mode 100644 index 00000000000..e2ce398bcdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/receiverUseSiteTargetOnExtensionFunction_before.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: -RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes + +@Target(AnnotationTarget.VALUE_PARAMETER) +annotation class Fancy + +fun @receiver:Fancy String.myExtension() { } +val @receiver:Fancy Int.asVal get() = 0 + +fun ((@receiver:Fancy Int) -> Unit).complexReceiver1() {} +fun ((Int) -> @receiver:Fancy Unit).complexReceiver2() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/repeatable.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/repeatable.fir.kt new file mode 100644 index 00000000000..bc12a82c794 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/repeatable.fir.kt @@ -0,0 +1,59 @@ +import kotlin.reflect.KProperty + +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class RepeatableAnn +annotation class Ann + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +public class A(@param:Ann @Ann val x: Int, @param: RepeatableAnn @Ann val y: Int) { + + @field:Ann @property:Ann @RepeatableAnn @property:RepeatableAnn + val a: Int = 0 + + @Ann @field:Ann @property:Ann + val b: Int = 0 + + @field:RepeatableAnn @field:RepeatableAnn + val c: Int = 0 + + @property:RepeatableAnn @RepeatableAnn + val d: Int = 0 + + @property:RepeatableAnn @RepeatableAnn @delegate:RepeatableAnn + val e: String by CustomDelegate() + + @property:Ann @delegate:Ann + val f: String by CustomDelegate() + + @Ann @delegate:Ann + val g: String by CustomDelegate() + + @Ann @field:Ann + val h: String = "" + + @property:Ann @field:Ann + val i: String = "" +} + +@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY) +annotation class fieldOrPropAnn + +@Target(AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.VALUE_PARAMETER) +annotation class getSetAndParamAnn + +public class B(@param:fieldOrPropAnn @fieldOrPropAnn val x: Int, + @property:fieldOrPropAnn @fieldOrPropAnn val y: Int) { + @fieldOrPropAnn @field:fieldOrPropAnn + val z: Int = 42 + + @getSetAndParamAnn + @setparam:getSetAndParamAnn + var w: Int + @getSetAndParamAnn @get:getSetAndParamAnn get() = 0 + // See KT-15470: fake INAPPLICABLE_TARGET_ON_PROPERTY + @getSetAndParamAnn @set:getSetAndParamAnn set(arg) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt new file mode 100644 index 00000000000..ab1df1b5508 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypesError.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(i: @setparam:Suppress Int) {} +fun test2(i: @param:Suppress Int) {} +fun test3(i: @receiver:Suppress Int) {} + +fun test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} + +fun ((@setparam:Suppress Int) -> Unit).test6() {} + +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt new file mode 100644 index 00000000000..ab1df1b5508 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_after.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(i: @setparam:Suppress Int) {} +fun test2(i: @param:Suppress Int) {} +fun test3(i: @receiver:Suppress Int) {} + +fun test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} + +fun ((@setparam:Suppress Int) -> Unit).test6() {} + +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt new file mode 100644 index 00000000000..3b9eed6b1b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/wrongParamAnnotationsOnTypes_before.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(i: @setparam:Suppress Int) {} +fun test2(i: @param:Suppress Int) {} +fun test3(i: @receiver:Suppress Int) {} + +fun test4(): @setparam:Suppress Int = TODO() +fun test5(i: (@setparam:Suppress Int) -> Unit) {} + +fun ((@setparam:Suppress Int) -> Unit).test6() {} + +fun test7(): ((@setparam:Suppress Int) -> Unit) = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetSet.fir.kt b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.fir.kt new file mode 100644 index 00000000000..db201619dcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetSet.fir.kt @@ -0,0 +1,6 @@ +class Flower() { + + var minusOne: Int = 1 + get() = field + 1 + set(n: Int) { field = n - 1 } +} diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetVal.fir.kt b/compiler/testData/diagnostics/tests/backingField/CustomGetVal.fir.kt new file mode 100644 index 00000000000..383f29764d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetVal.fir.kt @@ -0,0 +1,4 @@ +class CustomGetVal() { + val zz = 1 + get() = field * 2 +} diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetValGlobal.fir.kt b/compiler/testData/diagnostics/tests/backingField/CustomGetValGlobal.fir.kt new file mode 100644 index 00000000000..c76eab0e2c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetValGlobal.fir.kt @@ -0,0 +1,3 @@ +package customGetValGlobal + val zz = 1 + get() = field * 2 diff --git a/compiler/testData/diagnostics/tests/backingField/CustomGetVar.fir.kt b/compiler/testData/diagnostics/tests/backingField/CustomGetVar.fir.kt new file mode 100644 index 00000000000..62aebd10741 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomGetVar.fir.kt @@ -0,0 +1,4 @@ +class Raise() { + var zz = 1 + get() = field * 2 +} diff --git a/compiler/testData/diagnostics/tests/backingField/CustomSet.fir.kt b/compiler/testData/diagnostics/tests/backingField/CustomSet.fir.kt new file mode 100644 index 00000000000..e2319e7505a --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/CustomSet.fir.kt @@ -0,0 +1,4 @@ +class Raise() { + var zz = 1 + set(it) { field = it / 2 } +} diff --git a/compiler/testData/diagnostics/tests/backingField/ExtensionProperty.fir.kt b/compiler/testData/diagnostics/tests/backingField/ExtensionProperty.fir.kt new file mode 100644 index 00000000000..c66c6691dcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/ExtensionProperty.fir.kt @@ -0,0 +1,17 @@ +// See KT-9303: synthetic field variable does not exist for extension properties +val String.foo: Int + get() { + // No shadowing here + val field = 42 + return field + } + +val String.bar: Int = 13 + // Error + get() = field + +class My { + val String.x: Int = 7 + // Error + get() = field +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt new file mode 100644 index 00000000000..33541e1b809 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldAsParam.fir.kt @@ -0,0 +1,8 @@ +var y: Int = 1 + +// No backing field! +var x: Int + get() = y + set(field) { + y = field + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldAsProperty.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldAsProperty.fir.kt new file mode 100644 index 00000000000..a0990d567d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldAsProperty.fir.kt @@ -0,0 +1,9 @@ +class My(val field: Int) { + // Backing field, initializer + val second: Int = 0 + get() = field + + // No backing field, no initializer + val third: Int + get() = this.field +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldDerived.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldDerived.fir.kt new file mode 100644 index 00000000000..02c7621e8ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldDerived.fir.kt @@ -0,0 +1,18 @@ +open class Base { + open val x: Int = 1 + get() = field - 1 +} + +class Other: Base() { + override val x = 2 +} + +class Another: Base() { + override val x = 3 + get() = field + 1 +} + +class NoBackingField: Base() { + override val x: Int + get() = 5 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldInInterface.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldInInterface.fir.kt new file mode 100644 index 00000000000..991779fad58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldInInterface.fir.kt @@ -0,0 +1,4 @@ +interface My { + val x: Int = 0 + get() = field +} diff --git a/compiler/testData/diagnostics/tests/backingField/FieldInLocal.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldInLocal.fir.kt new file mode 100644 index 00000000000..cc14a9b10cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldInLocal.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +fun foo() { + open class Local { + val my: Int = 2 + get() = field + } + val your = object: Local() { + val your: Int = 3 + get() = field + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldOnVal.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldOnVal.fir.kt new file mode 100644 index 00000000000..02554ee0a3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldOnVal.fir.kt @@ -0,0 +1,2 @@ +val my: Int = 21 + get() = field * 2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldOnVar.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldOnVar.fir.kt new file mode 100644 index 00000000000..882c035d8e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldOnVar.fir.kt @@ -0,0 +1,5 @@ +var my: Int = 0 + get() = -field + set(arg) { + field = arg + } diff --git a/compiler/testData/diagnostics/tests/backingField/FieldReassignment_after.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldReassignment_after.fir.kt new file mode 100644 index 00000000000..a082948fe44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldReassignment_after.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +RestrictionOfValReassignmentViaBackingField + +val my: Int = 1 + get() { + field++ + return field + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldReassignment_before.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldReassignment_before.fir.kt new file mode 100644 index 00000000000..660a0ee1d2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldReassignment_before.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -RestrictionOfValReassignmentViaBackingField + +val my: Int = 1 + get() { + field++ + return field + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/FieldShadow.fir.kt b/compiler/testData/diagnostics/tests/backingField/FieldShadow.fir.kt new file mode 100644 index 00000000000..32add099380 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/FieldShadow.fir.kt @@ -0,0 +1,8 @@ +class My { + // No initialization needed because no backing field + val two: Int + get() { + val field = 2 + return field + } +} diff --git a/compiler/testData/diagnostics/tests/backingField/InitCustomSetter.fir.kt b/compiler/testData/diagnostics/tests/backingField/InitCustomSetter.fir.kt new file mode 100644 index 00000000000..b96daa2263e --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/InitCustomSetter.fir.kt @@ -0,0 +1,30 @@ +class My(val v: Int) { + // Ok: setter is just private + var x: Int + private set + + var y: Int + set(arg) { field = arg } + + var z: Int + set(arg) { field = arg } + + // Ok: initializer available + var w: Int = v + set(arg) { field = arg } + + // Ok: no backing field + var u: Int + get() = w + set(arg) { w = 2 * arg } + + constructor(): this(0) { + z = v + } + + init { + x = 1 + y = 2 + u = 3 + } +} diff --git a/compiler/testData/diagnostics/tests/backingField/InitOpenSetter.fir.kt b/compiler/testData/diagnostics/tests/backingField/InitOpenSetter.fir.kt new file mode 100644 index 00000000000..6a8de3b254b --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/InitOpenSetter.fir.kt @@ -0,0 +1,27 @@ +abstract class My(val v: Int) { + // Ok: variable is just abstract + abstract var x: Int + + open var y: Int + + open var z: Int + + // Ok: initializer available + open var w: Int = v + set(arg) { field = arg } + + // Ok: no backing field, no initializer possible + open var u: Int + get() = w + set(arg) { w = 2 * arg } + + constructor(): this(0) { + z = v + } + + init { + x = 1 + y = 2 + u = 3 + } +} diff --git a/compiler/testData/diagnostics/tests/backingField/SetterWithExplicitType.fir.kt b/compiler/testData/diagnostics/tests/backingField/SetterWithExplicitType.fir.kt new file mode 100644 index 00000000000..2a343535976 --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/SetterWithExplicitType.fir.kt @@ -0,0 +1,26 @@ +// KT-7042 Providing return type for property setter is not reported as error + +var x: Int = 1 + +// No backing field! +var y: Int + get() = x + set(value): Any { + x = value + } + +var z: Int + get() = x + set(value): Unit { + x = value + } + +var u: String = "" + set(value): Unit { + field = value + } + +var v: String = "" + set(value): String { + field = value + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/kt782packageLevel.fir.kt b/compiler/testData/diagnostics/tests/backingField/kt782packageLevel.fir.kt new file mode 100644 index 00000000000..a5bd01f37dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/backingField/kt782packageLevel.fir.kt @@ -0,0 +1,16 @@ +// KT-782 Allow backing field usage for accessors of variables on namespace level + +package kt782 + +val z : Int = 34 + +val y : Int = 11 +get() { + return field +} + +val x : Int +get() = z + +val w : Int = 56 +get() = field \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt new file mode 100644 index 00000000000..34cf4aafe65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt @@ -0,0 +1,8 @@ +fun f1() = Map::hashCode +fun f2() = Map.Entry::hashCode + +class Outer { + inner class Inner +} + +fun f3() = Outer.Inner::hashCode diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedCompanion.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedCompanion.fir.kt new file mode 100644 index 00000000000..870501ae0fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedCompanion.fir.kt @@ -0,0 +1,18 @@ +// FILE: 1.kt + +package a + +import b.B.* +import kotlin.reflect.KClass + +class Companion + +val f: KClass = Companion::class + +// FILE: 2.kt + +package b + +class B { + companion object Companion +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedObject.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedObject.fir.kt new file mode 100644 index 00000000000..0b2434d7c0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/classVsStarImportedObject.fir.kt @@ -0,0 +1,19 @@ +// FILE: 1.kt + +package a + +import b.* +import kotlin.reflect.KClass + +class A +object B + +val f: KClass = A::class +val g: KClass = B::class + +// FILE: 2.kt + +package b + +object A +object B diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/companionObject.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/companionObject.fir.kt new file mode 100644 index 00000000000..bd6cd6dc7e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/companionObject.fir.kt @@ -0,0 +1,39 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +package test + +class C { + companion object { + fun foo(): String = "companion" + fun bar() {} + } + + fun foo(): Int = 0 +} + +fun test() { + val r1 = C::foo + checkSubtype<(C) -> Int>(r1) + + val r2 = test.C::foo + checkSubtype<(C) -> Int>(r2) + + val r3 = C.Companion::foo + checkSubtype<() -> String>(r3) + + val r4 = test.C.Companion::foo + checkSubtype<() -> String>(r4) + + val r5 = (C)::foo + checkSubtype<() -> String>(r5) + + val r6 = (test.C)::foo + checkSubtype<() -> String>(r6) + + val c = C.Companion + val r7 = c::foo + checkSubtype<() -> String>(r7) + + C::bar +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/controlFlow.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/controlFlow.fir.kt new file mode 100644 index 00000000000..a7879898c7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/controlFlow.fir.kt @@ -0,0 +1,22 @@ +fun unusedExpression(s: String) { + s::hashCode + s::class +} + +fun noUnusedParameter(s: String): Int { + val f = s::hashCode + return f() +} + +fun unreachableCode(): Int { + (if (true) return 1 else return 0)::toString + return 0 +} + +fun unreachableCodeInLoop(): Int { + while (true) { + (break)::toString + return 1 + } + return 2 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/dataFlow.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/dataFlow.fir.kt new file mode 100644 index 00000000000..cd0dbeda4ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/dataFlow.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import kotlin.reflect.KClass + +fun f1(x: String?): String { + x!!::hashCode + return x +} + +fun f2(y: String?): String { + val f: KClass<*> = (y ?: return "")::class + return y +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/expectedType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/expectedType.fir.kt new file mode 100644 index 00000000000..2babceacb13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/expectedType.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import kotlin.reflect.KClass + +fun test(s: String) { + val f: () -> Int = s::hashCode + val g: () -> String = s::toString + val h: (Any?) -> Boolean = s::equals + + val k: KClass = s::class + val l: KClass<*> = s::class + val m: KClass = String::class + val n: KClass = Unit::class +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/expressionWithNullableType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/expressionWithNullableType.fir.kt new file mode 100644 index 00000000000..90a9adae93b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/expressionWithNullableType.fir.kt @@ -0,0 +1,15 @@ +// FILE: J.java + +public interface J { + String platformString(); +} + +// FILE: test.kt + +fun f1(x: Int?): Any = x::hashCode +fun f2(t: T): Any = t::hashCode +fun f3(s: S): Any = s::hashCode +fun f4(u: U?): Any = u::hashCode +fun f5(c: List<*>): Any = c[0]::hashCode + +fun f6(j: J): Any = j.platformString()::hashCode diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/functionCallWithoutArguments.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/functionCallWithoutArguments.fir.kt new file mode 100644 index 00000000000..be9c7e33b9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/functionCallWithoutArguments.fir.kt @@ -0,0 +1 @@ +fun test() = ("").hashCode::hashCode diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/innerNested.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/innerNested.fir.kt new file mode 100644 index 00000000000..07582d6980f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/innerNested.fir.kt @@ -0,0 +1,9 @@ +class Outer { + class Nested + inner class Inner +} + +fun test() { + Outer()::Inner + Outer()::Nested +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/kt12843.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/kt12843.fir.kt new file mode 100644 index 00000000000..18df77a2d46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/kt12843.fir.kt @@ -0,0 +1,6 @@ +class Foo { + fun bar() {} + fun f() = Unresolved()::bar +} + +val f: () -> Unit = Unresolved()::foo diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt new file mode 100644 index 00000000000..79bbc332054 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt @@ -0,0 +1,3 @@ +open class A(val x: Any) + +class B : A(this::class) diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/object.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/object.fir.kt new file mode 100644 index 00000000000..d2b6f013005 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/object.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +object Obj { + fun foo() {} + val bar = 2 +} + +fun test() { + checkSubtype<() -> Unit>(Obj::foo) + checkSubtype<() -> Int>(Obj::bar) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/privateToThis.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/privateToThis.fir.kt new file mode 100644 index 00000000000..e578a364358 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/privateToThis.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class Foo(name: T) { + private var prop: T = name + private set + + fun testProp() { + val ok1 = this::prop + val ok2 = this@Foo::prop + val ok3 = object { val y: Any = this@Foo::prop } + + val fail1 = Foo(prop)::prop + } + + fun testFunc() { + val ok1 = this::func + val ok2 = this@Foo::func + val ok3 = object { val y: Any = this@Foo::func } + + val fail1 = Foo(prop)::func + } + + private fun func(t: T): T = t +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/referenceToStaticMethodOnInstance.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/referenceToStaticMethodOnInstance.fir.kt new file mode 100644 index 00000000000..656a0a5d6dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/referenceToStaticMethodOnInstance.fir.kt @@ -0,0 +1,14 @@ +// FILE: A.java + +public class A { + public static void test() {} +} + +// FILE: test.kt + +enum class E { EN } + +fun test() { + A()::test + E.EN::valueOf +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax.fir.kt new file mode 100644 index 00000000000..554a28491c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +package test + +object ClassMemberMarker + +class a { + fun foo() = ClassMemberMarker +} + +class b { + fun foo() = ClassMemberMarker +} + +fun Int.foo() {} + +class Test { + val List.a: Int get() = size + val List.b: Int? get() = size + + fun List.testCallable1(): () -> Unit = a::foo + fun List.testCallable2(): () -> Unit = b?::foo + fun List.testCallable3(): () -> Unit = b::foo + fun List.testCallable4(): () -> Unit = b?::foo + + fun List.testClassLiteral1() = a::class + fun List.testClassLiteral2() = b?::class + fun List.testClassLiteral3() = b::class + + fun List.testUnresolved1() = unresolved::foo + fun List.testUnresolved2() = a::foo + fun List.testUnresolved3() = a<>::foo + fun List.testUnresolved4() = unresolved?::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax2.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax2.fir.kt new file mode 100644 index 00000000000..1283a601da5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax2.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +package test + +fun nullableFun(): Int? = null +fun Int.foo() {} + +val test1 = nullableFun()?::foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.fir.kt new file mode 100644 index 00000000000..06998a2aa87 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/reservedExpressionSyntax3.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +package test + +object Wrong +object Right + +class a { + class b { + class c { + fun foo() = Wrong + } + } +} + +fun Int.foo() = Right + +class Test { + val a: List = null!! + + val List.b: Int get() = 42 + + val Int.c: Int get() = 42 + + val test1: () -> Right = a.b.c::foo + val test1a: () -> Right = a.b.c::foo + + val test2: () -> Right = a.b.c?::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/syntheticExtensionOnLHS.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/syntheticExtensionOnLHS.fir.kt new file mode 100644 index 00000000000..43b869004af --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/syntheticExtensionOnLHS.fir.kt @@ -0,0 +1,13 @@ +// FILE: A.java + +class A { + public CharSequence getFoo() { return null; } +} + +// FILE: test.kt + +fun test() { + with (A()) { + foo::toString + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/valueOfTypeParameterType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/valueOfTypeParameterType.fir.kt new file mode 100644 index 00000000000..928a186a85c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/bound/valueOfTypeParameterType.fir.kt @@ -0,0 +1,3 @@ +fun get(t: T): () -> String { + return t::toString +} diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt new file mode 100644 index 00000000000..a70957b6ada --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +fun test() { + val a = if (true) { + val x = 1 + "".length + ::foo + } else { + ::foo + } + a checkType { _>() } +} + +fun foo(): Int = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/classVsPackage.fir.kt b/compiler/testData/diagnostics/tests/callableReference/classVsPackage.fir.kt new file mode 100644 index 00000000000..13c46fdf61e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/classVsPackage.fir.kt @@ -0,0 +1,24 @@ +// MODULE: m1 +// FILE: 1.kt + +package a + +class b { + class c +} + +// MODULE: m2 +// FILE: 2.kt + +package a.b + +class c { + fun foo() {} +} + +// MODULE: m3(m1, m2) +// FILE: test.kt + +package test + +fun test() = a.b.c::foo diff --git a/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.fir.kt b/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.fir.kt new file mode 100644 index 00000000000..cc06049c5b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirection.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 + +interface A +inline val T.bla get() = 1 + +class B +fun B.foo(p: KProperty1): B = TODO() + +fun B.bar(p: KProperty1): B = TODO() + +fun B.baz(p: KProperty1): B = TODO() + +fun B.star(p: KProperty1<*, V>): B = TODO() + + +fun B.test(){ + foo(A::bla) + bar(A::bla) + baz(A::bla) + star(A::bla) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.fir.kt new file mode 100644 index 00000000000..ccfc84684b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 + +class DTO { + val q: Int = 0 + operator fun get(prop: KProperty1<*, Int>): Int = 0 +} + +fun foo(intDTO: DTO?, p: KProperty1<*, Int>) { + if (intDTO != null) { + intDTO[DTO::q] + intDTO.q + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.fir.kt b/compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.fir.kt new file mode 100644 index 00000000000..c477e447579 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.fir.kt @@ -0,0 +1,20 @@ +// Different modules are important for this test because otherwise everything is analyzed at once and some errors +// already exist in the binding context when we're analyzing "User::surname". +// (The assertion at DoubleColonExpressionResolver.checkNoExpressionOnLHS is only performed when there are no errors in the binding context) + +// MODULE: m1 +// FILE: bar.kt + +fun bar(ff: Err.() -> Unit) { +} + +// MODULE: m2(m1) +// FILE: foo.kt + +data class User(val surname: String) + +fun foo() { + bar { + User::surname + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/emptyLhs.fir.kt b/compiler/testData/diagnostics/tests/callableReference/emptyLhs.fir.kt new file mode 100644 index 00000000000..cf009c8a4fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/emptyLhs.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION, -EXTENSION_SHADOWED_BY_MEMBER +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + +val topLevelVal = 1 +fun topLevelFun() = 2 + +val A.extensionVal: Int get() = 3 +fun A.extensionFun(): Int = 4 + +class A { + val memberVal = 5 + fun memberFun() = 6 + + val ok1 = ::topLevelVal + val ok2 = ::topLevelFun + + fun fail1() { + ::extensionVal + ::extensionFun + } + + fun fail2() { + ::memberVal + ::memberFun + } +} + + + +val ok1 = ::topLevelVal +val ok2 = ::topLevelFun + +fun A.fail1() { + ::extensionVal + ::extensionFun +} + +fun A.fail2() { + ::memberVal + ::memberFun +} diff --git a/compiler/testData/diagnostics/tests/callableReference/expectedTypeAsSubtypeOfFunctionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/expectedTypeAsSubtypeOfFunctionType.fir.kt new file mode 100644 index 00000000000..affb0318308 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/expectedTypeAsSubtypeOfFunctionType.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +abstract class SubFunction : kotlin.Function0 + +fun takeIt(x: T, f: SubFunction) {} + +fun cr() {} + +fun test() { + takeIt(42, ::cr) + takeIt(42, { }) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/abstractClassConstructors.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/abstractClassConstructors.fir.kt new file mode 100644 index 00000000000..82e9593dd3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/abstractClassConstructors.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +interface A +abstract class B +annotation class C +enum class D + +fun main() { + ::A + ::B + ::C // KT-3465 + ::D +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.fir.kt new file mode 100644 index 00000000000..ccddcecf6a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE +fun foo(x: Int, y: Any) = x +fun foo(x: Any, y: Int) = y + +fun main() { + ::foo + + val fooRef: (Int, Any) -> Unit = ::foo +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/annotationClassConstructor.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/annotationClassConstructor.fir.kt new file mode 100644 index 00000000000..1fac9d054b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/annotationClassConstructor.fir.kt @@ -0,0 +1,5 @@ +annotation class Ann(val prop: String) + +val annCtorRef = ::Ann +val annClassRef = Ann::class +val annPropRef = Ann::prop diff --git a/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.fir.kt new file mode 100644 index 00000000000..76c0a667973 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.fir.kt @@ -0,0 +1,9 @@ +open class A { + fun foo() = 42 + + object B: A() +} + +fun test() { + (A::foo)(A.B) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/classMemberVsConstructorLikeFunction.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/classMemberVsConstructorLikeFunction.fir.kt new file mode 100644 index 00000000000..5b1cccdd062 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/classMemberVsConstructorLikeFunction.fir.kt @@ -0,0 +1,16 @@ +// FILE: Foo.kt + +package test + +class Foo { + fun bar() {} +} + +// FILE: test.kt + +import test.Foo + +fun Foo(): String = "" + +val f = Foo::bar +val g = Foo::length diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromClass.fir.kt new file mode 100644 index 00000000000..fef4ee7ca36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromClass.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +class A { + fun main() { + val x = ::A + + checkSubtype>(x) + } +} + +class SomeOtherClass { + fun main() { + val x = ::A + + checkSubtype>(x) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.fir.kt new file mode 100644 index 00000000000..fef220c5282 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.fir.kt @@ -0,0 +1,22 @@ +// FILE: A.kt + +open class A(val x: T) + +// FILE: AFactory.kt + +abstract class AFactory { + abstract fun create(): A? +} + +// FILE: Util.kt + +inline fun createWith(x: T, f: (T) -> A?) + = f(x) + +// FILE: B.kt + +class B(x: Int) : A(x) { + companion object : AFactory() { + override fun create(): A? = createWith(0, ::B) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtension.fir.kt new file mode 100644 index 00000000000..07c789acecf --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtension.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +class A +class B + +fun A.ext() { + val x = ::A + val y = ::B + + checkSubtype>(x) + checkSubtype>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtensionInClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtensionInClass.fir.kt new file mode 100644 index 00000000000..56af7cecad4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromExtensionInClass.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +class A + +class B { + fun A.ext() { + val x = ::A + val y = ::B + + checkSubtype>(x) + checkSubtype>(y) + } + + fun B.ext() { + val x = ::A + val y = ::B + + checkSubtype>(x) + checkSubtype>(y) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromTopLevel.fir.kt new file mode 100644 index 00000000000..4417c6fdef1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorFromTopLevel.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +class A + +fun main() { + val x = ::A + + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/constructorOfNestedClassInObject.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/constructorOfNestedClassInObject.fir.kt new file mode 100644 index 00000000000..4c218d67696 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/constructorOfNestedClassInObject.fir.kt @@ -0,0 +1,21 @@ +// KT-15951 Callable reference to class constructor from object is not resolved + +object A { + class Wrapper +} + +class Outer { + companion object { + class Wrapper + } +} + +fun test() { + A::Wrapper + (A)::Wrapper + + Outer.Companion::Wrapper + (Outer.Companion)::Wrapper + Outer::Wrapper + (Outer)::Wrapper +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.fir.kt new file mode 100644 index 00000000000..f25fc6ddbc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// FILE: a.kt + +package first + +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +// FILE: b.kt + +package other + +import kotlin.reflect.* + +import first.A + +fun main() { + val x = first.A::foo + val y = first.A::bar + val z = A::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.fir.kt new file mode 100644 index 00000000000..7668bc02168 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// FILE: a.kt + +package first + +class A + +fun A.foo() {} +fun A.bar() {} +fun A.baz() {} + +// FILE: b.kt + +package other + +import kotlin.reflect.KFunction1 + +import first.A +import first.foo + +fun main() { + val x = first.A::foo + first.A::bar + A::baz + + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageTopLevel.fir.kt new file mode 100644 index 00000000000..0f7f02af9f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageTopLevel.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// FILE: a.kt + +package first + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +// FILE: b.kt + +package other + +import kotlin.reflect.* + +import first.foo +import first.bar +import first.baz + +fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/empty.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/empty.fir.kt new file mode 100644 index 00000000000..243660cb419 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/empty.fir.kt @@ -0,0 +1,6 @@ +class A + +fun main() { + val x = :: ; + val y = A:: +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.fir.kt new file mode 100644 index 00000000000..2ecb137ed46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A + +fun A.foo() {} +fun A.bar(x: Int) {} +fun A.baz() = "OK" + +fun main() { + val x = A::foo + val y = A::bar + val z = A::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt new file mode 100644 index 00000000000..8ece6d0a2f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION +class A { + fun Int.extInt() = 42 + fun A.extA(x: String) = x + + fun main() { + Int::extInt + A::extA + + eat(Int::extInt) + eat(A::extA) + } +} + +fun eat(value: Any) {} + +fun main() { + A::extInt + A::extA +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.fir.kt new file mode 100644 index 00000000000..5434e7241ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS:-UNUSED_VARIABLE + +import kotlin.reflect.* + +class A { + fun foo() {} +} + +fun A?.foo() {} + +val f: KFunction1 = A::foo +val g: KFunction1 = A?::foo diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionToSupertype.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionToSupertype.fir.kt new file mode 100644 index 00000000000..719a03b5e61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionToSupertype.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +interface A +interface B : A + +fun A.foo() {} + +fun take(f: (A) -> Unit) {} +fun take(f: () -> Unit) {} + +fun test() { + B::foo checkType { _>() } + + take(B::foo) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/fakeOverrideType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/fakeOverrideType.fir.kt new file mode 100644 index 00000000000..821dffbb84b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/fakeOverrideType.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction2 + +open class A { + fun foo(s: String): String = s +} + +class B : A() { +} + + +fun test() { + B::foo checkType { _>() } + + (B::hashCode)("No.") +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.fir.kt new file mode 100644 index 00000000000..3ebdabd9df1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction1 + +class A(val t: T) { + fun foo(): T = t +} + +fun bar() { + val x = A::foo + + checkSubtype, String>>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt new file mode 100644 index 00000000000..d41aab8ba36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +import A.Inner + +class A { + inner class Inner +} + +fun main() { + ::Inner +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt new file mode 100644 index 00000000000..5141391eb96 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt @@ -0,0 +1,34 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + +import kotlin.reflect.KFunction1 + +class A { + inner class Inner + + fun main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) + } + + companion object { + fun main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) + } + } +} + +class B { + fun main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.fir.kt new file mode 100644 index 00000000000..e7fb089d9b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + +import kotlin.reflect.KFunction1 + +class A { + inner class Inner +} + +fun A.main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) +} + +fun Int.main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.fir.kt new file mode 100644 index 00000000000..fa27fdca024 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +import kotlin.reflect.KFunction1 + +class A { + inner class Inner +} + +fun main() { + ::Inner + val y = A::Inner + + checkSubtype>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/javaStaticMethod.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/javaStaticMethod.fir.kt new file mode 100644 index 00000000000..405cf28f0f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/javaStaticMethod.fir.kt @@ -0,0 +1,24 @@ +// !CHECK_TYPE +// FILE: test/A.java + +package test; + +import java.util.Arrays; + +public class A { + public static void main(String[] args) { + System.out.println(Arrays.asList(args)); + } +} + +// FILE: 1.kt + +import kotlin.reflect.* +import test.A + +fun foo(args: Array) { + val main2 = A::main + checkSubtype, Unit>>(main2) + main2(args) + (A::main)(args) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt new file mode 100644 index 00000000000..f4f652c3b83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt @@ -0,0 +1,9 @@ +class A { + fun foo() = T::toString + + fun bar() = U::toString +} + +fun foo() = T::toString + +fun bar() = U::toString diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localConstructor.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localConstructor.fir.kt new file mode 100644 index 00000000000..d42785c511b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localConstructor.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +fun main() { + class A + + val x = ::A + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromExtensionInLocalClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromExtensionInLocalClass.fir.kt new file mode 100644 index 00000000000..28dcb81eeaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromExtensionInLocalClass.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +fun main() { + class A + + class B { + fun Int.foo() { + val x = ::A + checkSubtype>(x) + } + fun A.foo() { + val x = ::A + checkSubtype>(x) + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalClass.fir.kt new file mode 100644 index 00000000000..0bcab8a24d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalClass.fir.kt @@ -0,0 +1,10 @@ +import kotlin.reflect.KFunction0 + +fun main() { + class A + + class B { + val x = ::A + val f: KFunction0 = x + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalExtension.fir.kt new file mode 100644 index 00000000000..9fd725f079d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localConstructorFromLocalExtension.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +fun main() { + class A + + fun A.foo() { + val x = ::A + checkSubtype>(x) + } + + fun Int.foo() { + val x = ::A + checkSubtype>(x) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localNamedFun.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFun.fir.kt new file mode 100644 index 00000000000..c528b387fb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFun.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromExtensionInLocalClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromExtensionInLocalClass.fir.kt new file mode 100644 index 00000000000..066194937bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromExtensionInLocalClass.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + class B { + fun A.ext() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalClass.fir.kt new file mode 100644 index 00000000000..87aa5961b1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalClass.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + class A { + val x = ::foo + val y = ::bar + val z = ::baz + + fun main() { + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + } + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalExtension.fir.kt new file mode 100644 index 00000000000..d4621ce0203 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/localNamedFunFromLocalExtension.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A + +fun main() { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" + + fun A.ext() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.fir.kt new file mode 100644 index 00000000000..143296f288d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +// FILE: a.kt + +package a.b.c + +class D { + fun foo() = 42 +} + +// FILE: b.kt + +import kotlin.reflect.KFunction1 + +fun main() { + val x = a.b.c.D::foo + + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.fir.kt new file mode 100644 index 00000000000..df53d4d2ccb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +// FILE: a.kt + +package a.b.c + +class D { + fun foo(e: E, f: F) = this +} + +// FILE: b.kt + +import kotlin.reflect.KFunction3 + +fun main() { + val x = a.b.c.D::foo + + checkSubtype, String, Int, a.b.c.D>>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.fir.kt new file mode 100644 index 00000000000..fdbe223f494 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A { + fun foo() {} + fun bar(x: Int) {} + fun baz() = "OK" +} + +fun main() { + val x = A::foo + val y = A::bar + val z = A::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromClass.fir.kt new file mode 100644 index 00000000000..bdeaa0b46d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromClass.fir.kt @@ -0,0 +1,33 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +import kotlin.reflect.KFunction0 + +class A { + class Nested + + fun main() { + val x = ::Nested + val y = A::Nested + + checkSubtype>(x) + checkSubtype>(y) + } + + companion object { + fun main() { + ::Nested + val y = A::Nested + + checkSubtype>(y) + } + } +} + +class B { + fun main() { + ::Nested + val y = A::Nested + + checkSubtype>(y) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromExtension.fir.kt new file mode 100644 index 00000000000..195f5c0051b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromExtension.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +import kotlin.reflect.KFunction0 + +class A { + class Nested +} + +fun A.main() { + ::Nested + val y = A::Nested + + checkSubtype>(y) +} + +fun Int.main() { + ::Nested + val y = A::Nested + + checkSubtype>(y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromTopLevel.fir.kt new file mode 100644 index 00000000000..42ce7b8d21c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/nestedConstructorFromTopLevel.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction0 + +class A { + class Nested +} + +fun main() { + val x = A::Nested + + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityLocalVsTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityLocalVsTopLevel.fir.kt new file mode 100644 index 00000000000..77ed0bde41f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityLocalVsTopLevel.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +fun bar() = 42 + +fun main() { + fun bar() = 239 + + ::bar +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.fir.kt new file mode 100644 index 00000000000..f8cbe71c6b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +import kotlin.reflect.KFunction1 + +class A { + fun foo() = 42 +} + +fun A.foo() {} + +fun main() { + val x = A::foo + + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.fir.kt new file mode 100644 index 00000000000..64caf41012d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.fir.kt @@ -0,0 +1,31 @@ +// !CHECK_TYPE +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + +import kotlin.reflect.KFunction0 + +fun expectFunction0Unit(f: () -> Unit) = f +fun expectFunction0String(f: () -> String) = f +fun expectFunction1Unit(f: (A) -> Unit) = f +fun expectFunction1String(f: (A) -> String) = f + +fun foo(): String = "" + +class A { + fun foo() {} + + fun main() { + val x = ::foo + + checkSubtype>(x) + + expectFunction0Unit(x) + expectFunction0String(x) + expectFunction1Unit(x) + expectFunction1String(x) + + expectFunction0Unit(::foo) + expectFunction0String(::foo) + expectFunction1Unit(::foo) + expectFunction1String(::foo) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/privateStaticAndPublicMember.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/privateStaticAndPublicMember.fir.kt new file mode 100644 index 00000000000..4a1fcff935d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/privateStaticAndPublicMember.fir.kt @@ -0,0 +1,10 @@ +// SKIP_TXT +// FILE: A.java +class A { + private static void foo() {} + public String foo(int x) {} +} +// FILE: main.kt +fun main() { + (A::foo)(A(), 1) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.fir.kt new file mode 100644 index 00000000000..24d48d3fff5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.fir.kt @@ -0,0 +1,30 @@ +// !CHECK_TYPE +// FILE: a.kt + +package other + +fun foo() {} + +class A { + fun bar() = 42 +} + +fun A.baz(x: String) {} + +// FILE: b.kt + +import kotlin.reflect.* + +import other.foo as foofoo +import other.A as AA +import other.baz as bazbaz + +fun main() { + val x = ::foofoo + val y = AA::bar + val z = AA::bazbaz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromClass.fir.kt new file mode 100644 index 00000000000..957ac5d9a57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromClass.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +class A { + fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtension.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtension.fir.kt new file mode 100644 index 00000000000..6152a3cc17c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtension.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtensionInClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtensionInClass.fir.kt new file mode 100644 index 00000000000..726176d3407 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromExtensionInClass.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +class B { + fun A.main() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromTopLevel.fir.kt new file mode 100644 index 00000000000..b5a8194bacc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/topLevelFromTopLevel.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +fun foo() {} +fun bar(x: Int) {} +fun baz() = "OK" + +fun main() { + val x = ::foo + val y = ::bar + val z = ::baz + + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/unresolved.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/unresolved.fir.kt new file mode 100644 index 00000000000..d6e8601e7b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/function/unresolved.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +class A + +fun test1() { + val foo = ::foo + + ::bar + + A::bar + + B::bar +} + +fun test2() { + fun foo(x: Any) {} + fun foo() {} + + Unresolved::foo + foo(Unresolved::foo) + foo(Unresolved::unresolved) + ::unresolved +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt new file mode 100644 index 00000000000..ed924b0da86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE + +fun foo(a: String, b: Int = 5): String { + return a + b +} + +fun bar1(body: (String) -> String): String { + return body("something") +} + +fun bar2(body: (String, Int) -> String): String { + return body("something", 0) +} + +fun test() { + bar1(::foo) + bar2(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.fir.kt b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.fir.kt new file mode 100644 index 00000000000..f104ac67c15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType_enabled.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType + +fun foo(a: String, b: Int = 5): String { + return a + b +} + +fun bar1(body: (String) -> String): String { + return body("something") +} + +fun bar2(body: (String, Int) -> String): String { + return body("something", 0) +} + +fun test() { + bar1(::foo) + bar2(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt new file mode 100644 index 00000000000..c43049f5469 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun foo(x: T): R = TODO() + +fun fooReturnInt(x: T): Int = 1 +fun fooTakeString(x: String): T = TODO() + +fun bar(x: T, y: R, f: (T) -> R): Pair = TODO() +fun baz(f: (T) -> R, g: (T) -> R): Pair = TODO() + +class Pair(val a: A, val b: B) + +fun test1() { + bar("", 1, ::foo).checkType { _>() } + bar("", 1, ::fooReturnInt).checkType { _>() } + bar("", 1, ::fooTakeString).checkType { _>() } + bar("", "", ::fooReturnInt).checkType { _>() } + + val x: String = bar("", "", ::fooReturnInt) + + baz(Int::toString, ::foo).checkType { _>() } +} + +fun listOf(): List = TODO() +fun setOf(): Set = TODO() + +fun test2(x: T) { + bar(x, x, ::foo).checkType { _>() } + bar(x, 1, ::foo).checkType { _>() } + bar(1, x, ::foo).checkType { _>() } + + bar(listOf(), setOf(), ::foo).checkType { _, Set>> () } + bar(listOf(), 1, ::foo).checkType { _, Int>>() } + bar(1, listOf(), ::foo).checkType { _>>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.fir.kt new file mode 100644 index 00000000000..895abad9df6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Case +fun test(case: Case) {} +fun runTest(method: (Case) -> Unit) {} + +fun runTestGeneric(f: (Case) -> Unit) {} + +fun test() { + runTest(::test) + runTestGeneric(::test) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.fir.kt new file mode 100644 index 00000000000..44924ce85d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +SamConversionPerArgument +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void invokeLater(Runnable doRun) { + } +} + +// FILE: 1.kt + +fun foo(t: T, x: (() -> Unit) -> Unit) {} + +fun bar(s: T) {} +fun complex(t: T, f: (T) -> Unit) {} + +fun test1() { + foo(1, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE + foo(1, ::bar) + + complex(1, ::bar) +} + +fun test2(x: R) { + foo(x, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE + foo(x, ::bar) + + complex(x, ::bar) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/expectedFunctionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/expectedFunctionType.fir.kt new file mode 100644 index 00000000000..f4b473683e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/expectedFunctionType.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A1 { + fun a1(t: T): Unit {} + fun test1(): (String) -> Unit = A1()::a1 +} + +class A2 { + fun a2(key: K): V = TODO() + + fun test1(): (String) -> Unit = A2()::a2 + fun test2(): (T3) -> T3 = A2()::a2 +} + +class A3 { + fun a3(key: T): V = TODO() + + fun test1(): (T) -> Int = this::a3 + fun test2(): (T) -> Unit = A3()::a3 + fun test3(): (Int) -> String = A3()::a3 + + fun test4(): (R) -> Unit = this::a3 + fun test5(): (T) -> R = this::a3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt new file mode 100644 index 00000000000..2806859ae53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun takeFun(f: (T) -> Unit) {} +fun callFun(f: (T) -> R): R = TODO() + +fun foo(s: T) {} +fun fooInt(s: T) {} + +open class Wrapper(val value: T) +fun > createWrapper(s: T): R = TODO() + +fun Wrapper.baz(transform: (T) -> Unit): T = TODO() + +fun test() { + takeFun(::foo) + takeFun(::fooInt) + + callFun>(::createWrapper) + callFun>(::createWrapper) + callFun>(::createWrapper) + callFun>(::createWrapper) + + callFun>(::createWrapper).baz(::foo) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/genericExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/genericExtensionFunction.fir.kt new file mode 100644 index 00000000000..b2d645d4c59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/genericExtensionFunction.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +class Wrapper + +fun Wrapper.foo(x: R): S = TODO() +fun Wrapper.fooIntString(x: Int): String = "" +fun Wrapper.fooReturnString(x: T): String = "" +fun Wrapper.fooTakeInt(x: Int): T = TODO() + +fun bar(f: T.(R) -> S): Tripple = TODO() +fun baz(x: T, y: R, z: S, f: T.(R) -> S): Tripple = TODO() + +class Tripple(val a: A, val b: B, val c: C) + +fun test1() { + val x: Wrapper.(String) -> Boolean = Wrapper::foo + bar(Wrapper::foo).checkType { _>() } + bar(Wrapper::fooIntString).checkType { _>() } +} + +fun test2() { + bar(Wrapper::fooReturnString).checkType { _>() } + bar(Wrapper::fooReturnString).checkType { _>() } + bar(Wrapper::fooReturnString) + bar(Wrapper::fooReturnString) + + bar(Wrapper::fooTakeInt).checkType { _>() } + bar(Wrapper::fooTakeInt).checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt new file mode 100644 index 00000000000..33c47530fce --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun foo(x: T): R = TODO() +fun bar(x: T, y: R, f: (T) -> R): Pair = TODO() + +inline fun baz(x: T, y: R, f: (T) -> R) {} + +data class Pair(val a: A, val b: B) + +fun test(x: T) { + bar(1, "", ::foo).checkType { _>() } + bar(null, "", ::foo).checkType { _>() } + bar(1, null, ::foo).checkType { _>() } + bar(null, null, ::foo).checkType { _>() } + bar(1, x, ::foo).checkType { _>() } + + val s1: Pair = bar(1, "", ::foo) + val (a: Int, b: String?) = bar(1, "", ::foo) + + val s2: Pair = bar(null, null, ::foo) + + baz(null, null, ::foo) + + baz(null, null, ::foo) + baz(null, null, ::foo) + baz(null, "", ::foo) + baz(1, null, ::foo) + baz(null, null, ::foo) + + val s3: Pair = bar(null, null, ::foo) + val s4: Pair = bar(null, null, ::foo) + + val s5: Pair = bar(1, "", ::foo) + val (a1: Int, b1: String) = bar(1, "", ::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt10968.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt10968.fir.kt new file mode 100644 index 00000000000..fa82df7a68f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt10968.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// KT-10968 Callable reference: type inference by function return type + +fun getT(): T = null!! + +fun getString() = "" + +fun test() { + val a : () -> String = ::getString + val b : () -> String = ::getT +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt11075.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt11075.fir.kt new file mode 100644 index 00000000000..eca63b0f1d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt11075.fir.kt @@ -0,0 +1,10 @@ +// KT-11075 NONE_APPLICABLE reported for callable reference to an overloaded generic function with expected type provided + +object TestCallableReferences { + fun foo(x: A) = x + fun foo(x: List) = x + + fun test0(): (String) -> String = TestCallableReferences::foo + + fun test1(): (List) -> List = TestCallableReferences::foo +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt12286.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt12286.fir.kt new file mode 100644 index 00000000000..2286bb05bcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt12286.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// KT-12286 Strange type is required for generic callable reference + +fun > maxOf(a: T, b: T): T = if (a < b) b else a + +fun > useMaxOf() { + val f: (T, T) -> T = ::maxOf +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt7470.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt7470.fir.kt new file mode 100644 index 00000000000..8a20367ae65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt7470.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + + +fun shuffle(x: List): List = x + +fun bar() { + val s: (List) -> List = ::shuffle +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/nestedCallWithOverload.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/nestedCallWithOverload.fir.kt new file mode 100644 index 00000000000..20c94cb3ae6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/nestedCallWithOverload.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun foo(i: Int) {} +fun foo(s: String) {} +fun id(x: T): T = x +fun baz(x: T, y: T): T = TODO() + +fun test() { + val x1: (Int) -> Unit = id(id(::foo)) + val x2: (Int) -> Unit = baz(id(::foo), ::foo) + val x3: (Int) -> Unit = baz(id(::foo), id(id(::foo))) + val x4: (String) -> Unit = baz(id(::foo), id(id(::foo))) + val x5: (Double) -> Unit = baz(id(::foo), id(id(::foo))) + + + id<(Int) -> Unit>(id(id(::foo))) + id(id<(Int) -> Unit>(::foo)) + baz<(Int) -> Unit>(id(::foo), id(id(::foo))) + baz(id(::foo), id(id<(Int) -> Unit>(::foo))) + baz(id(::foo), id<(Int) -> Unit>(id(::foo))) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/noInferenceFeatureForCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/noInferenceFeatureForCallableReferences.fir.kt new file mode 100644 index 00000000000..76f8bdfc56b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/noInferenceFeatureForCallableReferences.fir.kt @@ -0,0 +1,67 @@ +// !LANGUAGE: -TypeInferenceOnGenericsForCallableReferences +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun bar(s: T) {} +fun complex(t: T, f: (T) -> Unit) {} +fun simple(f: (T) -> Unit) {} + +fun test1() { + complex(1, ::bar) + simple(::bar) +} + +// --- + +fun takeFun(f: (T) -> Unit) {} +fun callFun(f: (T) -> R): R = TODO() + +fun foo(s: T) {} + +open class Wrapper(val value: T) +fun > createWrapper(s: T): R = TODO() + +fun Wrapper.baz(transform: (T) -> Unit): T = TODO() + +fun test2() { + takeFun(::foo) + + callFun>(::createWrapper) + callFun>(::createWrapper) + callFun>(::createWrapper) + + callFun>(::createWrapper).baz(::foo) +} + +// --- + +fun test3() { + val a1: Array Double> = arrayOf(Double::plus, Double::minus) + val a2: Array Double> = arrayOf(Double::plus, Double::minus) +} + +// --- + +class A1 { + fun a1(t: T): Unit {} + fun test1(): (String) -> Unit = A1()::a1 +} + +class A2 { + fun a2(key: K): V = TODO() + + fun test1(): (String) -> Unit = A2()::a2 + fun test2(): (T3) -> T3 = A2()::a2 +} + +// --- + +fun foo1(x: Int?) {} +fun foo1(y: String?) {} +fun foo1(z: Boolean) {} + +fun baz1(element: (T) -> Unit): T? = null + +fun test4() { + val a1: Int? = baz1(::foo1) + val a2: String? = baz1(::foo1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/resolutionGenericCallableWithNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/resolutionGenericCallableWithNullableTypes.fir.kt new file mode 100644 index 00000000000..1d1c41ecace --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/resolutionGenericCallableWithNullableTypes.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun foo(x: Int?) {} +fun foo(y: String?) {} +fun foo(z: Boolean) {} + +fun baz(element: (T) -> Unit): T? = null + +fun test1() { + val a1: Int? = baz(::foo) + val a2: String? = baz(::foo) + val a3: Boolean? = baz(::foo) + + baz(::foo).checkType { _() } + baz(::foo).checkType { _() } + baz(::foo).checkType { _() } + + val b1: Int = baz(::foo) + val b2: String = baz(::foo) + val b3: Boolean = baz(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/resolutionWithGenericCallable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/resolutionWithGenericCallable.fir.kt new file mode 100644 index 00000000000..f5d5de415b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/resolutionWithGenericCallable.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun test() { + val a1: Array Double> = arrayOf(Double::plus, Double::minus) + val a2: Array Double> = arrayOf(Double::plus, Double::minus) + + val a3: Array Double> = arrayOf(Double::plus, Double::minus) + val a4: Array Double> = arrayOf(Int::plus, Double::minus) + val a5: Array Double> = arrayOf(Double::plus, Int::minus) +} + +fun foo(x: Int) {} +fun foo(y: String) {} + +fun bar(x: T, f: (T) -> Unit) {} + +fun test2() { + bar(1, ::foo) + bar("", ::foo) + bar(1.0, ::foo) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt new file mode 100644 index 00000000000..1d2645d1bfc --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun baz(i: Int) = i +fun bar(x: T): T = TODO() + +fun nullableFun(): ((Int) -> Int)? = null + +fun test() { + val x1: (Int) -> Int = bar(if (true) ::baz else ::baz) + val x2: (Int) -> Int = bar(nullableFun() ?: ::baz) + val x3: (Int) -> Int = bar(::baz ?: ::baz) + + val i = 0 + val x4: (Int) -> Int = bar(when (i) { + 10 -> ::baz + 20 -> ::baz + else -> ::baz + }) + + val x5: (Int) -> Int = bar(::baz!!) + + (if (true) ::baz else ::baz)(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt new file mode 100644 index 00000000000..d684aa7cc51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_VARIABLE + +fun test() { + data class Pair(val first: F, val second: S) + val (x, y) = + Pair(1, + if (1 == 1) + Pair::first + else + Pair::second) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/kt25433.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt25433.fir.kt new file mode 100644 index 00000000000..b9a172d117d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt25433.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// Issue: KT-25433 + +import kotlin.reflect.* + +fun hidden(nameProp: KProperty1, value: R) {} +fun hiddenFun(nameFunc: KFunction1, value: R) {} + +class App(val nullable: String?) { + fun nullableFun(): String? = null +} + +fun test() { + hidden(App::nullable, "foo") + hiddenFun(App::nullableFun, "foo") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/kt31981.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt31981.fir.kt new file mode 100644 index 00000000000..7c4da22aba5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt31981.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 +import kotlin.reflect.KMutableProperty1 + +class Inv { + val size: Int = 0 +} + +class DTO { + val test: Inv? = null + var q: Int = 0 + operator fun get(prop: KProperty1<*, R>): R = TODO() + operator fun set(prop: KMutableProperty1<*, R>, value: R) { } +} + +fun main(intDTO: DTO?) { + if (intDTO != null) { + intDTO[DTO::q] = intDTO[DTO::test]!!.size + intDTO[DTO::q] = intDTO[DTO::test]!!.size + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt32256.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt32256.fir.kt new file mode 100644 index 00000000000..09de610906f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt32256.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// Issue: KT-32256 + +fun main() { + myMethod(::refA) + myMethod(::refB) + anotherMethod(::refA) + anotherMethod(::refB) +} + +suspend fun refA(input: String): String { + return input +} + +suspend fun refB(): String { + return "Hello, World!" +} + +fun myMethod(f: suspend (String) -> String) {} + +fun myMethod(f: suspend () -> String) {} + +fun anotherMethod(f: suspend (I) -> O) {} + +fun anotherMethod(f: suspend () -> O) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.fir.kt new file mode 100644 index 00000000000..bcf23b25647 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +class Unrelated() + +class Test(val name: String = "") { + init { + Unrelated::name + Unrelated::foo + } + + fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/callableReference/memberExtensionsImportedFromObjectsUnsupported.fir.kt b/compiler/testData/diagnostics/tests/callableReference/memberExtensionsImportedFromObjectsUnsupported.fir.kt new file mode 100644 index 00000000000..acee4e1fb1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/memberExtensionsImportedFromObjectsUnsupported.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +import Obj.ext +import A.Companion.ext2 + +object Obj { + val String.ext: String get() = this +} + +class A { + companion object { + val String.ext2: String get() = this + } +} + +fun test() { + String::ext + Obj::ext + + String::ext2 + A.Companion::ext2 + A::ext2 + + A::foo + A::bar +} diff --git a/compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.fir.kt new file mode 100644 index 00000000000..02ada4d5b93 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +NewInference + +class DTO { + val q: Int = 0 + operator fun get(prop: KProperty1<*, Int>): Int = 0 +} + +fun foo(intDTO: DTO?, p: KProperty1<*, Int>) { + if (intDTO != null) { + intDTO[DTO::q] + intDTO.q + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/packageInLhs.fir.kt b/compiler/testData/diagnostics/tests/callableReference/packageInLhs.fir.kt new file mode 100644 index 00000000000..9a280b8ae57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/packageInLhs.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// FILE: simpleName.kt + +package foo + +fun test() { + foo::test +} + +// FILE: qualifiedName.kt + +package foo.bar + +fun test() { + foo.bar::test +} diff --git a/compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.fir.kt b/compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.fir.kt new file mode 100644 index 00000000000..9525642a22c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.fir.kt @@ -0,0 +1,9 @@ +package test + +class Foo { + fun bar(x: Int) = x +} + +fun test() { + Foo::bar < Int > (2 + 2) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.fir.kt new file mode 100644 index 00000000000..4a0a3b0b4c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.fir.kt @@ -0,0 +1,36 @@ +// !CHECK_TYPE + +import kotlin.reflect.KProperty1 + +interface Base { + val x: Any +} + +class A : Base { + override val x: String = "" +} + +open class B : Base { + override val x: Number = 1.0 +} + +class C : B() { + override val x: Int = 42 +} + +fun test() { + val base = Base::x + checkSubtype>(base) + checkSubtype(base.get(A())) + checkSubtype(base.get(B())) + checkSubtype(base.get(C())) + + val a = A::x + checkSubtype>(a) + checkSubtype(a.get(A())) + checkSubtype(a.get(B())) + + val b = B::x + checkSubtype>(b) + checkSubtype(b.get(C())) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.fir.kt new file mode 100644 index 00000000000..ec5c86975b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +import kotlin.reflect.KProperty1 + +open class Base { + val foo: Int = 42 +} + +open class Derived : Base() + +fun test() { + val o = Base::foo + checkSubtype>(o) + checkSubtype(o.get(Derived())) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.fir.kt new file mode 100644 index 00000000000..8630be83473 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS:-UNUSED_VARIABLE + +import kotlin.reflect.* + +class A(var g: A) { + val f: Int = 0 + + fun test() { + val fRef: KProperty1 = A::f + val gRef: KMutableProperty1 = A::g + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.fir.kt new file mode 100644 index 00000000000..de71e04316b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +val String.countCharacters: Int + get() = length + +var Int.meaning: Long + get() = 42L + set(value) {} + +fun test() { + val f = String::countCharacters + + checkSubtype>(f) + checkSubtype>(f) + checkSubtype(f.get("abc")) + f.set("abc", 0) + + val g = Int::meaning + + checkSubtype>(g) + checkSubtype(g.get(0)) + g.set(1, 0L) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/extensionPropertyOnNullable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/extensionPropertyOnNullable.fir.kt new file mode 100644 index 00000000000..ac0014dd549 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/extensionPropertyOnNullable.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +val Any?.meaning: Int + get() = 42 + +fun test() { + val f = Any?::meaning + checkSubtype(f.get(null)) + checkSubtype(f.get("")) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/genericClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/genericClass.fir.kt new file mode 100644 index 00000000000..709df31402c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/genericClass.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +import kotlin.reflect.KProperty1 + +class A(val t: T) { + val foo: T = t +} + +fun bar() { + val x = A::foo + checkSubtype, String>>(x) + checkSubtype, Any?>>(x) + + val y = A<*>::foo + checkSubtype, Any?>>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt new file mode 100644 index 00000000000..a5f8a33c53a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS:-UNUSED_VARIABLE +// FILE: JavaClass.java + +public class JavaClass { + public final int publicFinal; + public long publicMutable; + + protected final double protectedFinal; + protected char protectedMutable; + + private final String privateFinal; + private Object privateMutable; +} + +// FILE: test.kt + +import kotlin.reflect.* + +fun test() { + val pubFinRef: KProperty1 = JavaClass::publicFinal + val pubMutRef: KMutableProperty1 = JavaClass::publicMutable + val protFinRef: KProperty1 = JavaClass::protectedFinal + val protMutRef: KMutableProperty1 = JavaClass::protectedMutable + val privFinRef: KProperty1 = JavaClass::privateFinal + val privMutRef: KMutableProperty1 = JavaClass::privateMutable +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt new file mode 100644 index 00000000000..48a363f78fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS:-UNUSED_VARIABLE +// FILE: JavaClass.java + +public class JavaClass { + public static final String publicFinal; + public static volatile Object publicMutable; + + protected static final double protectedFinal; + protected static char protectedMutable; + + private static final JavaClass privateFinal; + private static Throwable privateMutable; +} + +// FILE: test.kt + +import JavaClass.* + +import kotlin.reflect.* + +fun test() { + val pubFinRef: KProperty0 = ::publicFinal + val pubMutRef: KMutableProperty0 = ::publicMutable + val protFinRef: KProperty = ::protectedFinal + val protMutRef: KMutableProperty = ::protectedMutable + val privFinRef: KProperty = ::privateFinal + val privMutRef: KMutableProperty = ::privateMutable +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/kt7564.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/kt7564.fir.kt new file mode 100644 index 00000000000..0be4a663de9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/kt7564.fir.kt @@ -0,0 +1,12 @@ +import kotlin.reflect.* + +fun checkSubtype(t: T) = t + +class A(var g: A) { + val f: Int = 0 + + fun test() { + checkSubtype>(A::f) + checkSubtype>(A::g) + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.fir.kt new file mode 100644 index 00000000000..719be10b741 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 + +class TestClass(var prop: Int) +open class OtherClass +fun OtherClass.test(prop: KProperty1): Unit = throw Exception() +class OtherClass2: OtherClass() { + val result = test(TestClass::result) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt new file mode 100644 index 00000000000..c170c78a97a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun eat(value: Any) {} + +fun test(param: String) { + val a = ::param + + val local = "local" + val b = ::local + + val lambda = { -> } + val g = ::lambda + + eat(::param) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.fir.kt new file mode 100644 index 00000000000..09e82f8d23d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +class A { + val foo: Int = 42 + var bar: String = "" +} + +fun test() { + val p = A::foo + + checkSubtype>(p) + checkSubtype>(p) + checkSubtype(p.get(A())) + p.get() + p.set(A(), 239) + + val q = A::bar + + checkSubtype>(q) + checkSubtype>(q) + checkSubtype(q.get(A())) + q.set(A(), "q") +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/protectedVarFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/protectedVarFromClass.fir.kt new file mode 100644 index 00000000000..b63c2baea8f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/protectedVarFromClass.fir.kt @@ -0,0 +1,22 @@ +// KT-12982 Incorrect type inference when accessing mutable protected property via reflection + +import kotlin.reflect.KMutableProperty1 + +class Foo { + protected var x = 0 + + fun baz(p: KMutableProperty1) = p + fun print() = baz(Foo::x) +} + + +open class A { + protected fun a() {} +} + +open class B : A() { + val x = C::a + val y = C()::a +} + +class C : B() diff --git a/compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.fir.kt new file mode 100644 index 00000000000..4cae96f7f07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.fir.kt @@ -0,0 +1,8 @@ +import kotlin.reflect.KProperty1 + +fun getProperty(x: T, property: KProperty1): R = + property.get(x) + +class Person(val name: String) + +val name1 = getProperty(Person("John Smith"), Person::name) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.fir.kt new file mode 100644 index 00000000000..218a2795117 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +import kotlin.reflect.KProperty1 + +class C { + val baz: Int = 12 +} + +fun Int.baz() {} + +fun test() { + C::baz checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.fir.kt new file mode 100644 index 00000000000..1fd83f1c2a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.fir.kt @@ -0,0 +1,19 @@ +// FILE: Customer.java +public class Customer { + private String name; + + public Customer(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + +// FILE: test.kt +val customerName = Customer::name diff --git a/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.fir.kt new file mode 100644 index 00000000000..cff6bfaaf0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.fir.kt @@ -0,0 +1,32 @@ +// !CHECK_TYPE + +import kotlin.reflect.* + +var x: Int = 42 +val y: String get() = "y" + +fun testX() { + val xx = ::x + checkSubtype>(xx) + checkSubtype>(xx) + checkSubtype>(xx) + checkSubtype>(xx) + checkSubtype>(xx) + + checkSubtype(xx.name) + checkSubtype(xx.get()) + xx.set(239) +} + +fun testY() { + val yy = ::y + checkSubtype>(yy) + checkSubtype>(yy) + checkSubtype>(yy) + checkSubtype>(yy) + checkSubtype>(yy) + + checkSubtype(yy.name) + checkSubtype(yy.get()) + yy.set("yy") +} diff --git a/compiler/testData/diagnostics/tests/callableReference/propertyOfNestedGenericClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/propertyOfNestedGenericClass.fir.kt new file mode 100644 index 00000000000..7d7c8a4353d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/propertyOfNestedGenericClass.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNUSED_VARIABLE + +import kotlin.reflect.KProperty1 + +class Scope { + abstract class Nested { + abstract val key: Int + abstract val keyT: T + } +} + +fun simple(a: Any?) {} +fun id(x: K): K = x + +fun test() { + simple(Scope.Nested::key) + val a = id(Scope.Nested::keyT) + + a + + val b = id(Scope.Nested<*>::keyT) + + b + + val c = id(Scope.Nested::keyT) + + c + + val d = id(Scope.Nested<*>::keyT as Scope.Nested) + + d + + val g = id, Any?>>(Scope.Nested<*>::keyT) + + g +} + +fun justResolve() { + val a = Scope.Nested::key + val b = Scope.Nested::keyT + val c = Scope.Nested<*>::keyT + val d = Scope.Nested::keyT +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.fir.kt new file mode 100644 index 00000000000..42cc26544a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: Int) {} +fun foo(y: String) {} + +fun bar(f: (T) -> Unit) {} + +fun test() { + bar(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.fir.kt new file mode 100644 index 00000000000..ba5ac78cc8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun fun1() {} +fun fun1(x: Int) {} + +val ref1 = ::fun1 + +fun fun2(vararg x: Int) {} +fun fun2(x: Int) {} + +val ref2 = ::fun2 + +fun fun3(x0: Int, vararg xs: Int) {} +fun fun3(x0: String, vararg xs: String) {} + +val ref3 = ::fun3 diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/applicableCallableReferenceFromDistantScope.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/applicableCallableReferenceFromDistantScope.fir.kt new file mode 100644 index 00000000000..55fa377705e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/applicableCallableReferenceFromDistantScope.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun foo(s: String) {} + +object Scope { + fun foo(a: Int) {} + fun foo(b: Boolean) {} + + fun bar(f: (T) -> Unit): T = TODO() + + fun test() { + val s: String = bar(::foo) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.fir.kt new file mode 100644 index 00000000000..bcae8c1979b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() {} +fun foo(s: String) {} + +fun fn(f: () -> Unit) {} + +fun test() { + fn(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.fir.kt new file mode 100644 index 00000000000..94b5a42062c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun ofType(x: T): T = x + +fun foo() {} +fun foo(s: String) {} + +val x1 = ofType<() -> Unit>(::foo) +val x2 = ofType<(String) -> Unit>(::foo) +val x3 = ofType<(Int) -> Unit>(::foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/byValType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/byValType.fir.kt new file mode 100644 index 00000000000..1ce622c783a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/byValType.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() {} +fun foo(s: String) {} + +val x1 = ::foo +val x2: () -> Unit = ::foo +val x3: (String) -> Unit = ::foo +val x4: (Int) -> Unit = ::foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt new file mode 100644 index 00000000000..04df73cbe96 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION + +class A { + fun foo(i: A) {} + + fun baz(i: A) {} +} + +class B { + fun foo(s: B) {} + fun foo(c: Char) {} + + fun baz(s: B) {} +} + +fun bar(f: (T) -> Unit): T = TODO() + +fun test() { + myWith(A()) { + val t1 = bar(::foo) + t1 + + val t2 = bar(::baz) + t2 + + myWith(B()) { + val a: A = bar(::foo) + val b: B = bar(::foo) + + val t3 = bar(::baz) + t3 + + bar(::foo) + } + } +} + +inline fun myWith(receiver: T, block: T.() -> R): R = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseMostSpecificCandidateUsingCandidateDescriptorNotReflectionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseMostSpecificCandidateUsingCandidateDescriptorNotReflectionType.fir.kt new file mode 100644 index 00000000000..0af36281c6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseMostSpecificCandidateUsingCandidateDescriptorNotReflectionType.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test() { + foo(String::extensionReceiver) + foo(::valueParameter) +} + +fun CharSequence.extensionReceiver(): CharSequence = TODO() +fun String.extensionReceiver(): String = TODO() + +fun valueParameter(c: CharSequence): CharSequence = TODO() +fun valueParameter(s: String): CharSequence = TODO() + +fun foo(f: (String) -> R) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseOuterCallBySingleCallableReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseOuterCallBySingleCallableReference.fir.kt new file mode 100644 index 00000000000..c0c15118202 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseOuterCallBySingleCallableReference.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 + +class Inv + +fun foo(prop: KProperty1, p: String = "") {} + +fun foo(prop: KProperty1>, p: Int = 42) {} + +class A { + val prop = 42 +} + +fun test() { + foo(A::prop) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/commonSupertypeFromReturnTypesOfCallableReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/commonSupertypeFromReturnTypesOfCallableReference.fir.kt new file mode 100644 index 00000000000..2f5cc8259c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/commonSupertypeFromReturnTypesOfCallableReference.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +interface Parent +interface Child1 : Parent +interface Child2 : Parent + +fun foo(): Child1 = TODO() +fun bar(): Child2 = TODO() + +fun select(x: K, y: K): K = TODO() + +fun test() { + val a = select(::foo, ::bar) + a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/constructor.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/constructor.fir.kt new file mode 100644 index 00000000000..6cde9ce2b55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/constructor.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Klass { + constructor(a: Int) {} + constructor(a: String) {} +} + +fun user(f: (Int) -> Klass) {} + +fun fn() { + user(::Klass) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.fir.kt new file mode 100644 index 00000000000..56770d43dd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.fir.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION + +interface A +interface B + +fun multiple(a: A) {} +fun multiple(b: B) {} + +fun singleA(a: A) {} +fun singleB(a: B) {} + +fun foo(f: (T) -> Unit, g: (T) -> Unit): T = TODO() + +fun test() { + val a1 = foo(::singleA, ::multiple) + a1 + + val a2 = foo(::singleB, ::multiple) + a2 + + val a3 = foo(::multiple, ::singleA) + a3 + + val a4 = foo(::multiple, ::singleB) + a4 + + val a5 = foo(::singleA, ::singleA) + a5 + + val a6 = foo(::singleA, ::singleB) + a6 + + foo(::multiple, ::multiple) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/eagerResolveOfSingleCallableReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerResolveOfSingleCallableReference.fir.kt new file mode 100644 index 00000000000..653866f6135 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerResolveOfSingleCallableReference.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A +class B : A() + +class Or(left: A, right: A) : A() + +class Out + +fun test(ls: Out) { + ls.reduce(::Or) +} + +fun Out.reduce(operation: (S, T) -> S): S = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/innerClassConstructorOnOuterClassInstance.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/innerClassConstructorOnOuterClassInstance.fir.kt new file mode 100644 index 00000000000..abf0ac624ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/innerClassConstructorOnOuterClassInstance.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +abstract class A { + inner class InnerInA +} + +abstract class B : A() + +fun foo(a: A) { + if (a is B) { + val v = a::InnerInA + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.fir.kt new file mode 100644 index 00000000000..92fbfedf7be --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KCallable + +class Foo { + fun installRoute(handler: T) where T : (String) -> Any?, T : KCallable<*> { + } + + fun installRoute(handler: T) where T : () -> Any?, T : KCallable<*> { + } + + fun foo() { + installRoute(::route) + } + +} + +fun route(s: String): Any? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.fir.kt new file mode 100644 index 00000000000..da79d5657c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// KT-10036 Ambiguous overload cannot be resolved when using a member function reference in Beta 2, that worked in Beta 1 + +class OverloadTest { + fun foo(bar: Boolean) {} + fun foo(bar: Any?) {} +} + +object Literal + +inline fun OverloadTest.overload(value: T?, function: OverloadTest.(T) -> Unit) { + if (value == null) foo(Literal) else function(value) +} + +// Overload resolution ambiguity +fun OverloadTest.overloadBoolean(value: Boolean?) = overload(value, OverloadTest::foo) + +// Works fine +fun OverloadTest.overloadBoolean2(value: Boolean?) = overload(value) { foo(it) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036_bound.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036_bound.fir.kt new file mode 100644 index 00000000000..128893c5704 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt10036_bound.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class OverloadTest { + fun foo(bar: Boolean) {} + fun foo(bar: Any?) {} +} + +inline fun OverloadTest.overload(value: T?, function: (T) -> Unit) { +} + +fun OverloadTest.overloadBoolean(value: Boolean?) = overload(value, OverloadTest()::foo) diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt12338.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt12338.fir.kt new file mode 100644 index 00000000000..4f5d6bf441a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt12338.fir.kt @@ -0,0 +1,9 @@ +// KT-12338 Compiler error ERROR: Rewrite at slice LEXICAL_SCOPE key: REFERENCE_EXPRESSION with when and function references + +fun a() { } + +fun test() { + when { + true -> ::a + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt12751.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt12751.fir.kt new file mode 100644 index 00000000000..47b939fef44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt12751.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// KT-12751 Type inference failed with forEach and bound reference + +class L + +fun L.foo(action: (T) -> Unit): Unit {} + +class B { + fun remove(charSequence: CharSequence) {} +} + +fun foo(list: L, b: B) { + list.foo(b::remove) + list.foo(b::remove) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt new file mode 100644 index 00000000000..fed7c090b75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// KT-8596 Rewrite at slice LEXICAL_SCOPE for nested class constructor reference in an argument position + +class K { + class Nested +} + +fun foo(f: Any) {} + +fun test1() { + foo(K::Nested) +} + +// KT-10567 Error: Rewrite at slice LEXICAL_SCOPE key: REFERENCE_EXPRESSION + +class Foo(val a: String, val b: String) + +fun test2() { + val prop : Foo.() -> String = if (true) { + Foo::a + } else { + Foo::b + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt9601.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt9601.fir.kt new file mode 100644 index 00000000000..377c0bad1e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt9601.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +open class A +class B: A() + +fun A.foo() {} +fun B.foo() {} // more specific + +fun bar(a: Any) {} +fun bar(a: Int) {} // more specific + +fun test() { + B::foo + ::bar +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificAmbiguousExtensions.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificAmbiguousExtensions.fir.kt new file mode 100644 index 00000000000..37ad6523f03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificAmbiguousExtensions.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +interface IA +interface IB : IA + +fun IA.extFun(x: IB) {} +fun IB.extFun(x: IA) {} + +fun test() { + val extFun1 = IA::extFun + val extFun2 = IB::extFun +} + +fun testWithExpectedType() { + val extFun_AB_A: IA.(IB) -> Unit = IA::extFun + val extFun_AA_B: IA.(IA) -> Unit = IB::extFun + val extFun_BB_A: IB.(IB) -> Unit = IA::extFun + val extFun_BA_B: IB.(IA) -> Unit = IB::extFun + val extFun_BB_B: IB.(IB) -> Unit = IB::extFun +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificSimple.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificSimple.fir.kt new file mode 100644 index 00000000000..432f4e57d12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/moreSpecificSimple.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +interface IA +interface IB : IA + +fun IA.extFun() {} +fun IB.extFun() {} + +fun test() { + val extFun = IB::extFun + checkSubtype Unit>(extFun) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/multipleOutersAndMultipleCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/multipleOutersAndMultipleCallableReferences.fir.kt new file mode 100644 index 00000000000..4ee3798be78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/multipleOutersAndMultipleCallableReferences.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Base +class Inv : Base + +fun foo(x: Int): Inv = TODO() +fun foo(y: String): Inv = TODO() + +fun bar(f: (T) -> Inv, p: String = "") {} + +fun bar(f: (T) -> Inv, p: Int = 4) {} + +fun test() { + bar(::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/noAmbiguityBetweenTopLevelAndMemberProperty.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/noAmbiguityBetweenTopLevelAndMemberProperty.fir.kt new file mode 100644 index 00000000000..8a1a1d391b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/noAmbiguityBetweenTopLevelAndMemberProperty.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty0 +import kotlin.reflect.KProperty1 + +fun property(property: KProperty0): Int = 1 +fun property(property: KProperty1): String = "" + +val subject = "" + +class O { + val subject = "" +} + +val someProperty0 = property(::subject) +val someProperty1 = property(O::subject) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.fir.kt new file mode 100644 index 00000000000..b925d9861e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE +// KT-12322 Overload resolution ambiguity with constructor references when class has a companion object + +class Foo { + companion object +} + +fun test() { + val a = ::Foo + checkSubtype<() -> Foo>(a) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/overloads.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/overloads.fir.kt new file mode 100644 index 00000000000..4d70f87fc21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/overloads.fir.kt @@ -0,0 +1,30 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION +import kotlin.reflect.KFunction1 + +open class A { + open fun bar() {} + + fun bas() {} +} +class B: A() { + override fun bar() {} + + fun bas(i: Int) {} +} + +fun A.foo() {} +fun B.foo() {} + +fun fas() {} +fun fas(i: Int = 1) {} + +fun test() { + B::foo // todo KT-9601 Chose maximally specific function in callable reference + + B::bar checkType { _>() } + + B::bas + + ::fas +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsBound.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsBound.fir.kt new file mode 100644 index 00000000000..f2c83059d3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsBound.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// KT-12799 Bound callable references not resolved for overload + +class C { + fun xf1(){} + fun xf1(s: String){} +} + +fun foo(p: (String) -> Unit){} + +fun bar(c: C) { + foo(c::xf1) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsMember.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsMember.fir.kt new file mode 100644 index 00000000000..3bb136804eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/overloadsMember.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION +// KT-9601 Chose maximally specific function in callable reference + +open class A { + fun foo(a: Any) {} + fun fas(a: Int) {} +} +class B: A() { + fun foo(a: Int) {} + fun fas(a: Any) {} +} + +fun test() { + B::foo + B::fas +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/postponedResolveOfManyCallableReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/postponedResolveOfManyCallableReference.fir.kt new file mode 100644 index 00000000000..d63b58549f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/postponedResolveOfManyCallableReference.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +interface A +interface B + +fun foo(i: A) {} +fun foo(b: B) {} + +fun bar1(f: (T) -> Unit): T = TODO() +fun bar2(f: (T) -> Unit, e: T) {} + +fun test(a: A, b: B) { + val expectedType1: A = bar1(::foo) + val expectedType2: B = bar1(::foo) + + bar2(::foo, a) + bar2(::foo, b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/resolveCallableReferencesAfterAllSimpleArguments.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/resolveCallableReferencesAfterAllSimpleArguments.fir.kt new file mode 100644 index 00000000000..563f1fdc365 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/resolveCallableReferencesAfterAllSimpleArguments.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A +interface B + +fun fooB(b: B) {} + +fun bar(f: (T) -> Unit, e: T) {} +fun baz(e: T, f: (T) -> Unit) {} + +fun test(a: A, b: B) { + // Note that diagnostic is always on callable references as they are resolved after simple arguments + baz(a, ::fooB) + bar(::fooB, a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/resolveEqualsOperatorWithAnyExpectedType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/resolveEqualsOperatorWithAnyExpectedType.fir.kt new file mode 100644 index 00000000000..5a9c7237ffb --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/resolveEqualsOperatorWithAnyExpectedType.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +NewInference + +interface Base + +fun materialize(): K = TODO() + +fun Base.transform(): T = materialize() + +fun test(child: Base) { + child == child.transform() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.fir.kt new file mode 100644 index 00000000000..44b0d4c9074 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +class A { + val x = 1 + fun x() {} +} + +fun f1(): KProperty = A::x // ok, property +fun f2(): (A) -> Unit = A::x // ok, function \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withAs.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withAs.fir.kt new file mode 100644 index 00000000000..649671b5eb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withAs.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() {} +fun foo(s: String) {} + +fun bar(f: () -> Unit) = 1 +fun bar(f: (String) -> Unit) = 2 + +val x1 = ::foo as () -> Unit +val x2 = bar(::foo as (String) -> Unit) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.fir.kt new file mode 100644 index 00000000000..0b8f7d52ee7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER + +import kotlin.reflect.* + +fun ofType(x: T): T = x + +class A { + val foo: Int = 0 + fun foo() {} + + fun bar() {} + val bar: Int = 0 +} + +fun A.foo(): String = "A" + +val x0 = A::foo + +val x1 = ofType<(A) -> Unit>(A::foo) +val x2 = ofType>(A::foo) +val x3: KProperty1 = A::foo +val x4: (A) -> String = A::foo + +val y0 = A::bar +val y1 = ofType<(A) -> Unit>(A::bar) +val y2 = ofType>(A::bar) +val y3: KProperty1 = A::bar diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.fir.kt new file mode 100644 index 00000000000..97276eddf24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// NI_EXPECTED_FILE + +fun apply(x: T, f: (T) -> R): R = f(x) + +fun foo(i: Int) {} +fun foo(s: String) {} + +val x1 = apply(1, ::foo) +val x2 = apply("hello", ::foo) +val x3 = apply(true, ::foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.fir.kt new file mode 100644 index 00000000000..529469c7d36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER,-CONFLICTING_JVM_DECLARATIONS +// NI_EXPECTED_FILE + +fun foo(i: Int) = "$i" +fun foo(s: String) = s + +fun bar(s: String) = s + +fun qux(i: Int, j: Int, k: Int): Int = i + j + k +fun qux(a: String, b: String, c: String, d: String) {} + +fun fn1(x: Int, f1: (Int) -> String, f2: (String) -> String) = f2(f1(x)) + +fun fn2(f1: (Int) -> String, f2: (String) -> String ) = f2(f1(0)) +fun fn2(f1: (Int) -> Int, f2: (Int) -> String ) = f2(f1(0)) +fun fn2(f1: (String) -> String, f2: (String) -> String ) = f2(f1("")) + +fun fn3(i: Int, f: (Int, Int, Int) -> Int): Int = f(i, i, i) + +val x1 = fn1(1, ::foo, ::foo) +val x2 = fn1(1, ::foo, ::bar) + +val x3 = fn2(::bar, ::foo) +val x4 = fn2(::foo, ::bar) +val x5 = fn2(::foo, ::foo) + +val x6 = fn3(1, ::qux) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt new file mode 100644 index 00000000000..364e0e57ca7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(vararg ii: Int) {} +fun foo(vararg ss: String) {} +fun foo(i: Int) {} + +val fn1: (Int) -> Unit = ::foo +val fn2: (IntArray) -> Unit = ::foo +val fn3: (Int, Int) -> Unit = ::foo +val fn4: (Array) -> Unit = ::foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.fir.kt b/compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.fir.kt new file mode 100644 index 00000000000..8fe7a6dc817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 + +class Sample(val str: String) + +class Inv + +class Form { + operator fun get(field: KProperty1<*, F>): Inv = TODO() +} + +fun foo(i: Inv) {} + +fun test(f: Form) { + foo(f[Sample::str]) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/sam.fir.kt b/compiler/testData/diagnostics/tests/callableReference/sam.fir.kt new file mode 100644 index 00000000000..e733d9060f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/sam.fir.kt @@ -0,0 +1,31 @@ +// FILE: test/GenericSam.java + +package test; + +public interface GenericSam { + void invoke(T t); +} + +// FILE: test.kt + +import test.GenericSam + +fun f1() = Runnable::class +fun f2() = Runnable::run +fun f3() = java.lang.Runnable::class +fun f4() = java.lang.Runnable::run + +fun f5() = GenericSam::class +fun f6() = GenericSam<*>::invoke +fun f7() = test.GenericSam::class +fun f8() = test.GenericSam::invoke + +fun g1() = Runnable {}::class +fun g2() = Runnable {}::run +fun g3() = java.lang.Runnable {}::class +fun g4() = java.lang.Runnable {}::run + +fun g5() = GenericSam {}::class +fun g6() = GenericSam {}::invoke +fun g7() = test.GenericSam {}::class +fun g8() = test.GenericSam {}::invoke diff --git a/compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.fir.kt new file mode 100644 index 00000000000..e6d7d426df4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +interface Parent +class Child : Parent + +class ChildHolder(var child: Child) + +interface Inv + +class Form { + fun get0(field: KMutableProperty): Inv = TODO() + fun get1(field: KProperty): Inv = TODO() + fun get2(field: KCallable): Inv = TODO() + fun get3(field: KMutableProperty1<*, F>): Inv = TODO() +} + +fun radio(field: Inv) {} + +fun test(form: Form) { + radio(form.get0(ChildHolder::child)) + radio(form.get1(ChildHolder::child)) + radio(form.get2(ChildHolder::child)) + radio(form.get3(ChildHolder::child)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.fir.kt b/compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.fir.kt new file mode 100644 index 00000000000..fdde41c88ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-32452 + +interface A { + suspend fun foo(input: String): String +} + +open class B { + fun call(function: suspend T.(U) -> R): R = TODO() + + fun call(function: suspend T.(U) -> List): List = TODO() +} + +class MyService : A, B() { + override suspend fun foo(input: String) = call(A::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/typealiases.fir.kt b/compiler/testData/diagnostics/tests/callableReference/typealiases.fir.kt new file mode 100644 index 00000000000..3fed265a53f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/typealiases.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// Issue: KT-31199 + +typealias Global = String + +fun String.toUpperCase(): String = TODO() + +inline fun Iterable.myMap(transform: (T) -> R): List { + TODO() +} + +fun usesGlobal(p: List) { + p.myMap(Global::toUpperCase) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unused.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unused.fir.kt new file mode 100644 index 00000000000..b6327ef551f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unused.fir.kt @@ -0,0 +1,23 @@ +fun foo() { + +} + +class A { + fun foo() { + + } + + class B +} + +fun A.bar() { + +} + +fun test() { + ::foo + ::A + A::B + A::foo + A::bar +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/whitespacesInExpression.fir.kt b/compiler/testData/diagnostics/tests/callableReference/whitespacesInExpression.fir.kt new file mode 100644 index 00000000000..a2505399877 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/whitespacesInExpression.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +class Foo + +fun Foo?.bar() {} + +fun test() { + val r1 = Foo ?:: bar + checkSubtype<(Foo?) -> Unit>(r1) + + val r2 = Foo ? :: bar + checkSubtype<(Foo?) -> Unit>(r2) + + val r3 = Foo ? ? :: bar + checkSubtype<(Foo?) -> Unit>(r3) +} diff --git a/compiler/testData/diagnostics/tests/cast/AsArray.fir.kt b/compiler/testData/diagnostics/tests/cast/AsArray.fir.kt new file mode 100644 index 00000000000..4905c48dc29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsArray.fir.kt @@ -0,0 +1 @@ +fun f(x: Any) = x as Array \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedError.fir.kt b/compiler/testData/diagnostics/tests/cast/AsErasedError.fir.kt new file mode 100644 index 00000000000..b587d66e767 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsErasedError.fir.kt @@ -0,0 +1,2 @@ + +fun ff(c: MutableCollection) = c as MutableList diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedFine.fir.kt b/compiler/testData/diagnostics/tests/cast/AsErasedFine.fir.kt new file mode 100644 index 00000000000..ef761f25328 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsErasedFine.fir.kt @@ -0,0 +1,2 @@ + +fun ff(c: MutableCollection) = c as MutableList diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedStar.fir.kt b/compiler/testData/diagnostics/tests/cast/AsErasedStar.fir.kt new file mode 100644 index 00000000000..2ec2a30cb89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsErasedStar.fir.kt @@ -0,0 +1,3 @@ + +fun ff(l: Any) = l as MutableList<*> + diff --git a/compiler/testData/diagnostics/tests/cast/AsErasedWarning.fir.kt b/compiler/testData/diagnostics/tests/cast/AsErasedWarning.fir.kt new file mode 100644 index 00000000000..09fadc462c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsErasedWarning.fir.kt @@ -0,0 +1,2 @@ + +fun ff(a: Any) = a as MutableList diff --git a/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt b/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt new file mode 100644 index 00000000000..87afc9c3581 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Base + +class Impl1 : Base + +class Impl2 : Base + +operator fun Base.plus(arg: Base) = Impl1() + +operator fun Impl2.plus(arg: Base) = Impl2() + +operator fun Base.plus(arg: Impl2) = Impl2() + +operator fun Base.unaryMinus() = Impl1() + +operator fun Impl2.unaryMinus() = Impl2() + +// See also KT-10384: in non-error functions, as is necessary! +fun add1(x: Impl2, y: Base): Impl1 = x as Base + y + +fun error1(x: Impl2, y: Base): Impl1 = x + y + +fun add2(x: Base, y: Impl2): Impl1 = x + y as Base + +fun error2(x: Base, y: Impl2): Impl1 = x + y + +fun minus3(x: Impl2): Impl1 = -(x as Base) + +fun error3(x: Impl2): Impl1 = -x diff --git a/compiler/testData/diagnostics/tests/cast/AsInBlockWithReturnType.fir.kt b/compiler/testData/diagnostics/tests/cast/AsInBlockWithReturnType.fir.kt new file mode 100644 index 00000000000..e29d857d649 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsInBlockWithReturnType.fir.kt @@ -0,0 +1,53 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun runWithoutReturn(r: () -> Unit) = r() + +fun testRun() { + run { + 1 as Any + 1 as Any + } + + run { + 1 as Any + 1 as Any + } + + fun foo(): Int = 1 + + run { + foo() as Any + } + + run { + (if (true) 1 else 2) as Any + } + + run { + 1 as Int + 1 as Int + } + + runWithoutReturn { + 1 as Any + 1 as Any + } +} + +fun testReturn(): Number { + run { 1 as Number } + return run { 1 as Number } +} + +fun testDependent() { + listOf(1).map { + it as Any + it as Any + } + + listOf().map { it as Any? } +} + +fun listOf(vararg elements: T): List = TODO() +fun Iterable.map(transform: (T) -> R): List = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsInExpressionBody.fir.kt b/compiler/testData/diagnostics/tests/cast/AsInExpressionBody.fir.kt new file mode 100644 index 00000000000..fc2124f4cb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsInExpressionBody.fir.kt @@ -0,0 +1,12 @@ +fun id(x: T): T = x + +fun foo() = 1 as Any +fun bar() = id(1) as Any +fun baz() = (1 + 1) as Any + +val functionLiteral1 = fun() = 1 as Any +val functionLiteral2 = fun() = id(1) as Any +val functionLiteral3 = fun() = (1 + 1) as Any + +// TODO: this and more complex cases are not supported yet +fun baz(b: Boolean) = if (b) 1 as Any else 42 as Any? \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsInPropertyAndPropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/cast/AsInPropertyAndPropertyAccessor.fir.kt new file mode 100644 index 00000000000..27cdb37c820 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsInPropertyAndPropertyAccessor.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun test() { + val a = 1 as Any? + val b: Number = 1 as Number + val c = null as String? + val d: Number = 1 as Int +} + +val c1 get() = 1 as Number +val c2: Number get() = 1 as Number + +val d: Number + get() { + 1 as Number + return 1 as Number + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsNothing.fir.kt b/compiler/testData/diagnostics/tests/cast/AsNothing.fir.kt new file mode 100644 index 00000000000..230f58ce8de --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsNothing.fir.kt @@ -0,0 +1,14 @@ +// Nothing can be cast to Nothing +fun foo(x: String) { + x as Nothing +} + +fun gav(y: String?) { + y as Nothing +} + +// Only nullable can be cast to Nothing? +fun bar(x: String, y: String?) { + x as Nothing? + y as Nothing? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/AsTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/cast/AsTypeAlias.fir.kt new file mode 100644 index 00000000000..279219ba2ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsTypeAlias.fir.kt @@ -0,0 +1,18 @@ +typealias MyString = String + +val x: MyString = "" +val y = x as Any + +interface Base +class Derived : Base +interface Other : Base +typealias IBase = Base +typealias IOther = Other + +val ib: IBase = Derived() +val d = ib as Derived +val o = ib as Other +val io = ib as IOther +val s = d as String +val ms = d as MyString + diff --git a/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.fir.kt b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.fir.kt new file mode 100644 index 00000000000..2b412a0f643 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/AsWithOtherParameter.fir.kt @@ -0,0 +1,34 @@ +// See also: KT-6611 (cast can never succeed: Class -> Class) + +class Class(val name: String, val instance: T) + +fun test(clazz: Class) { + println((clazz as Class).name) +} + +fun use() { + test(Class("String", "")) +} + +fun checkArrays(): Array { + val someArray = arrayOfNulls(5) + someArray as Array + return someArray as Array +} + +class Wrapper(val x: T) + +fun checkArrays2(): Array> { + val someArray = arrayOf(Wrapper(1), Wrapper(2)) + return someArray as Array> +} + +fun checkArrays3() { + val someArray = arrayOfNulls(1) + someArray as Array + val intArray = arrayOfNulls(1) + intArray as Array +} + +fun println(s: String) = s + diff --git a/compiler/testData/diagnostics/tests/cast/DowncastMap.fir.kt b/compiler/testData/diagnostics/tests/cast/DowncastMap.fir.kt new file mode 100644 index 00000000000..e7b33828ab6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/DowncastMap.fir.kt @@ -0,0 +1,10 @@ +interface Map +interface MutableMap: Map { + operator fun set(k: K, v: V) +} + +fun p(p: Map) { + if (p is MutableMap) { + p[""] = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/ExtensionAsNonExtension.fir.kt b/compiler/testData/diagnostics/tests/cast/ExtensionAsNonExtension.fir.kt new file mode 100644 index 00000000000..b7dde7e3775 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/ExtensionAsNonExtension.fir.kt @@ -0,0 +1,10 @@ +fun f(a: (Int) -> Unit) { + a as Int.() -> Unit + + f1(a as Int.() -> Unit) +} + +fun f1(a: Int.() -> Unit) { + a as (Int) -> Unit + f(a as (Int) -> Unit) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/FlexibleTargetType.fir.kt b/compiler/testData/diagnostics/tests/cast/FlexibleTargetType.fir.kt new file mode 100644 index 00000000000..8041cb1ef69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/FlexibleTargetType.fir.kt @@ -0,0 +1,26 @@ +// FILE: Foo.java + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class Foo { + static Foo create() { return null; } + + @Nullable + static Foo createN() { return null; } + + @NotNull + static Foo createNN() { return null; } +} + +// FILE: sample.kt + +fun test() { + Foo.create() as Foo + Foo.createN() as Foo + Foo.createNN() as Foo + + Foo.create() as Foo? + Foo.createN() as Foo? + Foo.createNN() as Foo? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.fir.kt new file mode 100644 index 00000000000..5df28bb45fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.fir.kt @@ -0,0 +1,5 @@ +open class BaseTwo +open class DerivedWithOne: BaseTwo() + +// a is BaseTwo => if (a is DerivedWithOne) a is DerivedWithOne +fun testing(a: BaseTwo) = a is DerivedWithOne diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.fir.kt new file mode 100644 index 00000000000..51c6eab4642 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForExactSupertypeCheck.fir.kt @@ -0,0 +1,5 @@ +open class Base +class Some: Base() + +// a is Some => a is Base +fun f(a: Some) = a is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForOverridenVarianceWithProjection.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForOverridenVarianceWithProjection.fir.kt new file mode 100644 index 00000000000..09d7b2f6792 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForOverridenVarianceWithProjection.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() + +open class Base +open class SubBase : Base() + +// l is Base<+B> => if (l is SubBase) l is SubBase<+B> => l is SubBase<+A> +fun ff(l: Base) = l is SubBase diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.fir.kt new file mode 100644 index 00000000000..db875931272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithContrvariance.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() + +open class Base +class SubBase: Base() + +// f is SubBase => f is Base => (Base, B <: A) f is Base +fun test(f: SubBase) = f is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.fir.kt new file mode 100644 index 00000000000..a7ca5876259 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForSupertypeCheckWithCovariance.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() + +open class Base +class SubBase: Base() + +// f is SubBase => (SubBase <: Base) f is Base => (B <: A, Base => SubBase <: Base) f is Base +fun test(f: SubBase) = f is Base \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithIrrelevantMixin.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithIrrelevantMixin.fir.kt new file mode 100644 index 00000000000..f69dc7a1aaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithIrrelevantMixin.fir.kt @@ -0,0 +1,9 @@ +interface A +interface B: A +interface D + +interface BaseSuper +interface BaseImpl: BaseSuper +interface DerivedSuper: BaseSuper, BaseImpl + +fun test(t: BaseSuper) = t is DerivedSuper \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithTwoSameTypeSubstitutions.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithTwoSameTypeSubstitutions.fir.kt new file mode 100644 index 00000000000..41baa2a3676 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithTwoSameTypeSubstitutions.fir.kt @@ -0,0 +1,6 @@ +open class BaseMulti +class SomeMultiDerived: BaseMulti() + +// t is BaseMulti<+String, String> => if (t is SomeMultiDerived) => t is SomeMultiDerived<+String> => +// => (String <: Any, SomeMultiDerived) t is SomeMultiDerived<+Any> +fun someDerived(t: BaseMulti) = t is SomeMultiDerived diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithoutTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithoutTypeArguments.fir.kt new file mode 100644 index 00000000000..a481246aaad --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowForTypeWithoutTypeArguments.fir.kt @@ -0,0 +1,5 @@ +open class Base +class Some: Base() + +// No erased types in check +fun f(a: Base) = a is Some diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.fir.kt new file mode 100644 index 00000000000..29ac268ad0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.fir.kt @@ -0,0 +1 @@ +fun f(a: MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.fir.kt new file mode 100644 index 00000000000..6f7bc4f981a --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut2.fir.kt @@ -0,0 +1 @@ +fun f(a: MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.fir.kt new file mode 100644 index 00000000000..f1ba3800c08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.fir.kt @@ -0,0 +1 @@ +fun f(a: List) = a is List diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowParameterSubtype.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowParameterSubtype.fir.kt new file mode 100644 index 00000000000..995258b9f83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowParameterSubtype.fir.kt @@ -0,0 +1,7 @@ + +open class A + +class B : A() + +fun ff(l: MutableCollection) = l is MutableList + diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameClassParameter.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameClassParameter.fir.kt new file mode 100644 index 00000000000..d8986f1938f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameClassParameter.fir.kt @@ -0,0 +1,3 @@ + +fun ff(l: MutableCollection) = l is MutableList + diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameParameterParameter.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameParameterParameter.fir.kt new file mode 100644 index 00000000000..d835e23aed3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowSameParameterParameter.fir.kt @@ -0,0 +1,3 @@ + +fun ff(l: MutableCollection) = l is MutableList + diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowDifferentArgInvariantPosition.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowDifferentArgInvariantPosition.fir.kt new file mode 100644 index 00000000000..0a56fe22872 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowDifferentArgInvariantPosition.fir.kt @@ -0,0 +1 @@ +fun f(a: MutableList) = a is MutableList \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForOverridenVariance.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForOverridenVariance.fir.kt new file mode 100644 index 00000000000..7960af40eff --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForOverridenVariance.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() + +open class Base +open class SubBase : Base() + + +fun ff(l: Base) = l is SubBase diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForTypeWithConstraints.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForTypeWithConstraints.fir.kt new file mode 100644 index 00000000000..afba616ee44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowForTypeWithConstraints.fir.kt @@ -0,0 +1,6 @@ +interface A +interface B: A + +interface Base + +fun test(a: Base) where T: Base = a is T \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromAny.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromAny.fir.kt new file mode 100644 index 00000000000..5d98c89982a --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromAny.fir.kt @@ -0,0 +1,2 @@ + +fun ff(l: Any) = l is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromIn.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromIn.fir.kt new file mode 100644 index 00000000000..f1894cfe1b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromIn.fir.kt @@ -0,0 +1 @@ +fun f(a: MutableList) = a is MutableList \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOut.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOut.fir.kt new file mode 100644 index 00000000000..0e3c75f4889 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOut.fir.kt @@ -0,0 +1,2 @@ + +fun f(a : MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.fir.kt new file mode 100644 index 00000000000..47977766298 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.fir.kt @@ -0,0 +1 @@ +fun f(a: List) = a is List diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithFirstInvalid.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithFirstInvalid.fir.kt new file mode 100644 index 00000000000..631525fddac --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithFirstInvalid.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() +open class D + +open class Base +open class Derived: Base() + +fun test(a: Base) = a is Derived \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithSecondInvalid.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithSecondInvalid.fir.kt new file mode 100644 index 00000000000..959156243a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDissallowForSubtypeMappedToTwoParamsWithSecondInvalid.fir.kt @@ -0,0 +1,8 @@ +open class A +open class B: A() +open class D + +open class Base +open class Derived: Base() + +fun test(a: Base) = a is Derived \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedNonGeneric.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedNonGeneric.fir.kt new file mode 100644 index 00000000000..a27a5165198 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedNonGeneric.fir.kt @@ -0,0 +1,3 @@ +interface A +interface B +fun testing(a: A) = a as B diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedNullableTasT.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedNullableTasT.fir.kt new file mode 100644 index 00000000000..0a32f3a862f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedNullableTasT.fir.kt @@ -0,0 +1 @@ +fun testing(a: T?) = a is T diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedStar.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedStar.fir.kt new file mode 100644 index 00000000000..0143c3643ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedStar.fir.kt @@ -0,0 +1,2 @@ + +fun ff(l: Any) = l is MutableList<*> diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedTasT.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedTasT.fir.kt new file mode 100644 index 00000000000..ae1fa33c9f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedTasT.fir.kt @@ -0,0 +1 @@ +fun testing(a: T) = a is T diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedToErrorType.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedToErrorType.fir.kt new file mode 100644 index 00000000000..21dd6efa00e --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedToErrorType.fir.kt @@ -0,0 +1 @@ +fun testing(a: Any) = a is UnresolvedType diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.fir.kt b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.fir.kt new file mode 100644 index 00000000000..84d2d5ea5f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsErasedUpcastToNonReified.fir.kt @@ -0,0 +1,27 @@ +fun test(x: T?, y: S, z: T) { + x is T + x is T? + + y is T + y is S + y is T? + y is S? + + z is T + z is T? + + null as T + null as T? + null as S +} + +inline fun test(x: T?) { + x is T + null as T + null as T? +} + +fun foo(x: List, y: List?) { + x is List + y is List +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsForTypeWithComplexUpperBound.fir.kt b/compiler/testData/diagnostics/tests/cast/IsForTypeWithComplexUpperBound.fir.kt new file mode 100644 index 00000000000..604eb17f20d --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsForTypeWithComplexUpperBound.fir.kt @@ -0,0 +1,34 @@ +interface A +class B : A {} + +fun > test1(a: U) { + a is B +} + +fun , U : S> test2(a: U) { + a is B +} + +fun , V : A> test3(a: T, b: V) { + a is B + b is B +} + +fun > test4(a: T, b: V) { + a is B + b is B +} + +interface Out +class OutNothing : Out + +fun > test5(a: S) { + a is OutNothing +} + +interface In +class InNothing : In + +fun > test6(a: S) { + a is InNothing +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsRecursionSustainable.fir.kt b/compiler/testData/diagnostics/tests/cast/IsRecursionSustainable.fir.kt new file mode 100644 index 00000000000..3efa41504ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsRecursionSustainable.fir.kt @@ -0,0 +1,6 @@ +open class RecA: RecB() +open class RecB: RecA() +open class SelfR: SelfR() + +fun test(f: SelfR) = f is RecA +fun test(f: RecB) = f is RecA \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/IsTraits.fir.kt b/compiler/testData/diagnostics/tests/cast/IsTraits.fir.kt new file mode 100644 index 00000000000..defcbfb3bc9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsTraits.fir.kt @@ -0,0 +1,4 @@ +interface Aaa +interface Bbb + +fun f(a: Aaa) = a is Bbb diff --git a/compiler/testData/diagnostics/tests/cast/IsWithCycleUpperBounds.fir.kt b/compiler/testData/diagnostics/tests/cast/IsWithCycleUpperBounds.fir.kt new file mode 100644 index 00000000000..598a3e7c21e --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/IsWithCycleUpperBounds.fir.kt @@ -0,0 +1,14 @@ +// check that there is no SOE on checking for instance +interface Visitor +interface Acceptor + +class Word : Acceptor> + +class V : Visitor + +class S, U : Visitor>(val visitor: U, val acceptor: T) { + fun test() { + visitor is V + acceptor is Word + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt b/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt new file mode 100644 index 00000000000..cd76ae9a3c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/NullableToNullable.fir.kt @@ -0,0 +1,7 @@ +// From KT-13324: always succeeds +val x = null as String? +// From KT-260: sometimes succeeds +fun foo(a: String?): Int? { + val c = a as? Int? + return c +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/StableTypeForUselessCast.fir.kt b/compiler/testData/diagnostics/tests/cast/StableTypeForUselessCast.fir.kt new file mode 100644 index 00000000000..fcd72edcbe1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/StableTypeForUselessCast.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I1 +interface I2 + +fun foo(i: I1) {} +fun foo(i: I2) {} + +fun bar(i: I1) { + if (i is I2) { + foo(i as I1) + foo(i as I2) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt b/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt new file mode 100644 index 00000000000..f35df122d02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun test(x: Int?) { + val a1 = x as? Int + val a2 = x as? Int? + val a3 = x as? Number + val a4 = x as? Number? + val a5: Int? = x as? Int + val a6: Number? = x as? Int + val a7: Number? = 1 as? Number + + run { x as? Int } + run { x as? Number } + + foo(x as? Number) + + if (x is Int) { + val b = x as? Int + } +} + +fun foo(x: Number?) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/WhenErasedDisallowFromAny.fir.kt b/compiler/testData/diagnostics/tests/cast/WhenErasedDisallowFromAny.fir.kt new file mode 100644 index 00000000000..b073dff8735 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/WhenErasedDisallowFromAny.fir.kt @@ -0,0 +1,5 @@ + +fun ff(l: Any) = when(l) { + is MutableList -> 1 + else 2 +} diff --git a/compiler/testData/diagnostics/tests/cast/WhenWithExpression.fir.kt b/compiler/testData/diagnostics/tests/cast/WhenWithExpression.fir.kt new file mode 100644 index 00000000000..9a60e0bf91e --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/WhenWithExpression.fir.kt @@ -0,0 +1,11 @@ +class List(val size : Int) { + companion object { + val Nil = List(0) + } +} + +fun List.join() = + when (this) { + List.Nil -> "[]" // CANNOT_CHECK_FOR_ERASED was reported + else -> "" + } diff --git a/compiler/testData/diagnostics/tests/cast/bare/AsNestedBare.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/AsNestedBare.fir.kt new file mode 100644 index 00000000000..92b6a51fcb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/AsNestedBare.fir.kt @@ -0,0 +1,10 @@ +interface Tr +interface G + +fun test(tr: Tr): Any { + return tr as G +} + +fun test1(tr: Tr): Any { + return tr as G.(G) -> G +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/AsNullable.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/AsNullable.fir.kt new file mode 100644 index 00000000000..36520d5aab8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/AsNullable.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +interface Tr +interface G : Tr + +fun test(tr: Tr) { + val v = tr as G? + // If v is not nullable, there will be a warning on this line: + checkSubtype>(v!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/AsNullableNotEnough.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/AsNullableNotEnough.fir.kt new file mode 100644 index 00000000000..1b46e9c5cdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/AsNullableNotEnough.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +interface Tr +interface G + +fun test(tr: Tr) { + val v = tr as G? + // If v is not nullable, there will be a warning on this line: + checkSubtype>(v!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/EitherAs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/EitherAs.fir.kt new file mode 100644 index 00000000000..7dd8ca15808 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/EitherAs.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +interface Either +interface Left: Either +interface Right: Either + +class C1(val v1: Int) +class C2(val v2: Int) + +fun _as_left(e: Either): Any { + val v = e as Left + return checkSubtype>(v) +} + +fun _as_right(e: Either): Any { + val v = e as Right + return checkSubtype>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/EitherIs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/EitherIs.fir.kt new file mode 100644 index 00000000000..81c74588732 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/EitherIs.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +interface Either +interface Left: Either { + val value: A +} +interface Right: Either { + val value: B +} + +class C1(val v1: Int) +class C2(val v2: Int) + +fun _is_l(e: Either): Any { + if (e is Left) { + return e.value.v1 + } + return e +} + +fun _is_r(e: Either): Any { + if (e is Right) { + return e.value.v2 + } + return e +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/EitherNotIs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/EitherNotIs.fir.kt new file mode 100644 index 00000000000..b84a60cd28d --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/EitherNotIs.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +interface Either +interface Left: Either { + val value: A +} +interface Right: Either { + val value: B +} + +class C1(val v1: Int) +class C2(val v2: Int) + +fun _is_l(e: Either): Any { + if (e !is Left) { + return e + } + return e.value.v1 +} + +fun _is_r(e: Either): Any { + if (e !is Right) { + return e + } + return e.value.v2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/EitherSafeAs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/EitherSafeAs.fir.kt new file mode 100644 index 00000000000..a2873a79f36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/EitherSafeAs.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +interface Either +interface Left: Either +interface Right: Either + +class C1(val v1: Int) +class C2(val v2: Int) + +fun _as_left(e: Either): Any? { + val v = e as? Left + return checkSubtype?>(v) +} + +fun _as_right(e: Either): Any? { + val v = e as? Right + return checkSubtype?>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/EitherWhen.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/EitherWhen.fir.kt new file mode 100644 index 00000000000..09855f1dbb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/EitherWhen.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +interface Either +interface Left: Either { + val value: A +} +interface Right: Either { + val value: B +} + +class C1(val v1: Int) +class C2(val v2: Int) + +fun _when(e: Either): Any { + return when (e) { + is Left -> e.value.v1 + is Right -> e.value.v2 + else -> e + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt new file mode 100644 index 00000000000..08f161ac261 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +interface B +interface G: B + +fun f(p: B): Any { + val v = p as G + return checkSubtype>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt new file mode 100644 index 00000000000..671a9ba8318 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +class G + +fun foo(p: P) { + val v = p as G? + checkSubtype>(v!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/NullableAs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/NullableAs.fir.kt new file mode 100644 index 00000000000..b11accdcd5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/NullableAs.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +interface Tr +interface G : Tr + +fun test(tr: Tr?) { + val v = tr as G + checkSubtype>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/NullableAsNotEnough.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNotEnough.fir.kt new file mode 100644 index 00000000000..e1509febc32 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNotEnough.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +interface Tr +interface G + +fun test(tr: Tr?) { + val v = tr as G + checkSubtype>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullable.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullable.fir.kt new file mode 100644 index 00000000000..110de538ed4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullable.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +interface Tr +interface G : Tr + +fun test(tr: Tr?) { + val v = tr as G? + // If v is not nullable, there will be a warning on this line: + checkSubtype>(v!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullableNotEnough.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullableNotEnough.fir.kt new file mode 100644 index 00000000000..7fa8d3c395e --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/NullableAsNullableNotEnough.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +interface Tr +interface G + +fun test(tr: Tr?) { + val v = tr as G? + checkSubtype>(v!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/RedundantNullable.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/RedundantNullable.fir.kt new file mode 100644 index 00000000000..5fd96375718 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/RedundantNullable.fir.kt @@ -0,0 +1,4 @@ +interface B +class G: B + +fun f(b: B?) = b is G?? \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/ToErrorType.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/ToErrorType.fir.kt new file mode 100644 index 00000000000..9508e3d1fd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/ToErrorType.fir.kt @@ -0,0 +1,6 @@ +class P + +fun foo(p: P): Any { + val v = p as G + return v +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/UnrelatedAs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedAs.fir.kt new file mode 100644 index 00000000000..3c480012ddb --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedAs.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +interface Tr +interface G + +fun test(tr: Tr) { + val v = tr as G + checkSubtype>(v) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.fir.kt new file mode 100644 index 00000000000..b63ed2cd2b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE +// NI_EXPECTED_FILE + +interface Tr +interface G + +fun test(tr: Tr) = checkSubtype(tr) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/UnrelatedIs.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedIs.fir.kt new file mode 100644 index 00000000000..31a82acc515 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedIs.fir.kt @@ -0,0 +1,4 @@ +interface Tr +interface G + +fun test(tr: Tr) = tr is G \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.fir.kt b/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.fir.kt new file mode 100644 index 00000000000..1b4e9c59bc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/checkCastToNullableType.fir.kt @@ -0,0 +1,38 @@ +// FILE: JavaClass.java + +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; + +public class JavaClass { + static Integer foo() { + return 1; + } + + @Nullable + static Integer fooN() { + return 1; + } + + @NotNull + static Integer fooNN() { + return 1; + } +} + +// FILE: test.kt + +fun test(x1: T, x2: T?, y1: S, y2: S?) { + x1 is T? + x2 is T? + y1 is S? + y2 is S? + + val f1 = JavaClass.foo() + f1 is Int? + + val f2 = JavaClass.fooN() + f2 is Int? + + val f3 = JavaClass.fooNN() + f3 is Int? +} diff --git a/compiler/testData/diagnostics/tests/cast/constants.fir.kt b/compiler/testData/diagnostics/tests/cast/constants.fir.kt new file mode 100644 index 00000000000..26ebc7dc2bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/constants.fir.kt @@ -0,0 +1,51 @@ +fun asCall() { + 1 as Int + 1 as Byte + 1 as Short + 1 as Long + 1 as Char + 1 as Double + 1 as Float + + 1.0 as Int + 1.0 as Byte + 1.0 as Short + 1.0 as Long + 1.0 as Char + 1.0 as Double + 1.0 as Float + + 1f as Int + 1f as Byte + 1f as Short + 1f as Long + 1f as Char + 1f as Double + 1f as Float +} + +fun asSafe() { + 1 as? Int + 1 as? Byte + 1 as? Short + 1 as? Long + 1 as? Char + 1 as? Double + 1 as? Float + + 1.0 as? Int + 1.0 as? Byte + 1.0 as? Short + 1.0 as? Long + 1.0 as? Char + 1.0 as? Double + 1.0 as? Float + + 1f as? Int + 1f as? Byte + 1f as? Short + 1f as? Long + 1f as? Char + 1f as? Double + 1f as? Float +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/isErasedAnyAndStarred.fir.kt b/compiler/testData/diagnostics/tests/cast/isErasedAnyAndStarred.fir.kt new file mode 100644 index 00000000000..61818b7a817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/isErasedAnyAndStarred.fir.kt @@ -0,0 +1,3 @@ +class G + +fun f(q: Any) = q is G<*> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/isErasedTAndStarred.fir.kt b/compiler/testData/diagnostics/tests/cast/isErasedTAndStarred.fir.kt new file mode 100644 index 00000000000..437cb1b0ef8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/isErasedTAndStarred.fir.kt @@ -0,0 +1,3 @@ +class G + +fun f(q: Q) = q is G<*> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt new file mode 100644 index 00000000000..f53785c40c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt @@ -0,0 +1,4 @@ +class G +interface Tr + +fun f(q: Tr) = q is G<*> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/kt15161.fir.kt b/compiler/testData/diagnostics/tests/cast/kt15161.fir.kt new file mode 100644 index 00000000000..da274164691 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/kt15161.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +class Array(e: E) { + val k = Array(1) { + 1 as Any + e as Any? + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/kt614.fir.kt b/compiler/testData/diagnostics/tests/cast/kt614.fir.kt new file mode 100644 index 00000000000..ee32fdc69fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/kt614.fir.kt @@ -0,0 +1 @@ +fun f(a: Collection<*>) = a is List<*>? \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.fir.kt b/compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.fir.kt new file mode 100644 index 00000000000..15e4ca66f5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.fir.kt @@ -0,0 +1,8 @@ +open class A { + fun foo() {} +} +class B : A() + +fun test(b: B?) { + (b as A).foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedDirect.fir.kt b/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedDirect.fir.kt new file mode 100644 index 00000000000..fd1651e8fab --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedDirect.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS +import java.lang.String as JString +import java.lang.CharSequence as JCS + +fun test( + s: String, + js: JString, + cs: CharSequence, + jcs: JCS +) { + s as JString + s as JCS + s as CharSequence + s as String + + js as JString + js as JCS + js as CharSequence + js as String + + cs as JString + cs as JCS + cs as CharSequence + cs as String + + jcs as JString + jcs as JCS + jcs as CharSequence + jcs as String + + jcs as Int + s as java.lang.Integer +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedSubtypes.fir.kt b/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedSubtypes.fir.kt new file mode 100644 index 00000000000..98982311d56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/neverSucceeds/MappedSubtypes.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS -ABSTRACT_MEMBER_NOT_IMPLEMENTED +import java.lang.CharSequence as JCS + +class JSub: JCS +class Sub: CharSequence + +fun test( + s: Sub, + js: JSub, + cs: CharSequence, + jcs: JCS +) { + // js as CharSequence // - this case is not supported due to limitation in PlatformToKotlinClassMap + js as JCS + + s as CharSequence + s as JCS + + js as Sub + s as JSub +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsRelated.fir.kt b/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsRelated.fir.kt new file mode 100644 index 00000000000..597e86183b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsRelated.fir.kt @@ -0,0 +1,46 @@ +// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS +interface T1 +interface T2 +interface T3 +open class OC1: T1 +open class OC2: OC1(), T2 +class FC1: OC2(), T3 +interface T4: OC1 +interface T5: T2 + +fun test( + t2: T2, + t4: T4, + fc1: FC1, + oc1: OC1, + oc2: OC2, + tp1: TP1, + tp2: TP2 +) { + fc1 as FC1 + fc1 as OC1 + fc1 as T1 + fc1 as TP1 + + oc1 as FC1 + oc1 as OC2 + oc2 as OC1 + oc1 as T2 + oc1 as T1 + oc1 as TP1 + oc1 as TP2 + + t2 as FC1 + t2 as OC2 + t4 as OC1 + t2 as T2 + t2 as T5 + t2 as TP2 + + tp1 as FC1 + tp1 as OC1 + tp1 as OC2 + tp2 as T2 + tp2 as T5 + tp1 as TP3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsUnrelated.fir.kt b/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsUnrelated.fir.kt new file mode 100644 index 00000000000..1aef98f1325 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/neverSucceeds/NoGenericsUnrelated.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -WARNING +CAST_NEVER_SUCCEEDS +interface Trait1 +interface Trait2 +open class OClass1 +open class OClass2 +class FClass1 +class FClass2 + +fun test( + t1: Trait1, + oc1: OClass1, + fc1: FClass1, + tp1: TP1 +) { + t1 as Trait2 + t1 as OClass2 + t1 as FClass2 + t1 as TP2 + + oc1 as Trait2 + oc1 as OClass2 + oc1 as FClass2 + oc1 as TP2 + + fc1 as Trait2 + fc1 as OClass2 + fc1 as FClass2 + fc1 as TP2 + + tp1 as Trait2 + tp1 as OClass2 + tp1 as FClass2 + tp1 as TP2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/nothingAs.fir.kt b/compiler/testData/diagnostics/tests/cast/nothingAs.fir.kt new file mode 100644 index 00000000000..55e07cfd39f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/nothingAs.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNREACHABLE_CODE + +fun TODO(): Nothing = throw java.lang.IllegalStateException() + +open class OpenClass +class FinalClass : OpenClass() +abstract class AbstractClass +interface Interface + +fun test() { + TODO() as Any + TODO() as Any? + TODO() as OpenClass + TODO() as FinalClass + TODO() as AbstractClass + TODO() as Interface + + val a = TODO() as Any + val b = TODO() as Any? + val c = TODO() as OpenClass + val d = TODO() as FinalClass + val e = TODO() as AbstractClass + val f = TODO() as Interface +} + +fun a() = TODO() as Any +fun b() = TODO() as Any? +fun c() = TODO() as OpenClass +fun d() = TODO() as FinalClass +fun e() = TODO() as AbstractClass +fun f() = TODO() as Interface diff --git a/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.fir.kt new file mode 100644 index 00000000000..10d2c17af24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.fir.kt @@ -0,0 +1,96 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !LANGUAGE: +ProhibitAssigningSingleElementsToVarargsInNamedForm + +fun array1(vararg a : T) = a + +fun main() { + val a = array1("a", "b") + val b = array1(1, 1) + join(1) + join(1, "2") + join(1, "2", "3") + join(*1, "2") + join(1, *"2") + join(x = 1, a = "2") + join(x = *1, a = *"2") + join(x = 1, a = *a) + join(x = 1, a = *b) + join(1, *a) + join(1, *b) + join(1, *a, "3") + join(1, *b, "3") + join(1, "4", *a, "3") + join(1, "4", *b, "3") + join(1, "4", *a) + join(1, "4", *a, *a, "3") + join(1, "4", *a, *b, "3") + join(a = *a, x = 1) + join(a = *b, x = 1) + join(a = a, x = 1) + + joinG(1, "2") + joinG(*1, "2") + joinG(1, *"2") + joinG(x = 1, a = *a) + joinG(x = 1, a = "2") + joinG(x = *1, a = *"2") + joinG(1, *a) + joinG(1, *a, "3") + joinG(1, "4", *a, "3") + joinG(1, "4", *a) + joinG(1, "4", *a, *a, "3") + joinG(a = *a, x = 1) + + joinG(1, "2") + joinG(*1, "2") + joinG(1, *"2") + joinG(x = 1, a = *a) + joinG(x = 1, a = "2") + joinG(x = *1, a = *"2") + joinG(1, *a) + joinG(1, *a, "3") + joinG(1, "4", *a, "3") + joinG(1, "4", *a) + joinG(1, "4", *a, *a, "3") + joinG(a = *a, x = 1) + + val x1 = joinT(1, "2") + checkSubtype(x1) + val x2 = joinT(*1, "2") + checkSubtype(x2) + val x6 = joinT(1, *a) + checkSubtype(x6) + val x7 = joinT(1, *a, "3") + checkSubtype(x7) + val x8 = joinT(1, "4", *a, "3") + checkSubtype(x8) + val x9 = joinT(1, "4", *a) + checkSubtype(x9) + val x10 = joinT(1, "4", *a, *a, "3") + checkSubtype(x10) + val x11 = joinT(a = *a, x = 1) + checkSubtype(x11) + val x12 = joinT(x = 1, a = *a) + checkSubtype(x12) +} + +fun join(x : Int, vararg a : String) : String { + val b = StringBuilder(x.toString()) + for (s in a) { + b.append(s) + } + return b.toString() +} + +fun joinG(x : Int, vararg a : T) : String { + val b = StringBuilder(x.toString()) + for (s in a) { + b.append(s) + } + return b.toString() +} + +fun joinT(x : Int, vararg a : T) : T? { + return null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSet.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSet.fir.kt new file mode 100644 index 00000000000..44253d12008 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSet.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object A { + operator fun set(x: Int, y: String = "y", z: Double) { + } +} + +object B { + operator fun set(x: Int, y: String = "y", z: Double = 3.14, w: Char = 'w', v: Boolean) { + } +} + +object D { + operator fun set(x: Int, vararg y: String, z: Double) { + } +} + +object Z { + operator fun set() { + } +} + +fun test() { + A[0] = "" + A[0] = 2.72 + + B[0] = "" + B[0] = 2.72 + B[0] = true + + D[0] = "" + D[0] = 2.72 + + Z[0] = "" +} diff --git a/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSetTooManyArgs.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSetTooManyArgs.fir.kt new file mode 100644 index 00000000000..a3725af26f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/arrayAccessSetTooManyArgs.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + operator fun get(x: Int) {} + operator fun set(x: String, value: Int) {} + + fun d(x: Int) { + this["", 1] = 1 + } +} diff --git a/compiler/testData/diagnostics/tests/checkArguments/booleanExpressions.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/booleanExpressions.fir.kt new file mode 100644 index 00000000000..4d6dbaa913d --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/booleanExpressions.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +fun foo1(b: Boolean, c: Int) { + if (b && c) {} + if (b || c) {} + if (c && b) {} + if (c || b) {} +} diff --git a/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt new file mode 100644 index 00000000000..9634aece459 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +//KT-1897 When call cannot be resolved to any function, save information about types of arguments + +package a + +fun bar() {} + +fun foo(i: Int, s: String) {} + +fun test() { + + bar(xx) + + bar { } + + foo("", 1, xx) + + foo(r = xx, i = "", s = "") + + foo(i = 1, i = 1, s = 11) + + foo("", s = 2) + + foo(i = "", s = 2, 33) + + foo("", 1) {} + + foo("", 1) {} {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/kt1940.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/kt1940.fir.kt new file mode 100644 index 00000000000..fa19aede37b --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/kt1940.fir.kt @@ -0,0 +1,9 @@ +//KT-1940 Exception while repeating named parameters +package kt1940 + +fun foo(i: Int) {} + +fun test() { + foo(1, i = 2) //exception + foo(i = 1, i = 2) //exception +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.fir.kt new file mode 100644 index 00000000000..f3502cbdb5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/overloadedFunction.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun foo() {} +fun foo(s: Int) {} + + +fun bar(a: Any) {} +fun bar(a: Int) {} + +fun test() { + foo(1, 2) + foo("") + + bar(1, 2) + bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/twoLambdasFunction.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/twoLambdasFunction.fir.kt new file mode 100644 index 00000000000..5e5310f50e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkArguments/twoLambdasFunction.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +fun test(x: () -> Unit, y: () -> Unit) { + +} + +fun main() { + test { + 1 + } { + 2 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkType.fir.kt b/compiler/testData/diagnostics/tests/checkType.fir.kt new file mode 100644 index 00000000000..f1e5dad30ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/checkType.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +interface A +interface B : A +interface C : B + +fun test(b: B) { + b checkType { _() } + b checkType { _() } + b checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/arrays.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/arrays.fir.kt new file mode 100644 index 00000000000..aaba90a3711 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/arrays.fir.kt @@ -0,0 +1,7 @@ +val a01 = Array::class +val a02 = Array::class +val a03 = Array::class +val a04 = Array?>::class +val a05 = Array::class +val a06 = kotlin.Array::class +val a07 = kotlin.Array::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/classAndObjectLiteralType.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/classAndObjectLiteralType.fir.kt new file mode 100644 index 00000000000..5b84d1aa74f --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/classAndObjectLiteralType.fir.kt @@ -0,0 +1,16 @@ +import kotlin.reflect.KClass + +abstract class Base(val klass: KClass) + +class DerivedClass : Base(DerivedClass::class) + +object DerivedObject : Base(DerivedObject::class) + +enum class TestEnum { + TEST_ENTRY +} + +val test1: KClass = DerivedClass::class +val test2: KClass = DerivedObject::class +val test3: KClass = TestEnum::class +val test4: KClass = TestEnum.TEST_ENTRY::class \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classLiteral/classLiteralType.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/classLiteralType.fir.kt new file mode 100644 index 00000000000..c52949ae609 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/classLiteralType.fir.kt @@ -0,0 +1,15 @@ +import kotlin.reflect.KClass + +class A +class B + +val listOfString: List = null!! +val arrayOfString: Array = null!! + +val a1 : KClass<*> = A::class +val a2 : KClass = A::class +val a3 : KClass = A::class +val a4 : B = A::class + +val a5 : KClass> = listOfString::class +val a6 : KClass> = arrayOfString::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/expressionWithNullableType.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/expressionWithNullableType.fir.kt new file mode 100644 index 00000000000..03b9ca0cab7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/expressionWithNullableType.fir.kt @@ -0,0 +1,15 @@ +// FILE: J.java + +public interface J { + String platformString(); +} + +// FILE: test.kt + +fun f1(x: Int?): Any = x::class +fun f2(t: T): Any = t::class +fun f3(s: S): Any = s::class +fun f4(u: U?): Any = u::class +fun f5(c: List<*>): Any = c[0]::class + +fun f6(j: J): Any = j.platformString()::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/genericArrays.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/genericArrays.fir.kt new file mode 100644 index 00000000000..28e72987269 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/genericArrays.fir.kt @@ -0,0 +1,11 @@ +import kotlin.reflect.KClass + +fun f1(): KClass> = Array::class +fun f2(): KClass>> = Array>::class +inline fun f3() = Array::class +inline fun f4() = Array>::class +fun f5(): KClass> = Array<*>::class +fun f6(): KClass> = Array::class +fun f7() = Array>::class +fun f8() = Array?>::class +fun f9() = Array?>::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/genericClasses.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/genericClasses.fir.kt new file mode 100644 index 00000000000..816f61b5303 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/genericClasses.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class A { + class Nested + + inner class Inner +} + +val a1 = A::class +val a2 = A<*>::class +val a3 = A::class +val a4 = A::class + +val n1 = A.Nested::class +val n2 = A.Nested<*>::class + +val i1 = A.Inner::class +val i2 = A<*>.Inner<*>::class +val i3 = A.Inner::class + +val m1 = Map::class +val m2 = Map::class +val m3 = Map.Entry::class + +val b1 = Int::class +val b2 = Nothing::class \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments.fir.kt new file mode 100644 index 00000000000..46b50f7168d --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +ProhibitTypeParametersInClassLiteralsInAnnotationArguments + +import kotlin.reflect.KClass + +annotation class Ann(val k: KClass<*>) +annotation class AnnArray(val kk: Array>) + +object AnObject + +class C { + companion object +} + +fun foo() = "foo" + +@Ann("foo"::class) +fun test1() {} + +@Ann(String::class) +fun test2() {} + +@Ann(AnObject::class) +fun test4() {} + +@Ann(C::class) +fun test5() {} + +@Ann(C.Companion::class) +fun test6() {} + +@Ann(foo()::class) +fun test7() {} + +@AnnArray(arrayOf(""::class, String::class, AnObject::class)) +fun test8() {} + +inline val T.test9 + get() = @AnnArray(arrayOf( + T::class, + Array::class, + Array>>::class + )) object {} + +inline val T.test10 + get() = @AnnArray([T::class]) object {} diff --git a/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments_noTypeParams.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments_noTypeParams.fir.kt new file mode 100644 index 00000000000..cda2d9dad0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/inAnnotationArguments_noTypeParams.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: -ProhibitTypeParametersInClassLiteralsInAnnotationArguments + +import kotlin.reflect.KClass + +annotation class Ann(vararg val k: KClass<*>) + +inline val T.test + get() = @Ann( + T::class, + Array::class, + Array>>::class + ) object {} diff --git a/compiler/testData/diagnostics/tests/classLiteral/integerValueType.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/integerValueType.fir.kt new file mode 100644 index 00000000000..53b51edd83f --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/integerValueType.fir.kt @@ -0,0 +1,11 @@ +// KT-13110 Strange type mismatch error on class literal with integer receiver expression + +import kotlin.reflect.KClass + +fun f(x: KClass) {} + +fun test() { + f(42::class) + f((40 + 2)::class) + 42::toInt +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt new file mode 100644 index 00000000000..a67baf0f668 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class A + +val a1 = A?::class +val a2 = A??::class + +val l1 = List?::class +val l2 = List?::class + +fun foo() { + val t1 = T::class + val t2 = T?::class +} + +inline fun bar() { + val t3 = T?::class +} + +val m = Map::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/qualifiedClassLiteral.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/qualifiedClassLiteral.fir.kt new file mode 100644 index 00000000000..d44fdcba193 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/qualifiedClassLiteral.fir.kt @@ -0,0 +1,7 @@ +package test.foo.bar + +class A + +val k = test.foo.bar.A::class + +val l = java.lang.Class::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/simpleClassLiteral.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/simpleClassLiteral.fir.kt new file mode 100644 index 00000000000..ecfe5bc206b --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/simpleClassLiteral.fir.kt @@ -0,0 +1,3 @@ +class A + +val k = A::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/smartCast.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/smartCast.fir.kt new file mode 100644 index 00000000000..c398d443048 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/smartCast.fir.kt @@ -0,0 +1,23 @@ +// KT-16291 Smart cast doesn't work when getting class of instance + +import kotlin.reflect.KClass + +class Foo { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other === null || other::class != this::class) return false + + return true + } +} + +fun test(f: Foo?): KClass? = if (f != null) f::class else null + +fun test2(): KClass? { + var f: Foo? = null + if (f != null) { + run { f = null } + return f::class + } + return null +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/typealiases.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/typealiases.fir.kt new file mode 100644 index 00000000000..ebc38e073af --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/typealiases.fir.kt @@ -0,0 +1,15 @@ +typealias TString = String +fun f1() = TString::class + +typealias TNullableString = String? +fun f2() = TNullableString::class + +typealias TNullableTString = TString? +typealias TTNullableTString = TNullableTString +fun f3() = TTNullableTString::class + +inline fun f4(b: Boolean): Any { + typealias X = T + typealias Y = T? + return if (b) X::class else Y::class +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/unresolvedClass.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/unresolvedClass.fir.kt new file mode 100644 index 00000000000..61b9805ec34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/unresolvedClass.fir.kt @@ -0,0 +1,2 @@ +val u = Unresolved::class +val g = UnresolvedGeneric::class diff --git a/compiler/testData/diagnostics/tests/classObjects/ClassObjectCannotAccessClassFields.fir.kt b/compiler/testData/diagnostics/tests/classObjects/ClassObjectCannotAccessClassFields.fir.kt new file mode 100644 index 00000000000..a76c28aba66 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/ClassObjectCannotAccessClassFields.fir.kt @@ -0,0 +1,9 @@ +// http://youtrack.jetbrains.net/issue/KT-20 + +class A() { + val x = 1 + + companion object { + val y = x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt b/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt new file mode 100644 index 00000000000..7e4d7e0d267 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt @@ -0,0 +1,30 @@ +package foo + +fun test() { + A.d + A.Companion.f + B.D + CCC + CCC.classObjectVar +} + +class A() { + public companion object { + val d = 3 + private object f { + + } + } +} + +class B { + class D { + private companion object + } +} + +class CCC() { + private companion object { + val classObjectVar = 3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/ClassObjects.fir.kt b/compiler/testData/diagnostics/tests/classObjects/ClassObjects.fir.kt new file mode 100644 index 00000000000..4cb3dd4fc51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/ClassObjects.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES +package Jet86 + +class A { + companion object { + val x = 1 + } + companion object { + val x = 1 + } +} + +class AA { + companion object { + val x = 1 + } + companion object A { + val x = 1 + } + companion object AA { + val x = 1 + } +} + +class B() { + val x = 12 +} + +object b { + companion object { + val x = 1 + } // error +} + +val a = A.x +val c = B.x +val d = b.x + +val s = System // error +fun test() { + System.out.println() + java.lang.System.out.println() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughClassObject.fir.kt new file mode 100644 index 00000000000..e50193d6d83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughClassObject.fir.kt @@ -0,0 +1,51 @@ +package a + +class A { + class Nested + inner class Inner + + + companion object { + + class Nested2 + + val c: Int = 1 + + object Obj2 { + val c: Int = 1 + } + } + + object Obj +} + +object O { + class A + + object O +} + +fun f() { + A.c + A.hashCode() + A().Nested + A.Nested() + A().Inner() + A.Companion.Nested + A.Companion.Inner + A.Inner + A.Companion.c + A.Companion.Obj2 + A.Companion.Obj2.c + + A.Companion.Nested2() + A.Companion.c + A.Obj + A.Companion.Obj2 + A.Obj2 + A.Obj2.c + A.Nested2 + + O.O + O.A() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt new file mode 100644 index 00000000000..999da4bb935 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner + +package a + + +enum class C { + E1, E2, E3 { + object O_O + + fun b() { + O_O + } + + class G + }, + + E4 { + fun c() { + this.B() + + C.A() + A() + //TODO: should be resolved with error + this.A() + } + }; + + class A + inner class B + object O { + object InO + } +} + +fun f() { + C.E1.A + C.E1.A() + C.E2.B() + + C.E2.O + C.E3.O.InO + + C.O + C.O.InO + C.A() + C.B() + + C.E3.O_O + C.E3.G() +} diff --git a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt new file mode 100644 index 00000000000..278924145be --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: -NestedClassesInEnumEntryShouldBeInner + +package a + + +enum class C { + E1, E2, E3 { + object O_O + + fun b() { + O_O + } + + class G + }, + + E4 { + fun c() { + this.B() + + C.A() + A() + //TODO: should be resolved with error + this.A() + } + }; + + class A + inner class B + object O { + object InO + } +} + +fun f() { + C.E1.A + C.E1.A() + C.E2.B() + + C.E2.O + C.E3.O.InO + + C.O + C.O.InO + C.A() + C.B() + + C.E3.O_O + C.E3.G() +} diff --git a/compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt new file mode 100644 index 00000000000..57d0532952a --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassClassObject.fir.kt @@ -0,0 +1,25 @@ +// http://youtrack.jetbrains.net/issue/KT-449 + +class A { + inner class B { + companion object { } + } +} + +class B { + companion object { + class B { + companion object { + class C { + companion object { } + } + } + } + } +} + +class C { + class D { + companion object { } + } +} diff --git a/compiler/testData/diagnostics/tests/classObjects/builtInClassObjects.fir.kt b/compiler/testData/diagnostics/tests/classObjects/builtInClassObjects.fir.kt new file mode 100644 index 00000000000..250ca38501f --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/builtInClassObjects.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun box(): String { + try { + // Objects + val i = Int + val d = Double + val f = Float + val l = Long + val sh = Short + val b = Byte + val ch = Char + val st = String + + test(Int) + test(Double) + test(Float) + test(Long) + test(Short) + test(Byte) + test(String) + test(Char) + + // Common Double + Double.POSITIVE_INFINITY + Double.NEGATIVE_INFINITY + Double.NaN + + // Common Float + Float.POSITIVE_INFINITY + Float.NEGATIVE_INFINITY + Float.NaN + } + catch (e: Throwable) { + return "Error: \n" + e + } + + return "OK" +} + +fun test(a: Any) {} + + diff --git a/compiler/testData/diagnostics/tests/classObjects/classObjectHeader.fir.kt b/compiler/testData/diagnostics/tests/classObjects/classObjectHeader.fir.kt new file mode 100644 index 00000000000..d7ff67b3a32 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/classObjectHeader.fir.kt @@ -0,0 +1,9 @@ +package test + +open class ToResolve(f : (Int) -> Int) +fun testFun(a : Int) = 12 + +class TestSome

{ + companion object : ToResolve

({testFun(it)}) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/classObjectInLocalClass.fir.kt b/compiler/testData/diagnostics/tests/classObjects/classObjectInLocalClass.fir.kt new file mode 100644 index 00000000000..5b91a35a64e --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/classObjectInLocalClass.fir.kt @@ -0,0 +1,9 @@ +fun test() { + class A { + companion object {} + } + + object { + companion object {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/classObjectRedeclaration.fir.kt b/compiler/testData/diagnostics/tests/classObjects/classObjectRedeclaration.fir.kt new file mode 100644 index 00000000000..564c96200af --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/classObjectRedeclaration.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES +package test + +class A { + object Companion + + companion object +} + +class B { + companion object Named + + object Named +} + +class C { + class Named + + companion object Named +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt b/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt new file mode 100644 index 00000000000..28f44a7fed7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt @@ -0,0 +1,19 @@ +package test + +fun use() { + Default.create() + + Explicit.create() +} + +private class Default { + companion object { + fun create() = Default() + } +} + +private class Explicit { + private companion object { + fun create() = Explicit() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/importClassInClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/importClassInClassObject.fir.kt new file mode 100644 index 00000000000..bc68cc2cd51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/importClassInClassObject.fir.kt @@ -0,0 +1,11 @@ +package f + +import f.A.Companion.B + +class A { + companion object { + class B + } +} + +fun test() = B() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt b/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt new file mode 100644 index 00000000000..c94cd61519c --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt @@ -0,0 +1,51 @@ +//FILE:a.kt +package a + +class A { + companion object { + fun foo() {} + } +} + +private class B { + companion object { + fun bar() {} + } +} + +class C { + private companion object { + fun baz() {} + } +} + +private class D { + private companion object { + fun quux() {} + } +} + +//FILE:b.kt +package b + +import a.A +import a.B +import a.C +import a.D + +fun test() { + f(A) + f(B) + f(C) + f(D) + + A.foo() + B.bar() + C.baz() + D.quux() + + a.A.foo() + a.C.baz() +} + +fun f(unused: Any) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/kt3866.fir.kt b/compiler/testData/diagnostics/tests/classObjects/kt3866.fir.kt new file mode 100644 index 00000000000..5a0f25e02f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/kt3866.fir.kt @@ -0,0 +1,20 @@ +open class C { +} + +fun C.foo() {} + +open class X { + companion object : C() {} +} + +open class Y { + companion object : C() {} +} + +fun bar() { + val x = X + x.foo() + X.foo() + (X as C).foo() + ((if (1<2) X else Y) as C).foo() +} diff --git a/compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt b/compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt new file mode 100644 index 00000000000..de7b2f48423 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/multipleDissallowedDefaultObjects.fir.kt @@ -0,0 +1,17 @@ +class A { + inner class I { + companion object A + + companion object B + + companion object C + } +} + +object O { + companion object A + + companion object B + + companion object C +} diff --git a/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt new file mode 100644 index 00000000000..5a029292302 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt @@ -0,0 +1,15 @@ +class A { + private companion object { + class B { + class C { + companion object { + fun foo() {} + } + } + } + } +} + +fun f1() = A.Companion.B.C + +fun f2() = A.Companion.B.C.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.fir.kt new file mode 100644 index 00000000000..498426201be --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.fir.kt @@ -0,0 +1,9 @@ +package test + +class Test { + fun test(): Int = 12 + + companion object { + val a = test() // Check if resolver will be able to infer type of a variable + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt new file mode 100644 index 00000000000..397d1642c30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE! +// ISSUE: KT-28999 + +fun case_1() { + val x = object { } // type of x is +} + +fun case_2() { + val x = object> { } +} + +fun case_3() { + val x = object where T : Comparable { } // ERROR: Where clause is not allowed for objects +} + +val x = object> { + fun test() = 10 as T // OK +} + +fun case_4() { + val x = object { + fun test() = 10 as T + } + + val y = x.test() // type y is T +} + +inline fun case_5() { + val x = object { + fun test() = 10 as T + } + + val z = x.test() + + if (z is T) { + // z is {T!! & T!!} (smart cast from T) + println(z) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt new file mode 100644 index 00000000000..d6f2b51acda --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +ProhibitTypeParametersInAnonymousObjects +// !DIAGNOSTICS: -UNUSED_VARIABLE! +// ISSUE: KT-28999 + +fun case_1() { + val x = object { } // type of x is +} + +fun case_2() { + val x = object> { } +} + +fun case_3() { + val x = object where T : Comparable { } // ERROR: Where clause is not allowed for objects +} + +val x = object> { + fun test() = 10 as T // OK +} + +fun case_4() { + val x = object { + fun test() = 10 as T + } + + val y = x.test() // type y is T +} + +inline fun case_5() { + val x = object { + fun test() = 10 as T + } + + val z = x.test() + + if (z is T) { + // z is {T!! & T!!} (smart cast from T) + println(z) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt new file mode 100644 index 00000000000..ee288a47ee3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt @@ -0,0 +1,21 @@ +object A +object B +object C> + +class D { + companion object +} + +class E { + companion object +} + +class F { + companion object C> +} + +class G { + companion object F +} + +object H() diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.fir.kt new file mode 100644 index 00000000000..9bcc0a4d510 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations + +annotation class Foo(val a: IntArray, val b: Array, val c: FloatArray) + +@Foo([1], ["/"], [1f]) +fun test1() {} + +@Foo([], [], []) +fun test2() {} + +@Foo([1f], [' '], [1]) +fun test3() {} + +@Foo(c = [1f], b = [""], a = [1]) +fun test4() {} + +@Foo([1 + 2], ["Hello, " + "Kotlin"], [1 / 0f]) +fun test5() {} + +const val ONE = 1 +val two = 2 + +@Foo([ONE], [], []) +fun test6() {} + +@Foo([ONE + two], [], []) +fun test7() {} + +@Foo([two], [], []) +fun test8() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.fir.kt new file mode 100644 index 00000000000..ff7c6d53274 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations + +import kotlin.reflect.KClass + +annotation class Foo(val a: Array> = []) + +class Gen + +annotation class Bar(val a: Array> = [Int::class, Array::class, Gen::class]) + +@Foo([]) +fun test1() {} + +@Foo([Int::class, String::class]) +fun test2() {} + +@Foo([Array::class]) +fun test3() {} + +@Foo([Gen::class]) +fun test4() {} + +@Foo([""]) +fun test5() {} + +@Foo([Int::class, 1]) +fun test6() {} + +@Bar +fun test7() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.fir.kt new file mode 100644 index 00000000000..dd381a3eb8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED + +fun test() { + val a = [] + val b: Array = [] + val c = [1, 2] + val d: Array = [1, 2] + val e: Array = [1] + + val f: IntArray = [1, 2] + val g = [f] +} + +fun check() { + [1, 2] checkType { _>() } + [""] checkType { _>() } + + val f: IntArray = [1] + [f] checkType { _>() } + + [1, ""] checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.fir.kt new file mode 100644 index 00000000000..99b93413995 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED + +fun basicTypes() { + val a: IntArray = [1] + val b: ByteArray = [1] + val c: BooleanArray = [true, false] + val d: CharArray = ['a'] + val e: ShortArray = [1] + val f: FloatArray = [1.0f] + val g: LongArray = [1] + val h: DoubleArray = [1.0] +} + +fun basicTypesWithErrors() { + val a: IntArray = [1.0] + val b: ShortArray = [1.0] + val c: CharArray = ["a"] +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.fir.kt new file mode 100644 index 00000000000..215c070f604 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun takeArray(array: Array) {} + +fun test() { + "foo bar".split([""]) + unresolved([""]) + takeArray([""]) + val v = [""] + [""] + [1, 2, 3].size +} + +fun baz(arg: Array = []) { + if (true) ["yes"] else {["no"]} +} + +class Foo( + val v: Array = [] +) diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.fir.kt new file mode 100644 index 00000000000..e395835eb6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.fir.kt @@ -0,0 +1,41 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations, +ProhibitAssigningSingleElementsToVarargsInNamedForm + +annotation class Ann1(vararg val a: String = []) +annotation class Ann2(vararg val a: Int = [1, 2]) +annotation class Ann3(vararg val a: Float = [1f]) +annotation class Ann4(vararg val a: String = ["/"]) + +annotation class Ann5(vararg val a: Ann4 = []) +annotation class Ann6(vararg val a: Ann4 = [Ann4(*["a", "b"])]) + +annotation class Ann7(vararg val a: Long = [1L, null, ""]) + +@Ann1(*[]) +fun test1_0() {} + +@Ann1(*["a", "b"]) +fun test1_1() {} + +@Ann1(*["a", 1, null]) +fun test1_2() {} + +@Ann2(*[]) +fun test2() {} + +@Ann3(a = *[0f, 1 / 0f]) +fun test3() {} + +@Ann5(Ann4(*["/"])) +fun test5() {} + +@Ann6(*[]) +fun test6() {} + +annotation class AnnArray(val a: Array) + +@AnnArray(*["/"]) +fun testArray() {} + +@Ann1([""]) +fun testVararg() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt new file mode 100644 index 00000000000..d193faf0ba5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations + +annotation class Foo( + val a: Array = ["/"], + val b: Array = [], + val c: Array = ["1", "2"] +) + +annotation class Bar( + val a: Array = [' '], + val b: Array = ["", ''], + val c: Array = [1] +) + +annotation class Base( + val a0: IntArray = [], + val a1: IntArray = [1], + val b1: FloatArray = [1f], + val b0: FloatArray = [] +) + +annotation class Err( + val a: IntArray = [1L], + val b: Array = [1] +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt new file mode 100644 index 00000000000..d3c0b59660a --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations + +const val ONE = 1 + +annotation class Foo( + val a: IntArray = [ONE], + val b: IntArray = [ONE, 2, 3] +) + +val TWO = 2 + +fun getOne() = ONE +fun getTwo() = TWO + +annotation class Bar( + val a: IntArray = [TWO], + val b: IntArray = [1, TWO], + val c: IntArray = [getOne(), getTwo()] +) + +annotation class Baz( + val a: IntArray = [null], + val b: IntArray = [1, null, 2], + val c: IntArray = [this] +) diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.fir.kt new file mode 100644 index 00000000000..2134e0ebeae --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -ArrayLiteralsInAnnotations +annotation class Foo( + val a: IntArray = [], + val b: FloatArray = [1f, 2f], + val c: Array = ["/"] +) + +@Foo +fun test1() {} + +@Foo(a = [1, 2], c = ["a"]) +fun test2() {} + +@Foo([1], [3f], ["a"]) +fun test3() {} + +fun test4() { + [1, 2] +} diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/noCollectionLiterals.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/noCollectionLiterals.fir.kt new file mode 100644 index 00000000000..9683fe6ce68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/noCollectionLiterals.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +fun test(): Array { + [1, 2] + [1, 2][0] + [1, 2].get(0) + + foo([""]) + + val p = [1, 2] + [3, 4] + + return [1, 2] +} + +fun foo(a: Array = [""]) {} + +class A(val a: Array = []) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/resolveToFunctionFromBuiltIns.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/resolveToFunctionFromBuiltIns.fir.kt new file mode 100644 index 00000000000..68aef2e6c7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/resolveToFunctionFromBuiltIns.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED + +annotation class Anno(val a: Array = [""], val b: IntArray = []) + +@Anno([], []) +fun test() {} + +fun arrayOf(): Array = TODO() +fun intArrayOf(): Array = TODO() + +fun local() { + val a1: IntArray = [1, 2] + val a2: IntArray = [] + + val s1: Array = [""] + val s2: Array = [] +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/afterInitialization.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/afterInitialization.fir.kt new file mode 100644 index 00000000000..269ed78f62b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/afterInitialization.fir.kt @@ -0,0 +1,6 @@ +class My(val x: Int) { + val y: Int = x + 3 + val z: Int? = foo() + + fun foo() = if (x >= 0) x else if (y >= 0) y else null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/aliencall.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/aliencall.fir.kt new file mode 100644 index 00000000000..f2582aebd28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/aliencall.fir.kt @@ -0,0 +1,29 @@ +fun foo() = 42 + +class Your { + fun bar() = 13 +} + +class My { + val your = Your() + + val x = foo() + + val y = Your().bar() + + val z = your.bar() + + // This extension function also can use our properties, + // so the call is also dangerous + val w = your.gav() + + val v = Your().gav() + + val t = your.other() + + val r = Your().other() + + fun Your.gav() = if (your.bar() == 0) t else r +} + +fun Your.other() = "3" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/assignment.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/assignment.fir.kt new file mode 100644 index 00000000000..02d1cb803f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/assignment.fir.kt @@ -0,0 +1,11 @@ +class My { + val x: String + + constructor() { + val temp = this + x = bar(temp) + } + +} + +fun bar(arg: My) = arg.x diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/backing.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/backing.fir.kt new file mode 100644 index 00000000000..57e7fa3c18a --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/backing.fir.kt @@ -0,0 +1,30 @@ +class My { + var x = 1 + set(value) { + field = value + } + + var y: Int = 1 + set(value) { + field = value + if (w == "") 0 else 1 + } + + var z: Int = 2 + set(value) { + field = value + if (w == "") 1 else 0 + } + + var m: Int = 2 + set + + init { + x = 3 + m = 6 + + // Writing properties using setters is dangerous + y = 4 + this.z = 5 + } + + val w = "6" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/basic.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/basic.fir.kt new file mode 100644 index 00000000000..48bfe299b62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/basic.fir.kt @@ -0,0 +1,13 @@ +class My { + val x: String + + constructor() { + val y = bar(this) + val z = foo() + x = "$y$z" + } + + fun foo() = x +} + +fun bar(arg: My) = arg.x diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/companion.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/companion.fir.kt new file mode 100644 index 00000000000..5b0313198a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/companion.fir.kt @@ -0,0 +1,19 @@ +class My { + + val x = foo() + + val w = bar() + + fun foo() = 0 + + companion object { + + val y = foo() + + val u = bar() + + val z: String? = bar() + + fun bar() = "1" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/comparison.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/comparison.fir.kt new file mode 100644 index 00000000000..0a387c86d4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/comparison.fir.kt @@ -0,0 +1,10 @@ +val instance = My() + +class My { + val equalsInstance = (this == instance) + + val isInstance = if (this === instance) "true" else "false" + + override fun equals(other: Any?) = + other is My && isInstance.hashCode() == other.isInstance.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/delegate.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/delegate.fir.kt new file mode 100644 index 00000000000..87b106a035c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/delegate.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class Delegate(val x: Int) { + operator fun getValue(t: Any?, p: KProperty<*>): Int = x +} + +class My { + val x: Int by Delegate(this.foo()) + + fun foo(): Int = x +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/derived.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/derived.fir.kt new file mode 100644 index 00000000000..c722cd64575 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/derived.fir.kt @@ -0,0 +1,11 @@ +open class Base(val x: String) { + fun foo() = bar() + + open fun bar() = -1 +} + +class Derived(x: String): Base(x) { + // It's still dangerous: we're not sure that foo() does not call some open function inside + val y = foo() + val z = x +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/derivedProperty.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/derivedProperty.fir.kt new file mode 100644 index 00000000000..be7f6b0fc58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/derivedProperty.fir.kt @@ -0,0 +1,11 @@ +interface Base { + val x: Int +} + +open class Impl(override val x: Int) : Base { + init { + if (this.x != 0) foo() + } +} + +fun foo() {} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/getset.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/getset.fir.kt new file mode 100644 index 00000000000..49468747f35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/getset.fir.kt @@ -0,0 +1,26 @@ +class My(var x: String) { + + var y: String + get() = if (x != "") x else z + set(arg) { + if (arg != "") x = arg + } + + val z: String + + var d: String = "" + get + set + + val z1: String + + init { + d = "d" + if (d != "") z1 = this.d else z1 = d + + // Dangerous: setter! + y = "x" + // Dangerous: getter! + if (y != "") z = this.y else z = y + } +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/init.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/init.fir.kt new file mode 100644 index 00000000000..e64714ea474 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/init.fir.kt @@ -0,0 +1,9 @@ +class My { + val x: String + + init { + x = foo() + } + + fun foo(): String = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.fir.kt new file mode 100644 index 00000000000..bcfc88c8f58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.fir.kt @@ -0,0 +1,20 @@ + +private const val A = 0L +private val B = 0L +private fun sample() = 0L + +private class PrivateClass + +class Foo { + var bar: Long = 0 + private var other: PrivateClass? = null + + init { + bar = A + bar = B + bar = sample() + other = PrivateClass() + } + + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/initwithgetter.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/initwithgetter.fir.kt new file mode 100644 index 00000000000..87577c486b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/initwithgetter.fir.kt @@ -0,0 +1,19 @@ +class My { + val x: Int + get() = field + if (z != "") 1 else 0 + + val y: Int + get() = field - if (z == "") 0 else 1 + + val w: Int + + init { + // Safe, val never has a setter + x = 0 + this.y = 0 + // Unsafe + w = this.x + y + } + + val z = "1" +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/inspection.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/inspection.fir.kt new file mode 100644 index 00000000000..deb9cb25b2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/inspection.fir.kt @@ -0,0 +1,56 @@ +class First { + val x: String + + init { + use(this) // NPE! Leaking this + x = foo() // NPE! Own function + } + + fun foo() = x +} + +fun use(first: First) = first.x.hashCode() + +abstract class Second { + val x: String + + init { + use(this) // Leaking this in non-final + x = bar() // Own function in non-final + foo() // Non-final function call + } + + private fun bar() = foo() + + abstract fun foo(): String +} + +fun use(second: Second) = second.x + +class SecondDerived : Second() { + val y = x // null! + + override fun foo() = y +} + +open class Third { + open var x: String + + constructor() { + x = "X" // Non-final property access + } +} + +class ThirdDerived : Third() { + override var x: String = "Y" + set(arg) { field = "$arg$y" } + + val y = "" +} + +class Fourth { + val x: String + get() = y + + val y = x // null! +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/lambdaInObject.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/lambdaInObject.fir.kt new file mode 100644 index 00000000000..eb4204ba880 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/lambdaInObject.fir.kt @@ -0,0 +1,18 @@ +interface Wise { + fun doIt(): Int +} + +fun Wise(f: () -> Int) = object: Wise { + override fun doIt() = f() +} + +class My { + // Still dangerous (???), nobogy can guarantee what Wise() will do with this lambda + val x = Wise { foo() } + + val y = 42 + + fun foo() = y + + fun bar() = x.doIt() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/lateInit.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/lateInit.fir.kt new file mode 100644 index 00000000000..87b435651e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/lateInit.fir.kt @@ -0,0 +1,15 @@ +class WithLateInit { + lateinit var x: String + + fun init(xx: String) { + x = xx + } + + init { + // This is obviously a bug, + // but with lateinit we explicitly want it to occur in runtime + use() + } + + fun use() = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/localObject.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/localObject.fir.kt new file mode 100644 index 00000000000..c4f8951c4f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/localObject.fir.kt @@ -0,0 +1,19 @@ +open class Wise { + + val x = 1 + + open fun doIt(): Int = 42 +} + +class My { + + fun foo(): Int { + val wise = object: Wise() { + var xx = 1 + override fun doIt() = super.doIt() + bar(this) + xx + } + return wise.doIt() + } +} + +fun bar(wise: Wise): Int = wise.x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.fir.kt new file mode 100644 index 00000000000..c3d2c6276eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Context +class Point + +class Example { + constructor(context: Context?) + constructor(context: Context?, arg1: Int) + constructor(context: Context?, arg1: Int, arg2: Int) + constructor(context: Context?, arg1: Int, arg2: Int, arg3: Int) + + var condition: Boolean = false + private var index = newIndex(condition) + private fun newIndex(zero: Boolean) = if (zero) 0 else 1 + + private lateinit var latePoint1: Point + private lateinit var latePoint2: Point + + private val point1 = Point() + private val point2 = Point() + private val point3 = Point() + private val point4 = Point() + private var nullPoint: Point? = null +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/nobacking.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/nobacking.fir.kt new file mode 100644 index 00000000000..0d62f81b31f --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/nobacking.fir.kt @@ -0,0 +1,12 @@ +class My { + + val x: Int + get() = 1 + + init { + // x has no backing field, so the call is safe + foo() + } + + fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/open.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/open.fir.kt new file mode 100644 index 00000000000..2917319c9ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/open.fir.kt @@ -0,0 +1,34 @@ +open class Base { + init { + register(this) + foo() + } + + open fun foo() {} +} + +fun register(arg: Base) { + arg.foo() +} + +class Derived(val x: Int) : Base() { + override fun foo() { + x.hashCode() // NPE in Base constructor + } +} + +enum class MyEnum { + FIRST() { + val x: Int = 42 + + override fun foo() { + x.hashCode() // NPE in MyEnum constructor + } + }; + + init { + foo() + } + + abstract fun foo() +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/openProperty.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/openProperty.fir.kt new file mode 100644 index 00000000000..35a6ae666fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/openProperty.fir.kt @@ -0,0 +1,14 @@ +open class Base { + open var x: Int + + open var y: Int + + constructor() { + x = 42 + this.y = 24 + val temp = this.x + this.x = y + y = temp + + } +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/outer.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/outer.fir.kt new file mode 100644 index 00000000000..a1027c124db --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/outer.fir.kt @@ -0,0 +1,11 @@ +class Outer { + + fun foo() = 1 + + inner class Inner { + + val x = this@Outer.foo() + + val y = foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/property.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/property.fir.kt new file mode 100644 index 00000000000..452aa636375 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/property.fir.kt @@ -0,0 +1,5 @@ +class My(x: String) { + val y: String = foo(x) + + fun foo(x: String) = "$x$y" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/propertyAccess.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/propertyAccess.fir.kt new file mode 100644 index 00000000000..33054eb8a4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/propertyAccess.fir.kt @@ -0,0 +1,7 @@ +class My { + val x: Int + + constructor(x: Int) { + this.x = x + } +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.fir.kt b/compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.fir.kt new file mode 100644 index 00000000000..3ecbd358560 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/twoSecondaryConstructors.fir.kt @@ -0,0 +1,12 @@ +fun use(x: Any?) = x + +class Eap { + private val foo = toString() + + constructor(foo: Int) { + use(foo) + } + constructor(foo: String) { + use(foo) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt new file mode 100644 index 00000000000..c63bea9bf28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.fir.kt @@ -0,0 +1,349 @@ +// !WITH_NEW_INFERENCE +package uninitialized_reassigned_variables + +fun doSmth(s: String) {} +fun doSmth(i: Int) {} + +// ------------------------------------------------ +// uninitialized variables + +fun t1(b : Boolean) { + val v : Int + if (v == 0) {} + + var u: String + if (b) { + u = "s" + } + doSmth(u) + + var r: String + if (b) { + r = "s" + } + else { + r = "tg" + } + doSmth(r) + + var t: String + if (b) + doSmth(t) + else + t = "ss" + doSmth(t) //repeat for t + + val i = 3 + doSmth(i) + if (b) { + return; + } + doSmth(i) + if (i is Int) { + return; + } +} + +fun t2() { + val s = "ss" + + for (i in 0..2) { + doSmth(s) + } +} + +class A() {} + +fun t4(a: A) { + a = A() +} + +// ------------------------------------------------ +// reassigned vals + +fun t1() { + val a : Int = 1 + a = 2 + + var b : Int = 1 + b = 3 +} + +enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + }, + + TALKING { + override fun signal() = ProtocolState.WAITING + }; + + abstract fun signal() : ProtocolState +} + +fun t3() { + val x: ProtocolState = ProtocolState.WAITING + x = x.signal() + x = x.signal() //repeat for x +} + +fun t4() { + val x = 1 + x += 2 + val y = 3 + y *= 4 + var z = 5 + z -= y +} + +fun t5() { + for (i in 0..2) { + i += 1 + fun t5() { + i += 3 + } + } +} + +// ------------------------------------------------ +// backing fields + +var x = 10 +val y = 10 +val z = 10 + +class AnonymousInitializers(var a: String, val b: String) { + init { + a = "30" + a = "s" + + b = "3" + b = "tt" //repeat for b + } + + val i: Int + init { + i = 121 + } + + init { + x = 11 + z = 10 + } + + val j: Int + get() = 20 + + init { + i = 13 + j = 34 + } + + val k: String + init { + if (1 < 3) { + k = "a" + } + else { + k = "b" + } + } + + val l: String + init { + if (1 < 3) { + l = "a" + } + else { + l = "b" + } + } + + val o: String + init { + if (1 < 3) { + o = "a" + } + } + + var m: Int = 30 + + init { + m = 400 + } + + val n: Int + + init { + while (n == 0) { + } + n = 10 + while (n == 0) { + } + } + + var p = 1 + init { + p++ + } +} + +fun reassignFunParams(a: Int) { + a = 1 +} + +open class Open(a: Int, w: Int) {} + +class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { + val x : Int + val y : Int + init { + x = 1 + val b = x + } + val b = a + + fun foo() { + val r : Int + doSmth(x) + doSmth(y) + doSmth(r) + doSmth(a) + } + var xx = w + var yy : Int + init { + w += 1 + yy = w + } +} + +class Outer() { + val a : Int + var b : Int + + init { + a = 1 + b = 1 + } + + inner class Inner() { + init { + a++ + b++ + } + } + + fun foo() { + a++ + b++ + } +} + +class ForwardAccessToBackingField() { //kt-147 + val a = a // error + val b = c // error + val c = 1 +} + +class ClassObject() { + companion object { + val x : Int + + init { + x = 1 + } + + + fun foo() { + val a : Int + doSmth(a) + } + } +} + +fun foo() { + val a = object { + val x : Int + val y : Int + val z : Int + init { + x = 1 + z = 3 + } + fun foo() { + y = 10 + z = 13 + } + } +} + +class TestObjectExpression() { + val a : Int + fun foo() { + val a = object { + val x : Int + val y : Int + init { + if (true) + x = 12 + else + x = 1 + } + fun inner1() { + y = 101 + a = 231 + } + fun inner2() { + y = 101 + a = 231 + } + } + } +} + + + +object TestObjectDeclaration { + val x : Int + val y : Int + init { + x = 1 + } + + fun foo() { + y = 10 + val i: Int + if (1 < 3) { + i = 10 + } + doSmth(i) + } +} + +fun func() { + val b = 1 + val a = object { + val x = b + init { + b = 4 + } + } +} + +// ------------------------------------------------ +// dot qualifiers +class M() { + val x = 11 + var y = 12 +} + +fun test(m : M) { + m.x = 23 + m.y = 23 +} + +fun test1(m : M) { + m.x++ + m.y-- +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInFinally.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInFinally.fir.kt new file mode 100644 index 00000000000..46dc8b1e6ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignedInFinally.fir.kt @@ -0,0 +1,10 @@ +fun test5() { + var a: Int + try { + a = 3 + } + finally { + a = 5 + } + a.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.fir.kt new file mode 100644 index 00000000000..d59def7d63d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/assignmentInLocalsInConstructor.fir.kt @@ -0,0 +1,67 @@ +// Tests for KT-13597 (val assignment inside local object in constructor) + +class Test { + val a: String + + init { + val t = object { + fun some() { + // See KT-13597 + a = "12" + } + } + + a = "2" + t.some() + } +} + +class Test2 { + init { + val t = object { + fun some() { + a = "12" + } + } + + a = "2" + t.some() + } + + val a: String +} + +// Tests for KT-14381 (val assignment inside lambda in constructor) + +fun exec(f: () -> T): T = f() + +class Test4 { + val a: String + + init { + exec { + // See KT-14381 + a = "12" + } + a = "34" + } +} + +// Additional tests to prevent something broken + +class Test5 { + + val y: Int + + val z: String + + init { + val x: String + x = "" + z = x + } + + constructor(y: Int) { + this.y = y + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_after.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_after.fir.kt new file mode 100644 index 00000000000..27b22820416 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_after.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +RestrictionOfValReassignmentViaBackingField + +package a + +import java.util.HashSet + +val a: MutableSet? = null + get() { + if (a == null) { + field = HashSet() + } + return a + } + +class R { + val b: String? = null + get() { + if (b == null) { + field = "b" + } + return b + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_before.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_before.fir.kt new file mode 100644 index 00000000000..f2d5f28e3aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/backingFieldInsideGetter_before.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: -RestrictionOfValReassignmentViaBackingField + +package a + +import java.util.HashSet + +val a: MutableSet? = null + get() { + if (a == null) { + field = HashSet() + } + return a + } + +class R { + val b: String? = null + get() { + if (b == null) { + field = "b" + } + return b + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakContinueInTryFinally.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakContinueInTryFinally.fir.kt new file mode 100644 index 00000000000..cd3d5ee92ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakContinueInTryFinally.fir.kt @@ -0,0 +1,24 @@ +fun foo() { + outer@while (true) { + try { + while (true) { + continue@outer + } + } finally { + break + } + } + "OK".hashCode() +} + +fun bar(): String { + outer@while (true) { + try { + while (true) { + continue@outer + } + } finally { + return "OK" + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakInsideLocal.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakInsideLocal.fir.kt new file mode 100644 index 00000000000..1cd78622a47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakInsideLocal.fir.kt @@ -0,0 +1,86 @@ +fun test() { + while (true) { + fun local1() { + break + } + } +} + +fun test2() { + while (true) { + { + continue + } + } +} + +fun test3() { + while (true) { + class LocalClass { + init { + continue + } + + fun foo() { + break + } + } + } +} + +fun test4() { + while (true) { + object: Any() { + init { + break + } + } + } +} + +fun test5() { + while (true) { + class LocalClass(val x: Int) { + constructor() : this(42) { + break + } + constructor(y: Double) : this(y.toInt()) { + continue + } + } + } +} + +fun test6() { + while (true) { + class LocalClass(val x: Int) { + init { + break + } + init { + continue + } + } + } +} + +fun test7() { + while (true) { + class LocalClass { + val x: Int = if (true) { + break + } + else { + continue + } + } + } +} + +fun test8() { + while (true) { + class LocalClass(val x: Int) { + constructor() : this(if (true) { 42 } else { break }) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt new file mode 100644 index 00000000000..da8fe3d06ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt @@ -0,0 +1,34 @@ +fun test() { + + l@ for (i in if (true) 1..10 else continue@l) {} + for (i in if (true) 1..10 else continue) {} + + while (break) {} + l@ while (break@l) {} + + do {} while (continue) + l@ do {} while (continue@l) + + //KT-5704 + var i = 0 + while (if(i++ == 10) break else continue) {} +} + +fun test2(b: Boolean) { + while (b) { + while (break) {} + } + + do { + while (continue) {} + } while (b) + + while (b) { + do {} while (break) + } + + for (i in 1..10) { + for (j in if (true) 1..10 else continue) { + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.fir.kt new file mode 100644 index 00000000000..1e5f0e60de9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.fir.kt @@ -0,0 +1,12 @@ +package c + +fun test() { + val x = 10 + fun inner1() { + fun inner2() { + fun inner3() { + val y = x + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkPropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkPropertyAccessor.fir.kt new file mode 100644 index 00000000000..98f5d3afdc9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkPropertyAccessor.fir.kt @@ -0,0 +1,38 @@ +package d + +val a: Int + get() { + val b: Int + val c: Int + 42 + + fun bar(): Int { + val d: Int + 42 + return d + } + + return b + } + +class A { + val a: Int + get() { + val b: Int + val c: Int + 42 + return b + } + + fun foo() { + class B { + val a: Int + get() { + val b: Int + val c: Int + 42 + return b + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/constructorPropertyInterdependence.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/constructorPropertyInterdependence.fir.kt new file mode 100644 index 00000000000..89a0f558c6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/constructorPropertyInterdependence.fir.kt @@ -0,0 +1,8 @@ +// See KT-12809 +open class A(val a: Any) { + override fun toString() = a.toString() +} + +object B : A(B.foo) { // call B.foo should be not-allowed + val foo = 4 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.fir.kt new file mode 100644 index 00000000000..7cd5ee47a01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testCommasAndWhitespaces() { + fun bar(i: Int, s: String, x: Any) {} + + bar( 1 , todo() , "" ) +} + +fun todo(): Nothing = throw Exception() + + + diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt new file mode 100644 index 00000000000..1eb8bff5c0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt @@ -0,0 +1,22 @@ +package a + +fun test1() { + bar( + 11, + todo(),//comment1 + ""//comment2 + ) +} + +fun test2() { + bar(11, todo()/*comment1*/, ""/*comment2*/) +} +fun test3() { + bar(11, l@(todo()/*comment*/), "") +} + +fun todo(): Nothing = throw Exception() + +fun bar(i: Int, s: String, a: Any) {} + + diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.fir.kt new file mode 100644 index 00000000000..a0c9af7bfbe --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.fir.kt @@ -0,0 +1,11 @@ +fun testInvoke() { + operator fun Nothing.invoke(): Nothing = this + todo()() +} + +fun testInvokeWithLambda() { + operator fun Nothing.invoke(i: Int, f: () -> Int) = f + todo()(1){ 42 } +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInReceiver.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInReceiver.fir.kt new file mode 100644 index 00000000000..4056042ba8b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInReceiver.fir.kt @@ -0,0 +1,11 @@ +fun test11() { + fun Any.bar(i: Int) {} + todo().bar(1) +} + +fun test12() { + fun Any.bar(i: Int) {} + todo()?.bar(1) +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt new file mode 100644 index 00000000000..02e113dc355 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt @@ -0,0 +1,168 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +fun t1() : Int{ + return 0 + 1 +} + +fun t1a() : Int { + return + return 1 + 1 +} + +fun t1b() : Int { + return 1 + return 1 + 1 +} + +fun t1c() : Int { + return 1 + return + 1 +} + +fun t2() : Int { + if (1 > 2) + return 1 + else return 1 + 1 +} + +fun t2a() : Int { + if (1 > 2) { + return 1 + 1 + } else { return 1 + 2 + } + 1 +} + +fun t3() : Any { + if (1 > 2) + return 2 + else return "" + 1 +} + +fun t4(a : Boolean) : Int { + do { + return 1 + } + while (a) + 1 +} + +fun t4break(a : Boolean) : Int { + do { + break + } + while (a) + return 1 +} + +fun t5() : Int { + do { + return 1 + 2 + } + while (1 > 2) + return 1 +} + +fun t6() : Int { + while (1 > 2) { + return 1 + 2 + } + return 1 +} + +fun t6break() : Int { + while (1 > 2) { + break + 2 + } + return 1 +} + +fun t7(b : Int) : Int { + for (i in 1..b) { + return 1 + 2 + } + return 1 +} + +fun t7break(b : Int) : Int { + for (i in 1..b) { + return 1 + 2 + } + return 1 +} + +fun t7() : Int { + try { + return 1 + 2 + } + catch (e : Any) { + 2 + } + return 1 // this is OK, like in Java +} + +fun t8() : Int { + try { + return 1 + 2 + } + catch (e : Any) { + return 1 + 2 + } + return 1 +} + +fun blockAndAndMismatch() : Boolean { + (return true) || (return false) + return true +} + +fun tf() : Int { + try {return 1} finally{return 1} + return 1 +} + +fun failtest(a : Int) : Int { + if (fail() || true) { + + } + return 1 +} + +fun foo(a : Nothing) : Unit { + 1 + a + 2 +} + +fun fail() : Nothing { + throw java.lang.RuntimeException() +} + +fun nullIsNotNothing() : Unit { + val x : Int? = 1 + if (x != null) { + return + } + fail() +} + +fun returnInWhile(a: Int) { + do {return} + while (1 > a) +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeFromDifferentSources.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeFromDifferentSources.fir.kt new file mode 100644 index 00000000000..d2c13049fb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeFromDifferentSources.fir.kt @@ -0,0 +1,23 @@ +package c + +fun test1() { + val r: Nothing = null!! +} + +fun test2(a: A) { + a + a + bar() +} + +fun test3() { + null!! + bar() +} + +fun throwNPE(): Nothing = null!! + +class A { + operator fun plus(a: A): Nothing = throw Exception() +} + +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInArrayAccess.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInArrayAccess.fir.kt new file mode 100644 index 00000000000..74ab2d9781b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInArrayAccess.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testArrayAccess1(array: Array) { + array[todo()] +} + +fun testArrayAccess2() { + operator fun Nothing.get(i: Int, s: String) {} + todo()[1, ""] +} + +fun testAraryAccess3() { + operator fun Nothing.get(n: Nothing) {} + todo()[todo()] +} + +fun testArrayAssignment1(array: Array) { + array[todo()] = 11 +} + +fun testArrayAssignment2(array: Array) { + array[1] = todo() +} + +fun testArrayAssignment3(n: Nothing) { + operator fun Nothing.set(i: Int, j: Int) {} + n[1] = 2 +} + +fun testArrayAssignment4(n: Nothing) { + operator fun Nothing.set(i: Int, a: Any) {} + n[1] = todo() +} + +fun testArrayPlusAssign(array: Array) { + operator fun Any.plusAssign(a: Any) {} + array[1] += todo() +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInAssignment.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInAssignment.fir.kt new file mode 100644 index 00000000000..62e8cdabb94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInAssignment.fir.kt @@ -0,0 +1,18 @@ +fun testAssignment() { + var a = 1 + a = todo() +} + +fun testVariableDeclaration() { + val a = todo() +} + +fun testPlusAssign() { + operator fun Int.plusAssign(i: Int) {} + + var a = 1 + a += todo() +} + + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInBinaryExpressions.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInBinaryExpressions.fir.kt new file mode 100644 index 00000000000..16c3669ddcc --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInBinaryExpressions.fir.kt @@ -0,0 +1,39 @@ +fun testBinary1() { + operator fun Int.times(s: String) {} + + todo() * "" +} +fun testBinary2() { + "1" + todo() +} + +fun testElvis1() { + todo() ?: "" +} + +fun testElvis2(s: String?) { + s ?: todo() + + bar() +} + +fun testAnd1(b: Boolean) { + b && todo() + + bar() +} + +fun testAnd2(b: Boolean) { + todo() && b +} + +fun returnInBinary1(): Boolean { + (return true) && (return false) +} + +fun returnInBinary2(): Boolean { + (return true) || (return false) +} + +fun todo(): Nothing = throw Exception() +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInCalls.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInCalls.fir.kt new file mode 100644 index 00000000000..3cbdbe4eb0e --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInCalls.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testArgumentInCall() { + fun bar(i: Int, s: String, x: Any) {} + + bar(1, todo(), "") +} + +fun testArgumentInVariableAsFunctionCall(f: (Any) -> Unit) { + f(todo()) +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInDeadCode.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInDeadCode.fir.kt new file mode 100644 index 00000000000..f18f12bb79c --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInDeadCode.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun unreachable0() { + return + return todo() +} + +fun unreachable2() { + return + val a = todo() +} + +fun unreachable3() { + return + bar(todo()) +} + +fun unreachable4(array: Array) { + return + array[todo()] +} + +fun bar(a: Any) {} +fun todo(): Nothing = throw Exception() diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInIf.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInIf.fir.kt new file mode 100644 index 00000000000..bd22f23be28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInIf.fir.kt @@ -0,0 +1,12 @@ +fun testIf() { + if (todo()) 1 else 2 +} + +fun testIf1(b: Boolean) { + if (b) todo() else 1 + + bar() +} + +fun todo(): Nothing = throw Exception() +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt new file mode 100644 index 00000000000..6263d0d7291 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInInnerExpressions.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testCompound() { + operator fun Nothing.get(i: Int) {} + todo()!![12] +} + +fun testCompound1() { + operator fun Int.times(s: String): Array = throw Exception() + (todo() * "")[1] +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLocalDeclarations.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLocalDeclarations.fir.kt new file mode 100644 index 00000000000..264569235d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLocalDeclarations.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testObject() { + object : Foo(todo()) { + fun foo() = 1 + } +} + +fun testObjectExpression() { + val a = object : Foo(todo()) { + fun foo() = 1 + } +} + +fun testObjectExpression1() { + fun bar(i: Int, x: Any) {} + + bar(1, object : Foo(todo()) { + fun foo() = 1 + }) +} + +fun testClassDeclaration() { + class C : Foo(todo()) {} + + bar() +} + +fun testFunctionDefaultArgument() { + fun foo(x: Int = todo()) { bar() } +} + +open class Foo(i: Int) {} + +fun todo(): Nothing = throw Exception() +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLoops.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLoops.fir.kt new file mode 100644 index 00000000000..533b7798499 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInLoops.fir.kt @@ -0,0 +1,21 @@ +fun testFor() { + operator fun Nothing.iterator() = (0..1).iterator() + + for (i in todo()) {} +} + +fun testWhile() { + while (todo()) { + } +} + +fun testDoWhile() { + do { + + } while(todo()) + + bar() +} + +fun todo(): Nothing = throw Exception() +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInReturn.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInReturn.fir.kt new file mode 100644 index 00000000000..704b1f3e7b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInReturn.fir.kt @@ -0,0 +1,5 @@ +fun testReturn() { + return todo() +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt new file mode 100644 index 00000000000..bd53f349b08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInUnaryExpr.fir.kt @@ -0,0 +1,15 @@ +fun testPrefix() { + operator fun Any.not() {} + !todo() +} + +fun testPostfixWithCall(n: Nothing) { + operator fun Nothing.inc(): Nothing = this + n++ +} + +fun testPostfixSpecial() { + todo()!! +} + +fun todo(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInWhileFromBreak.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInWhileFromBreak.fir.kt new file mode 100644 index 00000000000..8f2c49bd960 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeInWhileFromBreak.fir.kt @@ -0,0 +1,55 @@ +fun foo(a: Any) {} +fun bar(a: Any, b: Any) {} + +fun test(arr: Array) { + while (true) { + foo(break) + } + + + while (true) { + bar(arr, break) + } + + while (true) { + arr[break] + } + + while (true) { + arr[1] = break + } + + while (true) { + break + foo(1) + } + + while (true) { + var x = 1 + break + x = 2 + } + + while (true) { + var x = 1 + x = break + } + + // TODO: bug, should be fixed in CFA + while (true) { + if (1 > 2 && break && 2 > 3) { + + } + } + + // TODO: bug, should be fixed in CFA + while (true) { + if (1 > 2 || break || 2 > 3) { + + } + } + + while (true) { + break ?: null + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.fir.kt new file mode 100644 index 00000000000..4270d560304 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/expressionInUnitLiteral.fir.kt @@ -0,0 +1,8 @@ +fun main() { + "".run { + "" + } +} + + +fun T.run(f: (T) -> Unit): Unit = f(this) diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_1.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_1.fir.kt new file mode 100644 index 00000000000..e6f1e165083 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_1.fir.kt @@ -0,0 +1,12 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo(x: String): String { + try { + throw RuntimeException() + } finally { + try { + } catch (e: Exception) { + } + return x // <- Wrong UNREACHABLE_CODE + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_2.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_2.fir.kt new file mode 100644 index 00000000000..add01027427 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_2.fir.kt @@ -0,0 +1,23 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo() { + try { + throw RuntimeException() + } catch (e: Exception) { + return // <- Wrong UNREACHABLE_CODE + } finally { + while (true); + } +} + +fun bar() { + try { + throw RuntimeException() + } catch (e: Exception) { + return // <- Wrong UNREACHABLE_CODE + } finally { + while (cond()); + } +} + +fun cond() = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_3.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_3.fir.kt new file mode 100644 index 00000000000..f7bd9d8eb5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt2585_3.fir.kt @@ -0,0 +1,9 @@ +//KT-2585 Code in try-finally is incorrectly marked as unreachable + +fun foo(x: String): String { + try { + throw RuntimeException() //should be marked as unreachable, but is not + } finally { + throw NullPointerException() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt3162tryAsInitializer.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt3162tryAsInitializer.fir.kt new file mode 100644 index 00000000000..514476f04fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt3162tryAsInitializer.fir.kt @@ -0,0 +1,12 @@ +//KT-3162 More precise try-finally error marking + +fun foo(x: String) : String { + val a = try { + x + } finally { + try { + } catch (e: Exception) { + } + return x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.fir.kt new file mode 100644 index 00000000000..9401436a8c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/kt5200DeadCodeInLambdas.fir.kt @@ -0,0 +1,25 @@ +//KT-5200 Mark unreachable code in lambdas + +fun test1(): String { + doCall local@ { + throw NullPointerException() + "b3" //unmarked + } + + return "OK" +} + +fun test2(nonLocal: String, b: Boolean): String { + doCall local@ { + if (b) { + return@local "b1" + } else { + return@local "b2" + } + "b3" //unmarked + } + + return nonLocal +} + +inline fun doCall(block: ()-> String) = block() diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.fir.kt new file mode 100644 index 00000000000..723ab38f1fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.fir.kt @@ -0,0 +1,11 @@ + +inline fun myRun(b: () -> Unit) = b() + +fun foo() { + var a: Int + return + + myRun { + return + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/ReturnFromFunctionInObject.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/ReturnFromFunctionInObject.fir.kt new file mode 100644 index 00000000000..3673a7597d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/ReturnFromFunctionInObject.fir.kt @@ -0,0 +1,13 @@ +interface X { + fun f(): Boolean +} + +val m = object : X { + override fun f(): Boolean { + } + + fun foo() { + fun local(): Int { + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt3444_ReturnFromLocalFunctions.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt3444_ReturnFromLocalFunctions.fir.kt new file mode 100644 index 00000000000..29bcdda8fc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt3444_ReturnFromLocalFunctions.fir.kt @@ -0,0 +1,17 @@ +package f + + +//KT-3444 Front-end doesn't check if local function or function of anonymous class returns value + +fun box(): Int { + + fun local(): Int { + } + + return local() +} + +fun main() { + box() +} + diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt4034.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt4034.fir.kt new file mode 100644 index 00000000000..40c2f3f5871 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/kt4034.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// KT-4034 An expression of type Nothing may not affect 'definite return' analysis + +interface JavaClassifierType +interface TypeUsage +interface JetType + +private fun transformClassifierType(classifierType: JavaClassifierType, howThisTypeIsUsed: TypeUsage): JetType? { + null!! +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/simpleClass.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/simpleClass.fir.kt new file mode 100644 index 00000000000..74d1173e4b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturn/simpleClass.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt +package test + +class A {} + +// FILE: b.kt +package test.p; class C {fun f() {}} + +// FILE: c.kt +package test.p; open class G {open fun f(): T {} fun a() {}} + +// FILE: d.kt +package test.p; class G2 : G { fun g() : E {} override fun f() : E {}} + +// FILE: e.kt +package test.p; fun foo() {} + +// FILE: f.kt +package test.p; fun foo(a: C) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.fir.kt new file mode 100644 index 00000000000..9a82f54ac4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.fir.kt @@ -0,0 +1,6 @@ +fun illegalWhenBlock(a: Any): Int { + when(a) { + is Int -> return a + is String -> return a.length + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/delegatedPropertyEarlyAccess.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/delegatedPropertyEarlyAccess.fir.kt new file mode 100644 index 00000000000..25ca351fb4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/delegatedPropertyEarlyAccess.fir.kt @@ -0,0 +1,32 @@ +// See also KT-10869: Accessing lazy properties from init causes IllegalArgumentException + +import kotlin.reflect.KProperty + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +class Kaboom() { + // Here and below we should have errors for simple AND delegated + init { + delegated.hashCode() + simple.hashCode() + withGetter.hashCode() + } + + val other = delegated + + val another = simple + + val something = withGetter + + val delegated: String by CustomDelegate() + + val simple = "xyz" + + val withGetter: String + get() = "abc" + + // No error should be here + val after = delegated +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileAssignment.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileAssignment.fir.kt new file mode 100644 index 00000000000..08fc5a5616d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileAssignment.fir.kt @@ -0,0 +1,23 @@ +// See KT-15334: incorrect reassignment in do...while + +fun test() { + do { + val s: String + s = "" + } while (s == "") +} + +fun test2() { + do { + val s: String + s = "1" + s = s + "2" + } while (s == "1") +} + +fun test3() { + val s: String + do { + s = "" + } while (s != "") +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileNotDefined.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileNotDefined.fir.kt new file mode 100644 index 00000000000..92c4f436540 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/doWhileNotDefined.fir.kt @@ -0,0 +1,6 @@ +fun test(cond1: Boolean) { + do { + if (cond1) continue + val cond2 = false + } while (cond2) // cond2 may be not defined here +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.fir.kt new file mode 100644 index 00000000000..3709119f6f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.fir.kt @@ -0,0 +1,39 @@ +// !WITH_NEW_INFERENCE +// See KT-8277 +// NI_EXPECTED_FILE + +val v = { true } ?: ( { true } ?:null!! ) + +val w = if (true) { + { true } +} +else { + { true } ?: null!! +} + +val ww = if (true) { + { true } ?: null!! +} +else if (true) { + { true } ?: null!! +} +else { + null!! +} + +val n = null ?: (null ?: { true }) + +fun l(): (() -> Boolean)? = null + +val b = null ?: ( l() ?: false) + +val bb = null ?: ( l() ?: null!!) + +val bbb = null ?: ( l() ?: null) + +val bbbb = ( l() ?: null) ?: ( l() ?: null) + +fun f(x : Long?): Long { + var a = x ?: (fun() {} ?: fun() {}) + return a +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumCompanionInterdependence.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumCompanionInterdependence.fir.kt new file mode 100644 index 00000000000..ef40ac1e577 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumCompanionInterdependence.fir.kt @@ -0,0 +1,55 @@ +enum class B(val x: Int) { + B1(1), + B2(2); + + companion object { + val SUM = B1.x + B2.x + val COPY = B1 + } +} + +enum class C(val x: Int) { + C1(SUM), + C2(1); + + companion object { + val COPY = C2 + val SUM = C1.x + COPY.x + } +} + +// From KT-11769 +enum class Fruit(personal: Int) { + APPLE(1); + + companion object { + val common = 20 + } + + val score = personal + common +} + +// Another example from KT-11769 +enum class EnumCompanion1(val x: Int) { + INSTANCE(Companion.foo()), + ANOTHER(foo()); + + companion object { + fun foo() = 42 + } +} +// Also should be reported for implicit receiver +enum class EnumCompanion2(val x: Int) { + INSTANCE(foo()); + + companion object { + fun foo() = 42 + } +} +// But not for another enum +enum class EnumCompanion3(val x: Int) { + INSTANCE(EnumCompanion1.foo()), + ANOTHER(EnumCompanion2.foo()); + + companion object +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.fir.kt new file mode 100644 index 00000000000..8c282117050 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/enumInterdependence.fir.kt @@ -0,0 +1,35 @@ +enum class A(val v: A) { + A1(A2), + A2(A1) +} + +enum class D(val x: Int) { + D1(D2.x), + D2(D1.x) +} + +enum class E(val v: Int) { + // KT-11769 related: there is no predictable initialization order for enum entry with non-companion object + E1(Nested.COPY); + + object Nested { + val COPY = E1.v + } +} +// From KT-13322: cross reference should not be reported here +object Object1 { + val y: Any = Object2.z + object Object2 { + val z: Any = Object1.y + } +} + +// From KT-6054 +enum class MyEnum { + A, B; + val x = when(this) { + A -> 1 + B -> 2 + else -> 3 + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt new file mode 100644 index 00000000000..7ee3c670c3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// See KT-15566 +// NI_EXPECTED_FILE + +import DefaultHttpClient.client + +interface HttpClient + +class HttpClientImpl : HttpClient + +// Below we should have initialization error for both (!) delegates + +object DefaultHttpClient : HttpClient by client { + val client = HttpClientImpl() +} + +object DefaultHttpClientWithGetter : HttpClient by client { + val client get() = HttpClientImpl() +} + +object DefaultHttpClientWithFun : HttpClient by fClient() { +} + +private fun fClient() = HttpClientImpl() + +private fun lazy(init: () -> T): kotlin.Lazy { + init() + null!! +} + +object DefaultHttpClientWithBy : HttpClient by client { + val client by lazy { HttpClientImpl() } +} + +object DefaultFqHttpClient : HttpClient by DefaultFqHttpClient.client { + val client = HttpClientImpl() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/infiniteLoops.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/infiniteLoops.fir.kt new file mode 100644 index 00000000000..14d4aa846e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/infiniteLoops.fir.kt @@ -0,0 +1,55 @@ +fun unreachable() {} + +fun a() { + do { + } while (true) + unreachable() +} + +fun b() { + while (true) { + } + unreachable() +} + +fun c() { + do {} while (1 == 1) +} + +fun d() { + while (2 == 2) {} +} + +fun use(arg: Any) = arg + +fun f(cond: Boolean) { + val bar: Any + do { + if (cond) { + bar = "value" + break + } + } while (true) + use(bar) // should work + + val foo: Any + while (true) { + if (cond) { + foo = "value" + break + } + } + use(foo) // should work +} + +fun g(): Int { + do { + if (true) return 12 + } while (true) +} // should work + +fun h(): Int { + while (true) { + if (true) return 12 + } +} // should work \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLambda.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLambda.fir.kt new file mode 100644 index 00000000000..5af20bee534 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLambda.fir.kt @@ -0,0 +1,77 @@ +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +fun ignoreIt(f: () -> Unit) {} + +fun exec(f: () -> Unit) = f() + +fun foo() { + var x: Int + ignoreIt() { + // Ok + x = 42 + } + // Error! + x.hashCode() +} + +fun bar() { + val x: Int + exec { + x = 13 + } +} + +fun bar2() { + val x: Int + fun foo() { + x = 3 + } + foo() +} + +class My(val cond: Boolean) { + + val y: Int + + init { + val x: Int + if (cond) { + exec { + + } + x = 1 + } + else { + x = 2 + } + y = x + } + + constructor(): this(false) { + val x: Int + x = 2 + exec { + x.hashCode() + } + } +} + +class Your { + val y = if (true) { + val xx: Int + exec { + xx = 42 + } + 24 + } + else 0 +} + +val z = if (true) { + val xx: Int + exec { + xx = 24 + } + 42 +} +else 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt new file mode 100644 index 00000000000..95a87ad0c5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt @@ -0,0 +1,90 @@ +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +fun foo() { + var x: String + class A { + init { + x = "" + } + } + // Error! See KT-10042 + x.length +} + +fun bar() { + var x: String + object: Any() { + init { + x = "" + } + } + // Ok + x.length +} + +fun gav() { + val x: String + class B { + init { + // Error! See KT-10445 + x = "" + } + } + // Error! See KT-10042 + x.length + val y: String + class C(val s: String) { + constructor(): this("") { + // Error! + y = s + } + } + y.length +} + +open class Gau(val s: String) + +fun gau() { + val x: String + object: Any() { + init { + // Ok + x = "" + } + } + // Ok + x.length + val y: String + fun local() { + object: Any() { + init { + // Error! + y = "" + } + } + } + val z: String + object: Gau(if (true) { + z = "" + z + } + else "") {} +} + +class My { + init { + val x: String + class Your { + init { + // Error! See KT-10445 + x = "" + } + } + } +} + +val top: Int + +fun init() { + top = 1 +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalFun.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalFun.fir.kt new file mode 100644 index 00000000000..7a73b9b2a62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalFun.fir.kt @@ -0,0 +1,8 @@ +fun foo() { + var x: Int + fun bar() { + x = 42 + } + x.hashCode() + bar() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_after.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_after.fir.kt new file mode 100644 index 00000000000..6e7d54e92c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_after.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseCallsInPlaceEffect +// See KT-17479 + +class Test { + val str: String + init { + run { + this@Test.str = "A" + } + + run { + // Not sure do we need diagnostic also here + this@Test.str = "B" + } + + str = "C" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_before.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_before.fir.kt new file mode 100644 index 00000000000..b04ada52941 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalViaExplicitThis_before.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: -ReadDeserializedContracts -UseCallsInPlaceEffect +// See KT-17479 + +class Test { + val str: String + init { + run { + this@Test.str = "A" + } + + run { + // Not sure do we need diagnostic also here + this@Test.str = "B" + } + + str = "C" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.fir.kt new file mode 100644 index 00000000000..a277ad97574 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.fir.kt @@ -0,0 +1,34 @@ +//KT-1001 Argument 2 for @NotNull parameter of JetFlowInformationProvider.checkIsInitialized must not be null + +package kt1001 + +fun foo(c: Array) { + return + + for (i in c) {} + for (i in c) {} +} + +//more tests + +fun t1() : Int { + try { + return 1 + } + catch (e : Exception) { + return 2 + } + return 3 +} + +fun t2() : Int { + try { + return 1 + } + finally { + doSmth() + } + return 2 +} + +fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1027.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1027.fir.kt new file mode 100644 index 00000000000..c1de5c360e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1027.fir.kt @@ -0,0 +1,48 @@ +//KT-1027 Strange selection of unreachable code + +package kt1027 + +fun foo(c: List) { + var i = 2 + + return + + for (j in c) { //strange selection of unreachable code + i += 23 + } +} + +fun t1() { + return + + while(true) { + doSmth() + } +} + +fun t2() { + return + + do { + doSmth() + } while (true) +} + +fun t3() { + return + + try { + doSmth() + } + finally { + doSmth() + } +} + +fun t4() { + return + + (43) +} + +fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1066.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1066.fir.kt new file mode 100644 index 00000000000..60304fd2db5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1066.fir.kt @@ -0,0 +1,34 @@ +//KT-1066 false 'Variable cannot be initialized before declaration' + +package kt1066 + +fun randomDigit() = 0.toChar() + +fun foo(excluded: Set) { + var digit : Char + + do { + digit = randomDigit() +// ^^^^^ here! + } while (excluded.contains(digit)) +} + +fun test() { + var sum : Int = 0 + var first : Int = 1 + var second : Int = 2 + var temp : Int //= 0 // variable 'temp' initializer is redundant + + while (true) + { + if (second > 4000000) + break + + if (second % 2 == 0) + sum += second + + temp = second + second = first + second + first = temp + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10805.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10805.fir.kt new file mode 100644 index 00000000000..35863e4997f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10805.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// AssertionError for nested ifs with lambdas and Nothing as results +// NI_EXPECTED_FILE + +val fn = if (true) { + { true } +} +else if (true) { + { true } +} +else { + null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10823.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10823.fir.kt new file mode 100644 index 00000000000..14ffce99161 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt10823.fir.kt @@ -0,0 +1,33 @@ +fun find2(): Any? { + fun visit(element: Any) { + return@find2 element + } + return null +} + +// For find(): AssertionError at ControlFlowInstructionsGeneratorWorker.getExitPoint() + +fun find(): Any? { + object : Any() { + fun visit(element: Any) { + return@find element + } + } + return null +} + +fun find4(): Any? { + inline fun visit(element: Any) { + return@find4 element + } + return null +} + +fun find3(): Any? { + object : Any() { + inline fun visit(element: Any) { + return@find3 element + } + } + return null +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1156.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1156.fir.kt new file mode 100644 index 00000000000..dc513f6d0fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1156.fir.kt @@ -0,0 +1,7 @@ +//KT-1156 Throwing exception on the right side of elvis operator marks code unreachable + + +fun foo(maybe: Int?) { + val i : Int = maybe ?: throw RuntimeException("No value") + System.out.println(i) +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1185enums.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1185enums.fir.kt new file mode 100644 index 00000000000..80b24b11bdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1185enums.fir.kt @@ -0,0 +1,47 @@ +//KT-1185 Support full enumeration check for 'when' + +package kt1185 + +enum class Direction { + NORTH, + SOUTH, + WEST, + EAST +} + +class A { + companion object { + + } +} + +enum class Color(val rgb : Int) { + RED(0xFF0000), + GREEN(0x00FF00), + BLUE(0x0000FF) +} + +fun foo(d: Direction) = when(d) { //no 'else' should be requested + Direction.NORTH -> 1 + Direction.SOUTH -> 2 + A -> 1 + Direction.WEST -> 3 + Direction.EAST -> 4 +} + +fun foo1(d: Direction) = when(d) { + Direction.NORTH -> 1 + Direction.SOUTH -> 2 + Direction.WEST -> 3 +} + +fun bar(c: Color) = when (c) { + Color.RED -> 1 + Color.GREEN -> 2 + Color.BLUE -> 3 +} + +fun bar1(c: Color) = when (c) { + Color.RED -> 1 + Color.GREEN -> 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.fir.kt new file mode 100644 index 00000000000..0039e5d4d04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.fir.kt @@ -0,0 +1,38 @@ +//KT-1189 StackOverflow in ide +package kt1189 +import java.util.concurrent.locks.ReentrantReadWriteLock + +inline fun ReentrantReadWriteLock.write(action: ()->T) : T { + val rl = readLock() + var readCount = 0 + val writeCount = getWriteHoldCount() + if(writeCount == 0) { + readCount = getReadHoldCount() + if(readCount > 0) + for(i in 1..readCount) + rl.unlock() + } + + val wl = writeLock() + wl.lock() + try { + return action() + } + finally { + if(readCount > 0) { + for(j in 1..readCount) { + rl.lock() + } + } + wl.unlock() + } +} + +fun foo() { + try { + return + } + finally { + for (i in 1..10) {} + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1191.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1191.fir.kt new file mode 100644 index 00000000000..b4fef753131 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1191.fir.kt @@ -0,0 +1,21 @@ +//KT-1191 Wrong detection of unused parameters +package kt1191 + +interface FunctionalList { + val size: Int + val head: T + val tail: FunctionalList +} + +fun FunctionalList.plus(element: T) : FunctionalList = object: FunctionalList { + override val size: Int + get() = 1 + this@plus.size + override val tail: FunctionalList + get() = this@plus + override val head: T + get() = element +} + +fun foo(unused: Int) = object { + val a : Int get() = unused +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1219.1301.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1219.1301.fir.kt new file mode 100644 index 00000000000..6e975f1d8f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1219.1301.fir.kt @@ -0,0 +1,25 @@ +//KT-1219 Incorrect 'unused value' error in closures + +package kt1219 + +fun Iterable.fold(a: R, op: (T, R) -> R) : R { + var r = a + this.foreach { r = op(it, r) } //unused value here + return r +} + +//KT-1301 Modification of local of outer function in a local function should not be marked as unused assignment +fun foo(){ + var local = 0 + fun bar(){ + local = 1 + } + + bar() + System.out.println(local) +} + +fun Iterable.foreach(operation: (element: T) -> Unit) { + for (elem in this) + operation(elem) +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.fir.kt new file mode 100644 index 00000000000..399ca216f0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.fir.kt @@ -0,0 +1,42 @@ +//KT-1571 Frontend fails to check val reassigment for operator overloading. +package kt1571 + +var c0 = 0 +var c1 = 0 +var c2 = 0 + +class A() { + var p = 0 + operator fun divAssign(a : Int) { + c1++; + } + operator fun times(a : Int) : A { + c2++; + return this; + } +} + +val a : A = A() +get() { + c0++ + return field +} + +fun box() : String { + + a /= 3 + if (c0 != 1) { + return "1" + } + if (c1 != 1) { + return "2" + } + a *= 3 // a = a * 3, shouldn't be able to do this on val + if (c0 != 2) { + return "3" + } + if (c2 != 1) { + return "4" + } + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1977.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1977.fir.kt new file mode 100644 index 00000000000..9cedcf94ddf --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1977.fir.kt @@ -0,0 +1,51 @@ +package kt1977 + +//KT-1977 Wrong 'unused expression' in catch +fun strToInt(s : String) : Int? = +try { + Integer.parseInt(s) +} catch(e : NumberFormatException) { + null +} + +//more tests +fun test1(s : String) : Int? { + return try { + 88 + Integer.parseInt(s) + 22 + } + catch (e: NumberFormatException) { + 44 + } + finally { + 22 + } +} + +fun test2(s : String) : Int? { + return try { + 88 + Integer.parseInt(s) + 22 + } finally { + { + x : Int -> x + } + } +} + + +//KT-2015 False "Expression is unused" warnings +fun foo() { + val i : Int = try{ + bar() + 1 + } + catch(e : Exception){ + 0 + } +} + +fun bar() { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2166_kt2103.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2166_kt2103.fir.kt new file mode 100644 index 00000000000..1fadd54bb53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2166_kt2103.fir.kt @@ -0,0 +1,17 @@ +package a + +//KT-2166 Control flow analysis doesn't detect that a 'while(true)' loop never terminates +fun foo(): Int { + while (true) { + } +} + +//KT-2103 Compiler requires return statement after loop which never exits +fun foo1() : Boolean{ + while(true){ + if (bar()) continue + return true + } +} + +fun bar() : Boolean = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2226.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2226.fir.kt new file mode 100644 index 00000000000..f326ec0a926 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2226.fir.kt @@ -0,0 +1,15 @@ +//KT-2226 Parameter used as delegation by object marked as unused +package a + +interface A { + fun foo() : Int +} + +class B : A { + override fun foo() = 10 +} +fun foo(b: B) : Int { + val o = object : A by b { + } + return o.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.fir.kt new file mode 100644 index 00000000000..8f5c98ebdf4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.fir.kt @@ -0,0 +1,53 @@ +//KT-2330 Check visibility of getters and setters correspondingly +package a + +class P { + var x : Int = 0 + private set + + var y : Int = 0 + + val other = P(); + + init { + x = 23 + other.x = 4 + } + + val testInGetter : Int + get() { + x = 33 + return 3 + } +} + +fun foo() { + val p = P() + p.x = 34 //should be an error here + p.y = 23 + + fun inner() { + p.x = 44 + } +} + +class R { + val p = P(); + init { + p.x = 42 + } + + val testInGetterInOtherClass : Int + get() { + p.x = 33 + return 3 + } +} + +fun test() { + val o = object { + fun run() { + p.x = 43 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2334.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2334.fir.kt new file mode 100644 index 00000000000..8c1a5ae4aea --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2334.fir.kt @@ -0,0 +1,5 @@ +//KT-2334 An error 'local function without body' is not reported + +fun foo() { + fun bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.fir.kt new file mode 100644 index 00000000000..1f464cc382f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2369.fir.kt @@ -0,0 +1,13 @@ +//KT-2369 Variable is not marked as uninitialized in 'finally' section + +fun main() { + var x : Int + try { + throw Exception() + } + finally { + doSmth(x + 1) + } +} + +fun doSmth(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.fir.kt new file mode 100644 index 00000000000..c77cd41a908 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.fir.kt @@ -0,0 +1,18 @@ +//KT-2845 Wrong cf-analysys for variable initialization in try..finally +package h + +import java.util.ArrayList + +private fun doTest() : Int { + var list : MutableList? ; + try { + list = ArrayList() + // Not-null was just assigned to the list + list.add(3) + return 0 ; + } + finally { + if(list != null) { // Must be an ERROR + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2960.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2960.fir.kt new file mode 100644 index 00000000000..0058a90febb --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2960.fir.kt @@ -0,0 +1,36 @@ +//KT-2960 Perform control flow checks for package property initializers + +package b + +class P { + var x : Int = 0 + private set +} + +val p = P() +var f = { -> p.x = 32 } + +val o = object { + fun run() { + p.x = 4 + + val z : Int + doSmth(z) + } +} + +val g = { -> + val x: Int + doSmth(x) +} + +class A { + val a : Int = 1 + get() { + val x : Int + doSmth(x) + return field + } +} + +fun doSmth(i: Int) = i \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.fir.kt new file mode 100644 index 00000000000..2180b0912e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2972.fir.kt @@ -0,0 +1,28 @@ +//KT-2972 Wrong "unused value" warning when finally is present + +import java.io.Closeable + +public inline fun T.use(block: (T)-> R) : R { + var closed = false + try { + return block(this) + } catch (e: Exception) { + closed = true // warning here + try { + this.close() + } catch (closeException: Exception) { + // eat the closeException as we are already throwing the original cause + // and we don't want to mask the real exception + + // TODO on Java 7 we should call + // e.addSuppressed(closeException) + // to work like try-with-resources + // http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html#suppressed-exceptions + } + throw e + } finally { + if (!closed) { + this.close() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3444.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3444.fir.kt new file mode 100644 index 00000000000..6cc325f83bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3444.fir.kt @@ -0,0 +1,13 @@ +fun box() { + fun local():Int { + } +} + +interface X { + fun f(): Boolean +} + +val m = object : X { + override fun f(): Boolean { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3501.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3501.fir.kt new file mode 100644 index 00000000000..b65e04208d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt3501.fir.kt @@ -0,0 +1,9 @@ +//KT-3501 Variable/parameter is highlighted as unused if it is used in member of local class + +fun f(p: String) { // "p" is marked as unused + class LocalClass { + fun f() { + p + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4126.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4126.fir.kt new file mode 100644 index 00000000000..cebe74c945e --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4126.fir.kt @@ -0,0 +1,3 @@ +public data class ProductGroup(val short_name: String, val parent: ProductGroup?) { + val name: String = if (parent == null) short_name else "${parent.name} $short_name" +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.fir.kt new file mode 100644 index 00000000000..bdbd9ade546 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.fir.kt @@ -0,0 +1,30 @@ +//KT-4405 Control-flow analysis is not performed for some local declarations + +package d + +val closure = { + val x4 = "" // error: should be UNUSED_VARIABLE + + fun g() { + val x6 = "" // error: should be UNUSED_VARIABLE + } + + fun h(): Int { // error: should be NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY + } +} + +class A { + init { + fun foo(): Int { + } + + val closure = { + val x = "" + + fun local(): Int { + } + } + + val y = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.fir.kt new file mode 100644 index 00000000000..d9a7ecbfb9d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.fir.kt @@ -0,0 +1,18 @@ +//KT-510 `this.` allows initialization without backing field + +package kt510 + +public open class Identifier1() { + var field : Boolean + init { + field = false; // error + } +} + + +public open class Identifier2() { + var field : Boolean + init { + this.field = false; + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt607.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt607.fir.kt new file mode 100644 index 00000000000..e3fe9a716c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt607.fir.kt @@ -0,0 +1,18 @@ +//KT-607 Val reassignment is not marked as an error + +package kt607 + +fun foo(a: A) { + val o = object { + val y : Int + get() = 42 + } + + a.z = 23 + o.y = 11 //Should be an error here +} + +class A() { + val z : Int + get() = 3 +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt609.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt609.fir.kt new file mode 100644 index 00000000000..42b529d62f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt609.fir.kt @@ -0,0 +1,20 @@ +//KT-609 Analyze not only local variables, but function parameters as well in 'unused values' analysis + +package kt609 + +fun test(a: Int) { + var aa = a + aa = 324 //should be an 'unused value' warning here +} + +class C() { + fun foo(s: String) {} //should be an 'unused variable' warning +} + +open class A() { + open fun foo(s : String) {} //should not be a warning +} + +class B() : A() { + final override fun foo(s : String) {} //should not be a warning +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt610.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt610.fir.kt new file mode 100644 index 00000000000..7a6a2782ec3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt610.fir.kt @@ -0,0 +1,10 @@ +//KT-610 Distinguish errors 'unused variable' and 'variable is assigned but never accessed' + +package kt610 + +fun foo() { + var j = 9 //'unused variable' error + + var i = 1 //should be an error 'variable i is assigned but never accessed' + i = 2 +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt6788.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt6788.fir.kt new file mode 100644 index 00000000000..82e506baf31 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt6788.fir.kt @@ -0,0 +1,10 @@ +class A(val next: A? = null) { + val x: String + init { + next?.x = "a" + } +} + +class B(val next: B? = null) { + var x: String = next?.x ?: "default" // it's ok to use `x` of next +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt776.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt776.fir.kt new file mode 100644 index 00000000000..4095484537b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt776.fir.kt @@ -0,0 +1,38 @@ +//KT-776 Wrong detection of unreachable code + +package kt776 + +fun test5() : Int { + var x = 0 + while(true) { + try { + if(x < 10) { + x++ + continue + } + else { + break + } + } + finally { + x++ + } + } + return x +} + +fun test1() : Int { + try { + if (true) { + return 1 + } + else { + return 2 + } + } + finally { + doSmth() //unreachable + } +} + +fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt843.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt843.fir.kt new file mode 100644 index 00000000000..8c5ba56b94f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt843.fir.kt @@ -0,0 +1,8 @@ +//KT-843 Don't highlight incomplete variables as unused + +package kt843 + +fun main() { + // Integer type + val // this word is grey, which looks strange +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.fir.kt new file mode 100644 index 00000000000..2f74c87b7ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.fir.kt @@ -0,0 +1,20 @@ +//KT-897 Don't allow assignment to a property before it is defined + +package kt897 + +class A() { + init { + i = 11 + } + val i : Int? = null // must be an error + + init { + j = 1 + } + var j : Int = 2 + + init { + k = 3 + } + val k : Int +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.fir.kt new file mode 100644 index 00000000000..775de2d3bb3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.fir.kt @@ -0,0 +1,26 @@ +package f + +fun f() { + class LocalClass() { + init { + val x1 = "" // ok: unused + + fun loc1(): Int { + val x1_ = "" // ok: unused + } + } + + fun f() { + val x2 = "" // error: should be UNUSED_VARIABLE + + fun loc2(): Int { + val x2_ = "" // error: should be UNUSED_VARIABLE + } + } + + val v: String + get() { + val x3 = "" // ok: unused + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/localObjectInConstructor.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localObjectInConstructor.fir.kt new file mode 100644 index 00000000000..3cb2bd13754 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localObjectInConstructor.fir.kt @@ -0,0 +1,87 @@ +fun println(obj: Any?) = obj + +class Demo0 { + private val some = object { + fun foo() { + println(state) + } + } + + private var state: Boolean = true +} + +class Demo1 { + private val some = object { + fun foo() { + if (state) + state = true + + println(state) + } + } + + private var state: Boolean = true +} + +class Demo1A { + fun foo() { + if (state) + state = true + + println(state) + } + + private var state: Boolean = true +} + +class Demo2 { + private val some = object { + fun foo() { + if (state) + state = true + else + state = false + + println(state) + } + } + + private var state: Boolean = true +} + +class Demo3 { + private val some = run { + if (state) + state = true + + println(state) + } + + private var state: Boolean = true +} + +fun exec(f: () -> T): T = f() + +class Demo4 { + private val some = exec { + if (state) + state = true + + println(state) + } + + private var state: Boolean = true +} + +class Demo5 { + private var state: Boolean = true + + private val some = object { + fun foo() { + if (state) + state = true + + println(state) + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithWarningOnUnusedParam.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithWarningOnUnusedParam.fir.kt new file mode 100644 index 00000000000..647da0962c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithWarningOnUnusedParam.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +WarningOnMainUnusedParameter + +fun main(args: Array) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithoutWarningOnUnusedParam.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithoutWarningOnUnusedParam.fir.kt new file mode 100644 index 00000000000..9ed477daa2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/mainWithoutWarningOnUnusedParam.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: -WarningOnMainUnusedParameter + +fun main(args: Array) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/nestedTryFinally.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nestedTryFinally.fir.kt new file mode 100644 index 00000000000..eb493096c80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nestedTryFinally.fir.kt @@ -0,0 +1,24 @@ +fun use(arg: String?) = arg + +fun sample(): String? { + try { + if (false) { + return "fail" + } else { + if (false) { + if (false) { + var foo: String? = null + try { + foo = "test" + } catch (e: Exception) { + return "fail" + } finally { + use(foo) // 'foo' is initialized here + } + } + return "fail" + } + } + } finally {} + return null +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.fir.kt new file mode 100644 index 00000000000..f09cc4b1f50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnUnreachable.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// See also KT-5198 / KT-10186 + +inline fun doCall(f: () -> Unit) = f() + +fun test1(nonLocal: String): String { + val localResult = doCall { + return nonLocal //unreachable + } + return "NON_LOCAL_FAILED $localResult" //unreachable +} + +fun doSomething() {} + +fun test2() { + fun f(x: Any?) = x + f(null?.let { return }) + + // false unreachable here + doSomething() +} + +fun test3(x: Any?): Boolean = + x?.let { + return true + } ?: false diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnWithFinally.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnWithFinally.fir.kt new file mode 100644 index 00000000000..37c23610960 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/nonLocalReturnWithFinally.fir.kt @@ -0,0 +1,10 @@ +fun test(name: String?) { + try { + name?.let { + return + } + } + finally { + name?.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/privateSetter.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/privateSetter.fir.kt new file mode 100644 index 00000000000..87364ae72a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/privateSetter.fir.kt @@ -0,0 +1,17 @@ +open class X(s : String) { + public var n: String = s + private set + +} + +class Z : X("subclass") { + fun print(): String { + n = n + return n; + } +} + + +fun box() : String { + return Z().print() //error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstance.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstance.fir.kt new file mode 100644 index 00000000000..71ec7c200e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstance.fir.kt @@ -0,0 +1,12 @@ +class A(val next: A? = null) { + val x: String + init { + next?.x = "a" + x = "b" + this.x = "c" + x = "d" // don't repeat the same diagnostic again with this receiver + this.x = "e" + + next?.x = "f" + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceInner.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceInner.fir.kt new file mode 100644 index 00000000000..38e9e36656d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceInner.fir.kt @@ -0,0 +1,21 @@ +class Outer { + val outerProp: String + inner class Inner(inner: Inner, outer: Outer) { + val innerProp: String + init { + outerProp // use of outerProp is ok because we're suppose that Outer instance should be initialized + this@Outer.outerProp + + this@Outer.outerProp = "1" + outerProp = "2" // do not repeat the same diagnostic with this receiver of outer class + outer.outerProp = "3" + + innerProp = "4" + inner.innerProp + this@Inner.innerProp = "5" + innerProp = "6" // do not repeat the same diagnostic with this receiver + this@Inner.innerProp = "7" + + inner.innerProp = "8" + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceThisLabel.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceThisLabel.fir.kt new file mode 100644 index 00000000000..ed28c8edac7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesInitWithOtherInstanceThisLabel.fir.kt @@ -0,0 +1,12 @@ +class A(val next: A? = null) { + val x: String + init { + next?.x = "a" + this@A.x = "b" + this.x = "c" + x = "d" // don't repeat the same diagnostic again with this receiver + this@A.x = "e" + + next?.x = "f" + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesOrderInPackage.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesOrderInPackage.fir.kt new file mode 100644 index 00000000000..2ca95e2a6a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/propertiesOrderInPackage.fir.kt @@ -0,0 +1,4 @@ +package a + +val a : Int = b +val b : Int = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatch.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatch.fir.kt new file mode 100644 index 00000000000..f13951b8340 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatch.fir.kt @@ -0,0 +1,102 @@ +// KT-13612 related tests (reassignment in try-catch-finally) + +fun f1() { + val n: Int + try { + n = 1 + throw Exception() + } + catch (e: Exception) { + // KT-13612: reassignment + n = 2 + } + n.hashCode() +} + +fun f2() { + val n: Int + try { + n = 1 + throw Exception() + } + finally { + n = 2 + } + n.hashCode() +} + +fun g1(flag: Boolean) { + val n: Int + try { + if (flag) throw Exception() + n = 1 + } + catch (e: Exception) { + // KT-13612: ? reassignment or definite assignment ? + n = 2 + } + n.hashCode() +} + +fun g2(flag: Boolean) { + val n: Int + try { + if (flag) throw Exception() + n = 1 + } + finally { + n = 2 + } + n.hashCode() +} + +fun h1(flag: Boolean) { + val n = try { + if (flag) throw Exception() + 1 + } + catch (e: Exception) { + 2 + } + n.hashCode() +} + +fun h2(flag: Boolean) { + val n = try { + if (flag) throw Exception() + 1 + } + finally { + 2 + } + n.hashCode() +} + +fun j(flag: Boolean) { + if (flag) throw Exception() +} + +fun k1(flag: Boolean) { + val n: Int + try { + n = 1 + j(flag) + } + catch (e: Exception) { + // KT-13612: reassignment + n = 2 + } + n.hashCode() +} + +fun k2(flag: Boolean) { + val n: Int + try { + n = 1 + j(flag) + } + finally { + n = 2 + } + n.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.fir.kt new file mode 100644 index 00000000000..ea546d9889d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.fir.kt @@ -0,0 +1,55 @@ +fun exc(flag: Boolean) { + if (flag) throw Exception() +} + +fun f1(flag: Boolean) { + val n: Int + try { + if (flag) { + n = 1 + exc(flag) + return + } + } + catch (e: Exception) { + // KT-13612: reassignment + n = 3 + } + n.hashCode() +} + +fun f2(flag: Boolean) { + while (true) { + val n: Int + try { + if (flag) { + n = 1 + exc(flag) + break + } + } + catch (e: Exception) { + // KT-13612: reassignment + n = 3 + } + n.hashCode() + } +} + +fun f3(flag: Boolean) { + while (true) { + val n: Int + try { + if (flag) { + n = 1 + exc(flag) + continue + } + } + catch (e: Exception) { + // KT-13612: reassignment + n = 3 + } + n.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt new file mode 100644 index 00000000000..293091f3571 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +package o + +class TestFunctionLiteral { + val sum: (Int) -> Int = { x: Int -> + sum(x - 1) + x + } + val foo: () -> Unit = l@ ({ foo() }) +} + +open class A(val a: A) + +class TestObjectLiteral { + val obj: A = object: A(obj) { + init { + val x = obj + } + fun foo() { + val y = obj + } + } + val obj1: A = l@ ( object: A(obj1) { + init { + val x = obj1 + } + fun foo() = obj1 + }) +} + +class TestOther { + val x: Int = x + 1 +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/repeatUnitializedErrorOnlyForLocalVars.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/repeatUnitializedErrorOnlyForLocalVars.fir.kt new file mode 100644 index 00000000000..0f944cb0c97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/repeatUnitializedErrorOnlyForLocalVars.fir.kt @@ -0,0 +1,15 @@ +package aa + +val a : Int = b +val b : Int = a + b + +class C { + val a : Int = b + val b : Int = a + b +} + +fun foo() { + val a : Int + a + 1 + a + 1 +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.fir.kt new file mode 100644 index 00000000000..6958b958954 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.fir.kt @@ -0,0 +1,5 @@ +class AnonymousInitializers(var a: String) { + init { + a = "s" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.fir.kt new file mode 100644 index 00000000000..40108a81c53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/throwInLambda.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// See KT-10913 Bogus unreachable code warning + +fun fn() : String? = null +fun foo(): String { + val x = fn()?.let { throw Exception() } ?: "unreachable?" + return x +} +fun bar(): String { + val x = fn() ?: return "" + val y = x?.let { throw Exception() } ?: "unreachable" + return y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/tryWithAssignmentUsedInCatch.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/tryWithAssignmentUsedInCatch.fir.kt new file mode 100644 index 00000000000..953ca2944d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/tryWithAssignmentUsedInCatch.fir.kt @@ -0,0 +1,36 @@ +fun f() { + var foo = 1 + try { + foo = 2 + throw RuntimeException() + } catch (e: Throwable) { + foo.hashCode() + } + throw Exception() +} + +fun g() { + var foo = 1 + try { + foo = 2 + f() + } catch (e: Throwable) { + foo.hashCode() + } +} + +fun h() { + try { + + } + finally { + var foo = 1 + try { + foo = 2 + g() + } + catch (e: Throwable) { + foo.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/uninitializedInLocalDeclarations.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/uninitializedInLocalDeclarations.fir.kt new file mode 100644 index 00000000000..7182fbeede5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/uninitializedInLocalDeclarations.fir.kt @@ -0,0 +1,50 @@ +fun test1() { + fun bar() { + var i : Int + doSmth(i) + } +} + +fun test2() { + fun foo() { + val s: String? + + try { + s = "" + } + catch(e: Exception) { + doSmth(e) + } + + doSmth(s) + } +} + +fun test3() { + val f = { + val a : Int + doSmth(a) + } +} + +fun test4() { + doSmth { + val a : Int + doSmth(a) + } +} + +fun test5() { + fun inner1() { + fun inner2() { + fun inner3() { + fun inner4() { + val a : Int + doSmth(a) + } + } + } + } +} + +fun doSmth(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unmappedArgs.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unmappedArgs.fir.kt new file mode 100644 index 00000000000..0e41d12110d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unmappedArgs.fir.kt @@ -0,0 +1,5 @@ +fun foo(a: Int, b: Int) = a + b + +fun bar(i: Int) { + foo(1, 1, i) +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitRecursiveInLambda.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitRecursiveInLambda.fir.kt new file mode 100644 index 00000000000..718684da9b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitRecursiveInLambda.fir.kt @@ -0,0 +1,6 @@ +class Test { + lateinit var someRunnable: Runnable + init { + someRunnable = Runnable { someRunnable.run() } + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithConstructor.fir.kt new file mode 100644 index 00000000000..7a57d63a6f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithConstructor.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var bar: String + + constructor(baz: Int) { + bar = "" + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithErroneousDelegation.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithErroneousDelegation.fir.kt new file mode 100644 index 00000000000..b76c4504f2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithErroneousDelegation.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var x: String + + constructor() { + x = "Foo" + } + + constructor(x: String, y: String): this(y.hashCode()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithInit.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithInit.fir.kt new file mode 100644 index 00000000000..04830ba3d15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithInit.fir.kt @@ -0,0 +1,7 @@ +class Foo { + lateinit var bar: String + + init { + bar = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructors.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructors.fir.kt new file mode 100644 index 00000000000..fd270a5b94a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructors.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var bar: String + + constructor() { + bar = "" + } + + constructor(baz: Int) { + bar = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructorsAndDelegation.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructorsAndDelegation.fir.kt new file mode 100644 index 00000000000..34ab09baf8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithMultipleConstructorsAndDelegation.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var bar: String + + constructor() { + bar = "" + } + + constructor(a: Int) : this() { + } + + constructor(a: Int, b: Int) : this(a) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPlusAssign.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPlusAssign.fir.kt new file mode 100644 index 00000000000..332526497b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPlusAssign.fir.kt @@ -0,0 +1,8 @@ +class Foo { + lateinit var bar: String + + constructor(baz: Int) { + // At best, we should have error here despite of lateinit + bar += baz + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPrimaryConstructorAndConstructor.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPrimaryConstructorAndConstructor.fir.kt new file mode 100644 index 00000000000..d1d946dbf1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/lateinitWithPrimaryConstructorAndConstructor.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo() { + lateinit var bar: String + + constructor(baz: Int) : this() { + bar = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinit.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinit.fir.kt new file mode 100644 index 00000000000..abee30f6f36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinit.fir.kt @@ -0,0 +1,7 @@ +class Foo { + lateinit var bar: String + + fun init() { + bar = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinitWithTwoConstructors.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinitWithTwoConstructors.fir.kt new file mode 100644 index 00000000000..2c54f35a1f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/normalLateinitWithTwoConstructors.fir.kt @@ -0,0 +1,9 @@ +class Foo { + lateinit var x: String + + constructor(y: String) { + x = y + } + + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt new file mode 100644 index 00000000000..510b7e292f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var bar: String + + constructor() { + bar = "" + } + + constructor(a: Int) : this(a) { + bar = "a" + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt new file mode 100644 index 00000000000..596b60c7c99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + lateinit var bar: String + + constructor() { + bar = "" + } + + constructor(a: Int) : this(a, 0, 0) { + } + + constructor(a: Int, b: Int) : this(a) { + } + + constructor(a: Int, b: Int, c: Int) : this(a, b) { + } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.fir.kt new file mode 100644 index 00000000000..f8e4734ccb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.fir.kt @@ -0,0 +1,49 @@ +// See KT-6665: unresolved reference (v.bar) should not produce "unreachable code" after it + +fun foo(): Int { + val v = 1 + val c = v.bar ?: return 0 + return 42 +} + +fun foo2(): Int { + val v = 1 + val c = if (true) v.bar else return 3 + val b = c + return 42 +} + +fun foo3(): Int { + val v = 1 + val c = when { + true -> v.bar + else -> return 3 + } + val b = c + return 42 +} + +// Type + ErrorType should give Type, unless Type is Nothing + +fun bar(): Int { + val v = 1 + val c = v.bar ?: 42 + return c +} + +fun bar2(): Int { + val v = 1 + val c = if (true) v.bar else 3 + val b = c + return b +} + +fun bar3(): Int { + val v = 1 + val c = when { + true -> v.bar + else -> 3 + } + val b = c + return b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.fir.kt new file mode 100644 index 00000000000..7495cd3595d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -SingleUnderscoreForParameterName +// See KT-8813, KT-9631 + +fun someApi(f: (Int) -> Unit) = f(42) + +fun test() { + someApi(fun(p: Int) {}) + // Apparently "p" cannot be removed because the signature is fixed by "someApi +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.fir.kt new file mode 100644 index 00000000000..9c6fef2ec46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.fir.kt @@ -0,0 +1,6 @@ +fun bar(f: () -> Unit) = f() + +fun foo() { + var v: Any + bar { v.hashCode() } +} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/varInitializationInIfInCycle.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/varInitializationInIfInCycle.fir.kt new file mode 100644 index 00000000000..5757b44bd08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/varInitializationInIfInCycle.fir.kt @@ -0,0 +1,15 @@ +fun foo(numbers: Collection) { + for (i in numbers) { + val b: Boolean + if (1 < 2) { + b = false + } + else { + b = true + } + use(b) + continue + } +} + +fun use(vararg a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/controlStructures/ForLoopWithExtensionIteratorOnNullable.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ForLoopWithExtensionIteratorOnNullable.fir.kt new file mode 100644 index 00000000000..b7ff32fb78a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ForLoopWithExtensionIteratorOnNullable.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// See also KT-7428 +class Container(val k: K) +// iterator() must be an extension, otherwise code will not compile +operator fun Container.iterator(): Iterator = null!! + +fun test() { + val container: Container? = null + // Error + container.iterator() + // for extension iterator, this code compiles, but should not + for (s in container) {} +} +class OtherContainer(val k: K) { + operator fun iterator(): Iterator = null!! +} + +fun test2() { + val other: OtherContainer? = null + // Error + for (s in other) {} +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.fir.kt new file mode 100644 index 00000000000..d79dd7e77e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.fir.kt @@ -0,0 +1,8 @@ +// http://youtrack.jetbrains.net/issue/KT-552 +// KT-552 For variable unresolved if loop body is not block + +fun ff() { + var i = 1 + for (j in 1..10) + i += j +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt new file mode 100644 index 00000000000..764126042c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt @@ -0,0 +1,11 @@ + +fun foo1() = while (b()) {} + +fun foo2() = for (i in 10) {} + +fun foo3() = when (b()) { + true -> 1 + else -> 0 +} + +fun b(): Boolean = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.fir.kt new file mode 100644 index 00000000000..44d55d0b17a --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.fir.kt @@ -0,0 +1,26 @@ +// JAVAC_EXPECTED_FILE +// See KT-9816, KT-9742 + +// Not allowed in Java +class ZException(val p: T) : Exception() + +class YException(val p: T): java.lang.RuntimeException() + +class XException(val p: T): Throwable() + +fun bar() { + try { + throw ZException(11) + } catch (e: ZException<*>) {} +} + +inline fun tryCatch(lazy: () -> R, failure: (E) -> R): R = + try { + lazy() + } catch (e: E) { + failure(e) + } + +fun tryCatch() { + try { } catch (e: T) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics.fir.kt new file mode 100644 index 00000000000..7f3299674df --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable +// !DIAGNOSTICS: -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE + +class OuterGeneric { + inner class ErrorInnerExn : Exception() + + inner class InnerA { + inner class ErrorInnerExn2 : Exception() + } + + class OkNestedExn : Exception() + + val errorAnonymousObjectExn = object : Exception() {} + + fun foo() { + class OkLocalExn : Exception() + + val errorAnonymousObjectExn = object : Exception() {} + } + + fun genericFoo() { + class OkLocalExn : Exception() + + class LocalGeneric { + inner class ErrorInnerExnOfLocalGeneric : Exception() + } + } +} + +class Outer { + inner class InnerGeneric { + inner class ErrorInnerExn : Exception() + } +} + +fun genericFoo() { + class ErrorLocalExnInGenericFun : Exception() + + val errorkAnonymousObjectExnInGenericFun = object : Exception() {} +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics_deprecation.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics_deprecation.fir.kt new file mode 100644 index 00000000000..cbe8d725b61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/catchInnerClassesOfGenerics_deprecation.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: -ProhibitInnerClassesOfGenericClassExtendingThrowable +// !DIAGNOSTICS: -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE + +class OuterGeneric { + inner class ErrorInnerExn : Exception() + + inner class InnerA { + inner class ErrorInnerExn2 : Exception() + } + + class OkNestedExn : Exception() + + val errorAnonymousObjectExn = object : Exception() {} + + fun foo() { + class OkLocalExn : Exception() + + val errorAnonymousObjectExn = object : Exception() {} + } + + fun genericFoo() { + class OkLocalExn : Exception() + + class LocalGeneric { + inner class ErrorInnerExnOfLocalGeneric : Exception() + } + } +} + +class Outer { + inner class InnerGeneric { + inner class ErrorInnerExn : Exception() + } +} + +fun genericFoo() { + class ErrorLocalExnInGenericFun : Exception() + + val errorkAnonymousObjectExnInGenericFun = object : Exception() {} +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchWithDefault.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/catchWithDefault.fir.kt new file mode 100644 index 00000000000..8e568f28604 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/catchWithDefault.fir.kt @@ -0,0 +1,3 @@ +fun test() { + try { } catch (e: Exception = Exception()) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchingLocalClassesCapturingTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/catchingLocalClassesCapturingTypeParameters.fir.kt new file mode 100644 index 00000000000..39925d38fef --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/catchingLocalClassesCapturingTypeParameters.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +ProhibitInnerClassesOfGenericClassExtendingThrowable +package test + +var global: Throwable? = null + +fun foo(x: Throwable, z: T, b: (T) -> Unit) { + class A(val y : T) : Exception() + + try { + throw x + } catch (a: A) { + b(a.y) + } catch (e: Throwable) { + global = A(z) + } +} + +fun main() { + foo(RuntimeException(), 1) { throw IllegalStateException() } + foo(global!!, "") { it.length } // (*) +} + +// (*): +//Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String +// at test.TestKt$main$2.invoke(test.kt) +// at test.TestKt.foo(test.kt:12) +// at test.TestKt.main(test.kt:21) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.fir.kt new file mode 100644 index 00000000000..b6c4f6021ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.fir.kt @@ -0,0 +1,30 @@ +// KT-6774 Cannot find equals() when comparing with null + +fun fn(t1: T, t2: T?) { + val x = if (true) t1 else t2 + x == null + x?.equals(null) + x?.hashCode() + x.toString() + x!!.hashCode() + + val y = t2 ?: t1 + y == t1 + y.equals(null) + y.hashCode() + y.toString() + y.hashCode() +} + +interface Tr { + fun foo() +} + +fun fn(t1: T, t2: T?) { + val x = if (true) t1 else t2 + x?.foo() + x!!.foo() + + val y = t2 ?: t1 + y.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt new file mode 100644 index 00000000000..626811aacc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt @@ -0,0 +1,53 @@ +fun test1() { + test1@ for(i in 1..2) { + continue@test1 + } +} + +fun test2() { + test2@ while (true) { + break@test2 + } +} + +class Test3 { + fun Test3() { + Test3@ while (true) { + break@Test3 + } + } +} + +fun test4() { + break@test4 +} + +class Test5 { + fun Test5 { + return@Test5 + } +} + +class Test6 { + fun Test6() { + Test6@ while (true) { + break@Test6 + } + + Test6@ while (true) { + break@Test6 + } + } +} + +class Test7 { + fun Test7() { + Test8@ while (true) { + break@Test7 + } + + Test7@ while (true) { + break@Test8 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.fir.kt new file mode 100644 index 00000000000..761a023dac8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.fir.kt @@ -0,0 +1,16 @@ +fun foo(x: Unit) = x + +fun test() { + if (false); + if (true); + + val x = if (false); + foo(x) + + val y: Unit = if (false); + foo(y) + + foo({if (1==1);}()) + + return if (true); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.fir.kt new file mode 100644 index 00000000000..596d3d773b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/forLoopWithNullableRange.fir.kt @@ -0,0 +1,16 @@ +class Coll { + operator fun iterator(): It = It() +} + +class It { + operator fun next() = 1 + operator fun hasNext() = false +} + +fun test(c: Coll?) { + for (x in c) {} + + if (c != null) { + for(x in c) {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/forWithNullableIterator.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/forWithNullableIterator.fir.kt new file mode 100644 index 00000000000..3fa6d25c9b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/forWithNullableIterator.fir.kt @@ -0,0 +1,12 @@ +class Coll { + operator fun iterator(): It? = null +} + +class It { + operator fun next() = 1 + operator fun hasNext() = false +} + +fun test() { + for (x in Coll()) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt new file mode 100644 index 00000000000..d36e959db14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt @@ -0,0 +1,55 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// See also KT-10896: Wrong inference of if / else result type + +interface Option +class Some : Option +class None : Option + +fun bind(r: Option): Option { + return if (r is Some) { + // Ideally we should infer Option here (see KT-10896) + (if (true) None() else r) checkType { _>() } + // Works correctly + if (true) None() else r + } + else r +} + +fun bind2(r: Option): Option { + return if (r is Some) { + // Works correctly + if (true) None() else r + } + else r +} + +fun bind3(r: Option): Option { + return if (r is Some) { + // Diagnoses an error correctly + if (true) None() else r + } + else r +} + +fun bindWhen(r: Option): Option { + return when (r) { + is Some -> { + // Works correctly + if (true) None() else r + } + else -> r + } +} + +interface SimpleOption +class SimpleSome : SimpleOption +class SimpleNone : SimpleOption + +fun bindNoGeneric(r: SimpleOption): SimpleOption { + return if (r is SimpleSome) { + (if (true) SimpleNone() else r) checkType { _() } + if (true) SimpleNone() else r + } + else r +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifInResultOfLambda.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifInResultOfLambda.fir.kt new file mode 100644 index 00000000000..38c443697eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ifInResultOfLambda.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +val test1 = { if (true) 1 else "" } + +val test2 = { { if (true) 1 else "" } } + +val test3: (Boolean) -> Any = { if (it) 1 else "" } + +val test4: (Boolean) -> Any? = { if (it) 1 else "" } diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt new file mode 100644 index 00000000000..e51b1f00981 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt @@ -0,0 +1,62 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun println() {} +fun foo(x: Any) {} +fun fooGeneric(x: T) {} + +fun testResultOfLambda1() = + run { + if (true) 42 else println() + } + +fun testResultOfLambda2() = + run { + if (true) 42 else if (true) 42 else println() + } + +fun testResultOfAnonFun1() = + run(fun () = + if (true) 42 + else println() + ) + +fun testResultOfAnonFun2() = + run(fun () { + if (true) 42 else println() + }) + +fun testReturnFromAnonFun() = + run(fun () { + return if (true) 42 else println() + }) + +fun testReturn1() = + run { + return if (true) 42 + else println() + } + +fun testReturn2() = + run { + return if (true) 42 + else if (true) 42 + else println() + } + +fun testUsage1() = + if (true) 42 + else println() + +fun testUsage2() = + foo(if (true) 42 else println()) + +fun testUsage2Generic() = + fooGeneric(if (true) 42 else println()) + +val testUsage3 = + if (true) 42 + else println() + +val testUsage4: Any get() = + if (true) 42 else println() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.fir.kt new file mode 100644 index 00000000000..bd173b19cde --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun println() {} +fun foo(x: Any) {} +fun fooGeneric(x: T) {} + +fun testMixedIfAndWhen() = + if (true) + when { + true -> if (true) 42 + else 1 + true -> if (true) 42 + else println() + else -> if (true) println() + } + else println() + +fun testWrappedExpressions() = + if (true) { + println() + if (true) { + println() + if (true) { + println() + } + else {} + } + } + else { + (((((42)) + 1))) + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.fir.kt new file mode 100644 index 00000000000..ee00a4e882d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.fir.kt @@ -0,0 +1,86 @@ +// !WITH_NEW_INFERENCE +fun idAny(x: Any) = x +fun id(x: T) = x +fun idUnit(x: Unit) = x + +class MList { + // MutableCollection.add returns Boolean, but nobody cares + fun add(): Boolean = true +} +val mlist = MList() + +fun work() {} + +val xx1 = if (true) 42 +val xx2: Unit = if (true) 42 +val xx3 = idAny(if (true) 42) +val xx4 = id(if (true) 42) +val xx5 = idUnit(if (true) 42) +val xx6 = null ?: if (true) 42 +val xx7 = "" + if (true) 42 + +val wxx1 = when { true -> 42 } +val wxx2: Unit = when { true -> 42 } +val wxx3 = idAny(when { true -> 42 }) +val wxx4 = id(when { true -> 42 }) +val wxx5 = idUnit(when { true -> 42 }) +val wxx6 = null ?: when { true -> 42 } +val wxx7 = "" + when { true -> 42 } + +val fn1 = { if (true) 42 } +val fn2 = { if (true) mlist.add() } +val fn3 = { if (true) work() } +val fn4 = { when { true -> 42 } } +val fn5 = { when { true -> mlist.add() } } +val fn6 = { when { true -> work() } } + +val ufn1: () -> Unit = { if (true) 42 } +val ufn2: () -> Unit = { if (true) mlist.add() } +val ufn3: () -> Unit = { if (true) work() } +val ufn4: () -> Unit = { when { true -> 42 } } +val ufn5: () -> Unit = { when { true -> mlist.add() } } +val ufn6: () -> Unit = { when { true -> work() } } + +fun f1() = if (true) work() +fun f2() = if (true) mlist.add() +fun f3() = if (true) 42 +fun f4(): Unit = if (true) work() +fun f5(): Unit = if (true) mlist.add() +fun f6(): Unit = if (true) 42 +fun g1() = when { true -> work() } +fun g2() = when { true -> mlist.add() } +fun g3() = when { true -> 42 } +fun g4(): Unit = when { true -> work() } +fun g5(): Unit = when { true -> mlist.add() } +fun g6(): Unit = when { true -> 42 } + +fun foo1(x: String?) { + "" + if (true) 42 + w@while (true) { + x ?: if (true) break + x ?: when { true -> break@w } + } +} + +fun foo2() { + if (true) { + mlist.add() + } + else if (true) { + mlist.add() + } + else if (true) { + mlist.add() + } + + when { + true -> mlist.add() + else -> when { + true -> mlist.add() + else -> when { + true -> mlist.add() + } + } + } +} + diff --git a/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.fir.kt new file mode 100644 index 00000000000..b5d318da51f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.fir.kt @@ -0,0 +1,34 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun example() { + val a = if (true) true else false + val b = if (true) else false + val c = if (true) true + val d = if (true) true else; + val e = if (true) {} else false + val f = if (true) true else {} + + { + if (true) true + }(); + + { + if (true) true else false + }(); + + { + if (true) {} else false + }(); + + + { + if (true) true else {} + }() + + fun t(): Boolean { + return if (true) true + } + + return if (true) true else {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/jumpAcrossFunctionBoundary.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/jumpAcrossFunctionBoundary.fir.kt new file mode 100644 index 00000000000..188f881d28d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/jumpAcrossFunctionBoundary.fir.kt @@ -0,0 +1,17 @@ +fun call(f: () -> Unit) = f() + +fun f1() { + outer@ while (true) { + call { + break@outer + } + } +} + +fun f2() { + do { + fun inner() { + continue + } + } while (true) +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10322.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10322.fir.kt new file mode 100644 index 00000000000..42d730e7515 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10322.fir.kt @@ -0,0 +1,10 @@ +fun test1() { + run { + if (true) { + if (true) {} + } + else { + 1 + } + } +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10706.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10706.fir.kt new file mode 100644 index 00000000000..3f6ff3a7a21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10706.fir.kt @@ -0,0 +1,10 @@ +fun fn(c: Char?): Any? = + if (c == null) TODO() + else when (c) { + 'a' -> when (c) { + 'B' -> 1 + 'C' -> "sdf" + else -> TODO() + } + else -> TODO() + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt new file mode 100644 index 00000000000..1389d9e036d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_PARAMETER -RETURN_NOT_ALLOWED + +fun test1() = run { + return "OK" +} + +fun test2() = run { + fun local(): String { + return "" + } + return "" +} + +inline fun Iterable.map(transform: (T) -> R): List = null!! +fun test3(a: List, b: List) = a.map { + if (it.length == 3) return null + if (it.length == 4) return "" + if (it.length == 4) return 5 + if (it.length == 4) return b + 1 +} + +fun test4() = run { + fun test5() { + return + + return@test4 + + return return@test4 + + return fun() { return; return@test4 "" } + } + + return + 3 +} + +val foo: Int + get() = run { + if (true) return "" + + return + } + +fun test(): Int = run { + return "" +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt1075.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt1075.fir.kt new file mode 100644 index 00000000000..6883418762e --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt1075.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +package kt1075 + +//KT-1075 No type check for 'in range' condition in 'when' expression + +fun foo(b: String) { + if (b in 1..10) {} //type mismatch + when (b) { + in 1..10 -> 1 //no type mismatch, but it should be here + else -> 2 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt30406.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt30406.fir.kt new file mode 100644 index 00000000000..84e3d4291e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt30406.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// !CHECK_TYPE +// Issue: KT-30406 + +interface Option { + val s: String +} +class Some(override val s: String) : Option +class None(override val s: String = "None") : Option + +fun test(a: Int): Option = + if (a == 239) + Some("239") + else + None() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt4310.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt4310.fir.kt new file mode 100644 index 00000000000..4096d674340 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt4310.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +package f + +fun test(a: Boolean, b: Boolean): Int { + return if(a) { + 1 + } else { + if (b) { + 3 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt new file mode 100644 index 00000000000..4e9d18ad852 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt @@ -0,0 +1,20 @@ +//KT-657 Semantic checks for when without condition +package kt657 + +class Pair(a: A, b: B) + +fun foo() = + when { + cond1() -> 12 + cond2() -> 2 + 4 -> 34 + Pair(1, 2) -> 3 + in 1..10 -> 34 + 4 -> 38 + is Int -> 33 + else -> 34 + } + +fun cond1() = false + +fun cond2() = true diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt new file mode 100644 index 00000000000..04ddcacfd16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt @@ -0,0 +1,163 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNREACHABLE_CODE +package kt770_351_735 + + +//KT-770 Reference is not resolved to anything, but is not marked unresolved +fun main() { + var i = 0 + when (i) { + 1 -> i-- + 2 -> i = 2 // i is surrounded by a black border + else -> j = 2 + } + System.out.println(i) +} + +//KT-351 Distinguish statement and expression positions +val w = while (true) {} + +fun foo() { + var z = 2 + val r = { // type fun(): Any is inferred + if (true) { + 2 + } + else { + z = 34 + } + } + val f: ()-> Int = r + val g: ()-> Any = r +} + +//KT-735 Statements without braces are prohibited on the right side of when entries. +fun box() : Int { + val d = 2 + var z = 0 + when(d) { + 5, 3 -> z++ + else -> z = -1000 + } + return z +} + +//More tests + +fun test1() { while(true) {} } +fun test2(): Unit { while(true) {} } + +fun testCoercionToUnit() { + val simple: ()-> Unit = { + 41 + } + val withIf: ()-> Unit = { + if (true) { + 3 + } else { + 45 + } + } + val i = 34 + val withWhen : () -> Unit = { + when(i) { + 1 -> { + val d = 34 + "1" + doSmth(d) + + } + 2 -> '4' + else -> true + } + } + + var x = 43 + val checkType = { + if (true) { + x = 4 + } else { + 45 + } + } + val f : () -> String = checkType +} + +fun doSmth(i: Int) {} + +fun testImplicitCoercion() { + val d = 21 + var z = 0 + var i = when(d) { + 3 -> null + 4 -> { val z = 23 } + else -> z = 20 + } + + var u = when(d) { + 3 -> { + z = 34 + } + else -> z-- + } + + var iff = if (true) { + z = 34 + } + val g = if (true) 4 + val h = if (false) 4 else {} + + bar(if (true) { + 4 + } + else { + z = 342 + }) +} + +fun fooWithAnyArg(arg: Any) {} +fun fooWithAnyNullableArg(arg: Any?) {} + +fun testCoercionToAny() { + val d = 21 + val x1: Any = if (1>2) 1 else 2.0 + val x2: Any? = if (1>2) 1 else 2.0 + val x3: Any? = if (1>2) 1 else (if (1>2) null else 2.0) + + fooWithAnyArg(if (1>2) 1 else 2.0) + fooWithAnyNullableArg(if (1>2) 1 else 2.0) + fooWithAnyNullableArg(if (1>2) 1 else (if (1>2) null else 2.0)) + + val y1: Any = when(d) { 1 -> 1.0 else -> 2.0 } + val y2: Any? = when(d) { 1 -> 1.0 else -> 2.0 } + val y3: Any? = when(d) { 1 -> 1.0; 2 -> null; else -> 2.0 } + + fooWithAnyArg(when(d) { 1 -> 1.0 else -> 2.0 }) + fooWithAnyNullableArg(when(d) { 1 -> 1.0 else -> 2.0 }) + fooWithAnyNullableArg(when(d) { 1 -> 1.0; 2 -> null; else -> 2.0 }) +} + +fun fooWithAnuNullableResult(s: String?, name: String, optional: Boolean): Any? { + return if (s == null) { + if (!optional) { + throw java.lang.IllegalArgumentException("Parameter '$name' was not found in the request") + } + null + } else { + name + } +} + +fun bar(a: Unit) {} + +fun testStatementInExpressionContext() { + var z = 34 + val a1: Unit = z = 334 + val f = for (i in 1..10) {} + if (true) return z = 34 + return while (true) {} +} + +fun testStatementInExpressionContext2() { + val a2: Unit = while(true) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt786.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt786.fir.kt new file mode 100644 index 00000000000..26d6aeb6e5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt786.fir.kt @@ -0,0 +1,26 @@ +package kt786 + +//KT-786 Exception on incomplete code with 'when' +fun foo() : Int { + val d = 2 + var z = 0 + when(d) { + 5, 3 -> z++ + else -> { z = -1000 } + return z -> 34 + } +} + +//test unreachable code +fun fff(): Int { + var d = 3 + when(d) { + 4 -> 21 + return 2 -> return 47 + bar() -> 45 + 444 -> true + } + return 34 +} + +fun bar(): Int = 8 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt799.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt799.fir.kt new file mode 100644 index 00000000000..27b31997a8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt799.fir.kt @@ -0,0 +1,25 @@ +//KT-799 Allow 'return' expressions in conditionals assigned to variables + +package kt799 + +fun test() { + val a : Int = if (true) 6 else return // should be allowed + + val b = if (true) 6 else return // should be allowed + + doSmth(if (true) 3 else return) + + doSmth(if (true) 3 else return, 1) +} + +val a : Nothing = return 1 + +val b = return 1 + +val c = doSmth(if (true) 3 else return) + + +fun f(mi: Int = if (true) 0 else return) {} + +fun doSmth(i: Int) { +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt new file mode 100644 index 00000000000..f4dc5a89eb4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/lambdasInExclExclAndElvis.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun use(a: Any?) = a + +fun test() { + { }!! + use({ }!!); + + // KT-KT-9070 + { } ?: 1 + use({ 2 } ?: 1); + + 1 ?: { } + use(1 ?: { }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.fail b/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.fail index d94cf374132..d552b3e6439 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.fail +++ b/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.fail @@ -1,2 +1,2 @@ -Failures detected in FirImplicitTypeBodyResolveTransformerAdapter, file: /localReturnInsidePropertyAccessor.kt +Failures detected in FirImplicitTypeBodyResolveTransformerAdapter, file: /localReturnInsidePropertyAccessor.fir.kt Cause: kotlin.KotlinNullPointerException diff --git a/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.kt new file mode 100644 index 00000000000..310a467d293 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/localReturnInsidePropertyAccessor.fir.kt @@ -0,0 +1,20 @@ +interface ClassData + +fun f() = object : ClassData { + val someInt: Int + get() { + return 5 + } +} + +fun g() = object : ClassData { + init { + if (true) { + return 0 + } + } + + fun some(): Int { + return 6 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt new file mode 100644 index 00000000000..fd20b9f612b --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt @@ -0,0 +1,62 @@ +// !LANGUAGE: +RestrictReturnStatementTarget + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun testFunctionName() { + return@testFunctionName +} + +fun testHighOrderFunctionName() { + run { + return@run + } +} + +fun testLambdaLabel() = + lambda@ { + return@lambda + } + +fun testParenthesizedLambdaLabel() = + lambda@ ( { + return@lambda + } ) + +fun testAnnotatedLambdaLabel() = + lambda@ @Ann { + return@lambda + } + +fun testLambdaMultipleLabels1() = + lambda1@ lambda2@ { + return@lambda1 + } + +fun testLambdaMultipleLabels2() = + lambda1@ lambda2@ { + return@lambda2 + } + +fun testAnonymousFunctionLabel() = + anonFun@ fun() { + return@anonFun + } + +fun testLoopLabelInReturn(xs: List) { + L@ for (x in xs) { + if (x > 0) return@L + } +} + +fun testValLabelInReturn() { + L@ val fn = { return@L } + fn() +} + +fun testHighOrderFunctionCallLabelInReturn() { + L@ run { + return@L + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt new file mode 100644 index 00000000000..1a09741d73d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt @@ -0,0 +1,62 @@ +// !LANGUAGE: -RestrictReturnStatementTarget + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun testFunctionName() { + return@testFunctionName +} + +fun testHighOrderFunctionName() { + run { + return@run + } +} + +fun testLambdaLabel() = + lambda@ { + return@lambda + } + +fun testParenthesizedLambdaLabel() = + lambda@ ( { + return@lambda + } ) + +fun testAnnotatedLambdaLabel() = + lambda@ @Ann { + return@lambda + } + +fun testLambdaMultipleLabels1() = + lambda1@ lambda2@ { + return@lambda1 + } + +fun testLambdaMultipleLabels2() = + lambda1@ lambda2@ { + return@lambda2 + } + +fun testAnonymousFunctionLabel() = + anonFun@ fun() { + return@anonFun + } + +fun testLoopLabelInReturn(xs: List) { + L@ for (x in xs) { + if (x > 0) return@L + } +} + +fun testValLabelInReturn() { + L@ val fn = { return@L } + fn() +} + +fun testHighOrderFunctionCallLabelInReturn() { + L@ run { + return@L + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt new file mode 100644 index 00000000000..84449239afa --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt @@ -0,0 +1,39 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class Ann + +fun testLambdaLabel() = l@ { 42 } + +fun testAnonymousFunctionLabel() = l@ fun() {} + +fun testAnnotatedLambdaLabel() = lambda@ @Ann {} + +fun testParenthesizedLambdaLabel() = lambda@ ( {} ) + +fun testLabelBoundToInvokeOperatorExpression() = l@ { 42 }() + +fun testLabelBoundToLambda() = (l@ { 42 })() + +fun testWhileLoopLabel() { + L@ while (true) {} +} + +fun testDoWhileLoopLabel() { + L@ do {} while (true) +} + +fun testForLoopLabel(xs: List) { + L@ for (x in xs) {} +} + +fun testValLabel() { + L@ val fn = {} + fn() +} + +fun testHighOrderFunctionCallLabel() { + L@ run {} +} + +fun testAnonymousObjectLabel() = + L@ object {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt new file mode 100644 index 00000000000..133ac6dee04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt @@ -0,0 +1,40 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java +import java.util.*; + +public class J { + public static String s = null; + public static Map m = null; +} + +// FILE: k.kt + +val testImplicitExclExcl1: String = J.s +val testImplicitExclExcl2: String? = J.s + +val testImplicitExclExcl3: String = J.m[""] +val testImplicitExclExcl4: String? = J.m[""] + +val testExclExcl1: String = J.s!! +val testExclExcl2: String? = J.s!! + +val testExclExcl3: String = J.m[""]!! +val testExclExcl4: String? = J.m[""]!! + +val testSafeCall1: String = J.s?.let { it } +val testSafeCall2: String? = J.s?.let { it } + +val testSafeCall3: String = J.m[""]?.let { it } +val testSafeCall4: String? = J.m[""]?.let { it.toString() } + +val testIf1: String = if (true) J.s else J.s +val testIf2: String? = if (true) J.s else J.s + +val testIf3: String = if (true) J.m[""] else J.m[""] +val testIf4: String? = if (true) J.m[""] else J.m[""] + +val testWhen1: String = when { else -> J.s } +val testWhen2: String? = when { else -> J.s } + +val testWhen3: String = when { else -> J.m[""] } +val testWhen4: String? = when { else -> J.m[""] } diff --git a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsWithNullableExpectedType.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsWithNullableExpectedType.fir.kt new file mode 100644 index 00000000000..0e8ec5e19de --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsWithNullableExpectedType.fir.kt @@ -0,0 +1,20 @@ +val ns: String? = null + +val testElvis1: String? = ns ?: "" +val testElvis2: String = run { ns ?: "" } +val testElvis3: String? = run { ns ?: "" } + +val testIf1: String? = if (true) "" else "" +val testIf2: String? = run { if (true) "" else "" } +val testIf3: String? = if (true) run { "" } else "" +val testIf4: String? = run { run { if (true) "" else "" } } +val testIf5: String? = run { if (true) run { "" } else "" } + +val testWhen1: String? = when { else -> "" } +val testWhen2: String? = run { when { else -> "" } } +val testWhen3: String? = when { else -> run { "" } } +val testWhen4: String? = run { run { when { else -> "" } } } +val testWhen5: String? = run { when { else -> run { "" } } } + +val testExcl1: String? = run { ns!! } +val testExcl2: String? = run { run { ns!! } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.fir.kt new file mode 100644 index 00000000000..77b157a446e --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/tryReturnType.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo() : Int { + try { + doSmth() + } + catch (e: Exception) { + return "" + } + finally { + return "" + } +} + +fun bar() : Int = + try { + doSmth() + } + catch (e: Exception) { + "" + } + finally { + "" + } + + +fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/controlStructures/typeInferenceForExclExcl.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/typeInferenceForExclExcl.fir.kt new file mode 100644 index 00000000000..b136b408f54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/typeInferenceForExclExcl.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: A.java +public class A { + public static String foo() { + return ""; + } +} + +// FILE: b.kt +fun exclExcl(t: T?): T = t!! + +fun test11() { + // not 'String!' + exclExcl(A.foo()) checkType { _() } + exclExcl(A.foo()) checkType { _() } + + // not 'String!' + A.foo()!! checkType { _() } + A.foo()!! checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.fir.kt new file mode 100644 index 00000000000..f9b78e45309 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.fir.kt @@ -0,0 +1,13 @@ +fun f() { + try { + } catch (val e: Exception) { + } + + try { + } catch (var e: Exception) { + } + + try { + } catch (e: Exception) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.fir.kt new file mode 100644 index 00000000000..54716ccce9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.fir.kt @@ -0,0 +1,32 @@ +class Pair { + operator fun component1(): Int = null!! + operator fun component2(): Int = null!! +} + +class Coll { + operator fun iterator(): It = It() +} + +class It { + operator fun next() = Pair() + operator fun hasNext() = false +} + + +fun f() { + for (val i in 1..4) { + + } + + for (var i in 1..4) { + + } + + for (val (i,j) in Coll()) { + + } + + for (var (i,j) in Coll()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/when.fir.kt234.fir.kt973.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/when.fir.kt234.fir.kt973.fir.kt new file mode 100644 index 00000000000..b7fb0ec8796 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/when.fir.kt234.fir.kt973.fir.kt @@ -0,0 +1,41 @@ +//KT-234 Force when() expressions to have an 'else' branch +//KT-973 Unreachable code + +package kt234_kt973 + +class Pair(a: A, b: B) + +fun test(t : Pair) : Int { + when (t) { + Pair(10, 10) -> return 1 + } + return 0 // unreachable code +} + +fun test1(t : Pair) : Int { + when (t) { + Pair(10, 10) -> return 1 + else -> return 2 + } + return 0 // unreachable code +} + +//more tests +fun t1(x: Int) = when(x) { + else -> 1 +} + +fun t5(x: Int) = when (x) { + is Int -> 1 + 2 -> 2 +} + +fun foo3(x: Int) = when(x) { + else -> 1 + 2 -> 2 +} + +fun foo4(x: Int) = when(x) { + 2 -> x + else -> 3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/whenInResultOfLambda.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/whenInResultOfLambda.fir.kt new file mode 100644 index 00000000000..f7373d7a573 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/whenInResultOfLambda.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +val test1 = { when (true) { true -> 1; else -> "" } } + +val test2 = { { when (true) { true -> 1; else -> "" } } } + +val test3: (Boolean) -> Any = { when (true) { true -> 1; else -> "" } } + +val test4: (Boolean) -> Any? = { when (true) { true -> 1; else -> "" } } + +fun println() {} + +val test5 = { + when (true) { + true -> println() + else -> println() + } +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/whenToAnyDiscriminatingUsages.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/whenToAnyDiscriminatingUsages.fir.kt new file mode 100644 index 00000000000..96c68ac62d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/whenToAnyDiscriminatingUsages.fir.kt @@ -0,0 +1,83 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun println() {} +fun foo(x: Any) {} +fun fooGeneric(x: T) {} + +fun testResultOfLambda1() = + run { + when { + true -> 42 + else -> println() + } + } + +fun testResultOfLambda2() = + run { + when { + true -> 42 + else -> + when { + true -> 42 + else -> println() + } + } + } + +fun testReturn1() = + run { + return when { + true -> 42 + else -> println() + } + } + +fun testReturn2() = + run { + return when { + true -> 42 + else -> + when { + true -> 42 + else -> println() + } + } + } + +fun testUsage1() = + when { + true -> 42 + else -> println() + } + +fun testUsage2() = + foo(when { + true -> 42 + else -> println() + }) + +fun testUsage2Generic() = + fooGeneric(when { + true -> 42 + else -> println() + }) + +val testUsage3 = + when { + true -> 42 + else -> println() + } + +val testUsage4 = + when { + true -> 42 + true -> 42 + true -> 42 + else -> println() + } + +val testUsage5: Any get() = + when { + true -> 42 + else -> println() + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/callableReference/invokeOutideSuspend.fir.kt b/compiler/testData/diagnostics/tests/coroutines/callableReference/invokeOutideSuspend.fir.kt new file mode 100644 index 00000000000..a335dcf87c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/callableReference/invokeOutideSuspend.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +Coroutines +// SKIP_TXT + +import kotlin.reflect.KSuspendFunction0 + +fun test(c: KSuspendFunction0) { + c() +} diff --git a/compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.fir.kt b/compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.fir.kt new file mode 100644 index 00000000000..a3c6e936dbf --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE +// !LANGUAGE: +ReleaseCoroutines +// SKIP_TXT + +import kotlin.reflect.KSuspendFunction0 + +suspend fun foo() {} + +fun test() { + ::foo checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/classIndirectlyInheritsNested.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/classIndirectlyInheritsNested.fir.kt new file mode 100644 index 00000000000..3eb40751586 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/classIndirectlyInheritsNested.fir.kt @@ -0,0 +1,4 @@ +open class C : D() { + open class CC +} +open class D : C.CC() diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/classInheritsNested.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/classInheritsNested.fir.kt new file mode 100644 index 00000000000..8fa8ed8d9d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/classInheritsNested.fir.kt @@ -0,0 +1,3 @@ +open class E : E.EE() { + open class EE +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicAndUsualTypes.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicAndUsualTypes.fir.kt new file mode 100644 index 00000000000..77feb341b84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicAndUsualTypes.fir.kt @@ -0,0 +1,8 @@ +open class A : B() +open class B : A() + +fun select(vararg xs: T): T = xs[0] + +fun foo() { + val x = select(A(), B(), "foo") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicTypes.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicTypes.fir.kt new file mode 100644 index 00000000000..0f45068f764 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/commonSupertypeForCyclicTypes.fir.kt @@ -0,0 +1,8 @@ +open class A : B() +open class B : A() + +fun select(vararg xs: T): T = xs[0] + +fun foo() { + select(A(), B()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/cyclicHierarchy.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/cyclicHierarchy.fir.kt new file mode 100644 index 00000000000..0eaf10e17e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/cyclicHierarchy.fir.kt @@ -0,0 +1,30 @@ +interface A { + fun foo() {} +} +interface B : A, E {} +interface C : B {} +interface D : B {} +interface E : F {} +interface F : D, C {} +interface G : F {} +interface H : F {} + +val a : A? = null +val b : B? = null +val c : C? = null +val d : D? = null +val e : E? = null +val f : F? = null +val g : G? = null +val h : H? = null + +fun test() { + a?.foo() + b?.foo() + c?.foo() + d?.foo() + e?.foo() + f?.foo() + g?.foo() + h?.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaCycle.fir.kt new file mode 100644 index 00000000000..f7631022981 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaCycle.fir.kt @@ -0,0 +1,28 @@ +// FILE: A.java + +public interface A extends A { + int getFoo(); +} + +// FILE: B.java + +public class B { + interface B1 extends B2 { + int getFoo(); + } + interface B2 extends B3 { + int getFoo(); + } + interface B3 extends B2 { + int getFoo(); + } +} + +// FILE: main.kt +fun foo() { + object : A { override fun getFoo() = 1 } + object : B.B1 { override fun getFoo() = 1 } + object : B.B2 { override fun getFoo() = 1 } + object : B.B3 { override fun getFoo() = 1 } +} + diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaNested.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaNested.fir.kt new file mode 100644 index 00000000000..82a5d2f8eb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaJavaNested.fir.kt @@ -0,0 +1,24 @@ +// FILE: A.java + +public interface A extends A.B { + interface B extends A { public int getFoo() { return 1; } } +} + +// FILE: A0.java +public interface A0 extends A0.B { + interface B { public int getFoo() { return 1; } } +} + +// FILE: B.java + +public class B extends D { + public int getFoo() { return 1; } + public static class C { + public int getFoo() { return 1; } + } +} + +// FILE: D.java +public class D extends B.C { + public int getFoo() { return 1; } +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/javaKotlinJavaCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaKotlinJavaCycle.fir.kt new file mode 100644 index 00000000000..12cc4ee45a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/javaKotlinJavaCycle.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java + +interface A extends C { + void foo(); +} + +// FILE: B.kt + +interface B : A { + fun bar() +} + +// FILE: C.java + +interface C extends B { + void baz(); +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.kt new file mode 100644 index 00000000000..e05df739ef9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaCycle.fir.kt @@ -0,0 +1,11 @@ +// FILE: J.java + +class J extends K { + void foo() {} +} + +// FILE: K.kt + +class K : J() { + fun bar() {} +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.fir.kt new file mode 100644 index 00000000000..c805d4c1799 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.fir.kt @@ -0,0 +1,17 @@ +// FILE: I.kt + +open class I : K() { + fun foo() {} +} + +// FILE: J.java + +class J extends I { + void bar() {} +} + +// FILE: K.kt + +open class K : J() { + fun baz() {} +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.fir.kt new file mode 100644 index 00000000000..bcd66b00875 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.fir.kt @@ -0,0 +1,21 @@ +// FILE: ExceptionTracker.kt + +interface ExceptionTracker : LockBasedStorageManager.ExceptionHandlingStrategy { +} + +// FILE: StorageManager.kt + +interface StorageManager : ExceptionTracker { + fun foo() +} + +// FILE: LockBasedStorageManager.java + +class LockBasedStorageManager extends StorageManager { + interface ExceptionHandlingStrategy { + void bar(); + } + + @Override + void foo() {} +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kt303.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kt303.fir.kt new file mode 100644 index 00000000000..725831b1992 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kt303.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// KT-303 Stack overflow on a cyclic class hierarchy + +open class Foo() : Bar() { + val a : Int = 1 +} + +open class Bar() : Foo() { + +} + +val x : Int = Foo() diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/nestedClassInSuperClassParameter.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/nestedClassInSuperClassParameter.fir.kt new file mode 100644 index 00000000000..f33ddf14c37 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/nestedClassInSuperClassParameter.fir.kt @@ -0,0 +1,5 @@ +open class X + +class A: X() { + class B +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/objectInheritsNested.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/objectInheritsNested.fir.kt new file mode 100644 index 00000000000..554aa01effa --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/objectInheritsNested.fir.kt @@ -0,0 +1,22 @@ +// As in KT-18514 +object A : A.I { + interface I +} + +// Similar to 'classIndirectlyInheritsNested.kt' +object D : E() { + open class NestedD +} + +open class E : D.NestedD() + + + +// Similar to 'twoClassesWithNestedCycle.kt' +object G : H.NestedH() { + open class NestedG +} +object H : G.NestedG() { + open class NestedH +} + diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/twoClassesWithNestedCycle.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/twoClassesWithNestedCycle.fir.kt new file mode 100644 index 00000000000..d989abdff0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/twoClassesWithNestedCycle.fir.kt @@ -0,0 +1,6 @@ +open class A : B.BB() { + open class AA +} +open class B : A.AA() { + open class BB +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_after.fir.kt new file mode 100644 index 00000000000..971fc966757 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_after.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +open class Container { + open class Base { + open fun m() {} + } + + // note that Base() supertype will be resolved in scope that was created on recursion + abstract class DerivedAbstract : Base() + + companion object : DerivedAbstract() { + override fun m() {} + } +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_before.fir.kt new file mode 100644 index 00000000000..873ec0acf71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/everythingInOneScope_before.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +open class Container { + open class Base { + open fun m() {} + } + + // note that Base() supertype will be resolved in scope that was created on recursion + abstract class DerivedAbstract : Base() + + companion object : DerivedAbstract() { + override fun m() {} + } +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt new file mode 100644 index 00000000000..e25e2bfd70f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +abstract class DerivedAbstract : C.Base() { + open class Data +} + +public class C { + + open class Base () + + class Foo : Data() + + companion object : DerivedAbstract() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt new file mode 100644 index 00000000000..7f56616a319 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +abstract class DerivedAbstract : C.Base() { + open class Data +} + +public class C { + + open class Base () + + class Foo : Data() + + companion object : DerivedAbstract() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_after.fir.kt new file mode 100644 index 00000000000..350e095af2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_after.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +open class Container { + // Note that here we also have errors and diagnostics, even though there are actually no loops. + // (this is case because we can't know if there are any loops without resolving, but resolving + // itself provokes loops) + + interface Base { + open fun m() {} + } + + interface DerivedAbstract : Base + + companion object : DerivedAbstract { + override fun m() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_before.fir.kt new file mode 100644 index 00000000000..f9d0268fe6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/onlyInterfaces_before.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +open class Container { + // Note that here we also have errors and diagnostics, even though there are actually no loops. + // (this is case because we can't know if there are any loops without resolving, but resolving + // itself provokes loops) + + interface Base { + open fun m() {} + } + + interface DerivedAbstract : Base + + companion object : DerivedAbstract { + override fun m() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/typeIsLowEnough.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/typeIsLowEnough.fir.kt new file mode 100644 index 00000000000..e7d57338d70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/typeIsLowEnough.fir.kt @@ -0,0 +1,20 @@ +// see https://youtrack.jetbrains.com/issue/KT-21515 + +abstract class DerivedAbstract : C.Base() { + override abstract fun m() +} + +public class C { + class Data + + open class Base () { + open fun m() {} + } + + // Note that Data is resolved successfully here because we don't step on error-scope + val data: Data = Data() + + companion object : DerivedAbstract() { + override fun m() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_after.fir.kt new file mode 100644 index 00000000000..b402ba85820 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_after.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +interface SomeIrrelevantInterface + +// note that C.Base() supertype will be resolved in normal scope +abstract class DerivedAbstract : C.Base() + +class Data + +public class C { + + val data: Data = Data() + + // Note that any supertype of Base will be resolved in error-scope, even if it absolutely irrelevant + // to the types in cycle. + open class Base() : SomeIrrelevantInterface + + companion object : DerivedAbstract() +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_before.fir.kt new file mode 100644 index 00000000000..a44f2974ea0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withIrrelevantInterface_before.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +interface SomeIrrelevantInterface + +// note that C.Base() supertype will be resolved in normal scope +abstract class DerivedAbstract : C.Base() + +class Data + +public class C { + + val data: Data = Data() + + // Note that any supertype of Base will be resolved in error-scope, even if it absolutely irrelevant + // to the types in cycle. + open class Base() : SomeIrrelevantInterface + + companion object : DerivedAbstract() +} diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_after.fir.kt new file mode 100644 index 00000000000..4826e4a9fe1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_after.fir.kt @@ -0,0 +1,58 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +object WithFunctionInBase { + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + val data: Data = Data() + + open class Base() { + fun foo(): Int = 42 + } + + companion object : DerivedAbstract() + } +} + +object WithPropertyInBase { + // This case is very similar to previous one, but there are subtle differences from POV of implementation + + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + + open class Base() { + val foo: Int = 42 + } + + val data: Data = Data() + + companion object : DerivedAbstract() + } +} + +object WithPropertyInBaseDifferentOrder { + // This case is very similar to previous one, but there are subtle differences from POV of implementation + // Note how position of property in file affected order of resolve, and, consequently, its results and + // diagnostics. + + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + val data: Data = Data() + + open class Base() { + val foo: Int = 42 + + } + + companion object : DerivedAbstract() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_before.fir.kt new file mode 100644 index 00000000000..818214fdd83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withMembers_before.fir.kt @@ -0,0 +1,64 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// see https://youtrack.jetbrains.com/issue/KT-21515 + +object WithFunctionInBase { + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + // error-scope + val data: Data = Data() + + open class Base() { + // error-scope + fun foo(): Int = 42 + } + + companion object : DerivedAbstract() + } +} + +object WithPropertyInBase { + // This case is very similar to previous one, but there are subtle differences from POV of implementation + + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + + open class Base() { + // error-scope + val foo: Int = 42 + } + + // error-scope + val data: Data = Data() + + companion object : DerivedAbstract() + } +} + +object WithPropertyInBaseDifferentOrder { + // This case is very similar to previous one, but there are subtle differences from POV of implementation + // Note how position of property in file affected order of resolve, and, consequently, its results and + // diagnostics. + + abstract class DerivedAbstract : C.Base() + + class Data + + public class C { + // Now it is successfully resolved (vs. ErrorType like in the previous case) + val data: Data = Data() + + open class Base() { + // Now it is unresolved (vs. ErrorType like in the previous case) + val foo: Int = 42 + + } + + companion object : DerivedAbstract() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withoutTypeReference.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withoutTypeReference.fir.kt new file mode 100644 index 00000000000..b624ea1f79a --- /dev/null +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/withoutTypeReference.fir.kt @@ -0,0 +1,17 @@ +// see https://youtrack.jetbrains.com/issue/KT-21515 + +abstract class DerivedAbstract : C.Base() + +class Data + +open class C { + open class Base { + open fun m() {} + } + + val field = Data() + + companion object : DerivedAbstract() { + override fun m() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/componentNamedComponent1.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/componentNamedComponent1.fir.kt new file mode 100644 index 00000000000..045ee011574 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/componentNamedComponent1.fir.kt @@ -0,0 +1,6 @@ +data class A(val component1: Int) + +fun foo(a: A) { + a.component1() + a.component1 +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/conflictingCopyOverloads.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/conflictingCopyOverloads.fir.kt new file mode 100644 index 00000000000..791c7e10057 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/conflictingCopyOverloads.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +data class A(val x: Int, val y: String) { + fun copy(x: Int, y: String) = x + fun copy(x: Int, y: String) = A(x, y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/conflictingOverloads.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/conflictingOverloads.fir.kt new file mode 100644 index 00000000000..640a34b246d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/conflictingOverloads.fir.kt @@ -0,0 +1,4 @@ +data class A(val x: Int, val y: String) { + fun component1() = 1 + fun component2() = 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/copyOfPrivateClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/copyOfPrivateClass.fir.kt new file mode 100644 index 00000000000..d4e07be97da --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/copyOfPrivateClass.fir.kt @@ -0,0 +1,3 @@ +class Outer { + private data class Nested(val c: Int) +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyNoDefaults.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyNoDefaults.fir.kt new file mode 100644 index 00000000000..f73857723f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyNoDefaults.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitDataClassesOverridingCopy + +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String) : WithCopy { + override fun copy(str: String) = Test(str) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyWithDefaults.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyWithDefaults.fir.kt new file mode 100644 index 00000000000..4e62292ae3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassExplicitlyOverridingCopyWithDefaults.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitDataClassesOverridingCopy + +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String) : WithCopy { + override fun copy(str: String = this.str) = Test(str) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassNoName.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassNoName.fir.kt new file mode 100644 index 00000000000..4c9bb2fe3c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassNoName.fir.kt @@ -0,0 +1,9 @@ +// See EA-73584 +data class { + +} + +// See KT-9296 +data interface { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassNotOverridingCopy.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassNotOverridingCopy.fir.kt new file mode 100644 index 00000000000..aa5c85f6323 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassNotOverridingCopy.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitDataClassesOverridingCopy + +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String, val int: Int) : WithCopy { + override fun copy(str: String) = copy(str, int) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv12.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv12.fir.kt new file mode 100644 index 00000000000..725649fc673 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv12.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -ProhibitDataClassesOverridingCopy + +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String): WithCopy \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv13.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv13.fir.kt new file mode 100644 index 00000000000..78bbb6acfc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassOverridingCopy_lv13.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +ProhibitDataClassesOverridingCopy + +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String): WithCopy \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataClassVarargParam.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataClassVarargParam.fir.kt new file mode 100644 index 00000000000..394aa100f74 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataClassVarargParam.fir.kt @@ -0,0 +1,3 @@ +data class My(val x: Int, vararg val y: String) + +data class Your(vararg z: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataInheritance.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataInheritance.fir.kt new file mode 100644 index 00000000000..c65cabe764d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataInheritance.fir.kt @@ -0,0 +1,13 @@ +interface SuperInterface + +open class SuperClass + +abstract data class Base(val x: Int) + +class Derived: Base(42) + +data class Nasty(val z: Int, val y: Int): Base(z) + +data class Complex(val y: Int): SuperInterface, SuperClass() + +data class SubData(val sss: String) : Complex(42) diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt new file mode 100644 index 00000000000..6fb3b31efdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt @@ -0,0 +1 @@ +data object Object(val x: Int, val y: Int) diff --git a/compiler/testData/diagnostics/tests/dataClasses/emptyConstructor.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/emptyConstructor.fir.kt new file mode 100644 index 00000000000..ef979927e6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/emptyConstructor.fir.kt @@ -0,0 +1,6 @@ +data class A() + +fun foo(a: A) { + a.component1() + a.component2() +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/errorTypesInDataClasses.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/errorTypesInDataClasses.fir.kt new file mode 100644 index 00000000000..2d4f2129a41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/errorTypesInDataClasses.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +data class A(val i: Int, val j: G) +data class B(val i: G, val j: G) + + +fun fa(a: A) { + val (i, j) = a + val i2 = a.component1() + val j2 = a.component2() +} + +fun fb(b: B) { + val (i, j) = b + val i2 = b.component1() + val j2 = b.component2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/extensionComponentsOnNullable.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/extensionComponentsOnNullable.fir.kt new file mode 100644 index 00000000000..35a91f872ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/extensionComponentsOnNullable.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +class Data(val x: T, val y: T) + +operator fun Data.component1() = x + +operator fun Data.component2() = y + +fun foo(): Int { + val d: Data? = null + // An error must be here + val (x, y) = d + return x + y +} + +data class NormalData(val x: T, val y: T) + +fun bar(): Int { + val d: NormalData? = null + // An error must be here + val (x, y) = d + return x + y +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/finalMembersInBaseClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/finalMembersInBaseClass.fir.kt new file mode 100644 index 00000000000..1969596d600 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/finalMembersInBaseClass.fir.kt @@ -0,0 +1,16 @@ +abstract class Base { + final override fun equals(other: Any?) = false + final override fun hashCode() = 42 + + open override fun toString() = "OK" +} + +data class Data1(val field: String) : Base() + +interface AbstractAnyMembers { + abstract override fun equals(other: Any?): Boolean + abstract override fun hashCode(): Int + abstract override fun toString(): String +} + +data class Data2(val field: String): Base(), AbstractAnyMembers diff --git a/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt new file mode 100644 index 00000000000..be0e89007bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt @@ -0,0 +1,25 @@ +// KT-11306 ABSTRACT_MEMBER_NOT_IMPLEMENTED for data class should inheriting interfaces requiring equals(), hashCode(), or toString() + +interface Foo { + override fun equals(other: Any?): Boolean + override fun hashCode(): Int + override fun toString(): String +} + +data class FooImpl(val num: Int) : Foo + +data class FooImplSome(val num: Int) : Foo { + override fun hashCode() = 42 +} + +data class FooImplAll(val num: Int) : Foo { + override fun equals(other: Any?) = false + override fun hashCode() = 42 + override fun toString() = "OK" +} + + +data class WrongSignatures(val num: Int) : Foo { + override fun equals(other: WrongSignatures) = false + override fun hashCode(): Boolean = true +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasComponent1.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasComponent1.fir.kt new file mode 100644 index 00000000000..7cb40548632 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasComponent1.fir.kt @@ -0,0 +1,5 @@ +interface T { + fun component1(): Int +} + +data class A(val x: Int) : T diff --git a/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasFinalComponent1.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasFinalComponent1.fir.kt new file mode 100644 index 00000000000..107969b1faf --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/implementTraitWhichHasFinalComponent1.fir.kt @@ -0,0 +1,5 @@ +interface T { + final fun component1(): Int = 42 +} + +data class A(val x: Int) : T diff --git a/compiler/testData/diagnostics/tests/dataClasses/innerDataClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/innerDataClass.fir.kt new file mode 100644 index 00000000000..18c9b2307af --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/innerDataClass.fir.kt @@ -0,0 +1,3 @@ +class Outer { + inner data class Inner(val x: Int) +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/innerOuterDataClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/innerOuterDataClass.fir.kt new file mode 100644 index 00000000000..496921194f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/innerOuterDataClass.fir.kt @@ -0,0 +1 @@ +inner data class Outer(val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/multiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/multiDeclaration.fir.kt new file mode 100644 index 00000000000..803873a0464 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/multiDeclaration.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +data class A(val x: Int, val y: String) + +fun foo(a: A) { + val (b, c) = a + checkSubtype(b) + checkSubtype(c) +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/multiDeclarationFor.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/multiDeclarationFor.fir.kt new file mode 100644 index 00000000000..ce7a01130e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/multiDeclarationFor.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +data class A(val x: Int, val y: String) + +fun foo(arr: Array) { + for ((b, c) in arr) { + checkSubtype(b) + checkSubtype(c) + } +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/noConstructor.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/noConstructor.fir.kt new file mode 100644 index 00000000000..ddaab4d82a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/noConstructor.fir.kt @@ -0,0 +1,6 @@ +data class A + +fun foo(a: A) { + a.component1() + a.component2() +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/notADataClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/notADataClass.fir.kt new file mode 100644 index 00000000000..2561937f3e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/notADataClass.fir.kt @@ -0,0 +1,6 @@ +class A(val x: Int, val y: String) + +fun foo(a: A) { + a.component1() + a.component2() +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/oneValParam.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/oneValParam.fir.kt new file mode 100644 index 00000000000..6b9054c630b --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/oneValParam.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +data class A(val x: Int) + +fun foo(a: A) { + checkSubtype(a.component1()) + a.component2() +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.fir.kt new file mode 100644 index 00000000000..798f24affcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.fir.kt @@ -0,0 +1,9 @@ +data class A1(val x: Int, val y: String, val x: Int) { + val z = "" +} + +data class A2(val x: Int, val y: String) { + val x = "" +} + +data class A3(val :Int, val : Int) diff --git a/compiler/testData/diagnostics/tests/dataClasses/sealedDataClass.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/sealedDataClass.fir.kt new file mode 100644 index 00000000000..8899146b396 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/sealedDataClass.fir.kt @@ -0,0 +1,4 @@ +sealed data class My(val x: Int) { + object Your: My(1) + class His(y: Int): My(y) +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/strange.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/strange.fir.kt new file mode 100644 index 00000000000..51a73b39b19 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/strange.fir.kt @@ -0,0 +1,10 @@ +data enum class First(val x: Int) { + A(1), + B(2) +} + +data object Second + +data interface Third + +data annotation class Fourth(val x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/twoValParams.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/twoValParams.fir.kt new file mode 100644 index 00000000000..53228d514ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/twoValParams.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +data class A(val x: Int, val y: String) + +fun foo(a: A) { + checkSubtype(a.component1()) + checkSubtype(a.component2()) +} diff --git a/compiler/testData/diagnostics/tests/dataClasses/twoVarParams.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/twoVarParams.fir.kt new file mode 100644 index 00000000000..d7d038aabc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/twoVarParams.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +data class A(var x: Int, var y: String) + +fun foo(a: A) { + checkSubtype(a.component1()) + checkSubtype(a.component2()) +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/CalleeExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/CalleeExpression.fir.kt new file mode 100644 index 00000000000..7343419e835 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/CalleeExpression.fir.kt @@ -0,0 +1,7 @@ +class C(val f : () -> Unit) + +fun test(e : Any) { + if (e is C) { + (e.f)() + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.fir.kt new file mode 100644 index 00000000000..4b3db89acdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.fir.kt @@ -0,0 +1,24 @@ +// !CHECK_TYPE + +fun f1(s: String?) { + if (s!! == ""); + checkSubtype(s) +} + +fun f2(s: Number?) { + if (s is Int); + checkSubtype(s) + if (s as Int == 42); + checkSubtype(s) +} + +fun f3(s: Number?) { + if (s is Int && s as Int == 42); + checkSubtype(s) +} + +fun f4(s: Int?) { + var u = if (s!! == 42); + if (u == Unit) u = if (s == 239); + return u +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/IsExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/IsExpression.fir.kt new file mode 100644 index 00000000000..c97b7f0dab6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/IsExpression.fir.kt @@ -0,0 +1,6 @@ +fun f(a: Boolean, b: Int) {} + +fun foo(a: Any) { + f(a is Int, a) + 1 + a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/WhenSubject.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/WhenSubject.fir.kt new file mode 100644 index 00000000000..3b8d12cc256 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/WhenSubject.fir.kt @@ -0,0 +1,10 @@ +interface Expr +class BinOp(val operator : String) : Expr + +fun test(e : Expr) { + if (e is BinOp) { + when (e.operator) { + else -> 0 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/assignment/assignToNewVal.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/assignment/assignToNewVal.fir.kt new file mode 100644 index 00000000000..8db26209994 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/assignment/assignToNewVal.fir.kt @@ -0,0 +1,10 @@ +fun test(a: Any?) { + if (a == null) return + a.hashCode() + + val b = a + b.hashCode() + + val c: Any? = a + c.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/assignment/kt6118.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/assignment/kt6118.fir.kt new file mode 100644 index 00000000000..c16bb040bcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/assignment/kt6118.fir.kt @@ -0,0 +1,16 @@ +// KT-6118 Redundant type cast can be not redundant? + +fun foo(o: Any) { + if (o is String) { + val s = o as String + s.length + } +} + +fun foo1(o: Any) { + if (o is String) { + o.length + val s = o + s.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValIsCheck.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValIsCheck.fir.kt new file mode 100644 index 00000000000..4e946147fe0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValIsCheck.fir.kt @@ -0,0 +1,15 @@ +fun test(a: Any?, flag: Boolean, x: Any?) { + if (a !is String) return + a.length + + val b: Any? + + if (flag) { + b = a + b.length + } + else { + b = x + b.length() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValNullability.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValNullability.fir.kt new file mode 100644 index 00000000000..9becb2e132a --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/assignment/uninitializedValNullability.fir.kt @@ -0,0 +1,15 @@ +fun test(a: Any?, flag: Boolean, x: Any?) { + if (a == null) return + a.hashCode() + + val b: Any? + + if (flag) { + b = a + b.hashCode() + } + else { + b = x + b.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/assignment/when.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/assignment/when.fir.kt new file mode 100644 index 00000000000..04b1802c088 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/assignment/when.fir.kt @@ -0,0 +1,12 @@ +fun test(a: Any?) { + when (a) { + is String -> { + val s = a + s.length + } + "" -> { + val s = a + s.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassBase.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassBase.fir.kt new file mode 100644 index 00000000000..5875f99ead4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassBase.fir.kt @@ -0,0 +1,10 @@ +open class Base(x: String, y: Int) + +fun test(x: Any, y: Int?) { + if (x !is String) return + if (y == null) return + + class Local: Base(x, y) { + } +} + diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDefaultParameters.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDefaultParameters.fir.kt new file mode 100644 index 00000000000..8795f2753e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDefaultParameters.fir.kt @@ -0,0 +1,8 @@ +fun test(x: Any) { + if (x !is String) return + + class Local(s: String = x) { + fun foo(s: String = x): String = s + } +} + diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegatedProperties.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegatedProperties.fir.kt new file mode 100644 index 00000000000..d3ad13805bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegatedProperties.fir.kt @@ -0,0 +1,17 @@ +import kotlin.reflect.KProperty + +class Del { + operator fun getValue(_this: Any?, p: KProperty<*>): Int = 0 +} + +fun df(del: Del): Del = del + + +fun test(del: Any?) { + if (del !is Del) return + + class Local { + val delegatedVal by df(del) + val delegatedVal1: Int by df(del) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegation.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegation.fir.kt new file mode 100644 index 00000000000..8f89fe63db1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassDelegation.fir.kt @@ -0,0 +1,11 @@ +interface D { + fun foo() {} +} + +fun test(d: Any?) { + if (d !is D) return + + class Local : D by d { + } +} + diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassFunctions.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassFunctions.fir.kt new file mode 100644 index 00000000000..d71924e256b --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassFunctions.fir.kt @@ -0,0 +1,18 @@ +interface D { + fun foo(): String = "" +} + +fun test(d: Any?) { + if (d !is D) return + + class Local { + fun f() { + d.foo() + } + + fun f1() = d.foo() + + fun f2(): String = d.foo() + } +} + diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.fir.kt new file mode 100644 index 00000000000..aecbf5dd376 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.fir.kt @@ -0,0 +1,15 @@ +fun test(x: Any) { + if (x !is String) return + + class LocalOuter { + fun foo(y: Any) { + if (y !is String) return + class Local { + init { + x.length + y.length + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.fir.kt new file mode 100644 index 00000000000..361ec612108 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.fir.kt @@ -0,0 +1,16 @@ +// KT-338 Support.smartcasts in nested declarations + +fun f(a: Any?) { + if (a is B) { + class C : X(a) { + init { + a.foo() + } + } + } +} + +interface B { + fun foo() {} +} +open class X(b: B) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassProperty.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassProperty.fir.kt new file mode 100644 index 00000000000..9438e8363d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassProperty.fir.kt @@ -0,0 +1,12 @@ +fun test(x: Any?) { + if (x !is String) return + + class C { + val v = x.length + + val vGet: Int + get() = x.length + + val s: String = x + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalObject.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalObject.fir.kt new file mode 100644 index 00000000000..e867333101a --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalObject.fir.kt @@ -0,0 +1,9 @@ +fun foo(x: Any?) { + if (x is String) { + object : Base(x) { + fun bar() = x.length + } + } +} + +open class Base(s: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.fir.kt new file mode 100644 index 00000000000..06755b3f374 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.fir.kt @@ -0,0 +1,15 @@ +// KT-2225 Object expression delegation parameter should be checked with data flow info + +interface A { + fun foo() : Int +} + +class B : A { + override fun foo() = 10 +} +fun foo(b: B?) : Int { + if (b == null) return 0 + val o = object : A by b { //no info about b not null check + } + return o.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.fir.kt new file mode 100644 index 00000000000..c94b2140ba6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.fir.kt @@ -0,0 +1,11 @@ +fun test(x: Any) { + if (x !is String) return + + class LocalOuter { + inner class Local { + init { + x.length + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/kt2835.fir.kt b/compiler/testData/diagnostics/tests/dataFlow/local/kt2835.fir.kt new file mode 100644 index 00000000000..ccd49b6834d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlow/local/kt2835.fir.kt @@ -0,0 +1,8 @@ +open class X(val s: String) + +fun f(a: String?) { + if (a != null) { + object : X(a) { // Type mismatch: inferred type is kotlin.String? but kotlin.String was expected + } + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.fir.kt new file mode 100644 index 00000000000..90e0bb04051 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + if (x != null && bar(x) == 0) bar(bar(x)) + bar(x) + if (x == null || bar(x) == 0) bar(bar(x)) + bar(x) + if (x is Int && bar(x)*bar(x) == bar(x)) bar(x) + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.fir.kt new file mode 100644 index 00000000000..cdf5521eaa1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.fir.kt @@ -0,0 +1,13 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + val a = Array(3, {0}) + + if (x != null) bar(a[x]) else bar(a[x]) + bar(a[if (x == null) 0 else x]) + bar(a[x]) + + "123"[x]; + if (x != null) "123"[x]; +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayExpression.fir.kt new file mode 100644 index 00000000000..21d5cba59d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayExpression.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +fun foo(arr: Array): Int { + @Suppress("UNCHECKED_CAST") + val result = (arr as Array)[0] + checkSubtype>(arr) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt new file mode 100644 index 00000000000..17176604658 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayGetSetConvention.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE + +interface G { + operator fun get(x: Int, y: Int): Int = x + y + operator fun set(x: Int, y: Int, value: Int) {} +} + +fun foo1(a: Int?, b: G) { + b[a!!, a!!] = a + checkSubtype(a) +} + +fun foo2(a: Int?, b: G) { + b[0, a!!] = a + checkSubtype(a) +} + +fun foo3(a: Int?, b: G) { + val r = b[a!!, a] + checkSubtype(a) + checkSubtype(r) +} + +fun foo4(a: Int?, b: G) { + val r = b[0, a!!] + checkSubtype(a) + checkSubtype(r) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt new file mode 100644 index 00000000000..1fc7a3424b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayIndices.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun foo1(a: Int?, b: Array>) { + b[a!!][a!!] = a + checkSubtype(a) +} + +fun foo2(a: Int?, b: Array>) { + b[0][a!!] = a + checkSubtype(a) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Assignment.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Assignment.fir.kt new file mode 100644 index 00000000000..6645e4728ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Assignment.fir.kt @@ -0,0 +1,17 @@ +interface A +interface B : A { + fun foo() +} + +fun bar1(a: A) { + var b: B = a as B + a.foo() + b.foo() +} + +fun id(b: B) = b +fun bar2(a: A) { + var b: B = id(a as B) + a.foo() + b.foo() +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentInInitializer.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentInInitializer.fir.kt new file mode 100644 index 00000000000..dbe7546d770 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentInInitializer.fir.kt @@ -0,0 +1,21 @@ +// KT-2825 DataFlowInfo is not retained after assignment + +interface A + +interface B : A { + fun foo() +} + +fun baz(b: B) = b + +fun bar1(a: A) { + val b = a as B + a.foo() + b.foo() +} + +fun bar2(a: A) { + val b = baz(a as B) + a.foo() + b.foo() +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentOperation.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentOperation.fir.kt new file mode 100644 index 00000000000..dc1adc8f13f --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentOperation.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +fun bar1(x: Number, y: Int) { + var yy = y + yy += x as Int + checkSubtype(x) +} + +fun bar2(x: Number) { + y += x as Int + checkSubtype(x) +} + +fun bar3(x: Number, y: Array) { + y[0] += x as Int + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentToArrayElement.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentToArrayElement.fir.kt new file mode 100644 index 00000000000..97b08c9bd7d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AssignmentToArrayElement.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +fun arrayAccessRHS(a: Int?, b: Array) { + b[0] = a!! + checkSubtype(a) +} + +fun arrayAccessLHS(a: Int?, b: Array) { + b[a!!] = a + checkSubtype(a) +} + diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.fir.kt new file mode 100644 index 00000000000..1b8fe6d3ec4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + bar(1 + (if (x == null) 0 else x)) + bar(if (x == null) x else x) + if (x != null) bar(x + x/(x-x*x)) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionBooleanOperations.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionBooleanOperations.fir.kt new file mode 100644 index 00000000000..6dcd58c1a3d --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionBooleanOperations.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +fun foo1(x: Number, cond: Boolean): Boolean { + val result = cond && ((x as Int) == 42) + checkSubtype(x) + return result +} + +fun foo2(x: Number, cond: Boolean): Boolean { + val result = ((x as Int) == 42) && cond + checkSubtype(x) + return result +} + +fun foo3(x: Number, cond: Boolean): Boolean { + val result = cond || ((x as Int) == 42) + checkSubtype(x) + return result +} + +fun foo4(x: Number, cond: Boolean): Boolean { + val result = ((x as Int) == 42) || cond + checkSubtype(x) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionCompareToConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionCompareToConvention.fir.kt new file mode 100644 index 00000000000..2a8e9a02aa4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionCompareToConvention.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +interface A + +interface B : A +operator fun B.compareTo(b: B) = if (this == b) 0 else 1 + +fun foo(a: A): Boolean { + val result = (a as B) < a + checkSubtype(a) + return result +} + +fun bar(a: A, b: B): Boolean { + val result = b < (a as B) + checkSubtype(a) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionContainsConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionContainsConvention.fir.kt new file mode 100644 index 00000000000..53c7b299e76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionContainsConvention.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE + +fun foo(x: Number): Boolean { + val result = (x as Int) in 1..5 + checkSubtype(x) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionElvis.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionElvis.fir.kt new file mode 100644 index 00000000000..395d4b3ded5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionElvis.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +fun foo(x: Int?): Int = x!! + +fun elvis(x: Number?): Int { + val result = (x as Int?) ?: foo(x) + checkSubtype(x) + return result +} + + +fun elvisWithRHSTypeInfo(x: Number?): Any? { + val result = x ?: x!! + checkSubtype(x) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionEqualsConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionEqualsConvention.fir.kt new file mode 100644 index 00000000000..7c49c13700b --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionEqualsConvention.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +interface A +interface B : A + +fun foo1(a: A, b: B): Boolean { + val result = (a as B) == b + checkSubtype(a) + return result +} + +fun foo2(a: A, b: B): Boolean { + val result = b == (a as B) + checkSubtype(a) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionIdentifier.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionIdentifier.fir.kt new file mode 100644 index 00000000000..05a276ef07e --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionIdentifier.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +infix fun Int.compareTo(o: Int) = 0 + +fun foo(a: Number): Int { + val result = (a as Int) compareTo a + checkSubtype(a) + return result +} + +fun bar(a: Number): Int { + val result = 42 compareTo (a as Int) + checkSubtype(a) + return result +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionPlusConvention.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionPlusConvention.fir.kt new file mode 100644 index 00000000000..4ba75f34ed8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpressionPlusConvention.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +interface A + +interface B : A +operator fun B.plus(b: B) = if (this == b) b else this + +fun foo(a: A): B { + val result = (a as B) + a + checkSubtype(a) + return result +} + +fun bar(a: A, b: B): B { + val result = b + (a as B) + checkSubtype(a) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Condition.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Condition.fir.kt new file mode 100644 index 00000000000..b3fad0f71e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Condition.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE + +fun foo(x: Int?): Boolean { + val result = ((x!! == 0) && (checkSubtype(x) == 0)) + checkSubtype(x) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ContinueOuterLoop.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ContinueOuterLoop.fir.kt new file mode 100644 index 00000000000..4f0be07c6ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ContinueOuterLoop.fir.kt @@ -0,0 +1,34 @@ +// !CHECK_TYPE + +fun whileLoop(x: Int?) { + outer@ while (x != 0) { + while (x != 1) { + if (x == 2) continue@outer + } + checkSubtype(x) + } + checkSubtype(x) +} + +fun doWhileLoop(x: Int?) { + outer@ while (x != 0) { + do { + if (x == 2) continue@outer + } while (x == null) + checkSubtype(x) + } + checkSubtype(x) +} + +fun whileLoopContinueInnerOuter(x: Int?) { + outer@ while (x != 0) { + inner@ while (x != 1) { + while (x != 2) { + if (x == 3) continue@inner + } + checkSubtype(x) + } + checkSubtype(x) + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.fir.kt new file mode 100644 index 00000000000..2e9264619c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +fun bar(x: Int) = x + 1 + +fun foo() { + val x: Int? = null + + if (x != null) { + bar(x) + if (x != null) { + bar(x) + if (1 < 2) bar(x) + if (1 > 2) bar(x) + } + if (x == null) { + bar(x) + } + if (x == null) bar(x) else bar(x) + bar(bar(x)) + } else if (x == null) { + bar(x) + if (x != null) { + bar(x) + if (x == null) bar(x) + if (x == null) bar(x) else bar(x) + bar(bar(x) + bar(x)) + } else if (x == null) { + bar(x) + } + } + +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.fir.kt new file mode 100644 index 00000000000..0bbb351fb40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.fir.kt @@ -0,0 +1,16 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + do { + bar(x) + } while (x == null) + bar(x) + + val y: Int? = null + do { + bar(y) + } while (y != null) + bar(y) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhileCondition.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhileCondition.fir.kt new file mode 100644 index 00000000000..6013fd34399 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhileCondition.fir.kt @@ -0,0 +1,20 @@ +// !CHECK_TYPE + +fun simpleDoWhile(x: Int?, y0: Int) { + var y = y0 + do { + checkSubtype(x) + y++ + } while (x!! == y) + checkSubtype(x) +} + +fun doWhileWithBreak(x: Int?, y0: Int) { + var y = y0 + do { + checkSubtype(x) + y++ + if (y > 0) break + } while (x!! == y) + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.fir.kt new file mode 100644 index 00000000000..02bcd2bcdc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.fir.kt @@ -0,0 +1,9 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + bar(x ?: 0) + if (x != null) bar(x ?: x) + bar(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt new file mode 100644 index 00000000000..e7b403026f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +fun bar(x: Int) = x + 1 + +fun f1(x: Int?) { + bar(x) + if (x != null) bar(x!!) + if (x == null) bar(x!!) +} + +fun f2(x: Int?) { + if (x != null) else x!! +} + +fun f3(x: Int?) { + if (x != null) bar(x!!) else x!! +} + +fun f4(x: Int?) { + if (x == null) x!! else bar(x!!) +} + +fun f5(x: Int?) { + if (x == null) else bar(x!!) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.fir.kt new file mode 100644 index 00000000000..28b3d130b89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.fir.kt @@ -0,0 +1,22 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + val a = Array(3, {0}) + + for (p in a) { + bar(x) + if (x == null) continue + bar(x) + for (q in a) { + bar(x) + if (x == null) bar(x) + } + } + + for (p in a) { + bar(x) + if (x == null) break + bar(x) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ForLoopRange.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ForLoopRange.fir.kt new file mode 100644 index 00000000000..9b843e160aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ForLoopRange.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +fun foo(arr: Array?) { + for (x in arr!!) { + checkSubtype>(arr) + } + checkSubtype>(arr) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.fir.kt new file mode 100644 index 00000000000..1fc2dfb71ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.fir.kt @@ -0,0 +1,9 @@ +fun bar(x: Int) = x + 1 + +fun foo() { + val x: Int? = null + + fun baz() = bar(x) + fun quux() = if (x != null) bar(x) else baz() + fun quuux() = bar(if (x == null) 0 else x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfStatement.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfStatement.fir.kt new file mode 100644 index 00000000000..ef88daf14ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfStatement.fir.kt @@ -0,0 +1,31 @@ +// !CHECK_TYPE + +fun ifThen(x: Int?) { + if (x!! == 0) { + checkSubtype(x) + } + checkSubtype(x) +} + +fun ifElse(x: Int?) { + if (x!! == 0) else { + checkSubtype(x) + } + checkSubtype(x) +} + +fun ifThenElse(x: Int?) { + if (x!! == 0) { + checkSubtype(x) + } else { + checkSubtype(x) + } + checkSubtype(x) +} + +fun ifIs(x: Int?, cond: Boolean) { + if ((x is Int) == cond) { + checkSubtype(x) + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt new file mode 100644 index 00000000000..be811fb9c40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.fir.kt @@ -0,0 +1,30 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + bar(if (x == null) 0 else x) + + if (x == null) { + bar(x) + return + } else { + bar(x) + } + bar(x) + + val y: Int? = null + if (y is Int) { + bar(y) + } else { + bar(y) + return + } + bar(y) + + val z: Int? = null + if (z != null) bar(z) + bar(z) + bar(z!!) + if (z != null) bar(z!!) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.fir.kt new file mode 100644 index 00000000000..94aaf079517 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.fir.kt @@ -0,0 +1,16 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + bar(x) + if (x != 2) { + if (x == null) return + 2+ + } + else { + if (x == null) return + 2+ + } + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.fir.kt new file mode 100644 index 00000000000..565ded5a2b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IsExpression.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +fun foo(x: Number) { + if ((x as Int) is Int) { + checkSubtype(x) + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.fir.kt new file mode 100644 index 00000000000..e74aec692cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ManyIfs.fir.kt @@ -0,0 +1,32 @@ +// !CHECK_TYPE + +fun noUselessDataFlowInfoCreation(x: Number) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { + } } } } } } } } } } } } } } } } } } } } } } } } } +} + +fun dataFlowInfoAnd(a: Array) { + if (a[0] is Int) { if (a[1] is Int) { if (a[2] is Int) { if (a[3] is Int) { if (a[4] is Int) { + if (a[5] is Int) { if (a[6] is Int) { if (a[7] is Int) { if (a[8] is Int) { if (a[9] is Int) { + if (a[10] is Int) { if (a[11] is Int) { if (a[12] is Int) { if (a[13] is Int) { if (a[14] is Int) { + if (a[15] is Int) { if (a[16] is Int) { if (a[17] is Int) { if (a[18] is Int) { if (a[19] is Int) { + if (a[20] is Int) { if (a[21] is Int) { if (a[22] is Int) { if (a[23] is Int) { if (a[24] is Int) { + if (a[25] is Int) { if (a[26] is Int) { if (a[27] is Int) { if (a[28] is Int) { if (a[29] is Int) { + checkSubtype(a[0]) + } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } +} + +fun dataFlowInfoOr(a: Array) { + if (a[0] is Int || a[1] is Int || a[2] is Int || a[3] is Int || a[4] is Int || a[5] is Int || a[6] is Int || a[7] is Int || a[8] is Int || a[9] is Int || + a[10] is Int || a[11] is Int || a[12] is Int || a[13] is Int || a[14] is Int || a[15] is Int || a[16] is Int || a[17] is Int || a[18] is Int || a[19] is Int || + a[20] is Int || a[21] is Int || a[22] is Int || a[23] is Int || a[24] is Int || a[25] is Int || a[26] is Int || a[27] is Int || a[28] is Int || a[29] is Int || + a[30] is Int || a[31] is Int || a[32] is Int || a[33] is Int || a[34] is Int || a[35] is Int || a[36] is Int || a[37] is Int || a[38] is Int || a[39] is Int || + a[40] is Int || a[41] is Int || a[42] is Int || a[43] is Int || a[44] is Int || a[45] is Int || a[46] is Int || a[47] is Int || a[48] is Int || a[49] is Int || + a[50] is Int || a[51] is Int || a[52] is Int || a[53] is Int || a[54] is Int || a[55] is Int || a[56] is Int || a[57] is Int || a[58] is Int || a[59] is Int) { + checkSubtype(a[0]) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/MultiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/MultiDeclaration.fir.kt new file mode 100644 index 00000000000..9395107e292 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/MultiDeclaration.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +operator fun Int.component1() = "a" + +fun foo(a: Number) { + val (x) = a as Int + checkSubtype(a) + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.fir.kt new file mode 100644 index 00000000000..ff96ed65c89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE + +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + val a = object { + fun baz() = bar(if (x == null) 0 else x) + fun quux(): Int = if (x == null) x else x + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.fir.kt new file mode 100644 index 00000000000..81eddacff27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.fir.kt @@ -0,0 +1,13 @@ +fun baz(x: Int): Int = x + 1 + +class A { + fun bar(x: Int) = baz(x) +} + +fun foo() { + val x: Int? = null + + A().bar(x) + if (x == null) return + A().bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt new file mode 100644 index 00000000000..7165f3c6a56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +fun bar(x: Int): Int = x + 1 + +fun foo(): Int { + val x: Int? = null + + bar(x) + if (x != null) return x + + val y: Int? = null + if (y == null) return if (y != null) y else y + + val z: Int? = null + if (z != null) return if (z == null) z else z + + return z +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/StringTemplate.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/StringTemplate.fir.kt new file mode 100644 index 00000000000..991605891da --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/StringTemplate.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +fun foo(x: Number, y: String?): String { + val result = "abcde $x ${x as Int} ${y!!} $x $y" + checkSubtype(x) + checkSubtype(y) + return result +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.fir.kt new file mode 100644 index 00000000000..1d4dedb550e --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.fir.kt @@ -0,0 +1,21 @@ +open class Base { + fun bar(x: Int): Int = x + 1 +} + +class Derived : Base() { + fun baz(x: Int): Int = x + 1 + + fun foo() { + val x: Int? = null + + super.bar(x) + this.baz(x) + if (x == null) return + super.bar(x) + this.baz(x) + + val y: Int? = null + if (y != null) super.bar(this.baz(y)) + else this.baz(super.bar(y)) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.fir.kt new file mode 100644 index 00000000000..ffe940b64d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.fir.kt @@ -0,0 +1,9 @@ +fun bar(x: Int): RuntimeException = RuntimeException(x.toString()) + +fun foo() { + val x: Int? = null + + if (x == null) throw bar(x) + throw bar(x) + throw bar(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.fir.kt new file mode 100644 index 00000000000..48bcd7fe2aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.fir.kt @@ -0,0 +1,15 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + bar(x) + if (x == null) return + try { + bar(x) + } + catch (e: Exception) { + bar(x) + } + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.fir.kt new file mode 100644 index 00000000000..7bf4b2deb91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +fun tryFinally(x: Int?) { + try { + } finally { + x!! + } + checkSubtype(x) +} + +fun tryCatchFinally(x: Int?) { + try { + x!! + } catch (e: Exception) { + x!! + } finally { + checkSubtype(x) + x!! + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.fir.kt new file mode 100644 index 00000000000..168fea3ca59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.fir.kt @@ -0,0 +1,14 @@ +fun bar(x: Int): Int = x + 1 +fun baz(b: Boolean): Boolean = !b + +fun foo() { + val x: Int? = null + + bar(-x) + if (x != null) bar(-x) + bar(-x) + + val b: Boolean? = null + baz(!b) + if (b != null) baz(!b) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.fir.kt new file mode 100644 index 00000000000..5582e7b2346 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.fir.kt @@ -0,0 +1,18 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + + if (x != null) { + when (x) { + 0 -> bar(x) + else -> {} + } + } + + when (x) { + 0 -> { if (x == null) return } + else -> { if (x == null) return } + } + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryAs.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryAs.fir.kt new file mode 100644 index 00000000000..cd33062c286 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryAs.fir.kt @@ -0,0 +1,26 @@ +// !CHECK_TYPE + +fun foo(x: Number, y: Int) { + when (x) { + x as Int -> checkSubtype(x) + y -> {} + else -> {} + } + checkSubtype(x) +} + +fun bar(x: Number) { + when (x) { + x as Int -> checkSubtype(x) + else -> {} + } + checkSubtype(x) +} + +fun whenWithoutSubject(x: Number) { + when { + (x as Int) == 42 -> checkSubtype(x) + else -> {} + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryIs.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryIs.fir.kt new file mode 100644 index 00000000000..1b923955510 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenEntryIs.fir.kt @@ -0,0 +1,26 @@ +// !CHECK_TYPE + +fun foo(x: Number, y: Int) { + when (x) { + is Int -> checkSubtype(x) + y -> {} + else -> {} + } + checkSubtype(x) +} + +fun bar(x: Number) { + when (x) { + is Int -> checkSubtype(x) + else -> {} + } + checkSubtype(x) +} + +fun whenWithoutSubject(x: Number) { + when { + (x is Int) -> checkSubtype(x) + else -> {} + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenIn.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenIn.fir.kt new file mode 100644 index 00000000000..f287d76b098 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenIn.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +fun foo(x: Int, list: List?) { + when (x) { + in list!! -> checkSubtype>(list) + else -> {} + } +} + +fun whenWithoutSubject(x: Int, list: List?) { + when { + x in list!! -> checkSubtype>(list) + else -> {} + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenSubject.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenSubject.fir.kt new file mode 100644 index 00000000000..40cf4b1af2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhenSubject.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +fun foo(x: Number) { + when (x as Int) { + else -> checkSubtype(x) + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.fir.kt new file mode 100644 index 00000000000..1a78dde9378 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.fir.kt @@ -0,0 +1,22 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + while (x == null) { + bar(x) + } + bar(x) + + val y: Int? = null + while (y != null) { + bar(y) + } + bar(y) + + val z: Int? = null + while (z == null) { + bar(z) + break + } + bar(z) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhileCondition.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhileCondition.fir.kt new file mode 100644 index 00000000000..43948d78597 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/WhileCondition.fir.kt @@ -0,0 +1,26 @@ +// !CHECK_TYPE + +fun simpleWhile(x: Int?, y0: Int) { + var y = y0 + while (x!! == y) { + checkSubtype(x) + y++ + } + checkSubtype(x) +} + +fun whileWithBreak(x: Int?, y0: Int) { + var y = y0 + while (x!! == y) { + checkSubtype(x) + break + } + checkSubtype(x) +} + +fun whileWithNoCondition(x: Int?) { + while () { + x!! + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt4332WhenBranches.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt4332WhenBranches.fir.kt new file mode 100644 index 00000000000..37d2f02045a --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt4332WhenBranches.fir.kt @@ -0,0 +1,9 @@ +//KT-4332 when/smartcast underperforms + +fun testWhen(t: String?, x: String?): Int { + return when { + t == null -> 0 + x == null -> t.length // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if) + else -> (t + x).length + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5155WhenBranches.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5155WhenBranches.fir.kt new file mode 100644 index 00000000000..69c9c86f1d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5155WhenBranches.fir.kt @@ -0,0 +1,11 @@ +//KT-5155 Auto-casts do not work with when + +fun foo(s: String?) { + when { + s == null -> 1 + s.foo() -> 2 + else -> 3 + } +} + +fun String.foo() = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5182WhenBranches.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5182WhenBranches.fir.kt new file mode 100644 index 00000000000..fdceaaa2d8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/kt5182WhenBranches.fir.kt @@ -0,0 +1,13 @@ +//KT-5182 Data flow info is lost for 'when' branches + +open class A + +class B: A() { + fun foo() = 1 +} + +fun foo(a: A) = when { + a !is B -> 2 + true -> a.foo() //'foo' is unresolved, smart cast doesn't work + else -> a.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt new file mode 100644 index 00000000000..bd99e969b39 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt @@ -0,0 +1,16 @@ +interface B { + fun bar() {} +} + +class C() { + fun bar() { + } +} + +fun test(a : Any?) { + if (a is B) { + if (a is C) { + a.bar(); + } + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.fir.kt new file mode 100644 index 00000000000..738b370eb10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastsForStableIdentifiers.fir.kt @@ -0,0 +1,86 @@ +// FILE: a.kt +package example.ns + +val y : Any? = 2 + +// FILE: b.kt +package example + +import example.ns.y + +object Obj { + val y : Any? = 2 +} + +class AClass() { + companion object { + val y : Any? = 2 + } +} + +val x : Any? = 1 + +fun Any?.vars(a: Any?) : Int { + var b: Int = 0 + if (example.ns.y is Int) { + b = y + } + if (example.ns.y is Int) { + b = example.ns.y + } + if (Obj.y is Int) { + b = Obj.y + } + if (example.Obj.y is Int) { + b = Obj.y + } + if (AClass.y is Int) { + b = AClass.y + } + if (example.AClass.y is Int) { + b = AClass.y + } + if (x is Int) { + b = x + } + if (example.x is Int) { + b = x + } + if (example.x is Int) { + b = example.x + } + return 1 +} + +fun Any?.foo() : Int { + if (this is Int) + return this + if (this@foo is Int) + return this + if (this@foo is Int) + return this@foo + if (this is Int) + return this@foo + return 1 +} + + +interface T {} + +open class C { + fun foo() { + var t : T? = null + if (this is T) { + t = this + } + if (this is T) { + t = this@C + } + if (this@C is T) { + t = this + } + if (this@C is T) { + t = this@C + } + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt new file mode 100644 index 00000000000..e8bc3635afa --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/ComponentFunctionReturnTypeMismatch.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +class A { + operator fun component1() : Int = 1 + operator fun component2() : Int = 2 +} + +fun a(aa : A) { + val (a: String, b1: String) = aa +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ConflictingAndRedundantProjections.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ConflictingAndRedundantProjections.fir.kt new file mode 100644 index 00000000000..c46a729de20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/ConflictingAndRedundantProjections.fir.kt @@ -0,0 +1,20 @@ +class In +class Out +class Inv +class X + +fun f1(p: In) {} +fun f2(p: In) {} +fun f3(p: In) {} + +fun f4(p: Out) {} +fun f5(p: Out) {} +fun f6(p: Out) {} + +fun f6(p: Inv) {} +fun f7(p: Inv) {} +fun f8(p: Inv) {} + +fun f9(p: In<*>) {} +fun f10(p: Out<*>) {} +fun f11(p: Inv<*>) {} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInMultiDeclInFor.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInMultiDeclInFor.fir.kt new file mode 100644 index 00000000000..f84f4933f5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInMultiDeclInFor.fir.kt @@ -0,0 +1,15 @@ +// KT-2667 Support multi-declarations in for-loops in control flow analysis +package d + +class A { + operator fun component1() = 1 + operator fun component2() = 2 + operator fun component3() = 3 +} + +fun foo(list: List) { + for (var (c1, c2, c3) in list) { + c1 = 1 + c3 + 1 + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInfoInMultiDecl.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInfoInMultiDecl.fir.kt new file mode 100644 index 00000000000..59fec99c251 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/DataFlowInfoInMultiDecl.fir.kt @@ -0,0 +1,14 @@ +class A { + operator fun component1() : Int = 1 + operator fun component2() : Int = 2 +} + +fun a(aa : A?, b : Any) { + if (aa != null) { + val (a1, b1) = aa; + } + + if (b is A) { + val (a1, b1) = b; + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.fir.kt new file mode 100644 index 00000000000..35f770556d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.fir.kt @@ -0,0 +1,26 @@ +@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION) +annotation class a +interface A +interface B + +fun () {} +fun A.() {} + +@a fun () {} +fun @a A.() {} + +class Outer { + fun () {} + fun B.() {} + + @a fun () {} + fun @a A.() {} +} + +fun outerFun() { + fun () {} + fun B.() {} + + @a fun () {} + fun @a A.() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/LocalVariableWithNoTypeInformation.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/LocalVariableWithNoTypeInformation.fir.kt new file mode 100644 index 00000000000..12509208784 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/LocalVariableWithNoTypeInformation.fir.kt @@ -0,0 +1,3 @@ +fun test() { + val a +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.fir.kt new file mode 100644 index 00000000000..b6c3498867d --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +package a + +class MyClass { + fun component1(i: Int) {} +} + +class MyClass2 {} + +fun MyClass2.component1() = 1.2 +fun MyClass2.component1() = 1.3 + +fun test(mc1: MyClass, mc2: MyClass2) { + val (a, b) = mc1 + val (c) = mc2 + + //a,b,c are error types + use(a, b, c) +} + +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.fir.kt new file mode 100644 index 00000000000..0c7b4aad47f --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.fir.kt @@ -0,0 +1,15 @@ +class A { + operator fun component1() : Int = 1 + operator fun component2() : Int = 2 +} + +fun a() { + val (a, a) = A() + val (x, y) = A(); + val b = 1 + use(b) + val (b, y) = A(); +} + + +fun use(a: Any): Any = a diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt new file mode 100644 index 00000000000..1277796ace5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// KT-5068 Add special error for scala-like syntax 'fun foo(): Int = { 1 }' + +fun test1(): Int = { return 1 } +fun test2(): Int = { 1 } +val test3: () -> Int = fun (): Int = { return 1 } +val test4: () -> Int = fun (): Int = { 1 } +fun test5(): Int { return { 1 } } +fun test6(): Int = fun (): Int = 1 + +fun outer() { + fun test1(): Int = { return 1 } + fun test2(): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } + fun test5(): Int { return { 1 } } + fun test6(): Int = fun (): Int = 1 +} + +class Outer { + fun test1(): Int = { return 1 } + fun test2(): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } + fun test5(): Int { return { 1 } } + fun test6(): Int = fun (): Int = 1 + + class Nested { + fun test1(): Int = { return 1 } + fun test2(): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } + fun test5(): Int { return { 1 } } + fun test6(): Int = fun (): Int = 1 + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/VarianceOnFunctionAndPropertyTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/VarianceOnFunctionAndPropertyTypeParameters.fir.kt new file mode 100644 index 00000000000..504ca188548 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/VarianceOnFunctionAndPropertyTypeParameters.fir.kt @@ -0,0 +1,17 @@ +fun f() { + +} + +fun g() { + +} + +fun h() { + +} + +val T.x: Int + get() = 1 + +val T.y: Int + get() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.fir.kt new file mode 100644 index 00000000000..28f01fe3d3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.fir.kt @@ -0,0 +1,120 @@ +interface MyTrait { + fun f1() {} +} + +open class MyClass { + fun f2() {} +} + + +class Foo { + + private val privateProperty = object : MyClass(), MyTrait {} + + init { + privateProperty.f1() + privateProperty.f2() + } + + protected val protectedProperty = object : MyClass(), MyTrait {} + + val internalProperty = object : MyClass(), MyTrait {} + + internal val internal2Property = object : MyClass(), MyTrait {} + + public val publicProperty = object : MyClass(), MyTrait {} + + val propertyWithGetter + get() = object: MyClass(), MyTrait {} + + + private fun privateFunction() = object : MyClass(), MyTrait {} + + init { + privateFunction().f1() + privateFunction().f2() + } + + protected fun protectedFunction() = object : MyClass(), MyTrait {} + + fun internalFunction() = object : MyClass(), MyTrait {} + + internal fun internal2Function() = object : MyClass(), MyTrait {} + + public fun publicFunction() = object : MyClass(), MyTrait {} + + + + class FooInner { + private val privatePropertyInner = object : MyClass(), MyTrait {} + + init { + privatePropertyInner.f1() + privatePropertyInner.f2() + } + + protected val protectedProperty = object : MyClass(), MyTrait {} + + val internalProperty = object : MyClass(), MyTrait {} + + internal val internal2Property = object : MyClass(), MyTrait {} + + public val publicProperty = object : MyClass(), MyTrait {} + + + private fun privateFunctionInner() = object : MyClass(), MyTrait {} + + init { + privateFunctionInner().f1() + privateFunctionInner().f2() + } + + protected fun protectedFunction() = object : MyClass(), MyTrait {} + + fun internalFunction() = object : MyClass(), MyTrait {} + + internal fun internal2Function() = object : MyClass(), MyTrait {} + + public fun publicFunction() = object : MyClass(), MyTrait {} + + } + + fun foo() { + val localVar = object : MyClass(), MyTrait {} + localVar.f1() + localVar.f2() + + fun foo2() = object : MyClass(), MyTrait {} + foo2().f1() + foo2().f2() + } + +} + +private val packagePrivateProperty = object : MyClass(), MyTrait {} + +protected val packageProtectedProperty = object : MyClass(), MyTrait {} + +val packageInternalProperty = object : MyClass(), MyTrait {} + +internal val packageInternal2Property = object : MyClass(), MyTrait {} + +public val packagePublicProperty = object : MyClass(), MyTrait {} + +protected fun packageProtectedFunction() = object : MyClass(), MyTrait {} + +fun packageInternalFunction() = object : MyClass(), MyTrait {} + +internal fun packageInternal2Function() = object : MyClass(), MyTrait {} + +public fun packagePublicFunction() = object : MyClass(), MyTrait {} + +fun fooPackage() { + val packageLocalVar = object : MyClass(), MyTrait {} + packageLocalVar.f1() + packageLocalVar.f2() + + fun fooPackageLocal() = object : MyClass(), MyTrait {} + fooPackageLocal().f1() + fooPackageLocal().f2() +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.fir.kt new file mode 100644 index 00000000000..c43ed114e65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +// !CHECK_TYPE +fun foo(block: () -> (() -> Int)) {} + +fun test() { + foo { fun(): Int {return 1} } + foo({ fun() = 1 }) + + val x1 = + if (1 == 1) + fun(): Int {return 1} + else + fun() = 1 + + val x2 = + if (1 == 1) { + fun(): Int { + return 1 + } + } + else + fun() = 1 + + val x3 = when (1) { + 0 -> fun(): Int {return 1} + else -> fun() = 1 + } + + val x31 = when (1) { + 0 -> { + fun(): Int {return 1} + } + else -> fun() = 1 + } + + val x4 = { + y: Int -> fun(): Int {return 1} + } + + x4 checkType { _>>() } + + { y: Int -> fun(): Int {return 1} } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.fir.kt new file mode 100644 index 00000000000..e8ba7c71cb2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunUnusedLastExpressionInBlock.fir.kt @@ -0,0 +1,21 @@ +fun unusedExpressions() { + if (1 == 1) + fun(): Int {return 1} + else + fun() = 1 + + if (1 == 1) { + fun(): Int { + return 1 + } + } + else + fun() = 1 + + when (1) { + 0 -> fun(): Int {return 1} + else -> fun() = 1 + } + + fun() = 1 +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/DoubleDeclForLoop.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/DoubleDeclForLoop.fir.kt new file mode 100644 index 00000000000..065d6ac7c48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/DoubleDeclForLoop.fir.kt @@ -0,0 +1,14 @@ +class A { + operator fun component1() = 1 + operator fun component2() = 1 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, y) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt new file mode 100644 index 00000000000..bbbf1fca597 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/FolLoopTypeComponentTypeMismatch.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +class A { + operator fun component1() = 1 + operator fun component2() = 1.0 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x: Double, y: Int) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionAmbiguity.fir.kt new file mode 100644 index 00000000000..b9a927bbe78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionAmbiguity.fir.kt @@ -0,0 +1,15 @@ +class A { + operator fun component1() = 1 + operator fun component1() = 1 + operator fun component2() = 1 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, y) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionMissing.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionMissing.fir.kt new file mode 100644 index 00000000000..068be345d66 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopComponentFunctionMissing.fir.kt @@ -0,0 +1,13 @@ +class A { + operator fun component1() = 1 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, y) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopMissingLoopParameter.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopMissingLoopParameter.fir.kt new file mode 100644 index 00000000000..9bbbd640e91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopMissingLoopParameter.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +fun useDeclaredVariables() { + for ((a, b)) { + a + b + } +} + +fun checkersShouldRun() { + for ((@A a, _)) { + + } +} + +annotation class A diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopWithExtensions.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopWithExtensions.fir.kt new file mode 100644 index 00000000000..30fca7424e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForLoopWithExtensions.fir.kt @@ -0,0 +1,14 @@ +class A { +} +operator fun A.component1() = 1 +operator fun A.component2() = 1 + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, y) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForWithExplicitTypes.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForWithExplicitTypes.fir.kt new file mode 100644 index 00000000000..3e97d2fc5ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/ForWithExplicitTypes.fir.kt @@ -0,0 +1,14 @@ +class A { + operator fun component1() = 1 + operator fun component2() = 1.0 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x: Int, y: Double) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/RedeclarationInForLoop.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/RedeclarationInForLoop.fir.kt new file mode 100644 index 00000000000..36f980565b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/RedeclarationInForLoop.fir.kt @@ -0,0 +1,14 @@ +class A { + operator fun component1() = 1 + operator fun component2() = 1 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, x) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/SingleDeclForLoop.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/SingleDeclForLoop.fir.kt new file mode 100644 index 00000000000..660bec07ada --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/SingleDeclForLoop.fir.kt @@ -0,0 +1,13 @@ +class A { + operator fun component1() = 1 +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x) in C()) { + + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationAssignedUnresolved.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationAssignedUnresolved.fir.kt new file mode 100644 index 00000000000..d4235c70ed3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationAssignedUnresolved.fir.kt @@ -0,0 +1,11 @@ +fun useDeclaredVariables() { + val (a, b) = unresolved + a + b +} + +fun checkersShouldRun() { + val (@A a, _) = unresolved +} + +annotation class A diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationMissingInitializer.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationMissingInitializer.fir.kt new file mode 100644 index 00000000000..0cc0f05cc7e --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/destructuringDeclarationMissingInitializer.fir.kt @@ -0,0 +1,11 @@ +fun useDeclaredVariables() { + val (a, b) + a + b +} + +fun checkersShouldRun() { + val (@A a, _) +} + +annotation class A diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/kt2829.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/kt2829.fir.kt new file mode 100644 index 00000000000..d907ea26ca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/kt2829.fir.kt @@ -0,0 +1,16 @@ +package test + +fun a(s: String) { // <- ERROR + val (x, y) = Pair("", s) + println(x + y) +} + +fun b(s: String) { + val x = Pair("", s) + println(x) +} + +//from library +data class Pair(val a: A, val b: B) + +fun println(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.fir.kt new file mode 100644 index 00000000000..69faf3e913c --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/lastDestructuringDeclarationInBlock.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun test(list: A) { + if (true) { + val (c) = list + } + else {} + + if (true) { + Unit + val (c) = list + } + else {} + + when (1) { + 1 -> { + val (c) = list + } + } + + fn { it -> + val (a) = it + } +} + +class A { + operator fun component1() = 1 +} + +fun fn(x: (A) -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/underscore.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/underscore.fir.kt new file mode 100644 index 00000000000..10556a5c3dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/destructuringDeclarations/underscore.fir.kt @@ -0,0 +1,51 @@ +// !WITH_NEW_INFERENCE + +class A { + operator fun component1() = 1 + operator fun component2() = "" +} + +class C { + operator fun iterator(): Iterator = null!! +} + +fun test() { + for ((x, _) in C()) { + foo(x, _) + } + + for ((_, y) in C()) { + foo(_, y) + } + + for ((_, _) in C()) { + foo(_, _) + } + + for ((_ : Int, _ : String) in C()) { + foo(_, _) + } + + for ((_ : String, _ : Int) in C()) { + foo(_, _) + } + + val (x, _) = A() + val (_, y) = A() + + foo(x, y) + foo(x, _) + foo(_, y) + + val (`_`, z) = A() + + foo(_, z) + + val (_, `_`) = A() + + foo(_, y) + + val (unused, _) = A() +} + +fun foo(x: Int, y: String) {} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.fir.kt new file mode 100644 index 00000000000..16c6cc9b815 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithOneTypeParameter.fir.kt @@ -0,0 +1,17 @@ +interface A0> +interface A1> +interface A2> +// StackOverflowError +//interface A3> +interface A4?> + +interface B0> +interface B1> + +interface AA> +interface BB>> + +interface A> + +class X +class D>>> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithTwoTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithTwoTypeParameters.fir.kt new file mode 100644 index 00000000000..cb7f8d4438f --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/CasesWithTwoTypeParameters.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UPPER_BOUND_VIOLATED + +interface C0> + +interface C1, S : C1> // T -> S, S -> S +interface C2, S : C2<*, S>> // T -> S, S -> T + +interface D1 where T : U, U: D1<*, U> +interface D2 where T : U?, U: D2<*, *> +interface D3 where T : U, U : V, V: D3<*, *, V> + +interface A where T : A, U: A> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/JavaSuperType.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/JavaSuperType.fir.kt new file mode 100644 index 00000000000..48fa31cfc5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/finiteBoundRestriction/JavaSuperType.fir.kt @@ -0,0 +1,5 @@ +// FILE: A.java +public class A {} + +// FILE: 1.kt +class B> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/illegalModifiersOnClass.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/illegalModifiersOnClass.fir.kt new file mode 100644 index 00000000000..342314424da --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/illegalModifiersOnClass.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -MANY_COMPANION_OBJECTS -REDECLARATION -DUPLICATE_CLASS_NAMES + +// KT-3464 Front-end shouldn't allow override modifier in class declaration + +override class A { + override companion object {} + open companion object {} + abstract companion object {} + final companion object {} +} + +override object B1 {} +open object B2 {} +abstract object B3 {} +final object B4 {} + +override enum class C {} +override interface D {} +override annotation class E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt new file mode 100644 index 00000000000..9a1eca03800 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kClassInSignature.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -TYPE_PARAMETER_AS_REIFIED -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun test1() = T::class +fun test2() = T::class + +val test3 = T::class +val test4 get() = T::class + +fun test5() = listOf(T::class) + +fun test6(): kotlin.reflect.KClass = T::class +fun test7(): kotlin.reflect.KClass<*> = T::class +fun test8() = String?::class + +fun listOf(e: T): List = null!! + +fun locals() { + fun test1() = T::class + fun test2() = T::class + + val test3 = L::class + fun test4() = L::class +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt1141.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt1141.fir.kt new file mode 100644 index 00000000000..bf8bdff235d --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt1141.fir.kt @@ -0,0 +1,21 @@ +//KT-1141 No check that object in 'object expression' implements all abstract members of supertype + +package kt1141 + +public interface SomeTrait { + fun foo() +} + +fun foo() { + val x = object : SomeTrait { + } + x.foo() +} + +object Rr : SomeTrait {} + +class C : SomeTrait {} + +fun foo2() { + val r = object : Runnable {} //no error +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt1193.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt1193.fir.kt new file mode 100644 index 00000000000..b26f7fcbaf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt1193.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +//KT-1193 Check enum entry supertype / initialization + +package kt1193 + +enum class MyEnum(val i: Int) { + A(12), + B //no error +} + +open class A(x: Int = 1) + +val x: MyEnum = MyEnum.A \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt2096.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt2096.fir.kt new file mode 100644 index 00000000000..94875fba26f --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt2096.fir.kt @@ -0,0 +1,7 @@ +//KT-2096 Abstract property with no type specified causes compiler to crash + +package c + +abstract class Foo{ + protected abstract val prop +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt2142.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt2142.fir.kt new file mode 100644 index 00000000000..4410e01c0a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt2142.fir.kt @@ -0,0 +1,8 @@ +//KT-2142 function local classes do not work + +package a + +fun foo() { + class Foo() {} + Foo() // Unresolved reference Foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt2397.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt2397.fir.kt new file mode 100644 index 00000000000..2f85101af3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt2397.fir.kt @@ -0,0 +1,17 @@ +//KT-2397 Prohibit final methods in traits with no implementation +package a + +interface T { + final fun foo() + final val b : Int + + final fun bar() {} + final val c : Int + get() = 42 + + final val d = 1 +} + +class A { + final fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt2631_MultipleDeclaration.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt2631_MultipleDeclaration.fir.kt new file mode 100644 index 00000000000..3a8cba18859 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt2631_MultipleDeclaration.fir.kt @@ -0,0 +1,27 @@ +// !CHECK_TYPE + +//KT-2631 Check multiple assignment +package a + +class MyClass { + operator fun component1() = 1 + operator fun component2() = "a" +} + +class MyClass2 {} + +operator fun MyClass2.component1() = 1.2 + +fun test(mc1: MyClass, mc2: MyClass2) { + val (a, b) = mc1 + checkSubtype(a) + checkSubtype(b) + + val (c) = mc2 + checkSubtype(c) + + //check no error types + checkSubtype(a) + checkSubtype(b) + checkSubtype(c) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt2643MultiDeclInControlFlow.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt2643MultiDeclInControlFlow.fir.kt new file mode 100644 index 00000000000..bce3e510276 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt2643MultiDeclInControlFlow.fir.kt @@ -0,0 +1,27 @@ +//KT-2643 Support multi-declarations in Data-Flow analysis +package n + +class C { + operator fun component1() = 1 + operator fun component2() = 2 +} + +fun test1(c: C) { + val (a, b) = c +} + +fun test2(c: C) { + val (a, b) = c + a + 3 +} + +fun test3(c: C) { + var (a, b) = c + a = 3 +} + +fun test4(c: C) { + var (a, b) = c + a = 3 + a + 1 +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/kt559.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/kt559.fir.kt new file mode 100644 index 00000000000..9a9657ce04a --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/kt559.fir.kt @@ -0,0 +1,30 @@ +//KT-559 Forbid abstract method call through super + +package kt559 + +abstract class A { + abstract val i : Int + + abstract fun foo() : Int + + fun fff() {} +} + +abstract class D(): A() { + override val i : Int = 34 +} + +class C() : D() { + fun test() { + super.i + } +} + +class B() : A() { + override fun foo(): Int { + super.i + + super.fff() //everything is ok + return super.foo() //no error!! + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localDeclarationModifiers.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localDeclarationModifiers.fir.kt new file mode 100644 index 00000000000..6b7a7bc265a --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/localDeclarationModifiers.fir.kt @@ -0,0 +1,12 @@ +package d + +class T { + fun baz() = 1 +} + +fun foo() { + public val i = 11 + abstract val j + override fun T.baz() = 2 + private fun bar() = 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localFunctionNoInheritVisibility.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localFunctionNoInheritVisibility.fir.kt new file mode 100644 index 00000000000..9cb85c36042 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/localFunctionNoInheritVisibility.fir.kt @@ -0,0 +1,16 @@ +package d + +class T { + fun baz() = 1 +} + +override fun zzz() {} + +fun foo(t: T) { + override fun T.baz() = 2 + + // was "Visibility is unknown yet exception" + t.baz() + + zzz() +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt new file mode 100644 index 00000000000..23ee4fd91c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: -ProhibitTypeParametersForLocalVariables + +import kotlin.reflect.KProperty + +fun test() { + val a0 = 0 + val a1 = "" + val a2 = 0 + const val a3 = 0 + lateinit val a4 = 0 + val a5 by Delegate() + val a6 by Delegate() +} + +class Delegate { + operator fun getValue(thisRef: Any?, property: KProperty<*>): String = "" + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt new file mode 100644 index 00000000000..7aa9f13ca44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: +ProhibitTypeParametersForLocalVariables + +import kotlin.reflect.KProperty + +fun test() { + val a0 = 0 + val a1 = "" + val a2 = 0 + const val a3 = 0 + lateinit val a4 = 0 + val a5 by Delegate() + val a6 by Delegate() +} + +class Delegate { + operator fun getValue(thisRef: Any?, property: KProperty<*>): String = "" + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.fir.kt new file mode 100644 index 00000000000..a51b6884050 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED +fun test(vararg x1: Int, vararg x2: Int) { + fun test2(vararg x1: Int, vararg x2: Int) { + class LocalClass(vararg x1: Int, vararg x2: Int) { + constructor(vararg x1: Int, vararg x2: Int, xx: Int) {} + } + fun test3(vararg x1: Int, vararg x2: Int) {} + } +} + +fun Any.test(vararg x1: Int, vararg x2: Int, vararg x3: Int) {} + +interface I { + fun test(vararg x1: Int, vararg x2: Int) +} + +abstract class C(vararg x1: Int, vararg x2: Int, b: Boolean) { + fun test(vararg x1: Int, vararg x2: Int) {} + + abstract fun test2(vararg x1: Int, vararg x2: Int) + + class CC(vararg x1: Int, vararg x2: Int, b: Boolean) { + constructor(vararg x1: Int, vararg x2: Int) {} + fun test(vararg x1: Int, vararg x2: Int) {} + } +} + +object O { + fun test(vararg x1: Int, vararg x2: Int) {} + + class CC(vararg x1: Int, vararg x2: Int, b: Boolean) { + constructor(vararg x1: Int, vararg x2: Int) {} + fun test(vararg x1: Int, vararg x2: Int) {} + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt new file mode 100644 index 00000000000..6bfd3b74317 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt @@ -0,0 +1,75 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +// !CHECK_TYPE +fun foo(block: () -> (() -> Int)) {} + +fun test() { + val x = fun named1(x: Int): Int { return 1 } + x checkType { _>() } + + foo { fun named2(): Int {return 1} } + foo({ fun named3() = 1 }) + + val x1 = + if (1 == 1) + // TODO: Diagnostic content could be better + fun named4(): Int {return 1} + else + fun named5() = 1 + + val x2 = + if (1 == 1) { + fun named6(): Int { + return 1 + } + } + else + fun named7() = 1 + + val x3 = when (1) { + 0 -> fun named8(): Int {return 1} + else -> fun named9() = 1 + } + + val x31 = when (1) { + 0 -> { + fun named10(): Int {return 1} + } + else -> fun named11() = 1 + } + + val x4 = { + y: Int -> fun named12(): Int {return 1} + } + + x4 checkType { _>() } + + { y: Int -> fun named14(): Int {return 1} } + val b = (fun named15(): Boolean { return true })() + + baz(fun named16(){}) +} + +fun bar() = fun named() {} + +fun run(block: () -> T): T = null!! +fun run2(block: () -> Unit): Unit = null!! +fun baz(obj: Any?) {} + +fun success() { + run { fun named1() = 1 } + run2 { fun named2() = 1 } + + val x = run { fun named3() = 1 } + x checkType { _() } + + val y = when (1) { + 0 -> { + fun named4(): Int {return 1} + } + else -> { + fun named5(): Int {return 1} + } + } + y checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin.fir.kt new file mode 100644 index 00000000000..f26dc514958 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UPPER_BOUND_VIOLATED + +//// FILE: D.java +public interface D {} + +// FILE: Q.java +public interface Q {} + +// FILE: C.java +public interface C extends D> {} + +// FILE: 1.kt +interface P : Q, C>> + diff --git a/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin2.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin2.fir.kt new file mode 100644 index 00000000000..0e95d892f06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/JavaWithKotlin2.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UPPER_BOUND_VIOLATED + +//// FILE: D.java +public interface D {} + +// FILE: Q.java +public interface Q {} + +// FILE: C.java +public interface C extends D> {} + +// FILE: P.java +public interface P extends Q, C>> {} + +// FILE: 1.kt +interface P1 : P \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/PureKotlin.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/PureKotlin.fir.kt new file mode 100644 index 00000000000..378bbb5bd72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/nonExpansiveInheritanceRestriction/PureKotlin.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UPPER_BOUND_VIOLATED + +interface A +interface B : A> + +interface N0 +interface C0 : N0>>> + +interface N1 +interface C1 : N1>>> +interface C2 : C1> + +interface C : D> +interface P : Q, C>> +interface Q +interface D + +interface E0 +interface E1 +interface E2 : E0> + +interface F0 +interface F1, U : F2<*>> +interface F2 : F0, T>> + +interface G0 +interface G1> +interface G2 : G0, T>> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/packageDeclarationModifiers.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/packageDeclarationModifiers.fir.kt new file mode 100644 index 00000000000..a7bf8455a1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/packageDeclarationModifiers.fir.kt @@ -0,0 +1,12 @@ +package d + +abstract val a : Int = 1 + +override val c : Int = 1 + +final fun foo() = 2 + +abstract fun baz() = 2 + +class T {} +override fun T.bar() = 2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/propertyInPackageHasNoInheritVisibility.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/propertyInPackageHasNoInheritVisibility.fir.kt new file mode 100644 index 00000000000..e0a5a606190 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/propertyInPackageHasNoInheritVisibility.fir.kt @@ -0,0 +1,10 @@ +package d + +override val f : ()-> Int = { 12 } + +fun test() { + f() +} + +var g: Int = 1 + protected set(i: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/sealedOnMembers.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/sealedOnMembers.fir.kt new file mode 100644 index 00000000000..fd7e97ebe76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/sealedOnMembers.fir.kt @@ -0,0 +1,18 @@ +interface A { + sealed fun foo() + sealed var bar: Unit +} + +interface B { + abstract fun foo() + abstract var bar: Unit +} + +interface C : A, B + +abstract class D(sealed var x: Int) { + abstract var y: Unit + sealed set +} + +abstract class E : D(42) diff --git a/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.fir.kt new file mode 100644 index 00000000000..edca51dff64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.fir.kt @@ -0,0 +1,175 @@ +open class MyClass { + fun f1() {} +} + + +class Foo { + + protected val protectedProperty = object : MyClass() {} + + public val publicProperty = object : MyClass() {} + + protected val protected2Property : MyClass = object : MyClass() {fun invisible() {}} + + public val public2Property : MyClass = object : MyClass() {fun invisible() {}} + + private val privateProperty = object : MyClass() {fun visible() {}} + + internal val internalProperty = object : MyClass() { fun invisible() {}} + + + fun testProperties() { + privateProperty.f1() + internalProperty.f1() + protected2Property.f1() + public2Property.f1() + + privateProperty.visible() + protected2Property.invisible() + public2Property.invisible() + internalProperty.invisible() + } + + + protected fun protectedFunction() = object : MyClass() {} + + public fun publicFunction() = object : MyClass() {} + + protected fun protected2Function(): MyClass = object : MyClass() {fun visible() {}} + + public fun public2Function(): MyClass = object : MyClass() {fun visible() {}} + + private fun privateFunction() = object : MyClass() {fun visible() {}} + + internal fun internalFunction() = object : MyClass() {fun invisible() {}} + + + fun testFunctions() { + privateFunction().f1() + internalFunction().f1() + public2Function().f1() + protected2Function().f1() + + privateFunction().visible() + internalFunction().invisible() + public2Function().invisible() + protected2Function().invisible() + } + + + class FooInner { + + public val publicProperty = object : MyClass() {} + + protected val protectedProperty = object : MyClass() {} + + protected val protected2Property : MyClass = object : MyClass() {fun invisible() {}} + + public val public2Property : MyClass = object : MyClass() {fun invisible() {}} + + private val privateProperty = object : MyClass() {fun visible() {}} + + internal val internalProperty = object : MyClass() { fun invisible() {}} + + + fun testProperties() { + privateProperty.f1() + internalProperty.f1() + protected2Property.f1() + public2Property.f1() + + privateProperty.visible() + protected2Property.invisible() + public2Property.invisible() + internalProperty.invisible() + } + + + protected fun protectedFunction() = object : MyClass() {} + + public fun publicFunction() = object : MyClass() {} + + protected fun protected2Function(): MyClass = object : MyClass() {fun visible() {}} + + public fun public2Function(): MyClass = object : MyClass() {fun visible() {}} + + private fun privateFunction() = object : MyClass() {fun visible() {}} + + internal fun internalFunction() = object : MyClass() {fun invisible() {}} + + + fun testFunctions() { + privateFunction().f1() + internalFunction().f1() + public2Function().f1() + protected2Function().f1() + + privateFunction().visible() + internalFunction().invisible() + public2Function().invisible() + protected2Function().invisible() + } + } + + fun foo() { + val localVar = object : MyClass() {} + localVar.f1() + fun foo2() = object : MyClass() {} + foo2().f1() + } + +} + +protected val packageProtectedProperty = object : MyClass() {} + +public val packagePublicProperty = object : MyClass() {} + +public val packagePublic2Property : MyClass = object : MyClass() {fun invisible() {}} + +private val packagePrivateProperty = object : MyClass() {fun invisible() {}} + +internal val packageInternalProperty = object : MyClass() {fun invisible() {}} + + +fun testProperties() { + packagePrivateProperty.f1() + packageInternalProperty.f1() + packagePublic2Property.f1() + + packagePrivateProperty.invisible() + packageInternalProperty.invisible() + packagePublic2Property.invisible() +} + + +private fun privateFunction() = object : MyClass() {fun invisible() {}} + +protected fun protectedFunction() = object : MyClass() {} + +public fun publicFunction() = object : MyClass() {} + +public fun public2Function() : MyClass = object : MyClass() {fun invisible() {}} + +internal fun internalFunction() = object : MyClass() {fun invisible() {}} + + + +fun testFunctions() { + privateFunction().f1() + internalFunction().f1() + public2Function().f1() + + privateFunction().invisible() + internalFunction().invisible() + public2Function().invisible() +} + +fun fooPackage() { + val packageLocalVar = object : MyClass() {fun visible() {}} + packageLocalVar.f1() + packageLocalVar.visible() + + fun fooPackageLocal() = object : MyClass() {fun visible() {}} + fooPackageLocal().f1() + fooPackageLocal().visible() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/valVarFunctionParameter.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/valVarFunctionParameter.fir.kt new file mode 100644 index 00000000000..8ddd32db866 --- /dev/null +++ b/compiler/testData/diagnostics/tests/declarationChecks/valVarFunctionParameter.fir.kt @@ -0,0 +1,12 @@ +fun f( + val a: Int, + var b: Int, + c: Int, + vararg var d: Int, + vararg val e: Int, + vararg f: Int +) { + + + a + b + c + d[0] + e[0] + f[0] // to avoid 'unused parameter' +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt b/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt new file mode 100644 index 00000000000..c41593397bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt @@ -0,0 +1,11 @@ +interface A { + fun visit(a:Int, b:String="") : String = b + a +} + +class B : A { + override fun visit(a:Int, b:String) : String = b + a +} + +class C : A { + override fun visit(a:Int) : String = "" + a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/defaultArguments/superCall.fir.kt b/compiler/testData/diagnostics/tests/defaultArguments/superCall.fir.kt new file mode 100644 index 00000000000..77305e62156 --- /dev/null +++ b/compiler/testData/diagnostics/tests/defaultArguments/superCall.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -ABSTRACT_SUPER_CALL + +abstract class A { + open fun foo(a: String = "default") { + } + + final fun foo2(a: String = "default") { + } + + abstract fun foo3(a: String = "default") +} + +open class B : A() { + fun test() { + super.foo("123") + super.foo() + + super.foo2("123") + super.foo2() + + super.foo3("123") + super.foo3() + } + + override fun foo3(a: String) { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutInitializer.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutInitializer.fir.kt new file mode 100644 index 00000000000..293bb83f024 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutInitializer.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val a: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutType.fir.kt new file mode 100644 index 00000000000..4276b095160 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/absentErrorAboutType.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val a by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/abstractDelegatedProperty.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/abstractDelegatedProperty.fir.kt new file mode 100644 index 00000000000..14895513007 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/abstractDelegatedProperty.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +abstract class A { + abstract val a: Int by Delegate() +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/backingField.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/backingField.fir.kt new file mode 100644 index 00000000000..7ad3dc1881f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/backingField.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class B { + val a: Int by Delegate() + + fun foo() = $a +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.fir.kt new file mode 100644 index 00000000000..7b2135dd43f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val a: Int by Delegate() + get + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/defaultSetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/defaultSetter.fir.kt new file mode 100644 index 00000000000..b64b84beb28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/defaultSetter.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +var a: Int by Delegate() + private set + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + + operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTrait.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTrait.fir.kt new file mode 100644 index 00000000000..1a63e3362c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTrait.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +interface A { + val prop: Int +} + +class AImpl: A { + override val prop by Delegate() +} + +fun foo() { + AImpl().prop +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTraitTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTraitTypeMismatch.fir.kt new file mode 100644 index 00000000000..d23a9803b84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTraitTypeMismatch.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +interface A { + val prop: Int +} + +class AImpl: A { + override val prop by Delegate() +} + +fun foo() { + AImpl().prop +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): String { + return "" + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/disallowImplInTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/disallowImplInTypeParameter.fir.kt new file mode 100644 index 00000000000..6c6e19266f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/disallowImplInTypeParameter.fir.kt @@ -0,0 +1,7 @@ +import kotlin.reflect.KProperty0 + +val a: Int by A() + +class A { + fun getValue(t: Any?, p: KProperty0<*>): Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/genericGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/genericGetter.fir.kt new file mode 100644 index 00000000000..8c841bef535 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/genericGetter.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val a: Int by A(1) + +class A(i: T) { + operator fun getValue(t: Any?, p: KProperty<*>): T { + throw Exception() + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/getterWithSubtype.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/getterWithSubtype.fir.kt new file mode 100644 index 00000000000..c567c076187 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/getterWithSubtype.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +open class Base +class Derived: Base() + +val a: Base by A() + +class A { + operator fun getValue(t: Any?, p: KProperty<*>): Derived { + return Derived() + } +} + diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inTrait.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inTrait.fir.kt new file mode 100644 index 00000000000..cbffec8a11e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inTrait.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +interface T { + val a: Int by Delegate() +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt new file mode 100644 index 00000000000..8a6d09a8a9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A + +class D { + val c: Int by IncorrectThis() +} + +val cTopLevel: Int by IncorrectThis() + +class IncorrectThis { + fun get(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/callableReferenceArgumentInDelegatedExpression.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/callableReferenceArgumentInDelegatedExpression.fir.kt new file mode 100644 index 00000000000..8025b9d7d9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/callableReferenceArgumentInDelegatedExpression.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class Inv2 + +fun create(g: (T) -> K): Inv2 = TODO() + +operator fun Inv2.getValue(o: Sample, desc: KProperty<*>): V1 = TODO() +operator fun Inv2.setValue(o: Sample, desc: KProperty<*>, value: V2) {} + +class Version(val version: Int) + +class Sample { + var version: Version by create(::Version) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.fir.kt new file mode 100644 index 00000000000..2f1e994bd1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/delegateExpressionAsLambda.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +fun test(i: Int) { + val bad by myLazyDelegate { + createSample(i) { it.toString() } + } + + takeSample(bad) +} + +fun myLazyDelegate(i: () -> T): LazyDelegate = LazyDelegate(i()) + +class LazyDelegate(val v: T) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO() +} + +class Sample + +fun takeSample(g: Sample) {} +fun createSample(i: T, a: (T) -> S): Sample = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt new file mode 100644 index 00000000000..6e5716a408a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt @@ -0,0 +1,53 @@ +// !WITH_NEW_INFERENCE +package baz + +import kotlin.reflect.KProperty + +class A(outer: Outer) { + var i: String by + getMyConcreteProperty() + var d: String by getMyConcreteProperty() - 1 + var c: String by O.getMyProperty() + var g: String by outer.getContainer().getMyProperty() + + + var b: String by foo(getMyProperty()) + var r: String by foo(outer.getContainer().getMyProperty()) + var e: String by + foo(getMyProperty()) + var f: String by foo(getMyProperty()) - 1 +} + +fun foo(a: Any?) = MyProperty() + +fun getMyProperty() = MyProperty() + +fun getMyConcreteProperty() = MyProperty() + +class MyProperty { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + println("get $thisRef ${desc.name}") + return null as T + } + + operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) { + println("set $thisRef ${desc.name} $value") + } +} + +operator fun MyProperty.unaryPlus() = MyProperty() +operator fun MyProperty.minus(i: Int) = MyProperty() + +object O { + fun getMyProperty() = MyProperty() +} + +interface MyPropertyContainer { + fun getMyProperty(): MyProperty +} + +interface Outer { + fun getContainer(): MyPropertyContainer +} + +// ----------------- +fun println(a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionGet.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionGet.fir.kt new file mode 100644 index 00000000000..ad70419a6b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionGet.fir.kt @@ -0,0 +1,35 @@ +package foo + +import kotlin.reflect.KProperty + +class A1 { + val a: String by MyProperty1() +} + +class MyProperty1 {} +operator fun MyProperty1.getValue(thisRef: Any?, desc: KProperty<*>): String { + throw Exception("$thisRef $desc") +} + +//-------------------- + +class A2 { + val a: String by MyProperty2() +} + +class MyProperty2 {} +operator fun MyProperty2.getValue(thisRef: Any?, desc: KProperty<*>): T { + throw Exception("$thisRef $desc") +} + +//-------------------- + +class A3 { + val a: String by MyProperty3() + + class MyProperty3 {} + + operator fun MyProperty3.getValue(thisRef: Any?, desc: KProperty<*>): T { + throw Exception("$thisRef $desc") + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt new file mode 100644 index 00000000000..e34203d0b3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +package foo + +import kotlin.reflect.KProperty + +open class A { + val B.w: Int by MyProperty() +} + +val B.r: Int by MyProperty() + +val A.e: Int by MyProperty() + +class B { + val A.f: Int by MyProperty() +} + +class MyProperty { + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + throw Exception("$thisRef $desc") + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt new file mode 100644 index 00000000000..9ac6919c7db --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A() { + operator fun getValue(t: Any?, p: KProperty<*>): T = null!! + operator fun setValue(t: Any?, p: KProperty<*>, x: T) = Unit +} + +var a1: Int by A() +var a2: Int by A() + +class B() { + operator fun getValue(t: Any?, p: KProperty<*>): T = null!! + operator fun setValue(t: Any?, p: KProperty<*>, x: R) = Unit +} + +var b1: Int by B() +var b2: Int by B() + +class C() { + operator fun getValue(t: Any?, p: KProperty<*>): R = null!! + operator fun setValue(t: Any?, p: KProperty<*>, x: T) = Unit +} + +var c1: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt new file mode 100644 index 00000000000..eae33a570c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +import kotlin.reflect.KProperty + +var a: Int by A() +var a1 by A() + +var b: Int by B() + +val cObj = C() +var c: String by cObj + +class A { + operator fun getValue(t: Any?, p: KProperty<*>): T = null!! + operator fun setValue(t: Any?, p: KProperty<*>, x: T) = Unit +} + +class B + +operator fun B.getValue(t: Any?, p: KProperty<*>): T = null!! +operator fun B.setValue(t: Any?, p: KProperty<*>, x: T) = Unit + +class C + +operator inline fun C.getValue(t: Any?, p: KProperty<*>): T = null!! +operator inline fun C.setValue(t: Any?, p: KProperty<*>, x: T) = Unit diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt new file mode 100644 index 00000000000..f8290772eae --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt @@ -0,0 +1,11 @@ +import kotlin.reflect.KProperty + +class A3 { + val a: String by l@ MyProperty() + + class MyProperty {} + + operator fun MyProperty.getValue(thisRef: Any?, desc: KProperty<*>): T { + throw Exception("$thisRef $desc") + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt new file mode 100644 index 00000000000..8f2adfea2c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// FILE: main.kt +package test + +import first.* +import second.* + +val a12 by A() + +// FILE: first.kt +package first + +import kotlin.reflect.KProperty + +class A + +public operator fun A.getValue(thisRef: Any?, property: KProperty<*>): T = null!! + + +// FILE: second.kt +package second + +import first.A +import kotlin.reflect.KProperty + +public operator fun A.getValue(thisRef: Any?, property: KProperty<*>): T = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt new file mode 100644 index 00000000000..3e58fc32755 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt @@ -0,0 +1,45 @@ +// !WITH_NEW_INFERENCE +package foo + +import kotlin.reflect.KProperty + +class A { + var a5: String by MyProperty1() + var b5: String by getMyProperty1() +} + +fun getMyProperty1() = MyProperty1() + +class MyProperty1 { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + throw Exception() + } + + operator fun setValue(i: Int, j: Any, k: Int) { + println("set") + } +} + +// ----------------- + +class B { + var a5: String by MyProperty2() + var b5: String by getMyProperty2() +} + +fun getMyProperty2() = MyProperty2() + +class MyProperty2 { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + throw Exception() + } + + operator fun setValue(i: Int) { + println("set") + } +} + +// ----------------- +fun println(a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.fir.kt new file mode 100644 index 00000000000..d06461aa5d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +import kotlin.reflect.KProperty + +class A { + var a by MyProperty() +} + +class MyProperty { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + throw Exception("$thisRef $desc") + } + + operator fun setValue(thisRef: R, desc: KProperty<*>, t: T) { + throw Exception("$thisRef $desc $t") + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.fir.kt new file mode 100644 index 00000000000..0e4b41d5ec0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A +class B + +fun A.toB(f: (V) -> K, g: (K) -> V): B = B() + +operator fun B.getValue(o: Any, desc: KProperty<*>): E1 = TODO() +operator fun B.setValue(o: Any, desc: KProperty<*>, value: E2) {} + +val q = A() + +class Test { + var prop by q.toB({ "abc" }, { "cde" }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.fir.kt new file mode 100644 index 00000000000..5cc2c1fec01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val b: First by lazy { + object : First { } +} + +private val withoutType by lazy { + object : First { } +} + +private val withTwoSupertypes by lazy { + object : First, Second { } +} + +class A { + val a: First by lazy { + object : First { } + } +} + +interface First +interface Second + +fun lazy(initializer: () -> T): Lazy = TODO() +interface Lazy { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.fir.kt new file mode 100644 index 00000000000..684cd8878f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +import kotlin.reflect.KProperty + +class A { + val a by MyProperty() + + fun test() { + checkSubtype(a) + } +} + +class MyProperty { + operator fun getValue(thisRef: R, desc: KProperty<*>): Int = throw Exception("$thisRef $desc") +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedType.fir.kt new file mode 100644 index 00000000000..2b4955d7f04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedType.fir.kt @@ -0,0 +1,76 @@ +package foo + +import kotlin.reflect.KProperty + +class A1 { + var a1: String by MyProperty1() + var b1: String by getMyProperty1() +} + +var c1: String by getMyProperty1() +var d1: String by MyProperty1() + +fun getMyProperty1() = MyProperty1() + +class MyProperty1 { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + println("get $thisRef ${desc.name}") + throw Exception() + } + + operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) { + println("set $thisRef ${desc.name} $value") + } +} + +//-------------------------- + +class A2 { + var a2: String by MyProperty2() + var b2: String by getMyProperty2() +} + +var c2: String by getMyProperty2() +var d2: String by MyProperty2() + +fun getMyProperty2() = MyProperty2() + +class MyProperty2 { + + operator fun getValue(thisRef: Any?, desc: KProperty<*>): T { + println("get $thisRef ${desc.name}") + throw Exception() + } + + operator fun setValue(thisRef: Any?, desc: KProperty<*>, value: T) { + println("set $thisRef ${desc.name} $value") + } +} + +//-------------------------- + +class A3 { + var a3: String by MyProperty3() + var b3: String by getMyProperty3() +} + +var c3: String by getMyProperty3() +var d3: String by MyProperty3() + +fun getMyProperty3() = MyProperty3() + +class MyProperty3 { + + operator fun getValue(thisRef: T, desc: KProperty<*>): String { + println("get $thisRef ${desc.name}") + return "" + } + + operator fun setValue(thisRef: Any?, desc: KProperty<*>, value: T) { + println("set $thisRef ${desc.name} $value") + } +} + +//-------------------------- +fun println(a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedTypeForVal.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedTypeForVal.fir.kt new file mode 100644 index 00000000000..2a4e6fdd94a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedTypeForVal.fir.kt @@ -0,0 +1,64 @@ +package foo + +import kotlin.reflect.KProperty + +class A1 { + val a1: String by MyProperty1() + val b1: String by getMyProperty1() +} + +val c1: String by getMyProperty1() +val d1: String by MyProperty1() + +fun getMyProperty1() = MyProperty1() + +class MyProperty1 { + + operator fun getValue(thisRef: R, desc: KProperty<*>): T { + println("get $thisRef ${desc.name}") + throw Exception() + } +} + +//-------------------------- + +class A2 { + val a2: String by MyProperty2() + val b2: String by getMyProperty2() +} + +val c2: String by getMyProperty2() +val d2: String by MyProperty2() + +fun getMyProperty2() = MyProperty2() + +class MyProperty2 { + + operator fun getValue(thisRef: Any?, desc: KProperty<*>): T { + println("get $thisRef ${desc.name}") + throw Exception() + } +} + +//-------------------------- + +class A3 { + val a3: String by MyProperty3() + val b3: String by getMyProperty3() +} + +val c3: String by getMyProperty3() +val d3: String by MyProperty3() + +fun getMyProperty3() = MyProperty3() + +class MyProperty3 { + + operator fun getValue(thisRef: T, desc: KProperty<*>): String { + println("get $thisRef ${desc.name}") + return "" + } +} + +//-------------------------- +fun println(a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt new file mode 100644 index 00000000000..dbfc1239d50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt @@ -0,0 +1,11 @@ +//KT-4640 "Trace is erased after resolution completion" exception + +class ValueWrapper() +{ + var backingValue: Int = 0 + + fun getValue() = backingValue + fun setValue(v: Int) { backingValue = v } +} + +val foo by ValueWrapper() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/localVariable.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/localVariable.fir.kt new file mode 100644 index 00000000000..4816a3d23d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/localVariable.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +import kotlin.reflect.KProperty + +class Local { + fun foo() { + val a: Int by Delegate() + } +} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/localWithSmartCast.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/localWithSmartCast.fir.kt new file mode 100644 index 00000000000..fe1a2320bf8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/localWithSmartCast.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface A { + operator fun getValue(x: Any?, y: Any?): Any? +} + +interface B : A { + override fun getValue(x: Any?, y: Any?): Int +} + +fun test(a: A) { + if (a is B) { + val x: Int by a + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt new file mode 100644 index 00000000000..34e79520b60 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt @@ -0,0 +1,3 @@ +val a: Int by A() + +class A diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt new file mode 100644 index 00000000000..f0e5d03622b --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +var a: Int by A() + +class A { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt new file mode 100644 index 00000000000..bc1fa1e3ab4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt @@ -0,0 +1,12 @@ +// KT-11809 Assertion error when delegated property has getter + +class A { + val p1 by this + get + + var p2 by this + get() = "" + + operator fun getValue(a: Any?, p: Any?) = "" + operator fun setValue(a: Any?, p: Any?, v: Any?) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt new file mode 100644 index 00000000000..2ff3633fde0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// NI_EXPECTED_FILE + +import kotlin.reflect.KProperty + +class B { + val c by Delegate(ag) +} + +class Delegate(val init: T) { + operator fun getValue(t: Any?, p: KProperty<*>): Int = null!! +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/commonCaseForInference.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/commonCaseForInference.fir.kt new file mode 100644 index 00000000000..1da5044c59f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/commonCaseForInference.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object CommonCase { + interface Fas + + fun delegate() : Fas = TODO() + + operator fun Fas.provideDelegate(host: D, p: Any?): Fas = TODO() + operator fun Fas.getValue(receiver: E, p: Any?): R = TODO() + + val Long.test1: String by delegate() // common test, not working because of Inference1 + val Long.test2: String by delegate() // should work +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/genericProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/genericProvideDelegate.fir.kt new file mode 100644 index 00000000000..5ccafeeeac3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/genericProvideDelegate.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Cell(val value: V) + +class GenericDelegate(val value: V) + +operator fun T.provideDelegate(a: Any?, p: Any?) = GenericDelegate(this) + +operator fun GenericDelegate.getValue(a: Any?, p: Any?) = Cell(value) + +val test1: Cell by "OK" +val test2: Cell by "OK" +val test3 by "OK" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt new file mode 100644 index 00000000000..03a654b3bac --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object T1 { + operator fun Int.provideDelegate(host: T1, p: Any): Long = 2 + operator fun Long.getValue(receiver: String, p: Any): Double = 1.0 + + val String.test1 by 1 + val test2 by 1 +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt new file mode 100644 index 00000000000..550fd8ef522 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object T2 { + interface Foo + + fun delegate(): Foo = TODO() + + operator fun Foo.provideDelegate(host: T2, p: Any?): Foo = TODO() + operator fun Foo.getValue(receiver: String, p: Any?): T = TODO() + + val String.test1: String by delegate() + val test2: String by delegate() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver3.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver3.fir.kt new file mode 100644 index 00000000000..724f8ffddad --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver3.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object T3 { + interface Foo + + fun delegate(): Foo = TODO() + + operator fun Foo.provideDelegate(host: T3, p: Any?): Foo = TODO() + operator fun Foo.getValue(receiver: T3, p: Any?): T = TODO() + + val test1: String by delegate() +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver1.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver1.fir.kt new file mode 100644 index 00000000000..492602db86f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver1.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Inference1 { + interface Foo + + fun delegate(): Foo = TODO() + + operator fun Foo.getValue(receiver: T, p: Any?): String = TODO() + + // not working because resulting descriptor for getValue contains type `???` instead of `T` + val test1: String by delegate() + + val test2: String by delegate() +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver2.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver2.fir.kt new file mode 100644 index 00000000000..ab1e797532d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/inferenceFromReceiver2.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Inference2 { + interface Foo + + fun delegate(): Foo = TODO() + + operator fun Foo.provideDelegate(host: T, p: Any?): Foo = TODO() + operator fun Foo.getValue(receiver: Inference2, p: Any?): String = TODO() + + val test1: String by delegate() // same story like in Inference1 + val test2: String by delegate() +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/localDelegatedProperty.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/localDelegatedProperty.fir.kt new file mode 100644 index 00000000000..59e33c206a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/localDelegatedProperty.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +operator fun String.provideDelegate(a: Any?, p: KProperty<*>) = this +operator fun String.getValue(a: Any?, p: KProperty<*>) = this + +fun test(): String { + val result by "OK" + return result +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt new file mode 100644 index 00000000000..5f1e4692894 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class StringDelegate(val s: String) { + operator fun getValue(a: Any?, p: KProperty<*>): Int = 42 +} + +// NB no operator +fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this) + +operator fun String.getValue(a: Any?, p: KProperty<*>) = this + +val test1: String by "OK" +val test2: Int by "OK" +val test3 by "OK" + diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.fir.kt new file mode 100644 index 00000000000..ef9c64db88c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/overloadResolutionForSeveralProvideDelegates.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import kotlin.reflect.KProperty + +object Foo +object Bar +object Baz + +operator fun Foo.provideDelegate(receiver: Any?, property: KProperty<*>) = this +operator fun Bar.provideDelegate(receiver: Any?, property: KProperty<*>) = this + +operator fun Foo.getValue(nothing: Any?, property: KProperty<*>): Any = TODO() +operator fun Bar.getValue(nothing: Any?, property: KProperty<*>): Any = TODO() +operator fun Baz.getValue(nothing: Any?, property: KProperty<*>): Any = TODO() + +fun test() { + val bar by Baz +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.fir.kt new file mode 100644 index 00000000000..1bcc06edadb --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOperatorDeclaration.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +operator fun provideDelegate(x: Any?, p: KProperty<*>) {} + +operator fun Any.provideDelegate(x: Any?, p: KProperty<*>) {} + +operator fun Any.provideDelegate(x: Any?, p: Any) {} + +operator fun Any.provideDelegate(x: Any?, p: Int) {} + +class Host1 { + operator fun provideDelegate(x: Any?, p: KProperty<*>) {} +} + +class Host2 { + operator fun Any.provideDelegate(x: Any?, p: KProperty<*>) {} +} + +class Host3 { + operator fun provideDelegate(x: Any?, p: KProperty<*>, foo: Int) {} +} + +class Host4 { + operator fun provideDelegate(x: Any?, p: KProperty<*>, foo: Int = 0) {} +} + +class Host5 { + operator fun provideDelegate(x: Any?, p: KProperty<*>, vararg foo: Int) {} +} + diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.fir.kt new file mode 100644 index 00000000000..03d0eae31be --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Delegate + +operator fun Delegate<*>.getValue(receiver: Any?, p: Any): String = "" +operator fun Delegate.setValue(receiver: Any?, p: Any, value: T) {} + +operator fun String.provideDelegate(receiver: Any?, p: Any) = Delegate() + +var test1: String by Delegate() +var test2: String by Delegate() + +var test3: String by "OK" + +var test4: String by "OK".provideDelegate(null, "") +var test5: String by "OK".provideDelegate(null, "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/simpleProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/simpleProvideDelegate.fir.kt new file mode 100644 index 00000000000..313f52e12ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/simpleProvideDelegate.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +operator fun String.provideDelegate(a: Any?, p: KProperty<*>) = this +operator fun String.getValue(a: Any?, p: KProperty<*>) = this + +val test1: String by "OK" + +val test2 by "OK" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.fir.kt new file mode 100644 index 00000000000..cd1410a8fc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: -OperatorProvideDelegate + +class WrongDelegate(val x: Int) { + operator fun getValue(thisRef: Any?, prop: Any): Int = x +} + +operator fun String.provideDelegate(thisRef: Any?, prop: Any) = WrongDelegate(this.length) + +operator fun String.getValue(thisRef: Any?, prop: Any) = this + +val test1: String by "OK" +val test2: Int by "OK" +val test3 by "OK" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt new file mode 100644 index 00000000000..36cb8a7c3cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// NI_EXPECTED_FILE + +import kotlin.reflect.KProperty + +val a by a + +val b by Delegate(b) + +val c by d +val d by c + +class Delegate(i: Int) { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt new file mode 100644 index 00000000000..3749eb07218 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val a: Int by Delegate() + get() = 1 + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt new file mode 100644 index 00000000000..a7009e50fa9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +var a: Int by Delegate() + get() = 1 + set(i) {} + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + + operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt new file mode 100644 index 00000000000..8a56c046275 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class D { + var c: Int by Delegate() +} + +var cTopLevel: Int by Delegate() + +class A + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + operator fun setValue(t: A, p: KProperty<*>, i: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterWithSupertype.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterWithSupertype.fir.kt new file mode 100644 index 00000000000..694a5ca0436 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/setterWithSupertype.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +open class Base +class Derived: Base() + +var a: Derived by A() + +class A { + operator fun getValue(t: Any?, p: KProperty<*>): Derived { + return Derived() + } + + operator fun setValue(t: Any?, p: KProperty<*>, i: Base) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/severalReceivers.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/severalReceivers.fir.kt new file mode 100644 index 00000000000..f1864d532dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/severalReceivers.fir.kt @@ -0,0 +1,13 @@ +import kotlin.reflect.KProperty + +class A + +object Delegate { + operator fun getValue(state: A, desc: KProperty<*>): Int = 0 + operator fun setValue(state: A, desc: KProperty<*>, value: Int) {} +} + +open class B { + val A.foo: Int by Delegate + var A.bar: Int by Delegate +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt new file mode 100644 index 00000000000..86c404b813b --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val Int.a by Delegate(this) + +class A { + val Int.a by Delegate(this) +} + +class Delegate(i: Int) { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfAnyType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfAnyType.fir.kt new file mode 100644 index 00000000000..04ef269bb5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfAnyType.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A { + var a: Int by Delegate() +} + +var aTopLevel: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + operator fun setValue(t: Any?, p: KProperty<*>, a: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt new file mode 100644 index 00000000000..9a35ad515a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +import kotlin.reflect.KProperty + +class A { + var a: Int by Delegate() +} + +var aTopLevel: Int by Delegate() + +class Delegate { + operator fun getValue(t: Nothing?, p: KProperty<*>): Int { + return 1 + } + operator fun setValue(t: Nothing?, p: KProperty<*>, a: Int) { + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt new file mode 100644 index 00000000000..04161d13bc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +import kotlin.reflect.KProperty + +class A { + var a: Int by Delegate() +} + +var aTopLevel: Int by Delegate() + +class Delegate { + fun getValue(t: Nothing, p: KProperty<*>): Int { + return 1 + } + fun setValue(t: Nothing, p: KProperty<*>, a: Int) { + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt new file mode 100644 index 00000000000..5963ce7fcc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A { + val c: Int by Delegate() +} + +class Delegate { + fun getValue(t: Int, p: KProperty<*>): Int { + return 1 + } + + fun getValue(t: String, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt new file mode 100644 index 00000000000..86f995861b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +val c: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): String { + return "" + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt new file mode 100644 index 00000000000..4c101ed1aef --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A + +class B { + val b: Int by Delegate() +} + +val bTopLevel: Int by Delegate() + +class C { + val c: Int by Delegate() +} + +val cTopLevel: Int by Delegate() + +class Delegate { + operator fun getValue(t: T, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt new file mode 100644 index 00000000000..c7001296a54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A { + var a: Int by Delegate() +} + +var aTopLevel: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + operator fun setValue(t: Any?, p: KProperty<*>, i: String) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt new file mode 100644 index 00000000000..2b5712dd009 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +import kotlin.reflect.KProperty + +class B { + val b: Int by Delegate() +} + +val bTopLevel: Int by Delegate() + +class A + +class Delegate { + fun getValue(t: A, p: KProperty<*>): Int { + return 1 + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt new file mode 100644 index 00000000000..3feab5ec632 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A { + val a: Int by Delegate() +} + +val aTopLevel: Int by Delegate() + +class Delegate { + fun getValue(t: Any?, p: KProperty<*>, a: Int): Int { + return a + } +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt new file mode 100644 index 00000000000..747b8a09c8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A { + var a: Int by Delegate() +} + +var aTopLevel: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + + operator fun setValue(t: Any?, p: KProperty<*>, a: Int, c: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongSetterReturnType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongSetterReturnType.fir.kt new file mode 100644 index 00000000000..656d940c014 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/wrongSetterReturnType.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +var b: Int by Delegate() + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int { + return 1 + } + + operator fun setValue(t: Any?, p: KProperty<*>, i: Int): Int { + return i + } +} diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.fir.kt b/compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.fir.kt new file mode 100644 index 00000000000..0f8abd5ae75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.fir.kt @@ -0,0 +1,38 @@ +package override + +interface T { + fun foo() + val v : Int +} + +open class Br(t : T) : T { + +} + +class Br3(t : T) : Br(t) { + +} + +open class Br1(t : T) : T by t { + +} + +class Br2(t : T) : Br1(t) { + +} + +interface G { + fun foo(t : T) : T +} + +class GC() : G { + +} + +open class GC1(g : G) : G by g { + +} + +open class GC2(g : G) : GC1(g) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.fir.kt b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.fir.kt new file mode 100644 index 00000000000..3a14bea8dbe --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A { + fun foo(): Int +} + +class AImpl: A { + override fun foo() = 42 +} + +class B : A by AImpl() + +fun bar(): A = AImpl() + +class C : A by bar() + +fun baz(f: (T) -> T): A = AImpl() + +class D : A by baz({ it + 1 }) + +fun boo(t: T): A = AImpl() + +class E : A by boo("") + +class F : A by AImpl() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.fir.kt b/compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.fir.kt new file mode 100644 index 00000000000..a2be1fa6abc --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.fir.kt @@ -0,0 +1,15 @@ +open class Foo() { + +} + +class Barrr() : Foo by Foo() {} + +interface T {} + +class Br(t : T) : T by t {} + +open enum class EN() { + A +} + +class Test2(e : EN) : EN by e {} diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.fir.kt b/compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.fir.kt new file mode 100644 index 00000000000..07044ecce1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.fir.kt @@ -0,0 +1,4 @@ +// JAVAC_EXPECTED_FILE +class TestIface(r : Runnable) : Runnable by r {} + +class TestObject(o : Object) : Object by o {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.fir.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.fir.kt new file mode 100644 index 00000000000..075ec0d7e46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS +interface One { + public fun foo(): Any? +} +interface Two { + public fun foo(): String? +} + +interface Three { + public fun foo(): String +} + +class Test123(val v1: One, val v2: Two, val v3: Three) : One by v1, Two by v2, Three by v3 { } +class Test132(val v1: One, val v2: Two, val v3: Three) : One by v1, Three by v3, Two by v2 { } +class Test312(val v1: One, val v2: Two, val v3: Three) : Three by v3, One by v1, Two by v2 { } +class Test321(val v1: One, val v2: Two, val v3: Three) : Three by v3, Two by v2, One by v1 { } +class Test231(val v1: One, val v2: Two, val v3: Three) : Two by v2, Three by v3, One by v1 { } +class Test213(val v1: One, val v2: Two, val v3: Three) : Two by v2, One by v1, Three by v3 { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.fir.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.fir.kt new file mode 100644 index 00000000000..a92b0861c9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.fir.kt @@ -0,0 +1,12 @@ +interface A { + fun foo() {} +} + +open class B(a: A) : A by a + +class C(a: A): B(a), A { +} + +fun b(c: C) { + c.foo(); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.fir.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.fir.kt new file mode 100644 index 00000000000..22c4949bf8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS +interface One { + public open fun foo() : Int + private fun boo() = 10 +} +interface Two { + public open fun foo() : Int +} + +interface OneImpl : One { + public override fun foo() = 1 +} +interface TwoImpl : Two { + public override fun foo() = 2 +} + +class Test1() : TwoImpl, OneImpl {} +class Test2(a : One) : One by a, Two {} +class Test3(a : One, b : Two) : Two by b, One by a {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.fir.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.fir.kt new file mode 100644 index 00000000000..269d5360436 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.fir.kt @@ -0,0 +1,10 @@ +interface A { + fun foo() {} +} + +interface B : A {} + +class C(b : B) : B by b { + +} + diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.fir.kt b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.fir.kt new file mode 100644 index 00000000000..e22d9bc2926 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.fir.kt @@ -0,0 +1,56 @@ +// !WITH_NEW_INFERENCE +open class Final { + fun foo() {} + val bar: Int = 0 + var qux: Int = 0 +} + +open class Derived : Final() + +interface IFoo { + fun foo() +} + +class CFoo : IFoo { + override fun foo() {} +} + +interface IBar { + val bar: Int +} + +class CBar : IBar { + override val bar: Int get() = 0 +} + +interface IQux { + val qux: Int +} + +class CQux : IQux { + override val qux: Int get() = 0 +} + +interface IBarT { + val bar: T +} + +class CBarT : IBarT { + override val bar: T get() = null!! +} + +class Test1 : Final(), IFoo by CFoo() + +class Test2 : Final(), IBar by CBar() + +class Test3 : Final(), IQux by CQux() + +class Test4 : Derived(), IFoo by CFoo() + +class Test5 : Derived(), IBar by CBar() + +class Test6 : Derived(), IQux by CQux() + +class Test7 : Final(), IBarT by CBarT() + +class Test8 : Final(), IBarT by CBar() diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.fir.kt new file mode 100644 index 00000000000..023163cdfec --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.fir.kt @@ -0,0 +1,57 @@ +interface IStr { + val foo: String +} + +class CStr : IStr { + override val foo: String get() = "" +} + +interface IInt { + val foo: Int +} + +class CInt : IInt { + override val foo: Int get() = 42 +} + +interface IAny { + val foo: Any +} + +class CAny : IAny { + override val foo: Any get() = null!! +} + +interface IGeneric { + val foo: T +} + +class CGeneric : IGeneric { + override val foo: T get() = null!! +} + +abstract class Test1 : IStr by CStr(), IInt + +abstract class Test2 : IStr, IInt by CInt() + +abstract class Test3 : IStr by CStr(), IInt by CInt() + +abstract class Test4 : IStr by CStr(), IGeneric + +abstract class Test5 : IStr by CStr(), IGeneric + +abstract class Test6 : IStr by CStr(), IGeneric + +abstract class Test7 : IGeneric by CGeneric(), IStr + +abstract class Test8 : IGeneric by CGeneric(), IInt + +// Can't test right now due to https://youtrack.jetbrains.com/issue/KT-10258 +// abstract class Test9 : IGeneric by CGeneric(), IGeneric + +abstract class Test10 : IInt by CInt(), IStr by CStr(), IAny by CAny() + +abstract class Test11 : IInt, IStr by CStr(), IAny by CAny() + +abstract class Test12 : IInt, IStr, IAny by CAny() + diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.fir.kt new file mode 100644 index 00000000000..1b7454f373f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.fir.kt @@ -0,0 +1,59 @@ +interface IStr { + fun foo(): String +} + +class CStr : IStr { + override fun foo(): String = "" +} + +interface IInt { + fun foo(): Int +} + +class CInt : IInt { + override fun foo(): Int = 42 +} + +interface IAny { + fun foo(): Any +} + +class CAny : IAny { + override fun foo(): Any = null!! +} + +interface IGeneric { + fun foo(): T +} + +class CGeneric : IGeneric { + override fun foo(): T { + throw UnsupportedOperationException() + } +} + +abstract class Test1 : IStr by CStr(), IInt + +abstract class Test2 : IStr, IInt by CInt() + +abstract class Test3 : IStr by CStr(), IInt by CInt() + +abstract class Test4 : IStr by CStr(), IGeneric + +abstract class Test5 : IStr by CStr(), IGeneric + +abstract class Test6 : IStr by CStr(), IGeneric + +abstract class Test7 : IGeneric by CGeneric(), IStr + +abstract class Test8 : IGeneric by CGeneric(), IInt + +// Can't test due to https://youtrack.jetbrains.com/issue/KT-10258 +// abstract class Test9 : IGeneric by CGeneric(), IGeneric + +abstract class Test10 : IInt by CInt(), IStr by CStr(), IAny by CAny() + +abstract class Test11 : IInt, IStr by CStr(), IAny by CAny() + +abstract class Test12 : IInt, IStr, IAny by CAny() + diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.fir.kt b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.fir.kt new file mode 100644 index 00000000000..77def9382cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.fir.kt @@ -0,0 +1,29 @@ +interface IVar { + var foo: Int +} + +interface IDerived : IVar + +interface IVal { + val foo: Int +} + +class CVal : IVal { + override val foo: Int get() = 42 +} + +interface IValT { + val foo: T +} + +class CValT : IValT { + override val foo: T get() = null!! +} + +abstract class Test1 : IVar, IVal by CVal() + +abstract class Test2 : IVar, IValT by CValT() + +abstract class Test3 : IDerived, IVal by CVal() + +abstract class Test4 : IDerived, IValT by CValT() diff --git a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.fir.kt b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.fir.kt new file mode 100644 index 00000000000..b4db71d128a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.fir.kt @@ -0,0 +1,19 @@ +interface IBase1 { + fun foo(): Any +} + +open class IDerived1 : IBase1 { + override fun foo(): String = "1" +} + +class Broken1(val b: IBase1) : IBase1 by b, IDerived1() + +interface IBase2 { + val foo: Any +} + +open class IDerived2 : IBase2 { + override val foo: String = "2" +} + +class Broken2(val b: IBase2) : IBase2 by b, IDerived2() diff --git a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/irrelevant.fir.kt b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/irrelevant.fir.kt new file mode 100644 index 00000000000..a864c7c4a2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/irrelevant.fir.kt @@ -0,0 +1,19 @@ +interface IBase1 { + fun foo(): Any +} + +interface IDerived1 { + fun foo(): String +} + +class Broken1(val b: IBase1) : IBase1 by b, IDerived1 + +interface IBase2 { + val foo: Any +} + +interface IDerived2 { + val foo: String +} + +class Broken2(val b: IBase2) : IBase2 by b, IDerived2 diff --git a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/kt13952.fir.kt b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/kt13952.fir.kt new file mode 100644 index 00000000000..127b8af6c69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/kt13952.fir.kt @@ -0,0 +1,17 @@ +interface IA { + fun foo(): Number +} + +interface IB : IA { + override fun foo(): Int +} + +object AImpl : IA { + override fun foo() = 42 +} + +open class C : IA by AImpl, IB + +class D : C() { + override fun foo(): Double = 3.14 +} diff --git a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/simple.fir.kt b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/simple.fir.kt new file mode 100644 index 00000000000..5dd07749362 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/simple.fir.kt @@ -0,0 +1,19 @@ +interface IBase1 { + fun foo(): Any +} + +interface IDerived1 : IBase1 { + override fun foo(): String +} + +class Broken1(val b: IBase1) : IBase1 by b, IDerived1 + +interface IBase2 { + val foo: Any +} + +interface IDerived2 : IBase2 { + override val foo: String +} + +class Broken2(val b: IBase2) : IBase2 by b, IDerived2 diff --git a/compiler/testData/diagnostics/tests/delegation/kt8154.fir.kt b/compiler/testData/diagnostics/tests/delegation/kt8154.fir.kt new file mode 100644 index 00000000000..066fef5fa23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt8154.fir.kt @@ -0,0 +1,11 @@ +interface A { + fun foo() +} + +interface B : A { + fun bar() +} + +class BImpl(a: A) : B, A by a { + override fun bar() { throw UnsupportedOperationException() } +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/abstractOverride.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/abstractOverride.fir.kt new file mode 100644 index 00000000000..861ec527e6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/abstractOverride.fir.kt @@ -0,0 +1,18 @@ +public interface Base { + fun test() = "OK" +} + + +abstract class Impl : Base { + override abstract fun test(): String +} + +class Delegate : Base + + +fun box(): String { + object : Impl(), Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubType.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubType.fir.kt new file mode 100644 index 00000000000..930bd45514c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubType.fir.kt @@ -0,0 +1,19 @@ +public interface Base { + fun test() = "OK" +} + +public interface Base2 : Base + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + + } + + object : Base2, Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeProperty.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeProperty.fir.kt new file mode 100644 index 00000000000..9c55da1c50c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeProperty.fir.kt @@ -0,0 +1,20 @@ +public interface Base { + val test: String + get() = "OK" +} + +public interface Base2 : Base + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + + } + + object : Base2, Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverride.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverride.fir.kt new file mode 100644 index 00000000000..eb7a997f4d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverride.fir.kt @@ -0,0 +1,19 @@ +public interface Base { + fun test() = "OK" +} + +public interface Base2 : Base { + override fun test() = "OK2" +} + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + } + + object : Base2, Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverrideProperty.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverrideProperty.fir.kt new file mode 100644 index 00000000000..f11545756b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/delegationToSubTypeWithOverrideProperty.fir.kt @@ -0,0 +1,26 @@ +public interface Base { + var test: String + get() = "OK" + set(s: String) { + } +} + +public interface Base2 : Base { + override var test: String + get() = "OK2" + set(value) {} +} + +class Delegate : Base2 { + +} + +fun box(): String { + object : Base, Base2 by Delegate() { + } + + object : Base2, Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/diamond.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/diamond.fir.kt new file mode 100644 index 00000000000..a493209b585 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/diamond.fir.kt @@ -0,0 +1,43 @@ +public interface Base { + fun test() = "Base" +} + +public interface Base2 : Base { + override fun test() = "Base2" +} + +public interface Base3 : Base { + override fun test() = "Base3" +} + +class Impl : Base + +class Impl2 : Base2 + +class Impl3 : Base3 + +class ImplAll : Base, Base2, Base3 { + override fun test(): String { + return super.test() + } +} + +fun box(): String { + object : Base2, Base3, Base by Impl() { + + } + + object : Base2 by Impl2(), Base3, Base { + + } + + object : Base2, Base3 by Impl3(), Base { + + } + + object : Base2 by Impl2(), Base3 by Impl3(), Base by Impl() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/explicitOverride.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/explicitOverride.fir.kt new file mode 100644 index 00000000000..d2bc0a749f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/explicitOverride.fir.kt @@ -0,0 +1,18 @@ +public interface Base { + fun test() = "OK" +} + +open class Base2 : Base { + override fun test() = "OK2" +} + +class Delegate : Base + +fun box(): String { + + object : Base2(), Base by Delegate() { + override fun test() = "OK" + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/fakeOverrideInTheMiddle.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/fakeOverrideInTheMiddle.fir.kt new file mode 100644 index 00000000000..185b566065d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/fakeOverrideInTheMiddle.fir.kt @@ -0,0 +1,13 @@ +interface Base { + fun test() = "Base" +} + +class Delegate : Base + +abstract class Middle : Base { + override fun test() = "MyClass" +} + +abstract class MyClass : Middle() + +class A : MyClass(), Base by Delegate() diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/generic.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/generic.fir.kt new file mode 100644 index 00000000000..fb4fa1e4ee9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/generic.fir.kt @@ -0,0 +1,14 @@ +public interface Base { + fun test(p: T) = "Base" +} + +public interface Derived : Base + +class Delegate : Derived + +fun box(): String { + object : Derived by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy.fir.kt new file mode 100644 index 00000000000..382b104432c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy.fir.kt @@ -0,0 +1,16 @@ +public interface Base { + fun test() = "Base" +} + +class Delegate : Base { + override fun test() = "Base" +} + +public open class MyClass : Base by Delegate() + +fun box(): String { + object : MyClass(), Base by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy2.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy2.fir.kt new file mode 100644 index 00000000000..9807192268f --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/sameDelegationInHierarchy2.fir.kt @@ -0,0 +1,21 @@ +public interface Base { + fun test() = "Base" +} + +public interface Derived : Base { + override fun test() = "Derived" +} + + +class Delegate : Derived { + override fun test() = "Delegate" +} + +public open class MyClass : Base by Delegate() + +fun box(): String { + object : MyClass(), Derived by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/severalDelegates.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/severalDelegates.fir.kt new file mode 100644 index 00000000000..06098cc48fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/severalDelegates.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +interface Base1 { + fun test() = "OK" +} + +interface Base2 { + fun test2() = "OK" +} + + +class Delegate1 : Base1 + +class Delegate2 : Base2 + + +public abstract class MyClass : Base1, Base2 { + override fun test(): String { + return "Class" + } + + override fun test2(): String { + return "Class" + } +} + +class A : MyClass(), Base1 by Delegate1(), Base1 by Delegate2() { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simple.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simple.fir.kt new file mode 100644 index 00000000000..caf2804ed72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simple.fir.kt @@ -0,0 +1,19 @@ +public interface Base { + fun getValue(): String + + fun test() = getValue() +} + +class Delegate : Base { + override fun getValue() = "Delegate" +} + +public abstract class MyClass : Base { + override fun test(): String { + return "Class" + } +} + +class A : MyClass(), Base by Delegate() { + override fun getValue() = "Delegate" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleNoOverride.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleNoOverride.fir.kt new file mode 100644 index 00000000000..cacaab043f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleNoOverride.fir.kt @@ -0,0 +1,15 @@ +interface Base { + fun test() = "OK" +} + +open class Base2 : Base + +class Delegate : Base + +fun box(): String { + object : Base2(), Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleProp.fir.kt b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleProp.fir.kt new file mode 100644 index 00000000000..3878b279f00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleProp.fir.kt @@ -0,0 +1,17 @@ +public interface Base { + val test: String + get() = "OK" +} + +open class Delegate : Base { + override val test: String + get() = "OK" +} + +fun box(): String { + object : Delegate(), Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt new file mode 100644 index 00000000000..f8950a03263 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt @@ -0,0 +1,3 @@ +fun test() { + (d@ val bar = 2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.fir.kt new file mode 100644 index 00000000000..f5ccb9a914f --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.fir.kt @@ -0,0 +1,7 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class foo + +fun f(s : String?) : Boolean { + return (@foo s?.equals("a"))!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt new file mode 100644 index 00000000000..5a4a7138942 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package m + +fun test(i: Int?) { + if (i != null) { + foo(l1@ i) + foo((i)) + foo(l2@ (i)) + foo((l3@ i)) + } + + val a: Int = l4@ "" + val b: Int = ("") + val c: Int = checkSubtype("") + val d: Int = checkSubtype("") + + + foo(l4@ "") + foo(("")) + foo(checkSubtype("")) + foo(checkSubtype("")) + + use(a, b, c, d) +} + +fun foo(i: Int) = i + +fun use(vararg a: Any?) = a diff --git a/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt new file mode 100644 index 00000000000..e270df0ec1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt @@ -0,0 +1,3 @@ +fun f(s : String?) : Boolean { + return foo@(s?.equals("a"))!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deparenthesize/multiParenthesizedSafeCall.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/multiParenthesizedSafeCall.fir.kt new file mode 100644 index 00000000000..209ab44d1a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/multiParenthesizedSafeCall.fir.kt @@ -0,0 +1,3 @@ +fun f(s : String?) : Boolean { + return (((s?.equals("a"))))!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deparenthesize/parenthesizedSafeCall.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/parenthesizedSafeCall.fir.kt new file mode 100644 index 00000000000..bab8ed3f1be --- /dev/null +++ b/compiler/testData/diagnostics/tests/deparenthesize/parenthesizedSafeCall.fir.kt @@ -0,0 +1,3 @@ +fun f(s : String?) : Boolean { + return (s?.equals("a"))!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/annotationUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/annotationUsage.fir.kt new file mode 100644 index 00000000000..8b1d35a1758 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/annotationUsage.fir.kt @@ -0,0 +1,9 @@ +@Deprecated("text") +annotation class obsolete() + +@Deprecated("text") +annotation class obsoleteWithParam(val text: String) + +@obsolete class Obsolete + +@obsoleteWithParam("text") class Obsolete2 diff --git a/compiler/testData/diagnostics/tests/deprecated/classWithCompanionObject.fir.kt b/compiler/testData/diagnostics/tests/deprecated/classWithCompanionObject.fir.kt new file mode 100644 index 00000000000..4d851d7127a --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/classWithCompanionObject.fir.kt @@ -0,0 +1,8 @@ +class A { + @Deprecated("deprecated") companion object + + class B +} + +val x1 = A.B() + diff --git a/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt new file mode 100644 index 00000000000..b348132c308 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/companionObjectUsage.fir.kt @@ -0,0 +1,32 @@ +class Another { + @Deprecated("Object") + companion object { + fun use() {} + const val USE = 42 + } +} + +fun first() { + Another.use() + Another.Companion.USE + Another.USE +} + +fun useCompanion() { + val d = Another + val x = Another.Companion + Another.Companion.use() + Another.use() +} + +@Deprecated("Some") +class Some { + companion object { + fun use() {} + } +} + +fun some() { + Some.use() + Some.Companion.use() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/componentUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/componentUsage.fir.kt new file mode 100644 index 00000000000..a5c9bb6e78e --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/componentUsage.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class Data { + @Deprecated("text") + operator fun component1(): String = throw Exception() + operator fun component2(): String = throw Exception() +} + +fun use() { + val (x, y) = Data() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.fir.kt new file mode 100644 index 00000000000..9a8d8ec398b --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedConstructor.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.kt +class A(s: String) { + @Deprecated("") + constructor(i: Int) : this(i.toString()) { + + } +} + +// FILE: B.java +public class B extends A { + @Deprecated + public B(int i) { + + } + + public B(String s) { + + } +} + +// FILE: C.kt +class C @Deprecated("") constructor(s: String) { +} + +// FILE: use.kt +fun use(a: A, b: B, c: C) { + A(3) + A("") + B(3) + B("") + C("s") +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.kt new file mode 100644 index 00000000000..c39c8fb5c34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Deprecated("alas", level = DeprecationLevel.ERROR) +fun foo() {} + +@Deprecated("alas", level = DeprecationLevel.ERROR) +class C + +fun test(c: C) { + foo() + C() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.fir.kt new file mode 100644 index 00000000000..05dfbdabb77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class Table +class Tr + +fun table(body: Table.() -> Unit) {} +fun Table.tr(body: Tr.() -> Unit) {} +@Deprecated("Don't call me", level = DeprecationLevel.ERROR) +fun Tr.tr(body: Tr.() -> Unit) {} + +fun builderTest() { + table { + tr { + tr {} + table { + tr { + tr {} + } + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.fir.kt new file mode 100644 index 00000000000..f2449e1448c --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +@Deprecated("", level = DeprecationLevel.HIDDEN) +open class Foo + +fun test(f: Foo) { + f.toString() + val g: Foo? = Foo() +} + +class Bar : Foo() diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.fir.kt new file mode 100644 index 00000000000..b00759def84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.fir.kt @@ -0,0 +1,140 @@ +package foo + +interface WarningDeprecated { + @Deprecated("", level = DeprecationLevel.WARNING) + fun f() { + + } +} + +interface ErrorDeprecated { + @Deprecated("", level = DeprecationLevel.ERROR) + fun f() { + + } +} + +interface HiddenDeprecated { + @Deprecated("", level = DeprecationLevel.HIDDEN) + fun f() { + + } +} + +interface NotDeprecated { + fun f() { + + } +} + +open class WE : WarningDeprecated, ErrorDeprecated { + override fun f() { + + } +} + +open class WH : WarningDeprecated, HiddenDeprecated { + override fun f() { + + } +} + +open class EH : ErrorDeprecated, HiddenDeprecated { + override fun f() { + + } +} + +open class NW : WarningDeprecated, NotDeprecated { + override fun f() { + + } +} + +open class NE : ErrorDeprecated, NotDeprecated { + override fun f() { + + } +} + +open class NH : HiddenDeprecated, NotDeprecated { + override fun f() { + + } +} + +open class WEH: WarningDeprecated, ErrorDeprecated, HiddenDeprecated { + override fun f() { + + } +} + +open class NWEH: NotDeprecated, WarningDeprecated, ErrorDeprecated, HiddenDeprecated { + override fun f() { + + } +} + +class WE2: WE() + +class NWE2: WE(), NotDeprecated + +class NWE3: WE(), NotDeprecated { + override fun f() { + } +} + +interface E2: ErrorDeprecated +interface W2: WarningDeprecated + +interface EW2: E2, W2 { + override fun f() { + } +} + +interface HEW2: EW2, HiddenDeprecated { + override fun f() { + } +} + +interface ExplicitError: HEW2 { + @Deprecated("", level = DeprecationLevel.ERROR) + override fun f() { + super.f() + } +} + +fun use( + wd: WarningDeprecated, ed: ErrorDeprecated, hd: HiddenDeprecated, + we: WE, wh: WH, eh: EH, nw: NW, ne: NE, nh: NH, + weh: WEH, nweh: NWEH, + we2: WE2, nwe2: NWE2, nwe3: NWE3, + e2: E2, w2: W2, ew2: EW2, hew2: HEW2, + explicitError: ExplicitError +) { + wd.f() + ed.f() + hd.f() + + we.f() + wh.f() + eh.f() + + nw.f() + ne.f() + nh.f() + + weh.f() + nweh.f() + + we2.f() + nwe2.f() + nwe3.f() + + e2.f() + w2.f() + ew2.f() + hew2.f() + + explicitError.f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.fir.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.fir.kt new file mode 100644 index 00000000000..7767cce15ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.fir.kt @@ -0,0 +1,135 @@ +package foo + +interface HiddenDeprecated { + @Deprecated("", level = DeprecationLevel.HIDDEN) + var p: Int +} + +interface NoDeprecation { + var p: Int +} + + +open class WarningDeprecated { + @Deprecated("", level = DeprecationLevel.WARNING) + open var p: Int = 3 +} + +open class ErrorDeprecated { + @Deprecated("", level = DeprecationLevel.ERROR) + open var p: Int = 3 +} + +open class GetterDeprecated { + open var p: Int = 3 + @Deprecated("") get +} + +open class SetterDeprecated { + open var p: Int = 3 + @Deprecated("") set +} + +class WD: WarningDeprecated() { + override var p: Int + get() = 3 + set(value) {} +} + +class ED: ErrorDeprecated() { + override var p: Int + get() = 3 + set(value) { + } +} + +class GD: GetterDeprecated() { + override var p: Int + get() = 3 + set(value) { + } +} + +class SD: SetterDeprecated() { + override var p: Int + get() = 3 + set(value) { + } +} + +class SDH: SetterDeprecated(), HiddenDeprecated { + override var p: Int + get() = 3 + set(value) { + } +} + +class EDH: ErrorDeprecated(), HiddenDeprecated { + override var p: Int + get() = 3 + set(value) { + } +} + +class NED: ErrorDeprecated(), NoDeprecation { + override var p: Int + get() = 3 + set(value) { + } +} + +class Diff { + @Deprecated("", level = DeprecationLevel.WARNING) + var p: Int + @Deprecated("", level = DeprecationLevel.ERROR) get() = 3 + @Deprecated("", level = DeprecationLevel.HIDDEN) set(value) { + + } +} + +fun use( + warningDeprecated: WarningDeprecated, errorDeprecated: ErrorDeprecated, setterDeprecated: SetterDeprecated, + getterDeprecated: GetterDeprecated, hiddenDeprecated: HiddenDeprecated, + wd: WD, ed: ED, gd: GD, sd: SD, + sdh: SDH, edh: EDH, ned: NED, + diff: Diff +) { + warningDeprecated.p + warningDeprecated.p = 1 + + errorDeprecated.p + errorDeprecated.p = 1 + + getterDeprecated.p + getterDeprecated.p = 1 + + setterDeprecated.p + setterDeprecated.p = 1 + + hiddenDeprecated.p + hiddenDeprecated.p = 1 + + wd.p + wd.p = 1 + + ed.p + ed.p = 1 + + gd.p + gd.p = 1 + + sd.p + sd.p = 1 + + sdh.p + sdh.p = 1 + + edh.p + edh.p = 1 + + ned.p + ned.p = 1 + + diff.p + diff.p = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/functionUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/functionUsage.fir.kt new file mode 100644 index 00000000000..de878244f06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/functionUsage.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +import kotlin.reflect.KProperty + +class UsefulClass(val param: Int = 2) { + operator fun getValue(instance: Any, property: KProperty<*>) : Int = 1 + operator fun setValue(instance: Any, property: KProperty<*>, value: Int) {} + + @Deprecated("message") + fun member() {} +} + +@Deprecated("message") +fun Obsolete(param: Int = 1): UsefulClass = UsefulClass(param) + +class Invocable { + @Deprecated("message") + operator fun invoke() {} +} + +object InvocableHolder { + val invocable = Invocable() +} + +fun invoker() { + val invocable = Invocable() + invocable() + InvocableHolder.invocable() +} + +fun block() { + Obsolete() + Obsolete(2) +} + +fun expression() = Obsolete() + +fun reflection() = ::Obsolete +fun reflection2() = UsefulClass::member + +class Initializer { + val x = Obsolete() +} + +@Deprecated("does nothing good") +fun Any.doNothing() = this.toString() // "this" should not be marked as deprecated despite it referes to deprecated function + +class Delegation { + val x by Obsolete() + var y by Obsolete() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt new file mode 100644 index 00000000000..51c43c5b11c --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/genericConstructorUsage.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_PARAMETER + +open class C() { + @Deprecated("") + constructor(p: Int) : this(){} +} + +class D : C(1) diff --git a/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.fir.kt b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.fir.kt new file mode 100644 index 00000000000..1376223dd75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.fir.kt @@ -0,0 +1,40 @@ +val v1: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + +@Deprecated("", level = DeprecationLevel.HIDDEN) +val v2 = "" + +var v3: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + set(value) {} + +var v4: String + get() = "" + @Deprecated("", level = DeprecationLevel.HIDDEN) + set(value) {} + +var v5: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + @Deprecated("", level = DeprecationLevel.HIDDEN) + set(value) {} + +@Deprecated("", level = DeprecationLevel.HIDDEN) +var v6: String + get() = "" + set(value) {} + +fun test() { + v1 + v2 + v3 + v3 = "" + v4 + v4 = "" + v5 + v5 = "" + v6 + v6 = "" +} diff --git a/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt b/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt new file mode 100644 index 00000000000..8b28ed7ebfd --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.fir.kt @@ -0,0 +1,13 @@ +// SKIP_TXT +// FILE: test/J.java + +package test; + +@Deprecated +public interface J { + public String foo(int x); +} + +// FILE: K.kt + +import test.J diff --git a/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt b/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt new file mode 100644 index 00000000000..bd3a686540d --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/imports.fir.kt @@ -0,0 +1,8 @@ +import C as C2 + +@Deprecated("obsolete") +class C { + fun use() {} +} + +fun useAlias(c : C2) { c.use() } diff --git a/compiler/testData/diagnostics/tests/deprecated/iteratorUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/iteratorUsage.fir.kt new file mode 100644 index 00000000000..7f6615b6ab5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/iteratorUsage.fir.kt @@ -0,0 +1,24 @@ +class Iter { + @Deprecated("text") + operator fun iterator() : IterIterator = throw Exception() + + class IterIterator { + operator fun hasNext(): Boolean = throw UnsupportedOperationException() + operator fun next(): String = throw UnsupportedOperationException() + } +} + +class Iter2 { + operator fun iterator() : Iter2Iterator = throw Exception() + class Iter2Iterator { + @Deprecated("text") + operator fun hasNext(): Boolean = throw UnsupportedOperationException() + @Deprecated("text") + operator fun next(): String = throw UnsupportedOperationException() + } +} + +fun use() { + for (x in Iter()) {} + for (x in Iter2()) {} +} diff --git a/compiler/testData/diagnostics/tests/deprecated/javaDeprecated.fir.kt b/compiler/testData/diagnostics/tests/deprecated/javaDeprecated.fir.kt new file mode 100644 index 00000000000..4206722ba17 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/javaDeprecated.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER +// FILE: A.java + +@Deprecated +public class A { + @Deprecated + public String getFoo(String text) { + return text; + } +} + +// FILE: B.kt + +class B(private @property:Deprecated val foo: String) : A() { + override fun getFoo(text: String): String = super.getFoo(text + foo) +} diff --git a/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.fir.kt b/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.fir.kt new file mode 100644 index 00000000000..a3cf0deac2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/javaDeprecatedInheritance.fir.kt @@ -0,0 +1,53 @@ +// FILE: A.java + +public class A { + + @Deprecated + public static final String D = "d"; + + @Deprecated + public void f() { + return text; + } + + @Deprecated + public static void bar() { + } +} + +// FILE: B.java + +public class B extends A { + + public static final String D = "d"; + + @Override + public void f() { + return text; + } + + public static void bar() { + } +} + + +// FILE: C.java + +public class C extends A { +} + +// FILE: use.kt + +fun use(a: A, b: B, c: C) { + a.f() + b.f() + c.f() + + A.D + B.D + C.D + + A.bar() + B.bar() + C.bar() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt b/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt new file mode 100644 index 00000000000..35b7aa0977a --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER +// FILE: A.java + +/** + * @deprecated + */ +public class A { + /** + * @deprecated + */ + public String getFoo(String text) { + return text; + } +} + +// FILE: B.kt + +class B(private val foo: String) : A() { + override fun getFoo(text: String): String = super.getFoo(text + foo) +} diff --git a/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt new file mode 100644 index 00000000000..08721d085ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/nestedTypesUsage.fir.kt @@ -0,0 +1,18 @@ +class TopLevel { + @Deprecated("Nested") + class Nested { + companion object { + fun use() {} + + class CompanionNested2 + } + + class Nested2 + } +} + +fun useNested() { + val d = TopLevel.Nested.use() + TopLevel.Nested.Nested2() + TopLevel.Nested.CompanionNested2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt new file mode 100644 index 00000000000..5cfe5dab560 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/objectUsage.fir.kt @@ -0,0 +1,9 @@ +@Deprecated("Object") +object Obsolete { + fun use() {} +} + +fun useObject() { + Obsolete.use() + val x = Obsolete +} diff --git a/compiler/testData/diagnostics/tests/deprecated/propertyUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/propertyUsage.fir.kt new file mode 100644 index 00000000000..7620f3c6feb --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/propertyUsage.fir.kt @@ -0,0 +1,66 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +import kotlin.reflect.KProperty + +class Delegate() { + @Deprecated("text") + operator fun getValue(instance: Any, property: KProperty<*>) : Int = 1 + + @Deprecated("text") + operator fun setValue(instance: Any, property: KProperty<*>, value: Int) {} +} + +class PropertyHolder { + @Deprecated("text") + val x = 1 + + @Deprecated("text") + var name = "String" + + val valDelegate by Delegate() + var varDelegate by Delegate() + + public val test1: String = "" + @Deprecated("val-getter") get + + public var test2: String = "" + @Deprecated("var-getter") get + @Deprecated("var-setter") set + + public var test3: String = "" + @Deprecated("var-getter") get + set + + public var test4: String = "" + get + @Deprecated("var-setter") set +} + +fun PropertyHolder.extFunction() { + test2 = "ext" + test1 +} + +fun fn() { + PropertyHolder().test1 + PropertyHolder().test2 + PropertyHolder().test2 = "" + + PropertyHolder().test3 + PropertyHolder().test3 = "" + + PropertyHolder().test4 + PropertyHolder().test4 = "" + + val a = PropertyHolder().x + val b = PropertyHolder().name + PropertyHolder().name = "value" + + val d = PropertyHolder().valDelegate + PropertyHolder().varDelegate = 1 +} + +fun literals() { + PropertyHolder::test1 + PropertyHolder::name +} diff --git a/compiler/testData/diagnostics/tests/deprecated/propertyUseSiteTargetedAnnotations.fir.kt b/compiler/testData/diagnostics/tests/deprecated/propertyUseSiteTargetedAnnotations.fir.kt new file mode 100644 index 00000000000..1005ca88034 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/propertyUseSiteTargetedAnnotations.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +class PropertyHolder { + @Deprecated("") + val a1 = 1 + + @property:Deprecated("") + var a2 = "" + + @get:Deprecated("") + public val withGetter: String = "" + + @set:Deprecated("") + public var withSetter: String = "" +} + +fun fn() { + val holder = PropertyHolder() + + holder.a1 + holder.a2 + holder.withGetter + holder.withSetter = "A" +} + +fun literals() { + PropertyHolder::a1 + PropertyHolder::a2 + PropertyHolder::withGetter + PropertyHolder::withSetter +} diff --git a/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.fir.kt new file mode 100644 index 00000000000..c5f23583e4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.fir.kt @@ -0,0 +1,6 @@ +@Deprecated("No") +val f: () -> Unit = {} + +fun test() { + f() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/thisUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/thisUsage.fir.kt new file mode 100644 index 00000000000..cc5148216ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/thisUsage.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +@Deprecated("Use A instead") open class MyClass { + fun foo() { + val test = this + } +} diff --git a/compiler/testData/diagnostics/tests/deprecated/typeUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typeUsage.fir.kt new file mode 100644 index 00000000000..992e7825664 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/typeUsage.fir.kt @@ -0,0 +1,42 @@ +@Deprecated("Class") +open class Obsolete { + fun use() {} +} + +@Deprecated("Class") +open class Obsolete2 @Deprecated("Constructor") constructor() { + fun use() {} +} + +interface Generic + +open class Derived() : Obsolete() + +class Derived2() : Derived() + +class TypeParam : Generic + +object Object : Obsolete() + +class Properties { + val x : Obsolete = Obsolete() + var y : Obsolete = Obsolete() + + var n : Obsolete + get() = Obsolete() + set(value) {} +} + +fun param(param: Obsolete) { param.use() } + +fun funcParamReceiver(param: Obsolete.()->Unit) { Obsolete().param() } +fun funcParamParam(param: (Obsolete)->Unit) { param(Obsolete()) } +fun funcParamRetVal(param: ()->Obsolete) { param() } + +fun constraint() {} + +fun Obsolete.receiver() {} + +fun retVal(): Obsolete = Obsolete() + +fun nullableRetVal(): Obsolete? = null diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt new file mode 100644 index 00000000000..de07e15f95b --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasCompanionObject.fir.kt @@ -0,0 +1,12 @@ +class Relevant { + companion object { + val value = "" + } +} + +@Deprecated("Use Relevant") +typealias Obsolete = Relevant + +fun test1() = Obsolete +fun test2() = Obsolete.value +fun test3() = Obsolete.toString() diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt new file mode 100644 index 00000000000..558f6dc9a95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.fir.kt @@ -0,0 +1,17 @@ +@Deprecated("Deprecated class") +open class DeprecatedClass + +open class WithDeprecatedCtor(val x: Int) { + @Deprecated("Deprecated constructor") + constructor() : this(0) +} + +typealias DeprecatedClassAlias = DeprecatedClass +typealias WithDeprecatedCtorAlias = WithDeprecatedCtor +typealias ArrayListOfDeprecatedClass = ArrayList + +class Test1 : DeprecatedClassAlias() + +class Test2 : WithDeprecatedCtorAlias() + +val test3 = ArrayListOfDeprecatedClass() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasForDeprecatedClass.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasForDeprecatedClass.fir.kt new file mode 100644 index 00000000000..da64d0df0df --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasForDeprecatedClass.fir.kt @@ -0,0 +1,21 @@ +@Deprecated("") +class Foo + +@Deprecated("", level = DeprecationLevel.ERROR) +class Err + +typealias Test1 = Foo +typealias Test2 = List +typealias Test3 = List + +typealias TestErr1 = Err +typealias TestErr2 = List +typealias TestErr3 = List + +fun use1(b: Test1) = b +fun use2(b: Test2) = b +fun use3(b: Test3) = b + +fun useErr1(b: TestErr1) = b +fun useErr2(b: TestErr2) = b +fun useErr3(b: TestErr3) = b \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt b/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt new file mode 100644 index 00000000000..6ac0193e35c --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/typealiasUsage.fir.kt @@ -0,0 +1,24 @@ +open class Base { + companion object +} +interface IFoo +open class CG +interface IG + +@Deprecated("Obsolete") +typealias Obsolete = Base + +@Deprecated("Obsolete") +typealias IObsolete = IFoo + +fun test1(x: Obsolete) = x +fun test1a(x: List) = x + +val test2 = Obsolete() + +val test3 = Obsolete + +class Test4: Obsolete() +class Test4a: IObsolete +class Test4b: IG +class Test4c: CG() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt b/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt new file mode 100644 index 00000000000..67783b81d14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/unusedImport.fir.kt @@ -0,0 +1,10 @@ +// FILE: A.kt + +package test + +@Deprecated("A") +interface A + +// FILE: B.kt + +import test.A diff --git a/compiler/testData/diagnostics/tests/deprecated/warningOnConstructorErrorOnClass.fir.kt b/compiler/testData/diagnostics/tests/deprecated/warningOnConstructorErrorOnClass.fir.kt new file mode 100644 index 00000000000..fa8936a712d --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/warningOnConstructorErrorOnClass.fir.kt @@ -0,0 +1,8 @@ +// KT-15245 Report deprecation on associated declarations if level is greater than the deprecation on the declaration itself + +@Deprecated("error", level = DeprecationLevel.ERROR) +class Foo @Deprecated("warning", level = DeprecationLevel.WARNING) constructor() + +fun test1() = Foo() + +fun test2(): Foo = Foo() diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/accidentalOverrideFromGrandparent.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/accidentalOverrideFromGrandparent.fir.kt new file mode 100644 index 00000000000..6ed1c87836d --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/accidentalOverrideFromGrandparent.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +interface Foo { + fun foo(x: X) +} + +open class FooImpl : Foo { + override fun foo(x: String) { + } +} + +open class FooImpl2 : FooImpl() { + fun foo(x: Any) { + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByProperty.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByProperty.fir.kt new file mode 100644 index 00000000000..1b31212ede8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByProperty.fir.kt @@ -0,0 +1,8 @@ +open class B { + fun getX() = 1 +} + +class C : B() { + val x: Int + get() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyInConstructor.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyInConstructor.fir.kt new file mode 100644 index 00000000000..06b6b65787a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyInConstructor.fir.kt @@ -0,0 +1,5 @@ +open class B { + fun getX() = 1 +} + +class C(val x: Int) : B() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyNoGetter.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyNoGetter.fir.kt new file mode 100644 index 00000000000..ad7d1ce6e01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classFunctionOverriddenByPropertyNoGetter.fir.kt @@ -0,0 +1,7 @@ +open class B { + fun getX() = 1 +} + +class C : B() { + val x: Int = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classPropertyOverriddenByFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classPropertyOverriddenByFunction.fir.kt new file mode 100644 index 00000000000..672f4f7f5d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/classPropertyOverriddenByFunction.fir.kt @@ -0,0 +1,8 @@ +open class B { + val x: Int + get() = 1 +} + +class C : B() { + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/defaultFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/defaultFunction.fir.kt new file mode 100644 index 00000000000..2f56836984a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/defaultFunction.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Base { + open fun `foo$default`(d: Derived, i: Int, mask: Int, mh: Any) {} +} + +class Derived : Base() { + fun foo(i: Int = 0) {} +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/delegatedFunctionOverriddenByProperty.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/delegatedFunctionOverriddenByProperty.fir.kt new file mode 100644 index 00000000000..e4319933d85 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/delegatedFunctionOverriddenByProperty.fir.kt @@ -0,0 +1,10 @@ +interface B { + fun getX() = 1 +} + +interface D { + val x: Int +} + +class C(d: D) : D by d, B { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/genericClassFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/genericClassFunction.fir.kt new file mode 100644 index 00000000000..ca3514cd1e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/genericClassFunction.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class B { + fun foo(l: List) {} +} + +class C : B() { + fun foo(l: List) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt new file mode 100644 index 00000000000..664ad15e830 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt @@ -0,0 +1,7 @@ +interface B { + fun getX() = 1 +} + +class C : B { + override val x = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/privateClassFunctionOverriddenByProperty.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/privateClassFunctionOverriddenByProperty.fir.kt new file mode 100644 index 00000000000..f6c76cb59ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/privateClassFunctionOverriddenByProperty.fir.kt @@ -0,0 +1,8 @@ +open class B { + private fun getX() = 1 +} + +class C : B() { + val x: Int + get() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/require.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/require.fir.kt new file mode 100644 index 00000000000..ade55e7396d --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/require.fir.kt @@ -0,0 +1,7 @@ +open class C { + val x = 1 +} + +interface Tr : C { + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByProperty.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByProperty.fir.kt new file mode 100644 index 00000000000..edcd5abff9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByProperty.fir.kt @@ -0,0 +1,8 @@ +interface T { + fun getX() = 1 +} + +class C : T { + val x: Int + get() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByPropertyNoImpl.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByPropertyNoImpl.fir.kt new file mode 100644 index 00000000000..d78dd659bb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitFunctionOverriddenByPropertyNoImpl.fir.kt @@ -0,0 +1,8 @@ +interface T { + fun getX(): Int +} + +abstract class C : T { + val x: Int + get() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunction.fir.kt new file mode 100644 index 00000000000..ff9451649a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunction.fir.kt @@ -0,0 +1,8 @@ +interface T { + val x: Int + get() = 1 +} + +class C : T { + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunctionNoImpl.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunctionNoImpl.fir.kt new file mode 100644 index 00000000000..002e8217385 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/traitPropertyOverriddenByFunctionNoImpl.fir.kt @@ -0,0 +1,7 @@ +interface T { + val x: Int +} + +abstract class C : T { + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/class.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/class.fir.kt new file mode 100644 index 00000000000..b6a7692433a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/class.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class B { + open fun foo(t: T) {} +} + +class C : B() { + override fun foo(t: String) {} + + fun foo(o: Any) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/fakeOverrideTrait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/fakeOverrideTrait.fir.kt new file mode 100644 index 00000000000..817b75ed780 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/fakeOverrideTrait.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface B { + fun foo(t: T) {} +} + +class C : B { + fun foo(o: Any) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/trait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/trait.fir.kt new file mode 100644 index 00000000000..c931a0413e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/bridges/trait.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface B { + fun foo(t: T) {} +} + +class C : B { + override fun foo(t: String) {} + + fun foo(o: Any) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/caseInProperties.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/caseInProperties.fir.kt new file mode 100644 index 00000000000..8bf6f093521 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/caseInProperties.fir.kt @@ -0,0 +1,2 @@ +val aa = 1 +val Aa = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/clashFromInterfaceAndSuperClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/clashFromInterfaceAndSuperClass.fir.kt new file mode 100644 index 00000000000..e5730dcdd4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/clashFromInterfaceAndSuperClass.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +public open class A { + fun foo(x: T) = "O" + fun foo(x: A) = "K" +} + +interface C { + fun foo(x: E): String + fun foo(x: A): String +} + +interface D { + fun foo(x: A): String +} + +class B1 : A>(), D + +interface B2 : C>, D diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/collections.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/collections.fir.kt new file mode 100644 index 00000000000..ad06df1d2bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/collections.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(s: List) {} +fun foo(s: MutableList) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt new file mode 100644 index 00000000000..cd117843562 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegateToTwoTraits.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo { + fun foo(l: List) +} + +interface Bar { + fun foo(l: List) +} + +class Baz(f: Foo, b: Bar): Foo by f, Bar by b { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt new file mode 100644 index 00000000000..febee25b6b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationAndOwnMethod.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo { + fun foo(l: List) +} + +class Bar(f: Foo): Foo by f { + fun foo(l: List) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt new file mode 100644 index 00000000000..74fe8e60254 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/delegationToTraitImplAndOwnMethod.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo { + fun foo(l: List) { + + } +} + +class Bar(f: Foo): Foo by f { + fun foo(l: List) {} +} + +class BarOther(f: Foo): Foo by f { + override fun foo(l: List) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/extensionProperties.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/extensionProperties.fir.kt new file mode 100644 index 00000000000..a609f1a780a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/extensionProperties.fir.kt @@ -0,0 +1,7 @@ +class G + +val G.foo: Int + get() = 1 + +val G.foo: Int + get() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/genericType.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/genericType.fir.kt new file mode 100644 index 00000000000..d1ba83124eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/genericType.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class G + +fun foo(x: G): G {null!!} +fun foo(x: G): G {null!!} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/inheritFromTwoTraits.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/inheritFromTwoTraits.fir.kt new file mode 100644 index 00000000000..65473004235 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/inheritFromTwoTraits.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo { + fun foo(l: List) {} +} + +interface Bar { + fun foo(l: List) {} +} + +class Baz(): Foo, Bar { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/kotlinAndJavaCollections.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/kotlinAndJavaCollections.fir.kt new file mode 100644 index 00000000000..4d292586540 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/kotlinAndJavaCollections.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +fun foo(s: List) {} +fun foo(s: java.util.List) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/nullableType.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/nullableType.fir.kt new file mode 100644 index 00000000000..be18b4cef95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/nullableType.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: String) {} +fun foo(x: String?) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.fir.kt new file mode 100644 index 00000000000..7fecce1889a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A { + fun foo(l: List) +} + +interface B { + fun foo(l: List) {} +} + +class C(f: A): A by f, B + +class D(f: A): A by f, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/twoTraitsAndOwnFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/twoTraitsAndOwnFunction.fir.kt new file mode 100644 index 00000000000..77563b2f25d --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/twoTraitsAndOwnFunction.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo { + fun foo(l: List) {} +} + +interface Bar { + fun foo(l: List) {} +} + +class Baz(): Foo, Bar { + fun foo(l: List) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeMappedToJava.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeMappedToJava.fir.kt new file mode 100644 index 00000000000..1db144a121c --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeMappedToJava.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +fun foo(s: java.lang.String) {} +fun foo(s: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameter.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameter.fir.kt new file mode 100644 index 00000000000..16fc6848222 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameter.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: T): T {null!!} +fun foo(x: Any): Any {null!!} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithBound.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithBound.fir.kt new file mode 100644 index 00000000000..d8a12296201 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithBound.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo + +fun foo(x: T): T {null!!} +fun foo(x: Foo): Foo {null!!} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBounds.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBounds.fir.kt new file mode 100644 index 00000000000..92c1825fd8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBounds.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo +interface Bar + +fun foo(x: T): T where T: Foo, T: Bar {null!!} +fun foo(x: Foo): Foo {null!!} +fun foo(x: Bar): Bar {null!!} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBoundsInWhere.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBoundsInWhere.fir.kt new file mode 100644 index 00000000000..92c1825fd8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/typeParameterWithTwoBoundsInWhere.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo +interface Bar + +fun foo(x: T): T where T: Foo, T: Bar {null!!} +fun foo(x: Foo): Foo {null!!} +fun foo(x: Bar): Bar {null!!} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/enumMembers.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/enumMembers.fir.kt new file mode 100644 index 00000000000..8bc20f758b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/enumMembers.fir.kt @@ -0,0 +1,6 @@ +enum class E { + ENTRY; + + fun getDeclaringClass() {} + fun finalize() {} +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/waitNotifyGetClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/waitNotifyGetClass.fir.kt new file mode 100644 index 00000000000..434e35c0703 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/finalMembersFromBuiltIns/waitNotifyGetClass.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// KT-7174 Report error on members with the same signature as non-overridable methods from mapped Java types (like Object.wait/notify) + +class A { + fun notify() {} + fun notifyAll() {} + fun wait() {} + fun wait(l: Long) {} + fun wait(l: Long, i: Int) {} + fun getClass(): Class = null!! +} + +fun notify() {} +fun notifyAll() {} +fun wait() {} +fun wait(l: Long) {} +fun wait(l: Long, i: Int) {} +fun getClass(): Class = null!! diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/class.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/class.fir.kt new file mode 100644 index 00000000000..9cd7beedbcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/class.fir.kt @@ -0,0 +1,4 @@ +class C { + val x = 1 + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classObject.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classObject.fir.kt new file mode 100644 index 00000000000..5cbee7e1f34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classObject.fir.kt @@ -0,0 +1,6 @@ +class C { + companion object { + val x = 1 + fun getX() = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classPropertyInConstructor.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classPropertyInConstructor.fir.kt new file mode 100644 index 00000000000..c3ae39cecab --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/classPropertyInConstructor.fir.kt @@ -0,0 +1,3 @@ +class C(val x: Int) { + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionFunctionAndNormalFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionFunctionAndNormalFunction.fir.kt new file mode 100644 index 00000000000..a58a20fe15d --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionFunctionAndNormalFunction.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + fun foo(x: Any) {} + fun Any.foo() {} +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionPropertyAndFunction.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionPropertyAndFunction.fir.kt new file mode 100644 index 00000000000..e615b559530 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/extensionPropertyAndFunction.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + fun getX(t: Any) = 1 + val Any.x: Int + get() = 1 +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndSetter.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndSetter.fir.kt new file mode 100644 index 00000000000..b0f82f15b14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndSetter.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + fun setX(x: Int) {} + + var x: Int = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndVar.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndVar.fir.kt new file mode 100644 index 00000000000..14c42f4056e --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/functionAndVar.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + fun setX(x: Int) {} + + var x: Int = 1 + set(v) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClass.fir.kt new file mode 100644 index 00000000000..eea8020a118 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClass.fir.kt @@ -0,0 +1,6 @@ +fun foo() { + class C { + val x = 1 + fun getX() = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClassInClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClassInClass.fir.kt new file mode 100644 index 00000000000..c341cf3acfc --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/localClassInClass.fir.kt @@ -0,0 +1,8 @@ +class Outer { + fun foo() { + class C { + val x = 1 + fun getX() = 1 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/nestedClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/nestedClass.fir.kt new file mode 100644 index 00000000000..1bbfa664537 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/nestedClass.fir.kt @@ -0,0 +1,6 @@ +class B { + class C { + val x = 1 + fun getX() = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/object.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/object.fir.kt new file mode 100644 index 00000000000..fbd894a67f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/object.fir.kt @@ -0,0 +1,4 @@ +object C { + val x = 1 + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpression.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpression.fir.kt new file mode 100644 index 00000000000..01d6b6959c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpression.fir.kt @@ -0,0 +1,5 @@ +fun foo() = + object { + val x = 1 + fun getX() = 1 + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpressionInConstructor.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpressionInConstructor.fir.kt new file mode 100644 index 00000000000..262025fbeff --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpressionInConstructor.fir.kt @@ -0,0 +1,6 @@ +class Outer { + val x = object { + val x = 1 + fun getX() = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/privateClassPropertyNoClash.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/privateClassPropertyNoClash.fir.kt new file mode 100644 index 00000000000..9fcf9ce0da1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/privateClassPropertyNoClash.fir.kt @@ -0,0 +1,13 @@ +// FILE: A.java + +public class A { + public String getFoo() { + return "Foo"; + } +} + +// FILE: B.kt + +class B(private val foo: String) : A() { + override fun getFoo(): String = foo +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevel.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevel.fir.kt new file mode 100644 index 00000000000..5d0ee3abfc2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevel.fir.kt @@ -0,0 +1,2 @@ +val x = 1 +fun getX() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelDifferentFiles.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelDifferentFiles.fir.kt new file mode 100644 index 00000000000..568f17314a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelDifferentFiles.fir.kt @@ -0,0 +1,5 @@ +// FILE: a.kt +val x = 1 + +// FILE: b.kt +fun getX() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelGetter.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelGetter.fir.kt new file mode 100644 index 00000000000..29a9e2a007a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevelGetter.fir.kt @@ -0,0 +1,3 @@ +val x: Int + get() = 1 +fun getX() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/trait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/trait.fir.kt new file mode 100644 index 00000000000..57cd160985c --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/trait.fir.kt @@ -0,0 +1,5 @@ +interface T { + val x: Int + get() = 1 + fun getX() = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/withErrorTypes.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/withErrorTypes.fir.kt new file mode 100644 index 00000000000..142dfe5fdb2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/withErrorTypes.fir.kt @@ -0,0 +1,4 @@ +interface T { + val x: ErrorType + fun getX(): ErrorType1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.fir.kt new file mode 100644 index 00000000000..9bf897065b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.fir.kt @@ -0,0 +1,68 @@ +// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES +fun () { + +} + +fun Outer.() { + +} + +val : Int = 1 + +class { + +} + +object { + +} + +interface { + +} + +enum class { + +} + +annotation class { + +} + +class Outer { + fun () { + + } + + val : Int = 1 + + class { + + } + + object { + + } + + interface { + + } + + enum class { + + } + + annotation class { + + } +} + +fun outerFun() { + fun () { + + } + fun () { + + } +} + diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObject.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObject.fir.kt new file mode 100644 index 00000000000..653071684ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObject.fir.kt @@ -0,0 +1,5 @@ +class C { + companion object {} + + val Companion = C +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedField.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedField.fir.kt new file mode 100644 index 00000000000..88105c1b936 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedField.fir.kt @@ -0,0 +1,8 @@ +class C { + companion object { + val X = 1 + val `X$1` = 1 + } + + val X = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedFieldObject.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedFieldObject.fir.kt new file mode 100644 index 00000000000..4831e5ca1f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/classObjectCopiedFieldObject.fir.kt @@ -0,0 +1,13 @@ +class B { + companion object A { + } + + val A = this +} + +class C { + companion object A { + val A = this + } + +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/dataClassCopy.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/dataClassCopy.fir.kt new file mode 100644 index 00000000000..d92de0478f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/dataClassCopy.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +data class C(val c: Int) { + fun `copy$default`(c: C, x: Int, m: Int, mh: Any) = C(this.c) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/defaults.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/defaults.fir.kt new file mode 100644 index 00000000000..2b1ff02393e --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/defaults.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + fun `a$default`(c: C, x: Int, m: Int, mh: Any) {} + fun a(x: Int = 1) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/delegationBy.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/delegationBy.fir.kt new file mode 100644 index 00000000000..abfad6e56b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/delegationBy.fir.kt @@ -0,0 +1,5 @@ +interface Foo + +class Bar(f: Foo) : Foo by f { + val `$$delegate_0`: Foo? = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/enum.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/enum.fir.kt new file mode 100644 index 00000000000..e7673b24547 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/enum.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +enum class E { + A; + + fun values(): Array = null!! + fun valueOf(s: String): E = null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/innerClassField.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/innerClassField.fir.kt new file mode 100644 index 00000000000..e12fd85dd65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/innerClassField.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + inner class D { + val `this$0`: C? = null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/instance.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/instance.fir.kt new file mode 100644 index 00000000000..89a99a64881 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/instance.fir.kt @@ -0,0 +1,3 @@ +object O { + val INSTANCE: O = null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/propertyMetadataCache.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/propertyMetadataCache.fir.kt new file mode 100644 index 00000000000..55e41e660c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/specialNames/propertyMetadataCache.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +operator fun Any.getValue(x: Any?, y: Any): Any = null!! + +class C { + val x by 1 + val `$$delegatedProperties`: Array> = null!! +} + +val x by 1 +val `$$delegatedProperties`: Array> = null!! diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/jkjk.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/jkjk.fir.kt new file mode 100644 index 00000000000..76dccc40ce7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/jkjk.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: B.kt + +open class B : A() { +} + +// FILE: C.java + +public class C extends B { + public static void bar(int i) {} +} + +// FILE: K.kt + +open class K : C() { + fun foo() {} + fun foo(a: Any) {} + fun bar(i: Int) {} + fun bar(i: String) {} + fun baz(i: Int) {} + + companion object { + fun foo() {} + fun bar(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClass.fir.kt new file mode 100644 index 00000000000..2935e2a02e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClass.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static int a = 1; + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: K.kt + +open class K : A() { + val a = 1 + fun foo() {} + fun foo(i: Int) {} + fun baz(i: Int) {} + + companion object { + fun foo() {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClassExtendsJavaClass.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClassExtendsJavaClass.fir.kt new file mode 100644 index 00000000000..cdeb98655d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassExtendsJavaClassExtendsJavaClass.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: B.java + +public class B extends A { + public static void bar(int i) {} +} + +// FILE: K.kt + +open class K : B() { + fun foo() {} + fun foo(a: Any) {} + fun bar(i: Int) {} + fun bar(i: String) {} + fun baz(i: Int) {} + + companion object { + fun foo() {} + fun bar(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterface.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterface.fir.kt new file mode 100644 index 00000000000..9561d68a6c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterface.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public interface A { + public String a = ""; + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: K.kt + +open class K : A { + val a = "" + fun foo() {} + fun foo(i: Int) {} + fun baz(i: Int) {} + + companion object { + fun foo() {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterfaceExtendsJavaInteface.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterfaceExtendsJavaInteface.fir.kt new file mode 100644 index 00000000000..21ab1027a35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinClassImplementsJavaInterfaceExtendsJavaInteface.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public interface A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: B.java + +public interface B extends A { + public static void bar(int i) {} +} + +// FILE: K.kt + +open class K : B { + fun foo() {} + fun foo(a: Any) {} + fun bar(i: Int) {} + fun bar(i: String) {} + fun baz(i: Int) {} + + companion object { + fun foo() {} + fun bar(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt new file mode 100644 index 00000000000..5cde834931a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: foo/A.java + +package foo; + +public class A { + private static void foo(int s) {} + static void bar(double s) {} +} + +// FILE: K.kt +import foo.A + +open class K : A() { + fun foo(i: Int) {} + fun bar(d: Double) {} + fun baz(i: Int) {} + + companion object { + fun foo(i: Int) {} + fun bar(d: Double) {} + } +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/synthesized/enumValuesValueOf.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/synthesized/enumValuesValueOf.fir.kt new file mode 100644 index 00000000000..56528c8094c --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/synthesized/enumValuesValueOf.fir.kt @@ -0,0 +1,12 @@ +enum class A { + A1, + A2; + + fun valueOf(s: String): A = valueOf(s) + + fun valueOf() = "OK" + + fun values(): Array = null!! + + fun values(x: String) = x +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/oneTrait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/oneTrait.fir.kt new file mode 100644 index 00000000000..eee1418b21a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/oneTrait.fir.kt @@ -0,0 +1,7 @@ +interface T { + fun getX() = 1 +} + +class C : T { + val x = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitFunctionOverriddenByPropertyInTrait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitFunctionOverriddenByPropertyInTrait.fir.kt new file mode 100644 index 00000000000..20e46f71270 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitFunctionOverriddenByPropertyInTrait.fir.kt @@ -0,0 +1,8 @@ +interface T { + fun getX() = 1 +} + +interface C : T { + val x: Int + get() = 1 +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitPropertyOverriddenByFunctionInTrait.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitPropertyOverriddenByFunctionInTrait.fir.kt new file mode 100644 index 00000000000..9f4368ce1ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/traitPropertyOverriddenByFunctionInTrait.fir.kt @@ -0,0 +1,8 @@ +interface T { + val x: Int + get() = 1 +} + +interface C : T { + fun getX() = 1 +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/twoTraits.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/twoTraits.fir.kt new file mode 100644 index 00000000000..88080b65dc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/traitImpl/twoTraits.fir.kt @@ -0,0 +1,11 @@ +interface T1 { + fun getX() = 1 +} + +interface T2 { + val x: Int + get() = 1 +} + +class C : T1, T2 { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/vararg.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/vararg.fir.kt new file mode 100644 index 00000000000..481498c275a --- /dev/null +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/vararg.fir.kt @@ -0,0 +1,8 @@ +fun foo(vararg x: Int) {} +fun foo(x: IntArray) {} + +fun foo(vararg x: Int?) {} +fun foo(x: Array) {} + +fun foo(vararg nn: Number) {} +fun foo(nn: Array) {} diff --git a/compiler/testData/diagnostics/tests/dynamicTypes/delegationBy.fir.kt b/compiler/testData/diagnostics/tests/dynamicTypes/delegationBy.fir.kt new file mode 100644 index 00000000000..b21ee696104 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dynamicTypes/delegationBy.fir.kt @@ -0,0 +1,5 @@ +interface Tr { + fun foo() +} + +class C(d: dynamic) : Tr by d \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dynamicTypes/unsupported.fir.kt b/compiler/testData/diagnostics/tests/dynamicTypes/unsupported.fir.kt new file mode 100644 index 00000000000..f80596ec429 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dynamicTypes/unsupported.fir.kt @@ -0,0 +1,7 @@ +val foo: dynamic = 1 + +fun foo() { + class C { + val foo: dynamic = 1 + } +} diff --git a/compiler/testData/diagnostics/tests/dynamicTypes/withInvisibleSynthesized.fir.kt b/compiler/testData/diagnostics/tests/dynamicTypes/withInvisibleSynthesized.fir.kt new file mode 100644 index 00000000000..75cf307e6b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dynamicTypes/withInvisibleSynthesized.fir.kt @@ -0,0 +1,35 @@ +// !MARK_DYNAMIC_CALLS + +// FILE: p/J.java + +package p; + +public class J { + public static class C { + private void sam(Sam sam) {} + } + + + public interface Sam { + void sam(); + } +} + +// FILE: k.kt + +import p.* + +class K: J.C() { + fun dynamic.test() { + sam(null) + sam( + name = null, + name = null + ) + } + + fun test() { + sam(null) + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/AbstractEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/AbstractEnum.fir.kt new file mode 100644 index 00000000000..a1961b8a648 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/AbstractEnum.fir.kt @@ -0,0 +1,3 @@ +package abstract + +abstract enum class MyAbstractEnum() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/AbstractInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/AbstractInEnum.fir.kt new file mode 100644 index 00000000000..e5ba1ab9ddc --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/AbstractInEnum.fir.kt @@ -0,0 +1,47 @@ +package abstract + + +enum class MyEnum() { + INSTANCE; + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { field = v } + var c1: Int = 0; set(v: Int) { field = v } + abstract var c2: Int set(v: Int) { field = v } + abstract var c3: Int = 0; set(v: Int) { field = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/AbstractOverrideInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/AbstractOverrideInEnum.fir.kt new file mode 100644 index 00000000000..bb97e9dce60 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/AbstractOverrideInEnum.fir.kt @@ -0,0 +1,12 @@ +enum class E : T { + ENTRY { + override fun f() { + } + }; + + abstract override fun f() +} + +interface T { + fun f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/ConstructorCallFromOutside.fir.kt b/compiler/testData/diagnostics/tests/enum/ConstructorCallFromOutside.fir.kt new file mode 100644 index 00000000000..0701f5ccc4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/ConstructorCallFromOutside.fir.kt @@ -0,0 +1,10 @@ +// KT-7753: attempt to call enum constructor explicitly +enum class A(val c: Int) { + ONE(1), + TWO(2); +} + +fun createA(): A { + // Error should be here! + return A(10) +} diff --git a/compiler/testData/diagnostics/tests/enum/ExplicitConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/enum/ExplicitConstructorCall.fir.kt new file mode 100644 index 00000000000..9270790103b --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/ExplicitConstructorCall.fir.kt @@ -0,0 +1,10 @@ +// KT-7753: attempt to call enum constructor explicitly +enum class A(val c: Int) { + ONE(1), + TWO(2); + + fun createA(): A { + // Error should be here! + return A(10) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/InsideEntryConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/enum/InsideEntryConstructorCall.fir.kt new file mode 100644 index 00000000000..5cb64b5db2d --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/InsideEntryConstructorCall.fir.kt @@ -0,0 +1,15 @@ +// KT-7753: attempt to call enum constructor explicitly +enum class A(val c: Int) { + ONE(1) { + override fun selfOrFriend(): A { + return this + } + }, + TWO(2) { + override fun selfOrFriend(): A { + return A(42) + } + }; + + abstract fun selfOrFriend(): A +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/InsideSecondaryConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/enum/InsideSecondaryConstructorCall.fir.kt new file mode 100644 index 00000000000..c10af850cea --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/InsideSecondaryConstructorCall.fir.kt @@ -0,0 +1,13 @@ +// KT-7753: attempt to call enum constructor explicitly +enum class A(val c: Int) { + ONE(1), + TWO(2), + THREE(3), + FORTY_TWO(); + + var last: A? = null + + constructor(): this(42) { + last = A(13) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt new file mode 100644 index 00000000000..d13b99a1d75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt @@ -0,0 +1,7 @@ +enum class E public constructor(val x: Int) { + FIRST(); + + internal constructor(): this(42) + + constructor(y: Int, z: Int): this(y + z) +} diff --git a/compiler/testData/diagnostics/tests/enum/SecondaryConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/enum/SecondaryConstructorCall.fir.kt new file mode 100644 index 00000000000..303a241d6a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/SecondaryConstructorCall.fir.kt @@ -0,0 +1,9 @@ +// KT-7753 false positive: enum constructor can be called from secondary constructor +enum class A(val c: Int) { + ONE(1), + TWO(2), + THREE(3), + FORTY_TWO(); + + constructor(): this(42) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/classObjectInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/classObjectInEnum.fir.kt new file mode 100644 index 00000000000..2dfdccc2e2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/classObjectInEnum.fir.kt @@ -0,0 +1,9 @@ +enum class E { + ENTRY; + + companion object { + fun entry() = ENTRY + } +} + +fun bar() = E.entry() diff --git a/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.fir.kt b/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.fir.kt new file mode 100644 index 00000000000..e74ba426a8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/classObjectInEnumPrivate.fir.kt @@ -0,0 +1,10 @@ +enum class E { + ENTRY; + + private companion object +} + +fun foo() = E.values() +fun bar() = E.valueOf("ENTRY") +fun baz() = E.ENTRY +fun quux() = E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/commonSupertype.fir.kt b/compiler/testData/diagnostics/tests/enum/commonSupertype.fir.kt new file mode 100644 index 00000000000..31bda9beea4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/commonSupertype.fir.kt @@ -0,0 +1,7 @@ +// KT-5943 StackOverflowError from commonSupertype of two enums +// NI_EXPECTED_FILE + +enum class A { A } +enum class B { B } + +val x = if (true) A.A else B.B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/compareTwoDifferentEnums.fir.kt b/compiler/testData/diagnostics/tests/enum/compareTwoDifferentEnums.fir.kt new file mode 100644 index 00000000000..b07eaeb661f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/compareTwoDifferentEnums.fir.kt @@ -0,0 +1,16 @@ +// FILE: JavaEnumA.java + +public enum JavaEnumA {} + +// FILE: JavaEnumB.java + +public enum JavaEnumB {} + +// FILE: test.kt + +enum class KotlinEnumA +enum class KotlinEnumB + +fun jj(a: JavaEnumA, b: JavaEnumB) = a == b +fun jk(a: JavaEnumA, b: KotlinEnumB) = a == b +fun kk(a: KotlinEnumA, b: KotlinEnumB) = a == b diff --git a/compiler/testData/diagnostics/tests/enum/constructorWithDefaultParametersOnly.fir.kt b/compiler/testData/diagnostics/tests/enum/constructorWithDefaultParametersOnly.fir.kt new file mode 100644 index 00000000000..3d010151b8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/constructorWithDefaultParametersOnly.fir.kt @@ -0,0 +1,21 @@ +enum class TestOk(val x: String = "OK") { + TEST1, + TEST2(), + TEST3("Hello") +} + +enum class TestErrors(val x: String) { + TEST1, + TEST2(), + TEST3("Hello") +} + +enum class TestMultipleConstructors(val x: String = "", val y: Int = 0) { + TEST; + constructor(x: String = "") : this(x, 0) +} + +enum class TestVarargs(val x: Int) { + TEST; + constructor(vararg xs: Any) : this(xs.size) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt b/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt new file mode 100644 index 00000000000..867145131f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_after.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner + +enum class E { + FIRST, + SECOND { + class A + }; +} + +val foo: Any.() -> Unit = {} + +fun f1() = E.FIRST.foo() +fun f2() = E.FIRST.(foo)() +fun f3() = E.SECOND.foo() +fun f4() = E.SECOND.(foo)() +fun f5() = E.SECOND.A() diff --git a/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt b/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt new file mode 100644 index 00000000000..8e7216c011a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/dontCreatePackageTypeForEnumEntry_before.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -NestedClassesInEnumEntryShouldBeInner + +enum class E { + FIRST, + SECOND { + class A + }; +} + +val foo: Any.() -> Unit = {} + +fun f1() = E.FIRST.foo() +fun f2() = E.FIRST.(foo)() +fun f3() = E.SECOND.foo() +fun f4() = E.SECOND.(foo)() +fun f5() = E.SECOND.A() diff --git a/compiler/testData/diagnostics/tests/enum/emptyConstructor.fir.kt b/compiler/testData/diagnostics/tests/enum/emptyConstructor.fir.kt new file mode 100644 index 00000000000..97493b36a35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/emptyConstructor.fir.kt @@ -0,0 +1,4 @@ +enum class E { + A; // no constructor call needed + constructor() +} diff --git a/compiler/testData/diagnostics/tests/enum/entryShouldBeOfEnumType.fir.kt b/compiler/testData/diagnostics/tests/enum/entryShouldBeOfEnumType.fir.kt new file mode 100644 index 00000000000..336cfe9493e --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/entryShouldBeOfEnumType.fir.kt @@ -0,0 +1,9 @@ +enum class E { + E1, + E2 +} + +fun foo() { + var e = E.E1 + e = E.E2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumEntryCannotHaveClassObject.fir.kt b/compiler/testData/diagnostics/tests/enum/enumEntryCannotHaveClassObject.fir.kt new file mode 100644 index 00000000000..308f3146a45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumEntryCannotHaveClassObject.fir.kt @@ -0,0 +1,11 @@ +enum class E { + FIRST, + + SECOND { + companion object { + fun foo() = 42 + } + }; +} + +fun f() = E.SECOND.foo() diff --git a/compiler/testData/diagnostics/tests/enum/enumEntryInAbstractEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/enumEntryInAbstractEnum.fir.kt new file mode 100644 index 00000000000..d3ba8db322a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumEntryInAbstractEnum.fir.kt @@ -0,0 +1,13 @@ +enum class EnumClass { + E1 { + override fun foo() = 1 + override val bar: String = "a" + }, + + E2 { + + }; + + abstract fun foo(): Int + abstract val bar: String +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumImplementingTrait.fir.kt b/compiler/testData/diagnostics/tests/enum/enumImplementingTrait.fir.kt new file mode 100644 index 00000000000..3faa491a53d --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumImplementingTrait.fir.kt @@ -0,0 +1,21 @@ +interface T1 { + fun foo() +} + +enum class EnumImplementingTraitWithFun: T1 { + E1 { + override fun foo() {} + }, + E2 +} + +interface T2 { + val bar: Int +} + +enum class EnumImplementingTraitWithVal: T2 { + E1 { + override val bar = 1 + }, + E2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumInheritance.fir.kt b/compiler/testData/diagnostics/tests/enum/enumInheritance.fir.kt new file mode 100644 index 00000000000..2da6449c35f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumInheritance.fir.kt @@ -0,0 +1,11 @@ +// FILE: test.kt +enum class MyEnum(): MyClass() {} +enum class MyEnum2(): MyTrait {} +enum class MyEnum3(): MyEnumBase() {} + +open class MyClass() {} + +enum class MyEnumBase() {} + +interface MyTrait {} + diff --git a/compiler/testData/diagnostics/tests/enum/enumIsAssignableToBuiltInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/enumIsAssignableToBuiltInEnum.fir.kt new file mode 100644 index 00000000000..8b9d867bd49 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumIsAssignableToBuiltInEnum.fir.kt @@ -0,0 +1,14 @@ +import java.lang.annotation.RetentionPolicy + +enum class E { + ENTRY +} + +// Test resolve from source +val a: Enum = E.ENTRY + +// Test Java resolve +val b: Enum = RetentionPolicy.RUNTIME + +// Test deserialized resolve +val c: Enum = AnnotationTarget.CLASS diff --git a/compiler/testData/diagnostics/tests/enum/enumMissingName.fir.kt b/compiler/testData/diagnostics/tests/enum/enumMissingName.fir.kt new file mode 100644 index 00000000000..3c643de9647 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMissingName.fir.kt @@ -0,0 +1,6 @@ +// Error: name should present +enum class(val rgb : Int) { + RED(0xFF000), + GREEN(0x00FF00), + BLUE(0x0000FF) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumModifier.fir.kt b/compiler/testData/diagnostics/tests/enum/enumModifier.fir.kt new file mode 100644 index 00000000000..9dfe7b9878c --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumModifier.fir.kt @@ -0,0 +1,15 @@ +enum class B {} + +class A { + enum companion object {} +} + +enum object O {} + +enum interface T {} + +enum fun f() = 0 + +enum val x = 0 + +enum var y = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumStarImport.fir.kt b/compiler/testData/diagnostics/tests/enum/enumStarImport.fir.kt new file mode 100644 index 00000000000..59cd5488439 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumStarImport.fir.kt @@ -0,0 +1,20 @@ +// FILE: enum.kt + +package enum + +enum class HappyEnum { + CASE1, + CASE2 +} + +// FILE: user.kt + +import enum.HappyEnum +import enum.HappyEnum.* + +fun f(e: HappyEnum) { + when (e) { + CASE1 -> throw UnsupportedOperationException() // unresolved reference + CASE2 -> throw UnsupportedOperationException() // unresolved references + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt b/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt new file mode 100644 index 00000000000..c1e21b2b41d --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt @@ -0,0 +1,40 @@ +// See KT-14705 + +enum class En { A, B, С } + +fun foo() { + // nullable variable + val en2: Any? = En.A + if (en2 is En) { + when (en2) { + En.A -> {} + En.B -> {} + En.С -> {} + } + } + + // not nullable variable + val en1: Any = En.A + if (en1 is En) { + when (en1) { + En.A -> {} + En.B -> {} + En.С -> {} + } + } +} + +enum class En2 { D, E, F } + +fun useEn(x: En) = x +fun useEn2(x: En2) = x + +fun bar(x: Any) { + if (x is En && x is En2) { + when (x) { + En.A -> useEn(x) + En2.D -> useEn2(x) + else -> {} + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumWithAnnotationKeyword.fir.kt b/compiler/testData/diagnostics/tests/enum/enumWithAnnotationKeyword.fir.kt new file mode 100644 index 00000000000..2ecf57a0886 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumWithAnnotationKeyword.fir.kt @@ -0,0 +1,3 @@ +annotation enum class E { + D +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.fir.kt b/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.fir.kt new file mode 100644 index 00000000000..02cc1dbca97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.fir.kt @@ -0,0 +1,2 @@ +enum class { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/extendingEnumDirectly.fir.kt b/compiler/testData/diagnostics/tests/enum/extendingEnumDirectly.fir.kt new file mode 100644 index 00000000000..be44ac109a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/extendingEnumDirectly.fir.kt @@ -0,0 +1,9 @@ +class Test1 : Enum("", 0) + +class Outer { + class Test2 : Enum("", 0) +} + +fun outer() { + class Test3 : Enum("", 0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/extensionNamedAsEnumEntry.fir.kt b/compiler/testData/diagnostics/tests/enum/extensionNamedAsEnumEntry.fir.kt new file mode 100644 index 00000000000..7441eca0cfa --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/extensionNamedAsEnumEntry.fir.kt @@ -0,0 +1,8 @@ +enum class E { + entry +} + +val Int.entry: Int get() = 42 +val Long.entry: Int get() = 239 + +val e = E.entry diff --git a/compiler/testData/diagnostics/tests/enum/ifEnumEntry.fir.kt b/compiler/testData/diagnostics/tests/enum/ifEnumEntry.fir.kt new file mode 100644 index 00000000000..3995bc0e6fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/ifEnumEntry.fir.kt @@ -0,0 +1,6 @@ +enum class MyEnum { + FIRST, + SECOND +} + +fun foo(me: MyEnum): Boolean = if (me is MyEnum.FIRST) true else false \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/importEnumFromJava.fir.kt b/compiler/testData/diagnostics/tests/enum/importEnumFromJava.fir.kt new file mode 100644 index 00000000000..40fc2379b89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/importEnumFromJava.fir.kt @@ -0,0 +1,7 @@ +// FILE: test.kt + +package test + +import java.util.concurrent.TimeUnit.* + +val c = SECONDS diff --git a/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt b/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt new file mode 100644 index 00000000000..18fc2855e85 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt @@ -0,0 +1,90 @@ +interface I { + fun foo() +} + +enum class E1 : I { + A { + override fun foo() { + this == E2.A + + val q = this + when (q) { + this -> {} + E1.A -> {} + E1.B -> {} + E2.A -> {} + E2.B -> {} + else -> {} + } + } + }, + B { + override fun foo() { + + } + } +} + +enum class E2 : I { + A { + override fun foo() { + + } + }, + B { + override fun foo() { + + } + } +} + +fun foo1(e1: E1, e2: E2) { + e1 == e2 + e1 != e2 + + e1 == E2.A + E1.B == e2 + + E1.A == E2.B + + e1 == E1.A + E1.A == e1 + e2 == E2.B + E2.B == e2 +} + +fun foo2(e1: E1, e2: E2) { + when (e1) { + E1.A -> {} + E2.A -> {} + E2.B -> {} + e1 -> {} + e2 -> {} + else -> {} + } +} + +fun foo3(e1: Enum, e2: Enum, e: Enum<*>) { + e1 == e + e1 == e2 + + e1 == E1.A + e1 == E2.A + + when (e1) { + e1 -> {} + e2 -> {} + e -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } + + when (e) { + e -> {} + e2 -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } +} diff --git a/compiler/testData/diagnostics/tests/enum/incompatibleEnums.fir.kt b/compiler/testData/diagnostics/tests/enum/incompatibleEnums.fir.kt new file mode 100644 index 00000000000..b871cd0fe2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/incompatibleEnums.fir.kt @@ -0,0 +1,145 @@ +// !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums + +enum class E1 { + A, B +} + +enum class E2 { + A, B +} + +fun foo1(e1: E1, e2: E2) { + e1 == e2 + e1 != e2 + + e1 == E2.A + E1.B == e2 + + E1.A == E2.B + + e1 == E1.A + E1.A == e1 + e2 == E2.B + E2.B == e2 +} + +fun foo2(e1: E1, e2: E2) { + when (e1) { + E1.A -> {} + E2.A -> {} + E2.B -> {} + e1 -> {} + e2 -> {} + else -> {} + } +} + +fun foo3(e1: Enum, e2: Enum, e: Enum<*>) { + e1 == e + e1 == e2 + + e1 == E1.A + e1 == E2.A + + when (e1) { + e1 -> {} + e2 -> {} + e -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } + + when (e) { + e -> {} + e2 -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } +} + +interface MyInterface +open class MyOpenClass + +fun foo4(e1: E1, i: MyInterface, c: MyOpenClass) { + e1 == i + i == e1 + + e1 == c + c == e1 + + when (e1) { + i -> {} + c -> {} + else -> {} + } +} + +enum class E3 : MyInterface { X, Y } + +fun foo5(i: MyInterface, a: Any) { + E3.X == E3.Y + E3.X == i + E3.X == a +} + +fun foo6(e1: E1?, e2: E2) { + E1.A == null + null == E1.A + e1 == null + null == e1 + + e1 == E2.A + E2.A == e1 + e1 == e2 + e2 == e1 + + e2 == null + null == e2 + E1.A == null + null == E1.A +} + +fun foo7(e1: E1?, e2: E2?) { + e1 == e2 // There should be an IDE-inspection for such cases +} + +fun foo8(e1: E1?, e2: E2, t: T) { + e1 == t + t == e1 + + e2 == t + t == e2 + + E1.A == t + t == E1.A +} + +fun foo9(e1: E1?, e2: E2, t: T, k: K) where T : MyInterface, T : MyOpenClass, K : MyInterface { + e1 == t + t == e1 + + e2 == t + t == e2 + + E1.A == t + t == E1.A + + E3.X == t + + E3.X == k + k == E3.X +} + +interface Inv + +enum class E4 : Inv { A } + +fun foo10(e4: E4, invString: Inv) { + e4 == invString + invString == e4 + + E4.A == invString + invString == E4.A +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/incompatibleEnums_1_4.fir.kt b/compiler/testData/diagnostics/tests/enum/incompatibleEnums_1_4.fir.kt new file mode 100644 index 00000000000..a6e997afaa4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/incompatibleEnums_1_4.fir.kt @@ -0,0 +1,145 @@ +// !LANGUAGE: +ProhibitComparisonOfIncompatibleEnums + +enum class E1 { + A, B +} + +enum class E2 { + A, B +} + +fun foo1(e1: E1, e2: E2) { + e1 == e2 + e1 != e2 + + e1 == E2.A + E1.B == e2 + + E1.A == E2.B + + e1 == E1.A + E1.A == e1 + e2 == E2.B + E2.B == e2 +} + +fun foo2(e1: E1, e2: E2) { + when (e1) { + E1.A -> {} + E2.A -> {} + E2.B -> {} + e1 -> {} + e2 -> {} + else -> {} + } +} + +fun foo3(e1: Enum, e2: Enum, e: Enum<*>) { + e1 == e + e1 == e2 + + e1 == E1.A + e1 == E2.A + + when (e1) { + e1 -> {} + e2 -> {} + e -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } + + when (e) { + e -> {} + e2 -> {} + E1.A -> {} + E2.A -> {} + else -> {} + } +} + +interface MyInterface +open class MyOpenClass + +fun foo4(e1: E1, i: MyInterface, c: MyOpenClass) { + e1 == i + i == e1 + + e1 == c + c == e1 + + when (e1) { + i -> {} + c -> {} + else -> {} + } +} + +enum class E3 : MyInterface { X, Y } + +fun foo5(i: MyInterface, a: Any) { + E3.X == E3.Y + E3.X == i + E3.X == a +} + +fun foo6(e1: E1?, e2: E2) { + E1.A == null + null == E1.A + e1 == null + null == e1 + + e1 == E2.A + E2.A == e1 + e1 == e2 + e2 == e1 + + e2 == null + null == e2 + E1.A == null + null == E1.A +} + +fun foo7(e1: E1?, e2: E2?) { + e1 == e2 // There should be an IDE-inspection for such cases +} + +fun foo8(e1: E1?, e2: E2, t: T) { + e1 == t + t == e1 + + e2 == t + t == e2 + + E1.A == t + t == E1.A +} + +fun foo9(e1: E1?, e2: E2, t: T, k: K) where T : MyInterface, T : MyOpenClass, K : MyInterface { + e1 == t + t == e1 + + e2 == t + t == e2 + + E1.A == t + t == E1.A + + E3.X == t + + E3.X == k + k == E3.X +} + +interface Inv + +enum class E4 : Inv { A } + +fun foo10(e4: E4, invString: Inv) { + e4 == invString + invString == e4 + + E4.A == invString + invString == E4.A +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.fir.kt b/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.fir.kt new file mode 100644 index 00000000000..46f04bf9900 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inheritFromEnumEntry.fir.kt @@ -0,0 +1,5 @@ +enum class E { + ENTRY +} + +class A : E.ENTRY diff --git a/compiler/testData/diagnostics/tests/enum/inheritanceFromEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/inheritanceFromEnum.fir.kt new file mode 100644 index 00000000000..937cb42fbfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inheritanceFromEnum.fir.kt @@ -0,0 +1,13 @@ +// FILE: MyJavaEnum.java +public enum MyJavaEnum {} + +// FILE: test.kt +open enum class MyEnum() { + A() +} + +enum class MyEnum2() {} + +class MyClass(): MyEnum2() {} + +class MyClass2(): MyJavaEnum() {} diff --git a/compiler/testData/diagnostics/tests/enum/inline.fir.kt b/compiler/testData/diagnostics/tests/enum/inline.fir.kt new file mode 100644 index 00000000000..29e488c6785 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inline.fir.kt @@ -0,0 +1,3 @@ +enum class My { + inline +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.fir.kt new file mode 100644 index 00000000000..9bd71186e81 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.fir.kt @@ -0,0 +1,19 @@ +class A { + enum class E { + ENTRY + } + + companion object { + } +} + + + +class B { + companion object { + } + + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideClass.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideClass.fir.kt new file mode 100644 index 00000000000..27369f8033f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideClass.fir.kt @@ -0,0 +1,5 @@ +class A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.fir.kt new file mode 100644 index 00000000000..a95430c721f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.fir.kt @@ -0,0 +1,7 @@ +class A { + companion object { + enum class E { + ENTRY + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideEnum.fir.kt new file mode 100644 index 00000000000..e85746eb8eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideEnum.fir.kt @@ -0,0 +1,7 @@ +enum class E { + ABC; + + enum class F { + DEF + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_after.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_after.fir.kt new file mode 100644 index 00000000000..df48fc37e3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_after.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner + +enum class E { + ABC { + enum class F { + DEF + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_before.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_before.fir.kt new file mode 100644 index 00000000000..e1ac99322ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry_before.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -NestedClassesInEnumEntryShouldBeInner + +enum class E { + ABC { + enum class F { + DEF + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt new file mode 100644 index 00000000000..5adc47b7eb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.fir.kt @@ -0,0 +1,7 @@ +class A { + inner class B { + enum class E { + ENTRY + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideObject.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideObject.fir.kt new file mode 100644 index 00000000000..80f679f8167 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideObject.fir.kt @@ -0,0 +1,5 @@ +object A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideTrait.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/insideTrait.fir.kt new file mode 100644 index 00000000000..5d04181c73b --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideTrait.fir.kt @@ -0,0 +1,5 @@ +interface A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.fir.kt new file mode 100644 index 00000000000..5c974e726e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.fir.kt @@ -0,0 +1,11 @@ +class A { + enum class E { + ENTRY + } + + companion object { + enum class E { + ENTRY2 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/inner/twoEnums.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/twoEnums.fir.kt new file mode 100644 index 00000000000..fbf22f500c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/twoEnums.fir.kt @@ -0,0 +1,4 @@ +class A { + enum class E { ABC } + enum class F { DEF } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt b/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt new file mode 100644 index 00000000000..49cedfbdd6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.fir.kt @@ -0,0 +1,9 @@ +class A { + companion object { + enum class E { ENTRY } // OK + } + + inner class B { + enum class E { ENTRY } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/interfaceWithEnumKeyword.fir.kt b/compiler/testData/diagnostics/tests/enum/interfaceWithEnumKeyword.fir.kt new file mode 100644 index 00000000000..8db080692bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/interfaceWithEnumKeyword.fir.kt @@ -0,0 +1,8 @@ +enum interface Some { + // Enum part + D; + + // Interface like part + fun test() + val foo: Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/isEnumEntry.fir.kt b/compiler/testData/diagnostics/tests/enum/isEnumEntry.fir.kt new file mode 100644 index 00000000000..28becfcb3db --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/isEnumEntry.fir.kt @@ -0,0 +1,6 @@ +enum class MyEnum { + FIRST, + SECOND +} + +fun foo(me: MyEnum): Boolean = me is MyEnum.FIRST \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumValueOfMethod.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumValueOfMethod.fir.kt new file mode 100644 index 00000000000..971bb3fec1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumValueOfMethod.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE +// FILE: A.java +public enum A { + ENTRY; +} + +// FILE: test.kt +fun main() { + checkSubtype(A.valueOf("ENTRY")) +} diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumValuesMethod.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumValuesMethod.fir.kt new file mode 100644 index 00000000000..6089eef7c3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumValuesMethod.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE +// FILE: A.java +public enum A { + ENTRY, + ANOTHER; +} + +// FILE: test.kt +fun main() { + checkSubtype>(A.values()) +} diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumWithAbstractFun.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumWithAbstractFun.fir.kt new file mode 100644 index 00000000000..d6a3800ebc8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumWithAbstractFun.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE +// FILE: A.java +public enum A { + + ENTRY { + public String s() { + return "s"; + } + }; + public abstract String s(); +} + +// FILE: test.kt +fun main() { + checkSubtype(A.ENTRY.s()) +} diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumWithFuns.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumWithFuns.fir.kt new file mode 100644 index 00000000000..7d6399171d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumWithFuns.fir.kt @@ -0,0 +1,16 @@ +// FILE: A.java +public enum A { + ENTRY, + ANOTHER; + + public String s() { + return ""; + } +} + +// FILE: test.kt + +fun main() { + val c = A.ENTRY + c.s() +} diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumWithNameClashing.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumWithNameClashing.fir.kt new file mode 100644 index 00000000000..d06fca45d28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumWithNameClashing.fir.kt @@ -0,0 +1,15 @@ +// FILE: A.java +public enum A { + ENTRY, + ANOTHER; + + public String ENTRY = ""; +} + +// FILE: test.kt + +fun main() { + val c: A = A.ENTRY + val c2: String? = c.ENTRY + val c3: String? = A.ANOTHER.ENTRY +} diff --git a/compiler/testData/diagnostics/tests/enum/javaEnumWithProperty.fir.kt b/compiler/testData/diagnostics/tests/enum/javaEnumWithProperty.fir.kt new file mode 100644 index 00000000000..5ab0ebf77dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/javaEnumWithProperty.fir.kt @@ -0,0 +1,19 @@ +// FILE: A.java +public enum A { + ENTRY("1"), + ANOTHER("2"); + + public String s; + + private A(String s) { + this.s = s; + } +} + +// FILE: test.kt + +fun main() { + val c = A.ENTRY + c.s + A.ANOTHER.s +} diff --git a/compiler/testData/diagnostics/tests/enum/kt2834.fir.kt b/compiler/testData/diagnostics/tests/enum/kt2834.fir.kt new file mode 100644 index 00000000000..8144143dd11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/kt2834.fir.kt @@ -0,0 +1,6 @@ +private enum class MethodKind { + INSTANCE, + STATIC +} + +private fun MethodKind.hasThis() = this == MethodKind.INSTANCE diff --git a/compiler/testData/diagnostics/tests/enum/kt8972_cloneNotAllowed.fir.kt b/compiler/testData/diagnostics/tests/enum/kt8972_cloneNotAllowed.fir.kt new file mode 100644 index 00000000000..6a63b936836 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/kt8972_cloneNotAllowed.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +enum class E : Cloneable { + A; + override fun clone(): Any { + return super.clone() + } +} diff --git a/compiler/testData/diagnostics/tests/enum/localEnums.fir.kt b/compiler/testData/diagnostics/tests/enum/localEnums.fir.kt new file mode 100644 index 00000000000..22a4801d5a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/localEnums.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + enum class A { + FOO, + BAR + } + val foo = A.FOO + val b = object { + enum class B {} + } + class C { + enum class D {} + } + val f = { + enum class E {} + } + + enum class {} +} diff --git a/compiler/testData/diagnostics/tests/enum/modifiersOnEnumEntry.fir.kt b/compiler/testData/diagnostics/tests/enum/modifiersOnEnumEntry.fir.kt new file mode 100644 index 00000000000..d5d8bc23a3f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/modifiersOnEnumEntry.fir.kt @@ -0,0 +1,23 @@ +enum class E { + public final SUBCLASS { + fun foo() {} + }, + + public PUBLIC, + protected PROTECTED, + private PRIVATE, + internal INTERNAL, + + abstract ABSTRACT, + open OPEN, + override OVERRIDE, + final FINAL, + + inner INNER, + annotation ANNOTATION, + enum ENUM, + out OUT, + in IN, + vararg VARARG, + reified REIFIED +} diff --git a/compiler/testData/diagnostics/tests/enum/multipleConstructors.fir.kt b/compiler/testData/diagnostics/tests/enum/multipleConstructors.fir.kt new file mode 100644 index 00000000000..70a2c379ca7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/multipleConstructors.fir.kt @@ -0,0 +1,8 @@ +enum class E(val x: Int, val y: Int) { + A(1, 2), + B(1), + C; // no constructor call needed even here + + constructor(): this(0, 0) + constructor(x: Int): this(x, 0) +} diff --git a/compiler/testData/diagnostics/tests/enum/openMemberInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/openMemberInEnum.fir.kt new file mode 100644 index 00000000000..7f2e397e0fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/openMemberInEnum.fir.kt @@ -0,0 +1,17 @@ +enum class EnumWithOpenMembers { + E1 { + override fun foo() = 1 + override val bar: String = "a" + }, + + E2 { + override fun f() = 3 + override val b = 4 + }; + + open fun foo() = 1 + open val bar: String = "" + + fun f() = 2 + val b = 3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/overrideFinalEnumMethods.fir.kt b/compiler/testData/diagnostics/tests/enum/overrideFinalEnumMethods.fir.kt new file mode 100644 index 00000000000..69b11a657d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/overrideFinalEnumMethods.fir.kt @@ -0,0 +1,11 @@ +enum class E { + ENTRY; + + override val name: String = "lol" + override val ordinal: Int = 0 + + override fun compareTo(other: E) = -1 + + override fun equals(other: Any?) = true + override fun hashCode() = -1 +} diff --git a/compiler/testData/diagnostics/tests/enum/starImportNestedClassAndEntries.fir.kt b/compiler/testData/diagnostics/tests/enum/starImportNestedClassAndEntries.fir.kt new file mode 100644 index 00000000000..b2b9ba97aa3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/starImportNestedClassAndEntries.fir.kt @@ -0,0 +1,24 @@ +// FILE: E.kt +package foo + +enum class E { + ENTRY, + ANOTHER; + + class Nested { + companion object { + fun foo() = 42 + } + } +} + +// FILE: main.kt +package bar + +import foo.E.* + +fun f1() = ENTRY +fun f2() = ANOTHER +fun f3() = Nested() +fun f4() = Nested.foo() +fun f5() = values() diff --git a/compiler/testData/diagnostics/tests/enum/typeParametersInEnum.fir.kt b/compiler/testData/diagnostics/tests/enum/typeParametersInEnum.fir.kt new file mode 100644 index 00000000000..a2d2d1dc0a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/typeParametersInEnum.fir.kt @@ -0,0 +1,7 @@ +// KT-5696 Prohibit type parameters for enum classes + +package bug + +public enum class Foo { + A() +} diff --git a/compiler/testData/diagnostics/tests/enum/valuesValueOfAndEntriesAccessibility.fir.kt b/compiler/testData/diagnostics/tests/enum/valuesValueOfAndEntriesAccessibility.fir.kt new file mode 100644 index 00000000000..c023e705a4a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/valuesValueOfAndEntriesAccessibility.fir.kt @@ -0,0 +1,18 @@ +enum class E { + ENTRY; + + companion object { + fun foo(): E = ENTRY + fun bar(): Array = values() + fun baz(): E = valueOf("ENTRY") + val valuez = values() + } + + fun oof(): E = ENTRY + fun rab(): Array = values() + fun zab(): E = valueOf("ENTRY") +} + +fun foo() = E.ENTRY +fun bar() = E.values() +fun baz() = E.valueOf("ENTRY") diff --git a/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.fir.kt b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.fir.kt new file mode 100644 index 00000000000..d8913f128a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/wrongUnitializedEnumCompanion.fir.kt @@ -0,0 +1,9 @@ +// See KT-20959 + +enum class Foo {; + companion object { + val x = foo() // there should be no UNINITIALIZED_ENUM_COMPANION + + private fun foo() = "OK" + } +} diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt new file mode 100644 index 00000000000..fdf5c00a2af --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.fir.kt @@ -0,0 +1,30 @@ +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(1 - 1) + fooInt(1 - 1.toInt()) + fooInt(1 - 1.toByte()) + fooInt(1 - 1.toLong()) + fooInt(1 - 1.toShort()) + + fooByte(1 - 1) + fooByte(1 - 1.toInt()) + fooByte(1 - 1.toByte()) + fooByte(1 - 1.toLong()) + fooByte(1 - 1.toShort()) + + fooLong(1 - 1) + fooLong(1 - 1.toInt()) + fooLong(1 - 1.toByte()) + fooLong(1 - 1.toLong()) + fooLong(1 - 1.toShort()) + + fooShort(1 - 1) + fooShort(1 - 1.toInt()) + fooShort(1 - 1.toByte()) + fooShort(1 - 1.toLong()) + fooShort(1 - 1.toShort()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndepWoExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndepWoExpType.fir.kt new file mode 100644 index 00000000000..15c7b377c16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndepWoExpType.fir.kt @@ -0,0 +1,36 @@ +val p1 = 1 - 1 +val p2 = 1 - 1.toLong() +val p3 = 1 - 1.toByte() +val p4 = 1 - 1.toInt() +val p5 = 1 - 1.toShort() + +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(p1) + fooInt(p2) + fooInt(p3) + fooInt(p4) + fooInt(p5) + + fooLong(p1) + fooLong(p2) + fooLong(p3) + fooLong(p4) + fooLong(p5) + + fooShort(p1) + fooShort(p2) + fooShort(p3) + fooShort(p4) + fooShort(p5) + + fooByte(p1) + fooByte(p2) + fooByte(p3) + fooByte(p4) + fooByte(p5) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt new file mode 100644 index 00000000000..f7f924c32ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.fir.kt @@ -0,0 +1,24 @@ +val p1: Int = 1 - 1 +val p2: Long = 1 - 1 +val p3: Byte = 1 - 1 +val p4: Short = 1 - 1 + +val l1: Long = 1 - 1.toLong() +val l2: Byte = 1 - 1.toLong() +val l3: Int = 1 - 1.toLong() +val l4: Short = 1 - 1.toLong() + +val b1: Byte = 1 - 1.toByte() +val b2: Int = 1 - 1.toByte() +val b3: Long = 1 - 1.toByte() +val b4: Short = 1 - 1.toByte() + +val i1: Byte = 1 - 1.toInt() +val i2: Int = 1 - 1.toInt() +val i3: Long = 1 - 1.toInt() +val i4: Short = 1 - 1.toInt() + +val s1: Byte = 1 - 1.toShort() +val s2: Int = 1 - 1.toShort() +val s3: Long = 1 - 1.toShort() +val s4: Short = 1 - 1.toShort() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/divisionByZero.fir.kt b/compiler/testData/diagnostics/tests/evaluate/divisionByZero.fir.kt new file mode 100644 index 00000000000..3f87f1f39a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/divisionByZero.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +val a1 = 0 +val a2 = 1 / 0 +val a3 = 1 / a1 +val a4 = 1 / a2 +val a5 = 2 * (1 / 0) + +val a6 = 1.div(0) +val a7 = 1.div(a1) +val a8 = 1.div(a2) +val a9 = 2 * (1.div(0)) + +val b1: Byte = 1 / 0 +@Ann(1 / 0) val b2 = 1 + +annotation class Ann(val i : Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/float.fir.kt b/compiler/testData/diagnostics/tests/evaluate/float.fir.kt new file mode 100644 index 00000000000..67f8b0c5692 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/float.fir.kt @@ -0,0 +1,10 @@ +val a1: Float = 1F +val a2: Float = 1.0F +val a3: Float = 1e-1F +val a4: Float = 1.0e-1F + +val b5: Float = 1f +val b6: Float = 1.0f +val b7: Float = 1e-1f +val b8: Float = 1.0e-1f + diff --git a/compiler/testData/diagnostics/tests/evaluate/floatLiteralOutOfRange.fir.kt b/compiler/testData/diagnostics/tests/evaluate/floatLiteralOutOfRange.fir.kt new file mode 100644 index 00000000000..3f24b603407 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/floatLiteralOutOfRange.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_EXPRESSION + +fun test() { + 1.2E400F + 1.2E-400F + 11111111111111111111111111111111111111111111111111111111111111111F + 0.000000000000000000000000000000000000000000000000000000000000001F + 0.000000000000000000000000000000000000001000000000000000000000000F + + 1.2E400f + 1.2E-400f + 11111111111111111111111111111111111111111111111111111111111111111f + 0.000000000000000000000000000000000000000000000000000000000000001f + 0.000000000000000000000000000000000000001000000000000000000000000f + + val d1: Double = 1.2E400 + val d2: Double = 1.2E-400 + val d3: Double = 11111111111111111111111111111111111111111111111111111111111111111.0 + val d4: Double = 0.000000000000000000000000000000000000000000000000000000000000001 + val d5: Double = 0.000000000000000000000000000000000000001000000000000000000000000 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/infixFunOverBuiltinMemberInConst.fir.kt b/compiler/testData/diagnostics/tests/evaluate/infixFunOverBuiltinMemberInConst.fir.kt new file mode 100644 index 00000000000..d9361ac8aff --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/infixFunOverBuiltinMemberInConst.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER + +infix fun Int.rem(other: Int) = 10 +infix operator fun Int.minus(other: Int): Int = 20 + +const val a1 = (-5) rem 2 +const val a2 = (-5).rem(2) + +const val b1 = 5 minus 3 +const val b2 = 5.minus(3) diff --git a/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.fir.kt new file mode 100644 index 00000000000..efab6641d11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.fir.kt @@ -0,0 +1,44 @@ +// !LANGUAGE: +InlineClasses +// JAVAC_SKIP + +// FILE: uint.kt + +package kotlin + +inline class UByte(private val b: Byte) +inline class UShort(private val s: Short) +inline class UInt(private val i: Int) +inline class ULong(private val l: Long) + +// FILE: test.kt + +annotation class AnnoUB(val ub0: UByte, val ub1: UByte) +annotation class AnnoUS(val us0: UShort, val us1: UShort) +annotation class AnnoUI(val ui0: UInt, val ui1: UInt, val ui2: UInt, val ui3: UInt) +annotation class AnnoUL(val ul0: ULong, val ul1: ULong) + +const val ub0 = UByte(1) +const val us0 = UShort(2) +const val ul0 = ULong(3) + +const val ui0 = UInt(-1) +const val ui1 = UInt(0) +const val ui2 = UInt(40 + 2) + +@AnnoUB(UByte(1), ub0) +fun f0() {} + +@AnnoUS(UShort(2 + 5), us0) +fun f1() {} + +@AnnoUI(ui0, ui1, ui2, UInt(100)) +fun f2() {} + +@AnnoUL(ul0, ULong(5)) +fun f3() {} + +const val explicit: UInt = UInt(2) + +const val nullable: UInt? = UInt(3) + +annotation class NullableAnno(val u: UInt?) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/intOverflow.fir.kt b/compiler/testData/diagnostics/tests/evaluate/intOverflow.fir.kt new file mode 100644 index 00000000000..741f62a305a --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/intOverflow.fir.kt @@ -0,0 +1,77 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +val intMaxValue: Int = 0x7fffffff +val intMinValue: Int = 1 shl 31 + +val a3: Int = intMaxValue + 1 - 10 +val a4: Int = intMaxValue + 1 + 10 +val i2: Int = intMaxValue - 1 + 2 +val i3: Int = intMaxValue - intMinValue +val i4: Int = -intMinValue +val i5: Int = intMinValue - 1 +val i6: Int = intMinValue - intMaxValue +val i7: Int = intMinValue + intMaxValue +val i8: Int = -intMaxValue +val i10: Int = intMinValue * -1 +val i11: Int = intMinValue * 2 +val i12: Int = intMaxValue * -2 +val i13: Int = intMaxValue * -1 +val i15: Int = intMinValue / -1 +val l20: Int = 30 * 24 * 60 * 60 * 1000 +val l21: Int = intMinValue - intMinValue +val l22: Int = intMinValue + -intMinValue +val l23: Int = intMaxValue + -intMinValue +val l24: Int = (-1).mod(5) +val l25: Int = (-1).rem(5) +val l26: Int = (-1) % 5 + + +fun foo() { + val a3: Int = intMaxValue + 1 - 10 + val a4: Int = intMaxValue + 1 + 10 + val i2: Int = intMaxValue - 1 + 2 + val i3: Int = intMaxValue - intMinValue + val i4: Int = -intMinValue + val i5: Int = intMinValue - 1 + val i6: Int = intMinValue - intMaxValue + val i7: Int = intMinValue + intMaxValue + val i8: Int = -intMaxValue + val i10: Int = intMinValue * -1 + val i11: Int = intMinValue * 2 + val i12: Int = intMaxValue * -2 + val i13: Int = intMaxValue * -1 + val i15: Int = intMinValue / -1 + val l20: Int = 30 * 24 * 60 * 60 * 1000 + val l21: Int = intMinValue - intMinValue + val l22: Int = intMinValue + -intMinValue + val l23: Int = intMaxValue + -intMinValue + val l24: Int = (-1).mod(5) + val l25: Int = (-1).rem(5) + val l26: Int = (-1) % 5 +} + +class A { + fun foo() { + val a3: Int = intMaxValue + 1 - 10 + val a4: Int = intMaxValue + 1 + 10 + val i2: Int = intMaxValue - 1 + 2 + val i3: Int = intMaxValue - intMinValue + val i4: Int = -intMinValue + val i5: Int = intMinValue - 1 + val i6: Int = intMinValue - intMaxValue + val i7: Int = intMinValue + intMaxValue + val i8: Int = -intMaxValue + val i10: Int = intMinValue * -1 + val i11: Int = intMinValue * 2 + val i12: Int = intMaxValue * -2 + val i13: Int = intMaxValue * -1 + val i15: Int = intMinValue / -1 + val l20: Int = 30 * 24 * 60 * 60 * 1000 + val l21: Int = intMinValue - intMinValue + val l22: Int = intMinValue + -intMinValue + val l23: Int = intMaxValue + -intMinValue + val l24: Int = (-1).mod(5) + val l25: Int = (-1).rem(5) + val l26: Int = (-1) % 5 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/intOverflowWithJavaProperties.fir.kt b/compiler/testData/diagnostics/tests/evaluate/intOverflowWithJavaProperties.fir.kt new file mode 100644 index 00000000000..608b83b7c28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/intOverflowWithJavaProperties.fir.kt @@ -0,0 +1,14 @@ +// FILE: Test.java +public class Test { + public static int i1 = Integer.MAX_VALUE; + public static final int i2 = Integer.MAX_VALUE; + public final int i3 = Integer.MAX_VALUE; + public int i4 = Integer.MAX_VALUE; +} + + +// FILE: A.kt +val a1: Int = Test.i1 + 1 +val a2: Int = Test.i2 + 1 +val a3: Int = Test().i3 + 1 +val a4: Int = Test().i4 + 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/integer.fir.kt b/compiler/testData/diagnostics/tests/evaluate/integer.fir.kt new file mode 100644 index 00000000000..329bb5d10c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/integer.fir.kt @@ -0,0 +1,10 @@ +val a1: Int = 1L +val a2: Int = 0x1L +val a3: Int = 0X1L +val a4: Int = 0b1L +val a5: Int = 0B1L +val a6: Long = 1L +val a7: Long = 0x1L +val a8: Long = 0X1L +val a9: Long = 0b1L +val a10: Long = 0B1L \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/logicWithNumber.fir.kt b/compiler/testData/diagnostics/tests/evaluate/logicWithNumber.fir.kt new file mode 100644 index 00000000000..6c4ca0c41ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/logicWithNumber.fir.kt @@ -0,0 +1,8 @@ +fun bar() { + false and false +} + +// See exception in KT-13421 +fun foo() { + 42 and false +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/longOverflow.fir.kt b/compiler/testData/diagnostics/tests/evaluate/longOverflow.fir.kt new file mode 100644 index 00000000000..ef3d9841142 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/longOverflow.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +val longMaxValue: Long = 0x7fffffffffffffff +val longMinValue: Long = -longMaxValue - 1 +val intMaxValue: Int = 0x7fffffff +val intMinValue: Int = 1 shl 31 + +val a2: Long = longMinValue - 10 + +val l1: Long = longMaxValue + 1 +val l2: Long = longMaxValue - 1 + 2 +val l3: Long = longMaxValue - longMinValue +val l4: Long = -longMinValue +val l5: Long = longMinValue - 1 +val l6: Long = longMinValue - longMaxValue +val l7: Long = longMinValue + longMaxValue +val l8: Long = -longMaxValue +val l10: Long = -intMinValue.toLong() +val l11: Long = -1 + intMinValue.toLong() +val l12: Long = longMinValue * intMinValue +val l13: Long = longMinValue * -1 +val l14: Long = longMinValue * 2 +val l15: Long = longMaxValue * -2 +val l16: Long = intMinValue.toLong() * -1 +val l19: Long = longMinValue / -1 + +fun foo() { + val l1: Long = longMaxValue + 1 + val l2: Long = longMaxValue - 1 + 2 + val l3: Long = longMaxValue - longMinValue + val l4: Long = -longMinValue + val l5: Long = longMinValue - 1 + val l6: Long = longMinValue - longMaxValue + val l7: Long = longMinValue + longMaxValue + val l8: Long = -longMaxValue + val l10: Long = -intMinValue.toLong() + val l11: Long = -1 + intMinValue.toLong() + val l12: Long = longMinValue * intMinValue + val l13: Long = longMinValue * -1 + val l14: Long = longMinValue * 2 + val l15: Long = longMaxValue * -2 + val l16: Long = intMinValue.toLong() * -1 + val l19: Long = longMinValue / -1 +} + +class A { + fun foo() { + val l1: Long = longMaxValue + 1 + val l2: Long = longMaxValue - 1 + 2 + val l3: Long = longMaxValue - longMinValue + val l4: Long = -longMinValue + val l5: Long = longMinValue - 1 + val l6: Long = longMinValue - longMaxValue + val l7: Long = longMinValue + longMaxValue + val l8: Long = -longMaxValue + val l10: Long = -intMinValue.toLong() + val l11: Long = -1 + intMinValue.toLong() + val l12: Long = longMinValue * intMinValue + val l13: Long = longMinValue * -1 + val l14: Long = longMinValue * 2 + val l15: Long = longMaxValue * -2 + val l16: Long = intMinValue.toLong() * -1 + val l19: Long = longMinValue / -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/noOverflowWithZero.fir.kt b/compiler/testData/diagnostics/tests/evaluate/noOverflowWithZero.fir.kt new file mode 100644 index 00000000000..0e97797cf5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/noOverflowWithZero.fir.kt @@ -0,0 +1,11 @@ +val zero = 0 + +fun test() { + -0 + -0L + -0.0 + -(1 - 1) + -zero + + +0 +} diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt new file mode 100644 index 00000000000..3dbdd578b6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.fir.kt @@ -0,0 +1,26 @@ +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(1 + 1) + fooByte(1 + 1) + fooLong(1 + 1) + fooShort(1 + 1) + + fooInt(1 * 1) + fooByte(1 * 1) + fooLong(1 * 1) + fooShort(1 * 1) + + fooInt(1 / 1) + fooByte(1 / 1) + fooLong(1 / 1) + fooShort(1 / 1) + + fooInt(1 % 1) + fooByte(1 % 1) + fooLong(1 % 1) + fooShort(1 % 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt new file mode 100644 index 00000000000..3133c5b29d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.fir.kt @@ -0,0 +1,31 @@ +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(1.plus(1)) + fooByte(1.plus(1)) + fooLong(1.plus(1)) + fooShort(1.plus(1)) + + fooInt(1.times(1)) + fooByte(1.times(1)) + fooLong(1.times(1)) + fooShort(1.times(1)) + + fooInt(1.div(1)) + fooByte(1.div(1)) + fooLong(1.div(1)) + fooShort(1.div(1)) + + fooInt(1.mod(1)) + fooByte(1.mod(1)) + fooLong(1.mod(1)) + fooShort(1.mod(1)) + + fooInt(1.rem(1)) + fooByte(1.rem(1)) + fooLong(1.rem(1)) + fooShort(1.rem(1)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt new file mode 100644 index 00000000000..8a597af0b82 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.fir.kt @@ -0,0 +1,31 @@ +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(1 plus 1) + fooByte(1 plus 1) + fooLong(1 plus 1) + fooShort(1 plus 1) + + fooInt(1 times 1) + fooByte(1 times 1) + fooLong(1 times 1) + fooShort(1 times 1) + + fooInt(1 div 1) + fooByte(1 div 1) + fooLong(1 div 1) + fooShort(1 div 1) + + fooInt(1 mod 1) + fooByte(1 mod 1) + fooLong(1 mod 1) + fooShort(1 mod 1) + + fooInt(1 rem 1) + fooByte(1 rem 1) + fooLong(1 rem 1) + fooShort(1 rem 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/otherOverflow.fir.kt b/compiler/testData/diagnostics/tests/evaluate/otherOverflow.fir.kt new file mode 100644 index 00000000000..566394d268a --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/otherOverflow.fir.kt @@ -0,0 +1,2 @@ +val a1: Int = 32000.toShort() * 32000.toShort() * 32000.toShort() +val a2: Int = 128.toByte() * 128.toByte() * 128.toByte() * 128.toByte() * 128.toByte() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt b/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt new file mode 100644 index 00000000000..1b35f47790b --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/parentesized.fir.kt @@ -0,0 +1,12 @@ +val p1: Byte = (1 + 2) * 2 +val p2: Short = (1 + 2) * 2 +val p3: Int = (1 + 2) * 2 +val p4: Long = (1 + 2) * 2 + +val b1: Byte = (1.toByte() + 2) * 2 +val b2: Short = (1.toShort() + 2) * 2 +val b3: Int = (1.toInt() + 2) * 2 +val b4: Long = (1.toLong() + 2) * 2 + +val i1: Int = (1.toByte() + 2) * 2 +val i2: Int = (1.toShort() + 2) * 2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/qualifiedExpressions.fir.kt b/compiler/testData/diagnostics/tests/evaluate/qualifiedExpressions.fir.kt new file mode 100644 index 00000000000..b1b740cd1ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/qualifiedExpressions.fir.kt @@ -0,0 +1,8 @@ +// FILE: a.kt +package example.ns +val y: Any? = 2 + +// FILE: b.kt +package example + +val x: Int = if (example.ns.y is Int) example.ns.y else 2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.fir.kt new file mode 100644 index 00000000000..361eff19dee --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.fir.kt @@ -0,0 +1,36 @@ +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(-1) + fooInt(-1111111111111111111) + fooInt(-1.toInt()) + fooInt(-1.toByte()) + fooInt(-1.toLong()) + fooInt(-1.toShort()) + + fooByte(-1) + fooByte(-1111111111111111111) + fooByte(-1.toInt()) + fooByte(-1.toByte()) + fooByte((-1).toByte()) + fooByte(-1.toLong()) + fooByte(-1.toShort()) + + fooLong(-1) + fooLong(-1111111111111111111) + fooLong(-1.toInt()) + fooLong(-1.toByte()) + fooLong(-1.toLong()) + fooLong(-1.toShort()) + + fooShort(-1) + fooShort(-1111111111111111111) + fooShort(-1.toInt()) + fooShort(-1.toByte()) + fooShort(-1.toLong()) + fooShort(-1.toShort()) + fooShort((-1).toShort()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndepWoExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndepWoExpType.fir.kt new file mode 100644 index 00000000000..4e2b30d44b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndepWoExpType.fir.kt @@ -0,0 +1,41 @@ +val p1 = -1 +val p2 = -1.toLong() +val p3 = (-1).toByte() +val p4 = -1.toInt() +val p5 = (-1).toShort() +val p6 = -1111111111111111111 + +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(p1) + fooInt(p2) + fooInt(p3) + fooInt(p4) + fooInt(p5) + fooInt(p6) + + fooLong(p1) + fooLong(p2) + fooLong(p3) + fooLong(p4) + fooLong(p5) + fooLong(p6) + + fooShort(p1) + fooShort(p2) + fooShort(p3) + fooShort(p4) + fooShort(p5) + fooShort(p6) + + fooByte(p1) + fooByte(p2) + fooByte(p3) + fooByte(p4) + fooByte(p5) + fooByte(p6) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndependentExpType.fir.kt b/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndependentExpType.fir.kt new file mode 100644 index 00000000000..29a08c66433 --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/unaryMinusIndependentExpType.fir.kt @@ -0,0 +1,29 @@ +val p1: Int = -1 +val p2: Long = -1 +val p3: Byte = -1 +val p4: Short = -1 + +val lp1: Int = -1111111111111111111 +val lp2: Long = -1111111111111111111 +val lp3: Byte = -1111111111111111111 +val lp4: Short = -1111111111111111111 + +val l1: Long = -1.toLong() +val l2: Byte = -1.toLong() +val l3: Int = -1.toLong() +val l4: Short = -1.toLong() + +val b1: Byte = -1.toByte() +val b2: Int = -1.toByte() +val b3: Long = -1.toByte() +val b4: Short = -1.toByte() + +val i1: Byte = -1.toInt() +val i2: Int = -1.toInt() +val i3: Long = -1.toInt() +val i4: Short = -1.toInt() + +val s1: Byte = -1.toShort() +val s2: Int = -1.toShort() +val s3: Long = -1.toShort() +val s4: Short = -1.toShort() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/evaluate/wrongLongSuffix.fir.kt b/compiler/testData/diagnostics/tests/evaluate/wrongLongSuffix.fir.kt new file mode 100644 index 00000000000..1284617c8df --- /dev/null +++ b/compiler/testData/diagnostics/tests/evaluate/wrongLongSuffix.fir.kt @@ -0,0 +1,10 @@ +val a1: Int = 1l +val a2: Int = 0x1l +val a3: Int = 0X1l +val a4: Int = 0b1l +val a5: Int = 0B1l +val a6: Long = 1l +val a7: Long = 0x1l +val a8: Long = 0X1l +val a9: Long = 0b1l +val a10: Long = 0B1l \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/delegate.fir.kt b/compiler/testData/diagnostics/tests/exposed/delegate.fir.kt new file mode 100644 index 00000000000..e2e02550d2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/delegate.fir.kt @@ -0,0 +1,6 @@ +interface My + +internal class Your: My + +// Code is valid, despite of delegate is internal +class His: My by Your() diff --git a/compiler/testData/diagnostics/tests/exposed/exceptionOnFakeInvisible.fir.kt b/compiler/testData/diagnostics/tests/exposed/exceptionOnFakeInvisible.fir.kt new file mode 100644 index 00000000000..bba58b45e5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/exceptionOnFakeInvisible.fir.kt @@ -0,0 +1,12 @@ +// KT-14469: SOE during effective visibility evaluation + +abstract class Base(private val v: String) + +fun bar(arg: String) = arg + +class Derived : Base("123") { + + private inline fun foo() { + bar(v) + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/functional.fir.kt b/compiler/testData/diagnostics/tests/exposed/functional.fir.kt new file mode 100644 index 00000000000..6b49dbee9bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/functional.fir.kt @@ -0,0 +1,12 @@ +internal class My + +class Your + +// Both arguments should be exposed +fun foo(my: My, f: (My) -> Unit) = f(my) + +// Ok +fun bar(your: Your, f: (Your) -> Unit) = f(your) + +// Exposed, returns My +fun gav(f: () -> My) = f() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/implements.fir.kt b/compiler/testData/diagnostics/tests/exposed/implements.fir.kt new file mode 100644 index 00000000000..8e26914c1fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/implements.fir.kt @@ -0,0 +1,4 @@ +private interface My + +// valid, it's allowed to implement worse-visible interface +class Your: My \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/inaccessibleType.fir.kt b/compiler/testData/diagnostics/tests/exposed/inaccessibleType.fir.kt new file mode 100644 index 00000000000..9a2045952a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/inaccessibleType.fir.kt @@ -0,0 +1,89 @@ +// !DIAGNOSTICS: -USELESS_CAST -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +// FILE: j/Base.java +package j; +public interface Base { + void foo(); +} + +// FILE: j/Impl.java +package j; + +/* package */ abstract class Impl implements Base { + public void foo() {} +} + +// FILE: j/Derived1.java +package j; + +public class Derived1 extends Impl {} + +// FILE: j/Derived2.java +package j; + +public class Derived2 extends Impl {} + +// FILE: k/Client.kt +package k + +import j.* + +val d1 = Derived1() +val d2 = Derived2() + +fun select(x1: T, x2: T) = x1 +fun selectn(vararg xx: T) = xx[0] +fun foo(x: T) = x.foo() +fun listOf2(x1: T, x2: T): List = null!! +fun arrayOf2(x1: T, x2: T): Array = null!! + +fun test() { + val test1: Base = if (true) d1 else d2 + + val test2 = if (true) d1 else d2 + + val test3 = when { + true -> d1 + else -> d2 + } + + val test4: Base = when { + true -> d1 + else -> d2 + } + + val test5 = select(d1, d2) + + val test6 = select(d1, d2) + + val test7 = select(d1 as Base, d2) + + val test8 = selectn(d1, d2) + + val test9 = selectn(d1, d2) + + val test10 = listOf2(d1, d2) + + val test11: List = listOf2(d1, d2) + // NB Inferred type is List because List is covariant. + + val test12 = listOf2(d1, d2) + + val test13 = arrayOf2(d1, d2) + + val test14: Array = arrayOf2(d1, d2) + // NB Inferred type is Array because Array is invariant. + + val test15 = arrayOf2(d1, d2) + + for (test16 in listOf2(d1, d2)) {} +} + +fun testOkInJava() { + // The following is Ok in Java, but is an error in Kotlin. + // TODO do not generate unneeded CHECKCASTs. + // TODO do not report INACCESSIBLE_TYPE for corresponding cases. + select(d1, d2) + foo(select(d1, d2)) +} diff --git a/compiler/testData/diagnostics/tests/exposed/internal.fir.kt b/compiler/testData/diagnostics/tests/exposed/internal.fir.kt new file mode 100644 index 00000000000..e098b640ce4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internal.fir.kt @@ -0,0 +1,25 @@ +internal open class My + +// valid, internal from internal +internal open class Your: My() { + // valid, effectively internal + fun foo() = My() +} + +// error, public from internal +open class His: Your() { + protected open class Nested + // error, public from internal + val x = My() + // valid, private from internal + private fun bar() = My() + // valid, internal from internal + internal var y: My? = null + // error, protected from internal + protected fun baz() = Your() +} + +internal class Their: His() { + // error, effectively internal from protected + class InnerDerived: His.Nested() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/internalAndProtected.fir.kt b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.fir.kt new file mode 100644 index 00000000000..69c94fee1d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.fir.kt @@ -0,0 +1,10 @@ +public open class A { + protected open class B +} + +public open class C : A() { + protected open class D { + // internal & protected(in C) <= protected(in A): Ok + internal open class E : A.B() + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/internalFromLocal.fir.kt b/compiler/testData/diagnostics/tests/exposed/internalFromLocal.fir.kt new file mode 100644 index 00000000000..b1481169882 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internalFromLocal.fir.kt @@ -0,0 +1,10 @@ +interface Your + +class My { + internal val x = object : Your {} + + internal fun foo() = { + class Local + Local() + }() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/local.fir.kt b/compiler/testData/diagnostics/tests/exposed/local.fir.kt new file mode 100644 index 00000000000..7d6e06dbfea --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/local.fir.kt @@ -0,0 +1,18 @@ +// invalid, depends on local class +fun foo() = run { + class A + A() +} + +// invalid, depends on local class +fun gav() = { + class B + B() +} + +abstract class My + +// valid, object literal here is effectively My +fun bar() = run { + object: My() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/localFromInternal.fir.kt b/compiler/testData/diagnostics/tests/exposed/localFromInternal.fir.kt new file mode 100644 index 00000000000..89521bdd0dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/localFromInternal.fir.kt @@ -0,0 +1,7 @@ +class My { + internal open class ThreadLocal + // Private from local: ??? + private val values = + // Local from internal: Ok + object: ThreadLocal() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/localFromPrivate.fir.kt b/compiler/testData/diagnostics/tests/exposed/localFromPrivate.fir.kt new file mode 100644 index 00000000000..9156292343b --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/localFromPrivate.fir.kt @@ -0,0 +1,15 @@ +class A { + private open class B + fun f() { + // Local from private: Ok + class C : B() + } +} + +private open class D + +fun f(): Int { + // Local from private: Ok + val x = object : D() { } + return x.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/localInFunReturnType.fir.kt b/compiler/testData/diagnostics/tests/exposed/localInFunReturnType.fir.kt new file mode 100644 index 00000000000..c37928f2317 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/localInFunReturnType.fir.kt @@ -0,0 +1,60 @@ +class My(val value: T) + +open class Base + +fun invalid1() = run { + class Local + My(Local()) +} + +fun invalid2() = My(object {}) + +fun invalid3() = My(object : Base() {}) + +fun invalid4() = run { + class Local + My(My(Local())) +} + +fun invalid5() = run { + fun invalid5a() = run { + class Local + Local() + } + My(invalid5a()) +} + +// Valid: effectively Any +fun valid1() = object {} + +// Valid: effectively Base +fun valid2() = object : Base() {} + +// Valid: explicit type argument +fun valid3() = My(object : Base() {}) + +// Valid: explicit type specified +fun valid4() : My = My(object : Base() {}) + +// Valid: local class denotable in local scope +fun valid5() = run { + class Local + fun valid5a() = My(Local()) + My(valid5a()) +} + +// Valid: local class denotable in local scope +fun valid6() = run { + class Local + fun valid6a() = run { + fun valid6b() = My(Local()) + valid6b() + } + My(valid6a()) +} + +// Valid: effectively My +fun valid7() = run { + class Local + My>(My(Local())) +} diff --git a/compiler/testData/diagnostics/tests/exposed/localInMemberType.fir.kt b/compiler/testData/diagnostics/tests/exposed/localInMemberType.fir.kt new file mode 100644 index 00000000000..8bc8f6a0ca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/localInMemberType.fir.kt @@ -0,0 +1,21 @@ +class Something { + public val publicVal1 = object { override fun toString() = "!" } + protected val protectedVal1 = object { override fun toString() = "!" } + internal val internalVal1 = object { override fun toString() = "!" } + private val privateVal1 = object { override fun toString() = "!" } + + public val publicVal2 = run { class A; A() } + protected val protectedVal2 = run { class A; A() } + internal val internalVal2 = run { class A; A() } + private val privateVal2 = run { class A; A() } + + public fun publicFun1() = object { override fun toString() = "!" } + protected fun protectedFun1() = object { override fun toString() = "!" } + internal fun internalFun1() = object { override fun toString() = "!" } + private fun privateFun1() = object { override fun toString() = "!" } + + public fun publicFun2() = run { class A; A() } + protected fun protectedFun2() = run { class A; A() } + internal fun internalFun2() = run { class A; A() } + private fun privateFun2() = run { class A; A() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/localInPropertyType.fir.kt b/compiler/testData/diagnostics/tests/exposed/localInPropertyType.fir.kt new file mode 100644 index 00000000000..ca2fbd3d9fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/localInPropertyType.fir.kt @@ -0,0 +1,60 @@ +class My(val value: T) + +open class Base + +val invalid1 = run { + class Local + My(Local()) +} + +val invalid2 = My(object {}) + +val invalid3 = My(object : Base() {}) + +val invalid4 = run { + class Local + My(My(Local())) +} + +val invalid5 = run { + fun invalid5a() = run { + class Local + Local() + } + My(invalid5a()) +} + +// Valid: effectively Any +val valid1 = object {} + +// Valid: effectively Base +val valid2 = object : Base() {} + +// Valid: explicit type argument +val valid3 = My(object : Base() {}) + +// Valid: explicit type specified +val valid4 : My = My(object : Base() {}) + +// Valid: local class denotable in local scope +val valid5 = run { + class Local + fun valid5a() = My(Local()) + My(valid5a()) +} + +// Valid: local class denotable in local scope +val valid6 = run { + class Local + fun valid6a() = run { + fun valid6b() = My(Local()) + valid6b() + } + My(valid6a()) +} + +// Valid: effectively My +val valid7 = run { + class Local + My>(My(Local())) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/nested.fir.kt b/compiler/testData/diagnostics/tests/exposed/nested.fir.kt new file mode 100644 index 00000000000..57e35086ad8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/nested.fir.kt @@ -0,0 +1,6 @@ +internal open class My + +internal class Outer { + // Ok, effectively internal from internal + class Your: My() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/object.fir.kt b/compiler/testData/diagnostics/tests/exposed/object.fir.kt new file mode 100644 index 00000000000..ec72d2bbd68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/object.fir.kt @@ -0,0 +1,30 @@ +// From KT-10753 +object My : Inter() { + fun foo(arg: Inter): Inter = arg + val x: Inter? = null +} + +internal open class Inter + +// From KT-10799 +open class Test { + protected class Protected + + fun foo(x: Protected) = x + + interface NestedInterface { + fun create(x: Protected) + } + + class NestedClass { + fun create(x: Protected) = x + } + + object NestedObject { + fun create(x: Protected) = x + } + + companion object { + fun create(x: Protected) = x + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/packagePrivate.fir.kt b/compiler/testData/diagnostics/tests/exposed/packagePrivate.fir.kt new file mode 100644 index 00000000000..f99a0622b36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/packagePrivate.fir.kt @@ -0,0 +1,35 @@ +// JAVAC_EXPECTED_FILE +// FILE: test/My.java + +package test; + +class Internal {} + +public class My { + static public Internal foo() { return new Internal(); } +} + +// FILE: test/His.kt + +package test + +class His { + // Ok: private vs package-private + private fun private() = My.foo() + // Ok: internal vs package-private in same package + internal fun internal() = My.foo() + // Error: protected vs package-private + protected fun protected() = My.foo() + // Error: public vs package-private + fun public() = My.foo() +} + +// FILE: other/Your.kt + +package other + +import test.My + +class Your { + internal fun bar() = My.foo() +} diff --git a/compiler/testData/diagnostics/tests/exposed/privateFromLocal.fir.kt b/compiler/testData/diagnostics/tests/exposed/privateFromLocal.fir.kt new file mode 100644 index 00000000000..418bbfef433 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/privateFromLocal.fir.kt @@ -0,0 +1,12 @@ +interface Your + +class My { + // private from local: ??? + private val x = object : Your {} + + // private from local: ??? + private fun foo() = { + class Local + Local() + }() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/privatePropertyInPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/exposed/privatePropertyInPrivateConstructor.fir.kt new file mode 100644 index 00000000000..db0bb7a35bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/privatePropertyInPrivateConstructor.fir.kt @@ -0,0 +1,3 @@ +private enum class Foo { A, B } + +class Bar private constructor(private val foo: Foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/propertyInConstructorOfPrivateClass.fir.kt b/compiler/testData/diagnostics/tests/exposed/propertyInConstructorOfPrivateClass.fir.kt new file mode 100644 index 00000000000..d2b672f3f0e --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/propertyInConstructorOfPrivateClass.fir.kt @@ -0,0 +1,3 @@ +private enum class Foo { A, B } + +private class Bar(val foo: Foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/propertyInPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/exposed/propertyInPrivateConstructor.fir.kt new file mode 100644 index 00000000000..59754a5f667 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/propertyInPrivateConstructor.fir.kt @@ -0,0 +1,3 @@ +private enum class Foo { A, B } + +class Bar private constructor(val foo: Foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/propertyInSimpleConstructor.fir.kt b/compiler/testData/diagnostics/tests/exposed/propertyInSimpleConstructor.fir.kt new file mode 100644 index 00000000000..b93fcfa3b98 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/propertyInSimpleConstructor.fir.kt @@ -0,0 +1,3 @@ +private enum class Foo { A, B } + +class Bar(val foo: Foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protected.fir.kt b/compiler/testData/diagnostics/tests/exposed/protected.fir.kt new file mode 100644 index 00000000000..88919501eba --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protected.fir.kt @@ -0,0 +1,20 @@ +open class A { + // protected relative to A + protected open class B { + fun foo() {} + } + public open class C { + // protected relative to C, must be an error + protected open class D : B() + } +} + +class E : A.C() { + // F has invisible grandparent class B (E does not inherit from A) + class F : A.C.D() { + init { + // Invoke function from invisible grandparent + foo() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protectedInProtected.fir.kt b/compiler/testData/diagnostics/tests/exposed/protectedInProtected.fir.kt new file mode 100644 index 00000000000..9c55dbc067d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedInProtected.fir.kt @@ -0,0 +1,12 @@ +// See KT-9540 + +// all protected should have lower bound that is more permissive than private +// protected and internal should have lower bound that is more permissive than private +open class A { + private interface B + protected open class C { + protected interface D : B + internal interface E : B, D + } +} + diff --git a/compiler/testData/diagnostics/tests/exposed/protectedJava.fir.kt b/compiler/testData/diagnostics/tests/exposed/protectedJava.fir.kt new file mode 100644 index 00000000000..29096cf0d16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedJava.fir.kt @@ -0,0 +1,16 @@ +// FILE: Outer.java + +public abstract class Outer { + protected static class My {} + protected static class Your extends My {} + abstract protected Your foo(My my); +} + +// FILE: OuterDerived.kt + +class OuterDerived: Outer() { + // valid, My has better visibility + protected class His: Outer.My() + // valid, My and Your have better visibility + override fun foo(my: Outer.My) = Outer.Your() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/protectedSameWay.fir.kt b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.fir.kt new file mode 100644 index 00000000000..9925008e88c --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/protectedSameWay.fir.kt @@ -0,0 +1,13 @@ +abstract class Outer { + protected open class My + // Both valid: same way protected + protected class Your: My() + abstract protected fun foo(my: My): Your +} + +class OuterDerived: Outer() { + // valid, My has better visibility + protected class His: Outer.My() + // valid, My and Your have better visibility + override fun foo(my: Outer.My) = Outer.Your() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/exposed/simple.fir.kt b/compiler/testData/diagnostics/tests/exposed/simple.fir.kt new file mode 100644 index 00000000000..72ec119da23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/simple.fir.kt @@ -0,0 +1,23 @@ +private interface My + +private open class Base + +public interface Your: My { + fun foo(): T +} + +public class Derived(val x: My): Base() { + + constructor(xx: My?, x: My): this(xx ?: x) + + val y: Base? = null + + val My.z: Int + get() = 42 + + fun foo(m: My): My = m + + fun My.bar(): My = this +} + + diff --git a/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt b/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt new file mode 100644 index 00000000000..ff682fb7c35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/typeArgs.fir.kt @@ -0,0 +1,17 @@ +internal open class My + +abstract class Your { + // invalid, List is effectively internal + abstract fun give(): List +} + +// invalid, List is effectively internal +interface His: List + +// invalid, My is internal +interface Generic + +interface Our { + // invalid, Generic is effectively internal + fun foo(): Generic<*> +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.fir.kt b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.fir.kt new file mode 100644 index 00000000000..efd4ec1e4d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.fir.kt @@ -0,0 +1,76 @@ +// !WITH_NEW_INFERENCE +// FILE: b.kt +package outer + +fun Int?.optint() : Unit {} +val Int?.optval : Unit get() = Unit + +fun T.foo(x : E, y : A) : T { + y.plus(1) + y plus 1 + y + 1.0 + + this?.minus(this) + + return this +} + +class A + +infix operator fun A.plus(a : Any) { + + 1.foo() + true.foo() + + 1 +} + +operator fun A.plus(a : Int) { + 1 +} + +operator fun T.minus(t : T) : Int = 1 + +fun test() { + val y = 1.abs +} +val Int.abs : Int + get() = if (this > 0) this else -this; + +val T.foo : T + +fun Int.foo() = this + +// FILE: b.kt +package null_safety + +import outer.* + + fun parse(cmd: String): Command? { return null } + class Command() { + // fun equals(other : Any?) : Boolean + val foo : Int = 0 + } + + fun Any.equals(other : Any?) : Boolean = true + fun Any?.equals1(other : Any?) : Boolean = true + fun Any.equals2(other : Any?) : Boolean = true + + fun main() { + + System.out.print(1) + + val command = parse("") + + command.foo + + command.equals(null) + command?.equals(null) + command.equals1(null) + command?.equals1(null) + + val c = Command() + c?.equals2(null) + + if (command == null) 1 + } diff --git a/compiler/testData/diagnostics/tests/extensions/ExtensionsCalledOnSuper.fir.kt b/compiler/testData/diagnostics/tests/extensions/ExtensionsCalledOnSuper.fir.kt new file mode 100644 index 00000000000..165fbc3e271 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/ExtensionsCalledOnSuper.fir.kt @@ -0,0 +1,22 @@ +interface T { + fun foo() {} + fun buzz() {} + fun buzz1(i : Int) {} +} + +fun T.bar() {} + +fun T.buzz() {} +fun T.buzz1() {} + +class C : T { + fun test() { + fun T.buzz() {} + fun T.buzz1() {} + super.foo() // OK + super.bar() // Error + super.buzz() // OK, resolved to a member + super.buzz1() // Resolved to an extension + super.buzz1("") // Resolved to a member + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/GenericIterator.fir.kt b/compiler/testData/diagnostics/tests/extensions/GenericIterator.fir.kt new file mode 100644 index 00000000000..480c208080f --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/GenericIterator.fir.kt @@ -0,0 +1,36 @@ +import java.util.Enumeration + +fun java.util.Enumeration.iterator() = object: Iterator { + override fun hasNext(): Boolean = hasMoreElements() + + override fun next() = nextElement() +} + +interface MyIterator { + + operator fun hasNext() : Boolean + + operator fun next() : T +} + +operator fun T?.iterator() = object : MyIterator { + var hasNext = this@iterator != null + private set + override fun hasNext() = hasNext + + override fun next() : T { + if (hasNext) { + hasNext = false + return this@iterator!! + } + throw java.util.NoSuchElementException() + } +} + +fun main() { + val i : Int? = 1 + for (x in i) { + System.out.println(x) + } +} + diff --git a/compiler/testData/diagnostics/tests/extensions/GenericIterator2.fir.kt b/compiler/testData/diagnostics/tests/extensions/GenericIterator2.fir.kt new file mode 100644 index 00000000000..32790a9b6f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/GenericIterator2.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +import java.util.Enumeration + +operator fun java.util.Enumeration.iterator() = object : Iterator { + public override fun hasNext(): Boolean = hasMoreElements() + + public override fun next() = nextElement() +} + +fun a(e : java.util.Enumeration) { + for (i in e) { + checkSubtype(i) + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/classObject.fir.kt b/compiler/testData/diagnostics/tests/extensions/classObject.fir.kt new file mode 100644 index 00000000000..59906776f9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/classObject.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +interface Tr + +class A { companion object } +class B { companion object : Tr } + +fun Any.f1() {} +fun Any?.f2() {} +fun Tr.f3() {} +fun Tr?.f4() {} +fun A.f5() {} + +fun test() { + A.f1() + A.f2() + B.f3() + B.f4() + A.f5() + B.f5() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.fir.kt b/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.fir.kt new file mode 100644 index 00000000000..5b5862e9dae --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/extensionMemberInClassObject.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface JPAEntityClass { + fun T.findByName(s: String): D {null!!} +} + +class Foo { + companion object : JPAEntityClass +} + +fun main() { + with("", { + Foo.findByName("") + }) + with(Foo) { + findByName("") + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/extensionPropertyVsParameter.fir.kt b/compiler/testData/diagnostics/tests/extensions/extensionPropertyVsParameter.fir.kt new file mode 100644 index 00000000000..4ae6532be52 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/extensionPropertyVsParameter.fir.kt @@ -0,0 +1,8 @@ +val Int.foo: Int + get() = this + + +fun test(foo: Int) { + test(4.foo) + test(foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/kt1875.fir.kt b/compiler/testData/diagnostics/tests/extensions/kt1875.fir.kt new file mode 100644 index 00000000000..0ea80d168cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/kt1875.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +//KT-1875 Safe call should be binded with receiver or this object (but not with both by default) + +package kt1875 + +fun foo(a : Int?, b : Int.(Int)->Int) = a?.b(1) //unnecessary safe call warning + +interface T { + val f : ((i: Int) -> Unit)? +} + +fun test(t: T) { + t.f(1) //unsafe call error + t.f?.invoke(1) +} + +fun test1(t: T?) { + t.f(1) // todo resolve f as value and report UNSAFE_CALL + t?.f(1) + t.f?.invoke(1) + t?.f?.invoke(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/kt2317.fir.kt b/compiler/testData/diagnostics/tests/extensions/kt2317.fir.kt new file mode 100644 index 00000000000..6bd8ceac485 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/kt2317.fir.kt @@ -0,0 +1,15 @@ +//KT-2317 Wrong UNNECESSARY_SAFE_CALL + +package kt2317 + +fun Any?.baz() = 1 + +fun foo(l: Long?) = l?.baz() + + +fun Any?.bar(): Unit { } + +fun quux(x: Int?): Unit { + x?.baz() + x?.bar() +} diff --git a/compiler/testData/diagnostics/tests/extensions/kt3470.fir.kt b/compiler/testData/diagnostics/tests/extensions/kt3470.fir.kt new file mode 100644 index 00000000000..60704abda29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/kt3470.fir.kt @@ -0,0 +1,7 @@ +class A { + companion object { + fun foo() = toString() + } +} + +val a = A.toString() diff --git a/compiler/testData/diagnostics/tests/extensions/kt3563.fir.kt b/compiler/testData/diagnostics/tests/extensions/kt3563.fir.kt new file mode 100644 index 00000000000..802dc2207e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/kt3563.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// KT-3563 Compiler requiring java.io.File, and it's unclear why + +package bar + +import java.io.File + +class Customer(name1: String) + +fun foo(f: File, c: Customer) { + f.name1 + + c.name1 // name1 should be unresolved here +} + +val File.name1: String + get() = getName() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/kt819ExtensionProperties.fir.kt b/compiler/testData/diagnostics/tests/extensions/kt819ExtensionProperties.fir.kt new file mode 100644 index 00000000000..16cf1f80eae --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/kt819ExtensionProperties.fir.kt @@ -0,0 +1,37 @@ +//KT-819 Redeclaration error for extension properties with the same name and different receivers +// FULL_JDK + +import java.io.* + +val InputStream.buffered : BufferedInputStream + get() = if(this is BufferedInputStream) this else BufferedInputStream(this) + +val Reader.buffered : BufferedReader + get() = if(this is BufferedReader) this else BufferedReader(this) + + +//more tests +open class A() { + open fun String.foo() {} + open fun Int.foo() {} + + open val String.foo: Int + get() = 0 + open val Int.foo: Int + get() = 1 +} + +class B() : A() { + override fun String.foo() {} + override fun Int.foo() {} + + override val String.foo: Int + get() = 0 + override val Int.foo: Int + get() = 0 + + fun use(s: String) { + s.foo + s.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/noClassObjectsInJava.fir.kt b/compiler/testData/diagnostics/tests/extensions/noClassObjectsInJava.fir.kt new file mode 100644 index 00000000000..e95008cb979 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/noClassObjectsInJava.fir.kt @@ -0,0 +1,11 @@ +// FILE: A.java +public class A { + public static void foo() {} + public static class Nested {} +} + +// FILE: B.kt +fun Any?.bar() = 42 + +fun f1() = A.bar() +fun f2() = A.Nested.bar() diff --git a/compiler/testData/diagnostics/tests/extensions/object.fir.kt b/compiler/testData/diagnostics/tests/extensions/object.fir.kt new file mode 100644 index 00000000000..359316e1b95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/object.fir.kt @@ -0,0 +1,6 @@ +object O + +fun Any.foo() = 42 +val Any?.bar: Int get() = 239 + +val x = O.foo() + O.bar diff --git a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt new file mode 100644 index 00000000000..101fc69277d --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt @@ -0,0 +1,56 @@ +// !WITH_NEW_INFERENCE +package bar + + +// should be thrown away + +fun List.a() {} + +fun test1(i: Int?) { + 1.a() + i.a() +} + +fun test2(c: Collection) { + c.a() +} + +fun Int.foo() {} + +fun test3(s: String?) { + "".foo() + s.foo() + "".foo(1) + s.foo("a") +} + +interface A +fun T.c() {} + +fun test4() { + 1.c() +} + + +// should be an error on receiver, shouldn't be thrown away + +fun test5() { + 1.(fun String.()=1)() +} + +fun R?.sure() : R = this!! + +fun test6(l: List?) { + l.sure() +} + + +fun List.b() {} + +fun test7(l: List) { + l.b() +} + +fun test8(l: List?) { + l.b() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver2.fir.kt b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver2.fir.kt new file mode 100644 index 00000000000..634d38bae98 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver2.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +package a + +class A {} + +fun test(a1: A, a2: A) { + val range = "island".."isle" + + a1..a2 +} + + +public operator fun > T.rangeTo(that: T): ClosedRange { + throw UnsupportedOperationException() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt b/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt new file mode 100644 index 00000000000..831c40af196 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt @@ -0,0 +1,11 @@ +class A(foo: Int.() -> Unit) { + init { + 4.foo() + } +} + +fun test(foo: Int.(String) -> Unit) { + 4.foo("") + 4.foo(p1 = "") + 4.foo(p2 = "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/fileDependencyRecursion.fir.kt b/compiler/testData/diagnostics/tests/fileDependencyRecursion.fir.kt new file mode 100644 index 00000000000..d4302a476a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/fileDependencyRecursion.fir.kt @@ -0,0 +1,15 @@ +// FILE: fileDependencyRecursion.kt +package test + +import testOther.some + +val normal: Int = 1 +val fromImported: Int = some + +// FILE: fileDependencyRecursionOther.kt +package testOther + +import test.normal + +val some: Int = 1 +val fromImported: Int = normal \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.fir.kt new file mode 100644 index 00000000000..1b2f22647d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +fun Iterable.map(transform: (T) -> R): List = null!! + +fun autolabel(l: List) = l.map (fun (i: Int): Int { + return@map 4 +}) + +fun unresolvedMapLabel(l: List) = l.map (l@ fun(i: Int): Int { + return@map 4 +}) diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/Common.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/Common.fir.kt new file mode 100644 index 00000000000..ce39b853d92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/Common.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +annotation class ann(val name: String) +const val ok = "OK" + +class A + +val withoutName = fun () {} +val extensionWithoutName = fun A.() {} + +fun withAnnotation() = @ann(ok) fun () {} +val withReturn = fun (): Int { return 5} +val withExpression = fun() = 5 +val funfun = fun() = fun() = 5 + +val parentesized = (fun () {}) +val parentesizedWithType = checkSubtype<() -> Unit>((fun () {})) +val withType = checkSubtype<() -> Unit>((fun () {})) diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/DifficultInferenceForParameter.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/DifficultInferenceForParameter.fir.kt new file mode 100644 index 00000000000..1c940b44ac6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/DifficultInferenceForParameter.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun foo(f : (T) -> T) : T = throw Exception() + +fun test() { + val a : Int = foo(fun (x) = x) +} diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ForbiddenNonLocalReturn.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ForbiddenNonLocalReturn.fir.kt new file mode 100644 index 00000000000..f7936c4f4e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ForbiddenNonLocalReturn.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun test() { + fun bar() { + val bas = fun() { + return@bar + } + } + + val bar = fun() { + return@test + } +} + +fun foo() { + val bal = bag@ fun () { + val bar = fun() { + return@bag + } + return@bag + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.fir.kt new file mode 100644 index 00000000000..fb97f697159 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +fun testReturnType(foo: String) { + val bar = fun () = foo + + bar.checkType { _<() -> String>() } + + val bas: () -> String = fun () = foo + + val bag: () -> Int = fun () = foo +} + +fun testParamType() { + val bar = fun (bal: String){} + + bar.checkType { _<(String) -> Unit>() } + + val bas: (String) -> Unit = fun (param: String) {} + val bag: (Int) -> Unit = fun (param: String) {} +} + +fun testReceiverType() { + val bar = fun String.() {} + + bar.checkType { _ Unit>() } + + val bas: String.() -> Unit = fun String.() {} + + val bag: Int.() -> Unit = fun String.() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.fir.kt new file mode 100644 index 00000000000..8a6a7e6d36b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE +fun listOf(): List = null!! + +fun test(a: (Int) -> Int) { + test(fun (x) = 4) + + test(fun (x) = x) + + test(fun (x): Int { checkSubtype(x); return 4 }) +} + +fun test2(a: () -> List) { + test2(fun () = listOf()) +} + +val a: (Int) -> Unit = fun(x) { checkSubtype(x) } + +val b: (Int) -> Unit = fun(x: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt new file mode 100644 index 00000000000..1ce99177991 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +val a = fun (x) = x + +val b: (Int) -> Int = fun (x) = x + 3 + +val c: (Int, String) -> Int = fun (x) = 3 + +val d: (Int, String) -> Int = fun (x) = 3 + +val e: (Int, String) -> Int = fun (x: String) = 3 + +val f: (Int) -> Int = fun (x: String) = 3 + +fun test1(a: (Int) -> Unit) { + test1(fun (x) { checkSubtype(x)}) +} + +fun test2(a: (Int) -> Unit) { + test2(fun (x: String) {}) +} + +fun test3(a: (Int, String) -> Unit) { + test3(fun (x: String) {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt new file mode 100644 index 00000000000..903f86c4815 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt @@ -0,0 +1,9 @@ +fun foo() { + class A + fun bar() {} + (fun bar() {}) + fun A.foo() {} + (fun A.foo() {}) + + run(fun foo() {}) +} diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/NoOverloadError.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/NoOverloadError.fir.kt new file mode 100644 index 00000000000..13610785b58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/NoOverloadError.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +val bar = fun() {} +val bas = fun() {} + +fun gar(p: Any?) = fun() {} +fun gas(p: Any?) = fun() {} + +fun outer() { + val bar = fun() {} + val bas = fun() {} + + fun gar(p: Any?) = fun() {} + fun gas(p: Any?) = fun() {} + + gar(fun() {}) + gar(fun() {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.fir.kt new file mode 100644 index 00000000000..1b8ccc2cd78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +val bar = fun(p: Int = 3) {} +val bas = fun(vararg p: Int) {} + +fun gar() = fun(p: Int = 3) {} +fun gas() = fun(vararg p: Int) {} + +fun outer(b: Any?) { + val bar = fun(p: Int = 3) {} + val bas = fun(vararg p: Int) {} + + fun gar() = fun(p: Int = 3) {} + fun gas() = fun(vararg p: Int) {} + + outer(fun(p: Int = 3) {}) + outer(fun(vararg p: Int) {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.fir.kt new file mode 100644 index 00000000000..bcfd7229a3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReceiverByExpectedType.fir.kt @@ -0,0 +1,3 @@ +// !WITH_NEW_INFERENCE +fun foo(f: String.() -> Int) {} +val test = foo(fun () = length) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnAndLabels.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnAndLabels.fir.kt new file mode 100644 index 00000000000..519b889788a --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnAndLabels.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +val label_fun = label@ fun () { + return@label +} + +val parenthesized_label_fun = (label@ fun () { + return@label +}) diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt new file mode 100644 index 00000000000..c811328fbbb --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt @@ -0,0 +1,9 @@ +val foo = fun(a: Int): String { + if (a == 1) return "4" + when (a) { + 5 -> return "2" + 3 -> return null + 2 -> return 2 + } + return "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ScopeCheck.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ScopeCheck.fir.kt new file mode 100644 index 00000000000..39fcc22ac00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ScopeCheck.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface B { + fun b_fun() {} +} + +fun test(param: String) { + + val local_val = 4 + val bar = fun B.(fun_param: Int) { + param.length + b_fun() + val inner_bar = local_val + fun_param + + bar + } + + inner_bar + fun_param +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt new file mode 100644 index 00000000000..963a47446f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER + +interface A +fun devNull(a: Any?){} + +val generic_fun = fun(t: T): T = null!! +val extension_generic_fun = funT.(t: T): T = null!! + +fun fun_with_where() = fun T.(t: T): T where T: A = null!! + + +fun outer() { + devNull(fun () {}) + devNull(fun T.() {}) + devNull(fun (): T = null!!) + devNull(fun (t: T) {}) + devNull(fun () where T:A {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.fir.kt new file mode 100644 index 00000000000..ae58e457603 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithOuterGeneric.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun parameter() = fun (t: T) = t +fun receiver() = fun T.() = this +fun returnType() = fun (): T = null!! + +val T.fromVal: () -> T get() = fun (): T = this@fromVal + +fun devNull(a: Any?){} + +fun outer() { + fun parameter() = fun (t: T) = t + fun receiver() = fun T.() = this + fun returnType() = fun (): T = null!! + + devNull(fun (t: O) = t) + devNull(fun O.() = this) + devNull(fun (): O = null!!) +} + +class Outer { + fun parameter() = fun (t: T) = t + fun receiver() = fun T.() = this + fun returnType() = fun (): T = null!! + + init { + devNull(fun (t: O) = t) + devNull(fun O.() = this) + devNull(fun (): O = null!!) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt new file mode 100644 index 00000000000..ccb1f2408b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +annotation class ann +val bas = fun () + +fun bar(a: Any) = fun () + +fun outer() { + bar(fun ()) + bar(l@ fun ()) + bar(@ann fun ()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt new file mode 100644 index 00000000000..dac5ccb52fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +val receiver = { Int.() -> } +val receiverWithParameter = { Int.(a) -> } + +val receiverAndReturnType = { Int.(): Int -> 5 } +val receiverAndReturnTypeWithParameter = { Int.(a: Int): Int -> 5 } + +val returnType = { (): Int -> 5 } +val returnTypeWithParameter = { (b: Int): Int -> 5 } + +val receiverWithFunctionType = { ((Int) -> Int).() -> } + +val parenthesizedParameters = { (a: Int) -> } +val parenthesizedParameters2 = { (b) -> } + +val none = { -> } + + +val parameterWithFunctionType = { a: ((Int) -> Int) -> } // todo fix parser + +val newSyntax = { a: Int -> } +val newSyntax1 = { a, b -> } +val newSyntax2 = { a: Int, b: Int -> } +val newSyntax3 = { a, b: Int -> } +val newSyntax4 = { a: Int, b -> } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.fir.kt new file mode 100644 index 00000000000..65b92ccea1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER +package a + +interface Super +interface Trait : Super +class Sub : Trait + +fun foo(f: (Trait) -> Trait) = f + +fun test(s: Sub) { + foo { + t: Super -> s + } + foo { + t: Trait -> s + } + + foo(fun(t: Sub) = s) + foo(fun(t): Super = s) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.fir.kt new file mode 100644 index 00000000000..ac97071f7f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.fir.kt @@ -0,0 +1,45 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo0(f: () -> String) = f +fun foo1(f: (Int) -> String) = f +fun foo2(f: (Int, String) -> String) = f + +fun test1() { + foo0 { + "" + } + foo0 { + s: String-> "" + } + foo0 { + x, y -> "" + } + + foo1 { + "" + } + foo1 { + s: String -> "" + } + foo1 { + x, y -> "" + } + foo1 { + -> 42 + } + + + foo2 { + "" + } + foo2 { + s: String -> "" + } + foo2 { + x -> "" + } + foo2 { + -> 42 + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt new file mode 100644 index 00000000000..1d4a71b2a7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +package h + +//traits to make ambiguity with function literal as an argument +interface A +interface B +interface C: A, B + +fun foo(a: A, f: () -> T): T = f() +fun foo(b: B, f: () -> T): T = f() + +fun test(c: C) { + foo(c) f@ { + c!! + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambda.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambda.fir.kt new file mode 100644 index 00000000000..de80476b1b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambda.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +fun test(bal: Array) { + var bar = 4 + + val a = { bar += 4 } + checkSubtype<() -> Unit>(a) + + val b = { bar = 4 } + checkSubtype<() -> Unit>(b) + + val c = { bal[2] = 3 } + checkSubtype<() -> Unit>(c) + + val d = run { bar += 4 } + checkSubtype(d) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt new file mode 100644 index 00000000000..b6362529419 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +fun test(bal: Array) { + var bar = 4 + + val a: () -> Unit = { bar += 4 } + + val b: () -> Int = { bar = 4 } + + val c: () -> UNRESOLVED = { bal[2] = 3 } + + val d: () -> Int = { bar += 4 } + + val e: Unit = run { bar += 4 } + + val f: Int = run { bar += 4 } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt new file mode 100644 index 00000000000..11a8998209f --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt @@ -0,0 +1,48 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +// first parameter of the functional type of 'x' can only be inferred from a lambda parameter explicit type specification +fun foo(y: Y, x: (X, Y) -> Unit) {} + +fun bar(aInstance: A, bInstance: B) { + foo("") { + (a, b): A, c -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + } + + foo(aInstance) { + a: String, (b, c) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + } + + foo(bInstance) { + (a, b): A, (c, d) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + d checkType { _() } + } + + foo(bInstance) { + (a, b), (c, d) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + d checkType { _() } + } + + foo(bInstance) { + (a, b), (c, d) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + d checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/extensionComponents.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/extensionComponents.fir.kt new file mode 100644 index 00000000000..4eed101c9a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/extensionComponents.fir.kt @@ -0,0 +1,53 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A + +operator fun A.component1() = 1 +operator fun A.component2() = "" + +class B + +class D { + operator fun A.component1() = 1.0 + operator fun A.component2() = ' ' + + operator fun B.component1() = 1.0 + operator fun B.component2() = ' ' +} + +fun foo(block: (A) -> Unit) { } +fun foobaz(block: D.(B) -> Unit) { } +fun foobar(block: D.(A) -> Unit) { } + +fun bar() { + foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + foo { (a: Int, b: String) -> + a checkType { _() } + b checkType { _() } + } + + // From KEEP: Component-functions are resolved in the same scope as the first statement of the lambda + foobaz { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + // From KEEP: Component-functions are resolved in the same scope as the first statement of the lambda + // So `component1`/`component2` for lambda parameters were resolved to member extensions + foobar { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + // the following code fails with exception, see KT-13873 +// foobarbaz { +// component1: B.() -> Int, +// component2: B.() -> String, +// (a, b): B -> +// +// } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt new file mode 100644 index 00000000000..43835ece222 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt @@ -0,0 +1,34 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +fun Iterable.foo(x: (T) -> Unit) {} + +fun bar(aList: List) { + aList.foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + aList.foo { (a: Int, b: String) -> + a checkType { _() } + b checkType { _() } + } + + aList.foo { (a, b): A -> + a checkType { _() } + b checkType { _() } + } + + aList.foo { (a: String, b) -> + a checkType { _() } + b checkType { _() } + } + + aList.foo { (a, b): B -> + b checkType { _() } + a checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/modifiers.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/modifiers.fir.kt new file mode 100644 index 00000000000..c39cd83275e --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/modifiers.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) + +fun foo(block: (A) -> Unit) { } + +@Target(AnnotationTarget.VALUE_PARAMETER) +annotation class Ann + +fun bar() { + foo { (private inline a, @Ann b) -> + a checkType { _() } + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt new file mode 100644 index 00000000000..6fb33e99ee2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE +data class A(val x: Int, val y: String) + +fun bar() { + val x = { (a, b): A -> + a checkType { _() } + b checkType { _() } + } + + x checkType { _<(A) -> Unit>() } + + val y = { (a: Int, b): A -> + a checkType { _() } + b checkType { _() } + } + + y checkType { _<(A) -> Unit>() } + + val y2 = { (a: Number, b): A -> + a checkType { _() } + b checkType { _() } + } + + y2 checkType { _<(A) -> Unit>() } + + val z = { (a: Int, b: String) -> + a checkType { _() } + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.fir.kt new file mode 100644 index 00000000000..61c556743b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +fun foo(block: (A, B) -> Unit) { } + +fun bar() { + foo { (a, a), b -> + a checkType { _() } + b checkType { _() } + } + + foo { (a, b), a -> + a checkType { _() } + b checkType { _() } + } + + foo { a, (a, b) -> + a checkType { _() } + b checkType { _() } + } + + foo { (a, b), (c, b) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/shadowing.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/shadowing.fir.kt new file mode 100644 index 00000000000..5554968db9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/shadowing.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +data class A(val x: Int, val y: String) + +fun foo(block: (A) -> Unit) { } + +fun bar(a: Double) { + val b = 1.toShort() + // Do not report NAME_SHADOWING on lambda destructured parameter, the same way as for common parameters + foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + foo { (c, d) -> + c checkType { _() } + d checkType { _() } + + foo { (a, c) -> + a checkType { _() } + c checkType { _() } + d checkType { _() } + } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt new file mode 100644 index 00000000000..e7e9af3047b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt @@ -0,0 +1,54 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +fun foo(block: (A) -> Unit) { } +fun foobar(block: (A, B) -> Unit) { } + +fun bar() { + foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } + + foo { (a: Int, b: String) -> + a checkType { _() } + b checkType { _() } + } + + foo { (a, b): A -> + a checkType { _() } + b checkType { _() } + } + + foobar { (a, b), c -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + } + + foobar { a, (b, c) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + } + + foobar { (a, b), (c, d) -> + a checkType { _() } + b checkType { _() } + c checkType { _() } + d checkType { _() } + } + + foo { (a: String, b) -> + a checkType { _() } + b checkType { _() } + } + + foo { (a, b): B -> + a checkType { _() } + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt new file mode 100644 index 00000000000..f08a2af15d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt @@ -0,0 +1,63 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +fun foo(block: (A) -> Unit) { } + +fun bar() { + foo { (_, b) -> + _.hashCode() + b checkType { _() } + } + + foo { (a, _) -> + a checkType { _() } + _.hashCode() + } + + foo { (_, _) -> + _.hashCode() + } + + foo { (_: Int, b: String) -> + _.hashCode() + b checkType { _() } + } + + foo { (a: Int, _: String) -> + a checkType { _() } + _.hashCode() + } + + foo { (_: Int, _: String) -> + _.hashCode() + } + + foo { (_, _): A -> + _.hashCode() + } + + foo { (`_`, _) -> + _ checkType { _() } + } + + foo { (_, `_`) -> + _ checkType { _() } + } + + foo { (`_`, `_`) -> + _ checkType { _() } + } + + foo { (_: String, b) -> + _.hashCode() + b checkType { _() } + } + + foo { (_, b): B -> + _.hashCode() + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.fir.kt new file mode 100644 index 00000000000..96aa55ce781 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -DestructuringLambdaParameters +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) + +fun foo(block: (A) -> Unit) { } + +fun bar() { + foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt new file mode 100644 index 00000000000..b2de6659aee --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.fir.kt @@ -0,0 +1,43 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +data class A(val x: Int, val y: String) +data class B(val u: Double, val w: Short) + +fun foo(block: (A) -> Unit) { } +fun foobar(block: (A, B) -> Unit) { } + +fun bar() { + foo { (a, b) -> + a checkType { _() } + } + + foo { (a, b) -> + b checkType { _() } + } + + foo { (a: Int, b: String) -> + a checkType { _() } + } + + foo { (a: Int, b: String) -> + b checkType { _() } + } + + foobar { (a, b), c -> + a checkType { _() } + } + + foobar { a, (b, c) -> + c checkType { _() } + } + + foobar { (a, b), (c, d) -> + a checkType { _() } + d checkType { _() } + } + + foobar { (a, b), (c, d) -> + b checkType { _() } + c checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionExpressionAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/functionExpressionAsLastExpressionInBlock.fir.kt new file mode 100644 index 00000000000..61f1611b10e --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionExpressionAsLastExpressionInBlock.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION + +import java.util.HashSet + +fun test123() { + val g: (Int) -> Unit = if (true) { + val set = HashSet() + fun (i: Int) { + set.add(i) + } + } + else { + { it -> it } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.fir.kt new file mode 100644 index 00000000000..dbb2f2e3c3f --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE +fun test() { + val a = if (true) { + val x = 1 + ({ x }) + } else { + { 2 } + } + a checkType { _<() -> Int>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralAsArgumentForFunction.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralAsArgumentForFunction.fir.kt new file mode 100644 index 00000000000..2becbe62950 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralAsArgumentForFunction.fir.kt @@ -0,0 +1,25 @@ +class Log + +data class CalculatedVariable( + val idString: String, + val presentableName: String, + val units: String, + val function: (Log) -> ((TimeIndex) -> Any?)?, + val converter: (Any) -> Double +) { + constructor(idString: String, presentableName: String, units: String, function: (Log) -> ((TimeIndex) -> Double?)?) + : this(idString, presentableName, units, function, { it as Double }) +} + +object CalculatedVariables { + val x = CalculatedVariable( + "A", + "B", + "C", + fun(log: Log): ((TimeIndex) -> Double?)? { + return { 0.0 } + } + ) +} + +class TimeIndex \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralInIf.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralInIf.fir.kt new file mode 100644 index 00000000000..b007414c1bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralInIf.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION + +import java.util.HashSet + +fun test123() { + val g: (Int) -> Unit = if (true) { + val set = HashSet(); + { i -> + set.add(i) + } + } + else { + { it -> it } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.fir.kt new file mode 100644 index 00000000000..4ff47f19893 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE +fun id(t: T) = t + +fun foo() { + val i = id { 22 } //type inference error: no information for parameter + i checkType { _<()->Int>() } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.fir.kt new file mode 100644 index 00000000000..6d60bef632b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Iterable.filter(predicate: (T) -> Boolean): List = TODO() +operator fun Collection.plus(elements: Iterable): List = TODO() + +fun stringCollection(): Collection = TODO() + +fun test(c: Collection) { + var variants = stringCollection() + variants += variants.filter { true } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.fir.kt new file mode 100644 index 00000000000..7b5618f7a0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.fir.kt @@ -0,0 +1,16 @@ +// See KT-7813: Call to functional parameter with missing argument: no error detected but compiler crashes + +fun foo(p: (Int, () -> Int) -> Unit) { + // Errors except last call + p { 1 } + p() { 2 } + p(3) { 4 } +} + +fun bar(p: (String, Any, () -> String) -> Unit) { + // Errors except last call + p { "" } + p() { "x" } + p("y") { "z" } + p("v", Any()) { "w" } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.fir.kt new file mode 100644 index 00000000000..12b0dc6b6b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface Predicate + +fun Predicate(x: (T?) -> Boolean): Predicate = null!! + +fun foo() { + process(Predicate { + x -> x checkType { _() } + + true + }) +} + +fun process(x: Predicate) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.fir.kt new file mode 100644 index 00000000000..76a64dd2123 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +// FILE: Predicate.java +import org.jetbrains.annotations.NotNull; + +public interface Predicate { + // Same effect with @Nullable here + boolean invoke(@NotNull T t); +} +// FILE: Main.kt +fun process(x: Predicate) {} +fun main() { + process(Predicate { x -> x checkType { _() } + true + }) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt new file mode 100644 index 00000000000..8cf79ac6dfc --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt16016.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +val la = { a -> } +val las = { a: Int -> } + +val larg = { a -> }(123) +val twoarg = { a, b: String, c -> }(123, "asdf", 123) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt2906.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt2906.fir.kt new file mode 100644 index 00000000000..63c81f0c12d --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt2906.fir.kt @@ -0,0 +1,22 @@ +//KT-2906 If function parameter/variable is invoked in closure using parenthesis syntax, in IDEA it is not highlighted as captured in closure + +package bug + +public fun foo1(bar: () -> Unit) { + run { + bar() // ERROR: not highlighted as "captured in closure" + } +} + +public fun foo2(bar: () -> Unit) { + run { + bar.invoke() // CORRECT: highlighted as "captured in closure" + } +} + +fun main() { + foo1 { println ("foo1")} // prints "foo1" + foo2 { println ("foo2")} // prints "foo2" +} + +fun println(s: String) = s diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt3343.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt3343.fir.kt new file mode 100644 index 00000000000..8ed60159149 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt3343.fir.kt @@ -0,0 +1,25 @@ +// KT-3343 Type mismatch when function literal consists of try-catch with Int returning call, and Unit is expected + +fun main() { + "hello world".prt{ + try{ + print(it) + log("we are printing") + } + catch(e : Exception){ + log("Exception") + } + } +} + +fun log(str : String) : Int{ + print("logging $str") + return 0 +} + +fun print(obj: Any) {} + + +fun String.prt(action : (String) -> Unit){ + action(this) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt4529.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt4529.fir.kt new file mode 100644 index 00000000000..38833e5c513 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt4529.fir.kt @@ -0,0 +1,19 @@ +//KT-4529 Lambdas are analyzed improperly in an infix call nested inside a println + +class G { + infix fun foo(bar: (Int) -> Int) = bar +} + +fun main() { + use( + G().foo {it + 11} // no error + ) + use( + G() foo {it + 11} // ERROR + ) + use( + G() foo ({it + 1}) // 2 ERRORs + ) +} + +fun use(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt6541_extensionForExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt6541_extensionForExtensionFunction.fir.kt new file mode 100644 index 00000000000..69913673c8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt6541_extensionForExtensionFunction.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo +fun (Foo.() -> Unit).invoke(b : Foo.() -> Unit) {} + +object Z { + infix fun add(b : Foo.() -> Unit) : Z = Z +} + +val t2 = Z add { } { } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt6869.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt6869.fir.kt new file mode 100644 index 00000000000..3e504a8e29c --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt6869.fir.kt @@ -0,0 +1,10 @@ +fun main() { + var list = listOf(1) + + val a: Int? = 2 + + a?.let { list += it } +} + +operator fun Iterable.plus(element: T): List = null!! +fun listOf(vararg values: T): List = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt7383_starProjectedFunction.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt7383_starProjectedFunction.fir.kt new file mode 100644 index 00000000000..2fc651f8136 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt7383_starProjectedFunction.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +// KT-7383 Assertion failed when a star-projection of function type is used + +fun foo() { + val f : Function1<*, *> = { x -> x.toString() } + f(1) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.fir.kt new file mode 100644 index 00000000000..092ff35c70c --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +NewInference +// SKIP_TXT +// Issue: KT-35168 + +class Inv + +// Before the fix, here we had an exception while fixing a type variable for Inv due to prematurely analyzing a lambda +// The exception was: "UninitializedPropertyAccessException: lateinit property subResolvedAtoms has not been initialized" +class Foo(x: (T) -> T, y: Inv) + +fun bar() { + Foo({}, Inv()) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabels.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabels.fir.kt new file mode 100644 index 00000000000..f25dfe60cdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabels.fir.kt @@ -0,0 +1,22 @@ +fun f() { + foo { + return@foo 1 + } + foo({ + return@foo 1 + } + ) + foo(a = { + return@foo 1 + }) + + foo { + foo { + return@foo 1 + } + return@foo 1 + } +} + +fun foo(a: Any) {} + diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabelsNonLocal.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabelsNonLocal.fir.kt new file mode 100644 index 00000000000..ddf260e5d7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/AutoLabelsNonLocal.fir.kt @@ -0,0 +1,11 @@ +fun f() { + foo { + bar { + return@foo 1 + } + return@foo 1 + } +} + +fun foo(a: Any) {} +fun bar(a: Any) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.fir.kt new file mode 100644 index 00000000000..921de7f2663 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +fun test() { + run {return} + run {} +} + +fun test2() { + run {return@test2} + run {} +} + +fun test3() { + fun test4() { + run {return@test3} + run {} + } +} + +fun run(f: () -> T): T { return f() } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfInReturnedExpression.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfInReturnedExpression.fir.kt new file mode 100644 index 00000000000..05cd4632d05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfInReturnedExpression.fir.kt @@ -0,0 +1,9 @@ +val flag = true + +interface I +class A(): I +class B(): I + +val a = l@ { + return@l if (flag) A() else B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt new file mode 100644 index 00000000000..cf5888dab3d --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt @@ -0,0 +1,15 @@ +val flag = true + +// type of a was checked by txt +val a/*: () -> Any*/ = l@ { + if (flag) return@l 4 +} + +val b/*: () -> Int */ = l@ { + if (flag) return@l 4 + 5 +} + +val c/*: () -> Unit */ = l@ { + if (flag) 4 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt new file mode 100644 index 00000000000..1bba3f19ba7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt @@ -0,0 +1,22 @@ +val flag = true + +val a: () -> Int = l@ { + if (flag) return@l 4 +} + +val b: () -> Unit = l@ { + if (flag) return@l 4 +} + +val c: () -> Any = l@ { + if (flag) return@l 4 +} + +val d: () -> Int = l@ { + if (flag) return@l 4 + 5 +} + +val e: () -> Int = l@ { + if (flag) 4 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.fir.kt new file mode 100644 index 00000000000..777ef9e8a48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LambdaWithParameter.fir.kt @@ -0,0 +1,17 @@ +val flag = true + +val a /*: (Int) -> String */ = l@ { + i: Int -> + if (i == 0) return@l i.toString() + + "Ok" +} + +fun foo(f: (Int) -> T): T = f(0) + +val b /*:String */ = foo { + i -> + if (i == 0) return@foo i.toString() + + "Ok" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalAndNonLocalReturnInLambda.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalAndNonLocalReturnInLambda.fir.kt new file mode 100644 index 00000000000..dc0204cf421 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalAndNonLocalReturnInLambda.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun test2(a: Int) { + val x = run f@{ + if (a > 0) return + return@f 1 + } + checkSubtype(x) +} + +fun run(f: () -> T): T { return f() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelNoParens.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelNoParens.fir.kt new file mode 100644 index 00000000000..a0417a8fcca --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelNoParens.fir.kt @@ -0,0 +1,6 @@ +// !CHECK_TYPE + +fun test2() { + val x = run f@{return@f 1} + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.fir.kt new file mode 100644 index 00000000000..4e10c2dba99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +fun test() { + val x = run(f@{return@f 1}) + checkSubtype(x) +} + + +fun test1() { + val x = run(l@{return@l 1}) + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnHasTypeNothing.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnHasTypeNothing.fir.kt new file mode 100644 index 00000000000..d94c56a54d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnHasTypeNothing.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE + +fun test() { + run f@{ + checkSubtype(return@f 1) + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedFunction.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedFunction.fir.kt new file mode 100644 index 00000000000..0aad15f653f --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedFunction.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +fun test() { + val x = run f@{ + fun local(a: Int): String { + if (a > 0) return "2" + return@local "3" + } + return@f 1 + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedLambda.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedLambda.fir.kt new file mode 100644 index 00000000000..db53a69beab --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnInNestedLambda.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun test() { + val x = run f@{ + run ff@ { + return@ff "2" + } + return@f 1 + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNoCoercionToUnit.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNoCoercionToUnit.fir.kt new file mode 100644 index 00000000000..998fc7d5291 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNoCoercionToUnit.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +fun test(a: Int) { + run f@{ + if (a > 0) return@f + else return@f 1 + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNull.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNull.fir.kt new file mode 100644 index 00000000000..2e9d8675ca3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnNull.fir.kt @@ -0,0 +1,14 @@ +class A +val flag = true + +val a /*: () -> A?*/ = l@ { + if (flag) return@l null + + A() +} + +val b /*: () -> A?*/ = l@ { + if (flag) return@l null + + return@l A() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt new file mode 100644 index 00000000000..7f02acdf15b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt @@ -0,0 +1,6 @@ +val flag = true + +val a = b@ { + if (flag) return@b 4 + return@b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnit.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnit.fir.kt new file mode 100644 index 00000000000..5d19e6ac54c --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnit.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +fun test(a: Int) { + val x = run f@{ + if (a > 0) return@f + else return@f Unit + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitAndDontCareType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitAndDontCareType.fir.kt new file mode 100644 index 00000000000..96941889555 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitAndDontCareType.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +val flag = true + +// type of a was checked by txt +val a = run { // () -> Unit + return@run +} + +// Unit +val b = run { + if (flag) return@run + 5 +} + +// Unit +val c = run { + if (flag) return@run + + return@run 4 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitWithBodyExpression.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitWithBodyExpression.fir.kt new file mode 100644 index 00000000000..bd67e82f22d --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnUnitWithBodyExpression.fir.kt @@ -0,0 +1,7 @@ +val flag = true + +// type of lambda was checked by txt +val a = b@ { // () -> Unit + if (flag) return@b + else 54 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExpectedType.fir.kt new file mode 100644 index 00000000000..ca7f7434a65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExpectedType.fir.kt @@ -0,0 +1,9 @@ +fun listOf(): List = null!! +fun listOf(vararg values: T): List = null!! + +val flag = true + +val a: () -> List = l@ { + if (flag) return@l listOf() + listOf(5) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExplicitUnit.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExplicitUnit.fir.kt new file mode 100644 index 00000000000..1c12596f99a --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnWithExplicitUnit.fir.kt @@ -0,0 +1,16 @@ +val flag = true + +// type of lambda was checked by txt +val a = l@ { // () -> Any + if (flag) return@l 4 + return@l Unit +} + +val b = l@ { // () -> Any + if (flag) return@l Unit + 5 +} + +val c = l@ { // () -> Unit + if (flag) return@l Unit +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt new file mode 100644 index 00000000000..ac0c76d48db --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +fun test(a: Int) { + runf@{ + if (a > 0) return@f "" + return@f 1 + } + + run{ "" } + run{ 1 } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/MixedReturnsFromLambda.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/MixedReturnsFromLambda.fir.kt new file mode 100644 index 00000000000..1ee85944f8b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/MixedReturnsFromLambda.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +interface A +interface B: A +interface C: A + + +fun test(a: C, b: B) { + val x = run f@{ + if (a != b) return@f a + b + } + checkSubtype(x) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/NoCommonSystem.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/NoCommonSystem.fir.kt new file mode 100644 index 00000000000..22e46bb749e --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/NoCommonSystem.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +fun Iterable.map(transform: (T) -> R): List = null!! +fun listOf(): List = null!! +fun listOf(vararg values: T): List = null!! + +fun commonSystemFailed(a: List) { + a.map { + if (it == 0) return@map listOf(it) + listOf() + } + a.map { + if (it == 0) return@map listOf() + listOf(it) + } + a.map { + if (it == 0) listOf() + else listOf(it) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.fir.kt new file mode 100644 index 00000000000..a9649e4b4db --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCast.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// KT-6822 Smart cast doesn't work inside local returned expression in lambda + +val a /* :(Int?) -> Int? */ = l@ { it: Int? -> // but must be (Int?) -> Int + if (it != null) return@l it + 5 +} + +fun let(f: (Int?) -> R): R = null!! + +val b /*: Int? */ = let { // but must be Int + if (it != null) return@let it + 5 +} + +val c /*: Int*/ = let { + if (it != null) it else 5 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCastWithExplicitType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCastWithExplicitType.fir.kt new file mode 100644 index 00000000000..fe80cb50b70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/SmartCastWithExplicitType.fir.kt @@ -0,0 +1,17 @@ +// KT-6822 Smart cast doesn't work inside local returned expression in lambda + +val a : (Int?) -> Int = l@ { + if (it != null) return@l it + 5 +} + +fun let(f: (Int?) -> R): R = null!! + +val b: Int = let { + if (it != null) return@let it + 5 +} + +val c: Int = let { + if (it != null) it else 5 +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.fir.kt new file mode 100644 index 00000000000..b015a35ffd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.fir.kt @@ -0,0 +1,9 @@ +val a = l@ { + return@l r +} + +val b = l@ { + if ("" == "OK") return@l + + return@l r +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/returnNull.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/returnNull.fir.kt new file mode 100644 index 00000000000..a8d7942f421 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/returnNull.fir.kt @@ -0,0 +1,10 @@ +package m + +interface Element + +fun test(handlers: MapUnit>) { + + handlers.getOrElse("name", { null }) +} + +fun Map.getOrElse(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/returnNullWithReturn.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/returnNullWithReturn.fir.kt new file mode 100644 index 00000000000..491a77d8ad3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/returnNullWithReturn.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +package m + +interface Element + +fun test(handlers: MapUnit>) { + + handlers.getOrElse("name", l@ { return@l null }) +} + +fun Map.getOrElse(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.fir.kt new file mode 100644 index 00000000000..89475115666 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.fir.kt @@ -0,0 +1,48 @@ +// !CHECK_TYPE + +fun foo(block: (Int, String) -> Unit) { } +fun foobar(block: (Double) -> Unit) { } + +fun bar() { + foo { _, b -> + _.hashCode() + b checkType { _() } + } + + foo { a, _ -> + a checkType { _() } + _.hashCode() + } + + foo { _, _ -> + _.hashCode() + } + + foo { _: Int, b: String -> + _.hashCode() + b checkType { _() } + } + + foo { a: Int, _: String -> + a checkType { _() } + _.hashCode() + } + + foo { _: Int, _: String -> + _.hashCode() + } + + foo { `_`, _ -> + _ checkType { _() } + } + + foo { _, `_` -> + _ checkType { _() } + } + + foo { `_`, `_` -> + _ checkType { _() } + } + + foo(fun(x: Int, _: String) {}) +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.fir.kt new file mode 100644 index 00000000000..1cc8477b6fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.fir.kt @@ -0,0 +1,12 @@ +fun unusedLiteral(){ + { -> + val i = 1 + } +} + + +fun unusedLiteralInDoWhile(){ + do{ -> + val i = 1 + } while(false) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.fir.kt new file mode 100644 index 00000000000..48149e6bb47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/unusedLiteralInsideUnitLiteral.fir.kt @@ -0,0 +1,8 @@ +fun main() { + "".run { + {} + } +} + + +fun T.run(f: (T) -> Unit): Unit = f(this) diff --git a/compiler/testData/diagnostics/tests/generics/InconsistentTypeParameterBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/InconsistentTypeParameterBounds.fir.kt new file mode 100644 index 00000000000..e6f3a6df42c --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/InconsistentTypeParameterBounds.fir.kt @@ -0,0 +1,7 @@ +interface A +interface B : A + +interface ListA : List +interface ListB : List + +interface Z where T : ListA, T : ListB diff --git a/compiler/testData/diagnostics/tests/generics/Projections.fir.kt b/compiler/testData/diagnostics/tests/generics/Projections.fir.kt new file mode 100644 index 00000000000..483b2e5a128 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/Projections.fir.kt @@ -0,0 +1,54 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +class In() { + fun f(t : T) : Unit {} + fun f(t : Int) : Int = 1 + fun f1(t : T) : Unit {} +} + +class Out() { + fun f() : T {throw IllegalStateException()} + fun f(a : Int) : Int = a +} + +class Inv() { + fun f(t : T) : T = t + fun inf(t : T) : Unit {} + fun outf() : T {throw IllegalStateException()} +} + +fun testInOut() { + In().f("1"); + (null as In).f("1") + (null as In<*>).f("1") // Wrong Arg + + In().f(1); + (null as In).f(1) + (null as In<*>).f(1); + + Out().f(1) + (null as Out).f(1) + (null as Out<*>).f(1) + + Out().f() + (null as Out).f() + (null as Out<*>).f() + + Inv().f(1) + (null as Inv).f(1) + (null as Inv).f(1) // !! + (null as Inv<*>).f(1) // !! + + Inv().inf(1) + (null as Inv).inf(1) + (null as Inv).inf(1) // !! + (null as Inv<*>).inf(1) // !! + + Inv().outf() + checkSubtype((null as Inv).outf()) // Type mismatch + (null as Inv).outf() + (null as Inv<*>).outf() + + Inv().outf(1) // Wrong Arg +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.fir.kt b/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.fir.kt new file mode 100644 index 00000000000..f4fee390b7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/PseudoRawTypes.fir.kt @@ -0,0 +1,25 @@ +// JAVAC_EXPECTED_FILE +// FILE: java/util/Collection.java +package java.util; + +public class Collection { + public void foo() {} +} + +// FILE: test/Usage.java +package test; + +import java.util.*; + +public class Usage { + void foo(Collection c) { + c.foo(); + } +} + +// FILE: Kotlin.kt +package test + +fun foo(u: Usage) { + u.foo(null) +} diff --git a/compiler/testData/diagnostics/tests/generics/RawTypeInIsExpression.fir.kt b/compiler/testData/diagnostics/tests/generics/RawTypeInIsExpression.fir.kt new file mode 100644 index 00000000000..e106601f1e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/RawTypeInIsExpression.fir.kt @@ -0,0 +1,14 @@ +package p + +public fun foo(a: Any) { + a is Map + a is Map + a is Map + a is Map<*, *> + a is Map<> + a is List + a is List + a is Int + + (a as Map) is Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/RawTypeInIsPattern.fir.kt b/compiler/testData/diagnostics/tests/generics/RawTypeInIsPattern.fir.kt new file mode 100644 index 00000000000..f76110a228e --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/RawTypeInIsPattern.fir.kt @@ -0,0 +1,13 @@ +public fun foo(a: Any, b: Map) { + when (a) { + is Map -> {} + is Map -> {} + is Map -> {} + is Map<*, *> -> {} + is Map<> -> {} + is List -> {} + is List -> {} + is Int -> {} + else -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundCheck.fir.kt b/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundCheck.fir.kt new file mode 100644 index 00000000000..49811563193 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundCheck.fir.kt @@ -0,0 +1,3 @@ +open class C> +class TestOK : C() +class TestFail : C>() diff --git a/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundWithTwoArguments.fir.kt b/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundWithTwoArguments.fir.kt new file mode 100644 index 00000000000..ceed755ac5d --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/RecursiveUpperBoundWithTwoArguments.fir.kt @@ -0,0 +1 @@ +class D, B : D> diff --git a/compiler/testData/diagnostics/tests/generics/TypeParameterBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/TypeParameterBounds.fir.kt new file mode 100644 index 00000000000..3612db3e2f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/TypeParameterBounds.fir.kt @@ -0,0 +1,23 @@ +// See KT-9438: Enforce the Single Instantiation Inheritance Rule for type parameters + +interface A + +interface B + +interface D + +interface IncorrectF> where T : D + +interface CorrectF where T : D, T : D + +interface G + +interface IncorrectH>> where T : G> + +interface CorrectH where T : G>, T : G> + +interface incorrectJ>> where T : G> + +interface correctJ where T : G>, T : G> + +fun bar() where T : D, T : D {} diff --git a/compiler/testData/diagnostics/tests/generics/TypeParametersInTypeParameterBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/TypeParametersInTypeParameterBounds.fir.kt new file mode 100644 index 00000000000..327e1d0d831 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/TypeParametersInTypeParameterBounds.fir.kt @@ -0,0 +1,15 @@ +interface I1 +interface I2 +open class C + +interface A1 where V : K, V : K +interface A2 where W : K, W : V +interface A3 where V : I1, V : K, V : I2 +interface A4 where K : I1, K : I2, K : C, K : V, V : I2, V : I1 + +fun f1() where V : K, V : K {} +fun f2() where W : K, W : V { + fun f3() where T : K, T : V {} + fun f4() where T : K, T : K {} +} +fun f3() where W : K, W : V, W : Any {} diff --git a/compiler/testData/diagnostics/tests/generics/argumentsForT.fir.kt b/compiler/testData/diagnostics/tests/generics/argumentsForT.fir.kt new file mode 100644 index 00000000000..ff8797c74e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/argumentsForT.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(t: T) {} + +interface A +class B +fun foo1(t: T>) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/captured.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/captured.fir.kt new file mode 100644 index 00000000000..354763be0a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/captured.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class X { + abstract class Y + + fun foo(y: Y, t: T) { + } +} + + +fun testStar(y: X.Y<*>, t: Any) { + X().foo(y, t) +} + +fun testOut(y: X.Y, t: Any) { + X().foo(y, t) +} + +fun testIn(y: X.Y, t: Any) { + X().foo(y, t) +} + +fun testWithParameter(y: X.Y, t: Any) { + X().foo(y, t) +} + +fun testWithCapturedParameter(y: X.Y, t: Any) { + X().foo(y, t) +} diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.fir.kt new file mode 100644 index 00000000000..9db00cd330e --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/innerLocalClass.fir.kt @@ -0,0 +1,35 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// NI_EXPECTED_FILE +private class Outer { + private inner class Inner { + private fun foo() = { + fun baz() = { + class Local { + val e: E = magic() + val f: F = magic() + val g: G = magic() + } + Local() + } + baz()() + } + + private var doubleCharSequenceInt = Outer().Inner().foo()() + private var doubleStringNumber = Outer().Inner().foo()() + private var doubleStringInt = Outer().Inner().foo()() + + private fun bar() { + doubleCharSequenceInt = doubleStringNumber + doubleCharSequenceInt = doubleStringInt + + doubleStringInt = Outer().Inner().foo()() + + doubleStringInt.e.checkType { _() } + doubleStringInt.f.checkType { _() } + doubleStringInt.g.checkType { _() } + } + } +} + +fun magic(): T = null!! diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/localClass.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/localClass.fir.kt new file mode 100644 index 00000000000..6a62c440362 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/localClass.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun magic(): T = null!! + +class Q { + private fun foo() = { + class C { + val prop: E = magic() + } + C() + } + + private var x = foo()() + private var y = foo()() + + fun bar() { + x = y + x = foo()() + y = foo()() + + x.prop.checkType { _() } + y.prop.checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/localWithTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/localWithTypeParameter.fir.kt new file mode 100644 index 00000000000..034d17b6ce0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/localWithTypeParameter.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE + +fun magic(): T = null!! + +class Q { + private fun foo() = { + class C { + val e: E = magic() + val f: F = magic() + val g: G = magic() + } + C() + } + + private var x = foo()() + + fun bar() { + x.e.checkType { _() } + x.f.checkType { _() } + x.g.checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/objectLiteral.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/objectLiteral.fir.kt new file mode 100644 index 00000000000..6443c348009 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/objectLiteral.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun magic(): T = null!! + +class Q { + private fun foo() = + object { + val prop: E = magic() + } + + private var x = foo() + private var y = foo() + + fun bar() { + x = y + x = foo() + y = foo() + + x.prop.checkType { _() } + y.prop.checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.fir.kt b/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.fir.kt new file mode 100644 index 00000000000..7b382fd4076 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/capturedParameters/uncheckedCast.fir.kt @@ -0,0 +1,37 @@ +fun foo(x: Any, y: Any) : Any { + class C + // without E? + if(x is C) { + return x + } + + if (1 == 2) { + x as C + } + + if (2 == 3) { + x as? C + } + + class Outer { + inner class Inner + } + + // bare type + if (y is Outer.Inner) { + return y + } + + y as Outer<*>.Inner + + return C() +} + +fun noTypeParameters(x: Any) : Any { + class C + if(x is C) { + return x + } + + return C() +} diff --git a/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.fir.kt b/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.fir.kt new file mode 100644 index 00000000000..4108d6dc3e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.fir.kt @@ -0,0 +1,10 @@ +// NI_EXPECTED_FILE + +interface In + +class En : In +class A : In +fun select(x: T, y: T): T = x ?: y + +// Return type should be In<*> nor In +fun foobar(e: En<*>) = select(A(), e) diff --git a/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant2.fir.kt b/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant2.fir.kt new file mode 100644 index 00000000000..89a3999ae58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant2.fir.kt @@ -0,0 +1,9 @@ +// NI_EXPECTED_FILE + +interface In +class A : In +class B : In +fun select(x: T, y: T) = x ?: y + +// Return type should be In<*> nor In +fun foobar(a: A, b: B) = select(a, b) diff --git a/compiler/testData/diagnostics/tests/generics/cyclicBounds/functions.fir.kt b/compiler/testData/diagnostics/tests/generics/cyclicBounds/functions.fir.kt new file mode 100644 index 00000000000..e51939427e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/cyclicBounds/functions.fir.kt @@ -0,0 +1,7 @@ +fun foo1() {} + +fun foo2() {} + +fun foo3() where T : F?, F : T {} + +fun foo4() where T : F?, F : E, E : F? {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/cyclicBounds/inClass.fir.kt b/compiler/testData/diagnostics/tests/generics/cyclicBounds/inClass.fir.kt new file mode 100644 index 00000000000..aa08e862771 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/cyclicBounds/inClass.fir.kt @@ -0,0 +1,7 @@ +class A1 + +class A2 + +class A3 where T : F?, F : T? + +class A4 where T : F?, F : E, E : F \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/doNotCaptureSupertype.fir.kt b/compiler/testData/diagnostics/tests/generics/doNotCaptureSupertype.fir.kt new file mode 100644 index 00000000000..8c96719d74b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/doNotCaptureSupertype.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE +// SKIP_TXT +fun test(b: S) { + b.collect(toList()) checkType { _>() } +} + +interface S { + fun collect(collector: C): R +} + +class C + +fun toList(): C> = null!! + +class Inv diff --git a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithOverride.fir.kt b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithOverride.fir.kt new file mode 100644 index 00000000000..425e4ecb019 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithOverride.fir.kt @@ -0,0 +1,97 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +// Issues: KT-25105 + +class Message1 +class Task +object Message2 +enum class Message3 +data class Message4(val x: Int) + +sealed class Message5 { + open fun execute() {} +} + +interface Manager { + fun execute1(task: Task) {} + fun execute2(task: T) {} + fun execute3() {} + fun execute4() {} + fun execute5() {} + val A.x get() = 10 + var A.y + get() = 10 + set(value) {} +} + +object MessageManager1 : Manager { + override fun execute1(task: Task) {} + override fun execute2(task: T) {} + override fun execute3() {} +} + +object MessageManager2 : Manager { + override fun execute4() {} +} + +object MessageManager3 : Manager { + override fun execute5() {} +} + +class MessageManager4 : Manager { + override fun execute1(task: Task) {} + override fun execute2(task: T) {} + override fun execute3() {} +} + +class MessageManager5 : Manager { + override fun execute4() {} +} + +class MessageManager6 : Manager { + override fun execute5() {} +} + +interface MessageManager7 : Manager { + override fun execute5() {} +} + +interface MessageManager8 : Manager { + override fun execute1(task: Task) {} + override fun execute2(task: T) {} + override fun execute3() {} +} + +interface MessageManager9 : Manager { + override fun execute4() {} +} + +object MessageManager10 : Message5() { + override fun execute() {} +} + +class MessageManager11 : Message5>() { + override fun > execute() {} +} + +data class MessageManager12(val x: Int) : Message5() { + override fun execute() {} +} + +sealed class MessageManager13 : Message5() { + override fun execute() {} +} + +class MessageManager14 : Manager { + override val T.x get() = 10 + override var T.y + get() = 10 + set(value) {} +} + +object MessageManager15 : Manager { + override val T.x get() = 10 + override var T.y + get() = 10 + set(value) {} +} diff --git a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt new file mode 100644 index 00000000000..e78300647c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt @@ -0,0 +1,82 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +// Issues: KT-25105 + +class Message1 +class Task +object Message2 +enum class Message3 +data class Message4(val x: Int) +interface Manager {} + +object MessageManager1 : Manager { + fun execute1(task: Task) {} + fun execute2(task: T) {} + fun execute3() {} +} + +object MessageManager2 : Manager { + fun execute4() {} +} + +object MessageManager3 : Manager { + fun execute5() {} +} + +class MessageManager4 : Manager { + fun execute1(task: Task) {} + fun execute2(task: T) {} + fun execute3() {} +} + +class MessageManager5 : Manager { + fun execute4() {} +} + +class MessageManager6 : Manager { + fun execute5() {} +} + +interface MessageManager7 : Manager { + fun execute5() {} +} + +interface MessageManager8 : Manager { + fun execute1(task: Task) {} + fun execute2(task: T) {} + fun execute3() {} +} + +interface MessageManager9 : Manager { + fun execute4() {} +} + +object MessageManager10 : Message5() { + fun execute() {} +} + +class MessageManager11 : Message5>() { + fun > execute() {} +} + +data class MessageManager12(val x: Int) : Message5() { + fun execute() {} +} + +sealed class MessageManager13 : Message5() { + fun execute() {} +} + +class MessageManager14 : Manager { + val T.x get() = 10 + var T.y + get() = 10 + set(value) {} +} + +object MessageManager15 : Manager { + val T.x get() = 10 + var T.y + get() = 10 + set(value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/genericsInType.fir.kt b/compiler/testData/diagnostics/tests/generics/genericsInType.fir.kt new file mode 100644 index 00000000000..176fd4ff604 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/genericsInType.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + + +class Foo { + class Bar { + class Baz { + + } + } +} + +fun a() {} + +fun test() { + Foo::class + Foo.Bar::class + Foo.Bar.Baz::class + + a>() + a() + + Foo.Bar::class + Foo.Bar.Baz::class + + a.Bar>() + a.Bar.Baz>() + + a>() + a.Baz>() +} + +fun > x() {} +fun Foo.Bar.ext() {} + +fun ex1(a: Foo.Bar): Foo.Bar { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypes.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypes.fir.kt new file mode 100644 index 00000000000..b88ad364875 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypes.fir.kt @@ -0,0 +1,20 @@ +class Outer { + inner class Inner { + inner abstract class Inner2Base + inner class Inner2 : Inner2Base() + + inner abstract class Inner3Base + inner class Inner3 : Inner3Base() + } + + fun foo(x: Outer<*>.Inner<*, *>.Inner2Base) { + if (x is Inner.Inner2) return + } +} + +fun bare(x: Outer<*>.Inner<*, *>.Inner2Base, y: Outer<*>.Inner<*, *>.Inner3Base) { + if (x is Outer.Inner.Inner2) return + if (y is Outer.Inner.Inner3) return + if (y is Outer.Inner.Inner3) return + if (y is Outer.Inner.Inner3) return +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.fir.kt new file mode 100644 index 00000000000..0bb4850fb9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/bareTypesComplex.fir.kt @@ -0,0 +1,14 @@ +open class SuperOuter { + inner open class SuperInner +} + +class DerivedOuter : SuperOuter() { + inner class DerivedInner : SuperOuter.SuperInner() +} + +fun bare(x: SuperOuter<*>.SuperInner<*>, y: Any?) { + if (x is SuperOuter.SuperInner) return + if (y is SuperOuter.SuperInner) { + return + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/checkBoundsOuter.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/checkBoundsOuter.fir.kt new file mode 100644 index 00000000000..f273fb31857 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/checkBoundsOuter.fir.kt @@ -0,0 +1,5 @@ +class Outer { + inner class Inner +} + +val x: Outer.Inner = null!! diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_after.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_after.fir.kt new file mode 100644 index 00000000000..dcc376a304d --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_after.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +open class Outer { + inner class Inner + +} + +class Derived : Outer() { + // Inner here means Outer.Inner + fun foo(x: Inner) {} +} + +class A { + companion object : Outer() + + // Does not work, could be Outer.Inner + // TODO: Should work? + fun foo(x: Inner) { + // Inner() call use companion as implicit receiver + val y: Outer.Inner = Inner() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_before.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_before.fir.kt new file mode 100644 index 00000000000..6a546fe3d55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromCompanionObject_before.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +open class Outer { + inner class Inner + +} + +class Derived : Outer() { + // Inner here means Outer.Inner + fun foo(x: Inner) {} +} + +class A { + companion object : Outer() + + // Does not work, could be Outer.Inner + // TODO: Should work? + fun foo(x: Inner) { + // Inner() call use companion as implicit receiver + val y: Outer.Inner = Inner() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt new file mode 100644 index 00000000000..22600b275a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt @@ -0,0 +1,15 @@ +class A { + fun foo() { + val q = object { + open inner class B + inner class C : B() + + // No WRONG_NUMBER_OF_TYPE_ARGUMENTS should be reported on these types + val x: B = B() + val y: C = C() + } + + q.x + q.y + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.fir.kt new file mode 100644 index 00000000000..671cdf3cf64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// !CHECK_TYPE +open class Outer { + inner class Inner + typealias Alias = Map +} + +class Derived : Outer() { + fun foo(): Inner = null!! + fun baz(): Alias = null!! +} + + +class A : Outer() { + class B : Outer() { + fun bar(): Inner = null!! + fun x(): Alias = null!! + } +} + +fun foo() { + Derived().foo() checkType { _.Inner>() } + Derived().baz() checkType { _>() } + A.B().bar() checkType { _.Inner>() } + A.B().x() checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.fir.kt new file mode 100644 index 00000000000..95c97c0dfd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.fir.kt @@ -0,0 +1,55 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY + +class A + +private fun foobar() = { + open class LocalOuter { + inner class LocalInner { + fun a() = A() + } + + typealias LocalAlias = A + } + + class Derived : LocalOuter() { + fun foo(): LocalInner = null!! + fun bar(): LocalAlias = null!! + } + + Derived() +} + +private fun noParameters() = { + open class LocalOuter2 { + inner class LocalInner2 { + fun a() = A() + } + + typealias LocalAlias2 = A + } + + class Derived2 : LocalOuter2() { + fun foo(): LocalInner2 = null!! + fun bar(): LocalAlias2 = null!! + } + + Derived2() +} + +fun test() { + var x = foobar() + x = foobar() + + x().foo().a() checkType { _>() } + x().bar() checkType { _>() } + + x = foobar() + + var y = noParameters() + y = noParameters() + + y().foo().a() checkType { _>() } + y().bar() checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.fir.kt new file mode 100644 index 00000000000..43541fe539a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.fir.kt @@ -0,0 +1,59 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY + +class A + +class Outer { + inner class Inner { + private fun foobar() = { + open class LocalOuter { + inner class LocalInner { + fun a() = A() + } + + typealias LocalAlias = A + } + + class Derived : LocalOuter() { + fun foo(): LocalInner = null!! + fun bar(): LocalAlias = null!! + } + + Derived() + } + + private fun noParameters() = { + open class LocalOuter2 { + inner class LocalInner2 { + fun a() = A() + } + + typealias LocalAlias2 = A + } + + class Derived2 : LocalOuter2() { + fun foo(): LocalInner2 = null!! + fun bar(): LocalAlias2 = null!! + } + Derived2() + } + + fun test(z: Outer.Inner) { + var x = foobar() + x = foobar() + + x().foo().a() checkType { _>() } + x().bar() checkType { _>() } + + x = foobar() + x = z.foobar() + + var y = noParameters() + y = noParameters() + + y().foo().a() checkType { _>() } + y().bar() checkType { _>() } + } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.fir.kt new file mode 100644 index 00000000000..0086dbfa03e --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// !CHECK_TYPE +open class Outer { + inner class Inner + typealias Alias = Map +} + +open class BaseDerived1 : Outer() +open class BaseDerived2 : BaseDerived1() + +class Derived : BaseDerived2() { + fun foo(): Inner = null!! + fun baz(): Alias = null!! +} + +fun foo() { + Derived().foo() checkType { _.Inner>() } + Derived().baz() checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/inStaticScope.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/inStaticScope.fir.kt new file mode 100644 index 00000000000..44a567abaa0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/inStaticScope.fir.kt @@ -0,0 +1,7 @@ +interface Inv +class Outer { + inner class Inner + + class Nested : Inv + object Obj : Inv +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/secondLevelDepth.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/secondLevelDepth.fir.kt new file mode 100644 index 00000000000..e5f856332b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/secondLevelDepth.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +open class Outer { + inner open class Inner { + inner class Inner2 { + + } + } +} + +class DerivedOuter : Outer() { + inner class DerivedInner : Inner() { + fun foo(): Inner2 = null!! + } +} + +fun foo() { + DerivedOuter().DerivedInner().foo() checkType { _.Inner.Inner2>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/importedInner.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/importedInner.fir.kt new file mode 100644 index 00000000000..5246f574368 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/importedInner.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +import Outer.Inner + + +class Outer { + inner class Inner + + fun foo() { + class E + val x: Inner = Inner() + } + + class Nested { + fun bar(x: Inner) {} + } +} + +class E + +fun bar(x: Inner) {} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCall.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCall.fir.kt new file mode 100644 index 00000000000..64d4139d014 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCall.fir.kt @@ -0,0 +1,9 @@ +open class Super { + inner open class Inner { + } +} + +class Sub : Super() { + // TODO: it would be nice to have a possibility to omit explicit type argument in supertype + inner class SubInner : Super.Inner() {} +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCallSecondary.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCallSecondary.fir.kt new file mode 100644 index 00000000000..9d96d736e46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerSuperCallSecondary.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class Super { + inner open class Inner { + } +} + +class Sub : Super() { + inner class SubInner : Super.Inner { + constructor() + constructor(x: Int) : super() {} + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.fir.kt new file mode 100644 index 00000000000..fc90a12c068 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.fir.kt @@ -0,0 +1,42 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo() = this + fun baz(): Inner = null!! + } + + fun innerFactory(): Outer.Inner = null!! + + fun bar() = Inner() + fun set(inner: Inner) {} + + fun inside() { + innerFactory().checkType { _>() } + } +} + +fun factoryString(): Outer.Inner = null!! + +fun infer(x: T, y: Y): Outer.Inner = null!! +val inferred = infer("", 1) + +fun main() { + val outer = Outer() + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner<*>>(outer.bar()) + checkSubtype.Inner<*>>(outer.Inner()) + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + outer.set(outer.bar()) + outer.set(outer.Inner()) + + val x: Outer.Inner = factoryString() + outer.set(x) +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerUncheckedCast.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerUncheckedCast.fir.kt new file mode 100644 index 00000000000..f954a3c35fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerUncheckedCast.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +class Outer { + inner open class InnerBase + inner class Inner : InnerBase() { + val prop: E = null!! + } + + fun foo(x: InnerBase, y: Any?, z: Outer<*>.InnerBase) { + if (x is Inner) { + x.prop.checkType { _() } + } + + if (y is Inner) return + + if (z is Inner) { + z.prop.checkType { _() } + return + } + + if (y is Outer<*>.Inner<*>) { + y.prop.checkType { _() } + } + } + + fun bar(x: InnerBase, y: Any?, z: Outer<*>.InnerBase) { + x as Inner + y as Inner + z as Inner + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerVariance.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerVariance.fir.kt new file mode 100644 index 00000000000..976d5e03690 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerVariance.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class Outer { + inner class Inner { + fun unsafe1(x: E) {} + fun unsafe2(x: Collection) {} + fun unsafe3(): F? = null + fun unsafe4(): Collection? = null + } + + // Should be errors + // Refinement of variance checker is needed + fun foo(x: Inner) {} + fun bar(): Inner? = null +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/iterator.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/iterator.fir.kt new file mode 100644 index 00000000000..f1a49b86889 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/iterator.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE +import java.util.* + +class A : AbstractCollection() { + override fun iterator(): MyIt = MyIt() + + override val size: Int + get() = 1 + + inner class MyIt : MutableIterator { + override fun next(): T { + throw UnsupportedOperationException() + } + + override fun hasNext(): Boolean { + throw UnsupportedOperationException() + } + + override fun remove() { + throw UnsupportedOperationException() + } + } +} + +fun commonSupertype(x: E, y: E): E = x + +fun foo() { + var myIt = A().iterator() + myIt = A().iterator() + + val csIt: Iterator = A().iterator() + + commonSupertype(A().iterator(), A().iterator()).checkType { _.MyIt>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/j+k.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/j+k.fir.kt new file mode 100644 index 00000000000..464f3290453 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/j+k.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// FILE: Outer.java + +public class Outer { + public class Inner { + E foo() {} + F bar() {} + + Outer outer() {} + } + + Inner baz() { } + void set(Inner x) {} +} + +// FILE: main.kt + +fun main() { + var outerStr: Outer = Outer() + outerStr.baz().checkType { _.Inner>() } + + val strInt: Outer.Inner = outerStr.Inner() + + strInt.foo().checkType { _() } + strInt.bar().checkType { _() } + strInt.outer().checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/j+k_complex.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/j+k_complex.fir.kt new file mode 100644 index 00000000000..22f0faaa562 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/j+k_complex.fir.kt @@ -0,0 +1,35 @@ +// !CHECK_TYPE +// FILE: BaseOuter.java +// See KT-10285 +public class BaseOuter { + abstract public class BaseInner { + public H foo1() { + return null; + } + + public E foo2() { + return null; + } + + public F foo3() { + return null; + } + } +} + +// FILE: Outer.java +public class Outer extends BaseOuter { + public BaseInner bar() { return null; } + public class Inner extends BaseOuter.BaseInner {} +} + +// FILE: main.kt +fun foo(x1: Outer, x2: Outer.Inner) { + x1.bar().foo1().checkType { _() } + x1.bar().foo2().checkType { _() } + x1.bar().foo3().checkType { _() } + + x2.foo1().checkType { _() } + x2.foo2().checkType { _() } + x2.foo3().checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/kt3357.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/kt3357.fir.kt new file mode 100644 index 00000000000..795e8235a6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/kt3357.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +open class Super { + inner open class Inner { + open fun getOuter(): Super = throw UnsupportedOperationException() + } +} + +class Sub(): Super() { + inner class SubInner : Super.Inner() { // 'Inner' is unresolved + // Also, T1 is not resolved to anything, and not marked as resolved + init { + val x: Super.Inner = this // T1 is not resolved to anything + } + + override fun getOuter(): Sub = throw UnsupportedOperationException() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/kt408.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/kt408.fir.kt new file mode 100644 index 00000000000..02585cbc7cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/kt408.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +interface T { + fun f() : E = null!! +} +open class A() { + inner class B() : T {} +} + +fun test() { + val a = A() + val b : A.B = a.B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/kt6325.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/kt6325.fir.kt new file mode 100644 index 00000000000..7a617258247 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/kt6325.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +class Outer { + inner class Inner { + fun newInner(): Inner = Inner() + //type mismatch + fun newOuterInner(): Outer.Inner = Outer().Inner() + //^ U here is not analyzed + fun foo(t: T, r: R) {} + } +} + +fun test0() { + val inner: Outer.Inner = Outer().Inner() + Outer().Inner().foo(1, "") // type mismatch on second argument +} + + +fun test1() { + Outer().Inner().newOuterInner().foo(1.0, true) // type mismatch on 1.0 +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/outerArgumentsRequired.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/outerArgumentsRequired.fir.kt new file mode 100644 index 00000000000..a26cddf1a78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/outerArgumentsRequired.fir.kt @@ -0,0 +1,23 @@ +import A.B.D +import A.B.C +import A.B.D.Innermost + +class A { + inner class B { + inner class C + inner class D { + inner class Innermost + } + } + + class Nested { + val x: B? = null + val y: B.C? = null + val z: B.D? = null + + val c: C? = null + val d: D? = null + + val innerMost: Innermost? = null + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/parameterShadowing.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/parameterShadowing.fir.kt new file mode 100644 index 00000000000..21286722014 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/parameterShadowing.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo(): E = null!! + fun outerE() = baz() + } + + fun baz(): E = null!! +} + +fun main() { + val inner = Outer().Inner() + + inner.foo().checkType { _() } + inner.outerE().checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedOuter.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedOuter.fir.kt new file mode 100644 index 00000000000..0b3c53ddefe --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedOuter.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +class Outer { + inner class Inner + fun foo(x: Outer.Inner, y: Outer.Inner, z: Inner) { + var inner = Inner() + x.checkType { _() } + x.checkType { _.Inner>() } + z.checkType { _() } + z.checkType { _.Inner>() } + + inner = x + } + + class Nested + fun bar(x: Outer.Nested) { + var nested = Nested() + nested = x + + x.checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedTypesResolution.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedTypesResolution.fir.kt new file mode 100644 index 00000000000..b21c57691f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/qualifiedTypesResolution.fir.kt @@ -0,0 +1,51 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// FILE: test.kt + +package test + +class Outer { + inner class Inner { + inner class Inner2 + inner class Inner3 + } + + class Nested { + inner class Inner4 + } + + object Obj { + class Nested2 { + inner class Inner5 + } + } +} + +// FILE: main.kt + +import test.*; + +class A +class B +class C +class D + +fun ok1(): Outer.Inner.Inner2 = null!! +fun ok2(): Outer.Inner.Inner2 = null!! +fun ok22(): test.Outer.Inner.Inner3 = null!! +fun ok3(): Outer.Nested.Inner4 = null!! +fun ok4(): Outer.Obj.Nested2.Inner5 = null!! +fun ok5(): test.Outer.Obj.Nested2.Inner5 = null!! + +// All arguments are resolved +fun errorTypeWithArguments(): Q.W.R.M = null!! + +fun error1(): Outer.Inner.Inner3 = null!! +fun error2(): Outer.Inner.Inner2 = null!! +fun error3(): Outer.Inner.Inner3 = null!! + +fun error4(): Outer.Nested.Inner4 = null!! +fun error5(): Outer.Obj.Nested2.Inner5 = null!! +fun error6(): Outer.Obj.Nested2.Inner5 = null!! + +fun error7(): test.Outer.Obj.Nested2.Inner5 = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/simple.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/simple.fir.kt new file mode 100644 index 00000000000..ed3d9809b04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/simple.fir.kt @@ -0,0 +1,36 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo() = this + fun baz(): Inner = this + } + + fun bar() = Inner() + + fun set(inner: Inner) {} +} + +fun factoryString(): Outer.Inner = null!! + +fun infer(x: T): Outer.Inner = null!! +val inferred = infer("") + +fun main() { + val outer = Outer() + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + outer.set(outer.bar()) + outer.set(outer.Inner()) + + val x: Outer.Inner = factoryString() + outer.set(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/simpleIn.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleIn.fir.kt new file mode 100644 index 00000000000..e0180d525c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleIn.fir.kt @@ -0,0 +1,40 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo() = this + fun baz(): Inner = this + } + + fun bar() = Inner() + + fun set(inner: Inner) {} +} + +fun factoryString(): Outer.Inner = null!! + +fun infer(x: T): Outer.Inner = null!! +val inferred = infer("") + +fun main() { + val outer = Outer() + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + outer.set(outer.bar()) + outer.set(outer.Inner()) + + val x: Outer.Inner = factoryString() + outer.set(x) + val y: Outer.Inner = infer("") + outer.set(y) + + outer.set(infer("")) +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOut.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOut.fir.kt new file mode 100644 index 00000000000..e155df657c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOut.fir.kt @@ -0,0 +1,37 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo() = this + fun baz(): Inner = this + } + + fun bar() = Inner() + + // Should be unsafe variance error here + fun set(inner: Inner) {} +} + +fun factoryString(): Outer.Inner = null!! + +fun infer(x: T): Outer.Inner = null!! +val inferred = infer("") + +fun main() { + val outer = Outer() + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + outer.set(outer.bar()) + outer.set(outer.Inner()) + + val x: Outer.Inner = factoryString() + outer.set(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOutUseSite.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOutUseSite.fir.kt new file mode 100644 index 00000000000..b894c10f9f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/simpleOutUseSite.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun foo() = this + fun baz(): Inner = this + } + + fun bar() = Inner() + + fun set(inner: Inner) {} +} + +fun factoryString(): Outer.Inner = null!! + +fun infer(x: T): Outer.Inner = null!! +val inferred = infer("") + +fun main() { + val outer: Outer = Outer() + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + checkSubtype.Inner>(outer.bar()) + checkSubtype.Inner>(outer.Inner()) + + outer.set(outer.bar()) + outer.set(outer.Inner()) + + val x: Outer.Inner = factoryString() + outer.set(x) +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/substitutedMemberScope.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/substitutedMemberScope.fir.kt new file mode 100644 index 00000000000..914dfb898c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/substitutedMemberScope.fir.kt @@ -0,0 +1,49 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun instance() = this@Outer + fun foo(): E = null!! + fun bar(e: E, f: F) {} + fun baz(): F = null!! + + fun act() { + foo().checkType { _() } + outerE().checkType { _() } + instance().checkType { _>() } + instance().outerE().checkType { _() } + + bar(foo(), baz()) + bar(outerE(), baz()) + bar(instance().outerE(), baz()) + + bar(topLevel().Inner().baz(), topLevel().Inner().baz()) + bar(topLevel().Inner().foo(), topLevel().Inner().baz()) + + setE(foo()) + } + } + + fun outerE(): E = null!! + + fun setE(e: E) {} + fun setInner(inner: Inner) {} +} + +fun topLevel(): Outer = null!! + +fun foo() { + val strInt: Outer.Inner = Outer().Inner() + + strInt.foo().checkType { _() } + strInt.baz().checkType { _() } + + strInt.instance().setE("") + strInt.instance().outerE().checkType { _() } + + strInt.instance().Inner().checkType { _.Inner>() } + + Outer().setInner(strInt) + Outer().setInner(strInt) +} diff --git a/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.fir.kt b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.fir.kt new file mode 100644 index 00000000000..4225780a004 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/invalidArgumentsNumberInWhere.fir.kt @@ -0,0 +1,19 @@ +class A +interface I0> +interface I1 where T : A +interface I2> where T : A + +fun > foo0() {} +fun foo1() where E : A {} +fun > foo2() where E : A {} + +val > E.p1: Int + get() = 1 +val E.p2: Int where E : A + get() = 1 +val > E.p3: Int where E : A + get() = 1 + +// See KT-8200 +interface X +public class EnumAttribute>(val klass: Class) where T : Enum diff --git a/compiler/testData/diagnostics/tests/generics/kt1575-Class.fir.kt b/compiler/testData/diagnostics/tests/generics/kt1575-Class.fir.kt new file mode 100644 index 00000000000..87a3d632526 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt1575-Class.fir.kt @@ -0,0 +1 @@ +class C> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/kt1575-Function.fir.kt b/compiler/testData/diagnostics/tests/generics/kt1575-Function.fir.kt new file mode 100644 index 00000000000..58a6f6bc1fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt1575-Function.fir.kt @@ -0,0 +1,2 @@ +class C +fun > foo() {} diff --git a/compiler/testData/diagnostics/tests/generics/kt30590.fir.kt b/compiler/testData/diagnostics/tests/generics/kt30590.fir.kt new file mode 100644 index 00000000000..fc7f293f8c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt30590.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// NI_EXPECTED_FILE + +interface A +fun emptyStrangeMap(): Map = TODO() +fun test7() : Map = emptyStrangeMap() + +fun test() = emptyStrangeMap() diff --git a/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt b/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt new file mode 100644 index 00000000000..f7b373f9128 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// KT-5508 Stackoverflow in type substitution + +abstract class A { + public abstract fun foo(x: T) + public abstract fun bar(x: T) + + public inner abstract class B : A>() { + public inner class C : B>() + { + // Here B> means A.B>.B.B.C>>.B.B>.B.B.C>.C> + // while for being a correct override it should be A.B>.B.B.C> + // It happens because at the beginning we search implicit arguments for an outer classes through supertypes + // See TypeResolver.computeImplicitOuterClassArguments for clarifications + override fun foo(x: B>) { + throw UnsupportedOperationException() + } + + override fun bar(x: A.B>.B.B.C>) { + throw UnsupportedOperationException() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/kt9203.fir.kt b/compiler/testData/diagnostics/tests/generics/kt9203.fir.kt new file mode 100644 index 00000000000..01d1f6f9ee0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt9203.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.stream.Collectors +import java.util.stream.IntStream + +fun main() { + val xs = IntStream.range(0, 10).mapToObj { it.toString() } + .collect(Collectors.toList()) + xs[0] +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/kt9203_1.fir.kt b/compiler/testData/diagnostics/tests/generics/kt9203_1.fir.kt new file mode 100644 index 00000000000..369d4f017d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt9203_1.fir.kt @@ -0,0 +1,18 @@ +public interface Collector + +class A { + fun foo(): T = null!! +} + +public fun toList(): Collector> = null!! + +interface Stream { + public fun collect(collector: Collector): R +} +fun stream(): Stream = null!! + +fun main() { + val stream: Stream = stream() + val xs = stream.collect(toList()) + xs.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/kt9985.fir.kt b/compiler/testData/diagnostics/tests/generics/kt9985.fir.kt new file mode 100644 index 00000000000..6af3f78e7e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/kt9985.fir.kt @@ -0,0 +1,46 @@ +// !CHECK_TYPE +// Incorrect "type mismatch" error for generic extension safe call (required not-null, found nullable) + +// FILE: B.java + +public class B { + public String gav() { + return ""; + } + + public static B create() { + return new B(); + } +} + +// FILE: A.kt + +class A { + fun gav() = "" +} +fun foo(x: R) = x +fun A.bar() = "" +fun B.bar() = "" + +fun foo(l: A?) { + // No errors should be here + foo(l?.bar()) checkType { _() } + foo(l?.gav()) checkType { _() } + if (l != null) { + foo(l?.bar()) checkType { _() } + foo(l?.gav()) checkType { _() } + } +} + +fun fooNotNull(l: A) { + // No errors should be here + foo(l?.bar()) checkType { _() } + foo(l?.gav()) checkType { _() } +} + +fun bar() { + val l = B.create() + foo(l?.bar()) checkType { _() } + foo(l?.gav()) checkType { _() } +} + diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/conflictingReturnType.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/conflictingReturnType.fir.kt new file mode 100644 index 00000000000..21c273e3c1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/conflictingReturnType.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence +} + +interface B { + fun foo(): String? +} + +fun test(x: T) where T : B, T : A { + x.foo() +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/flexibleTypes.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/flexibleTypes.fir.kt new file mode 100644 index 00000000000..48dbfbe7bbc --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/flexibleTypes.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE +// FILE: A.java +public interface A { + String foo(); +} + +// FILE: main.kt + +interface B { + fun foo(): String? +} + +interface C { + fun foo(): String +} + +fun test(x: T) where T : B, T : A, T : C { + x.foo().checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/mostSpecific.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/mostSpecific.fir.kt new file mode 100644 index 00000000000..60fb0f2154b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/mostSpecific.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence? +} + +interface B { + fun foo(): String +} + +fun test(x: T) where T : B, T : A { + x.foo().checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt new file mode 100644 index 00000000000..24de5e835b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/properties.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +interface A { + val foo: Any? +} + +interface C: A { + override val foo: String? +} +interface B: A { + override var foo: String +} + +fun test(a: T) where T : B, T : C { + a.foo = "" + a.foo = null + + a.foo.checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/propertiesConflict.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/propertiesConflict.fir.kt new file mode 100644 index 00000000000..a026254004d --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/propertiesConflict.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +interface A { + val foo: Any? +} + +interface C: A { + override val foo: String +} +interface B: A { + override var foo: String? +} + +fun test(a: T) where T : B, T : C { + a.foo = "" + a.foo = null + + a.foo.checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/simple.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/simple.fir.kt new file mode 100644 index 00000000000..3eb3f039f43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/simple.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +interface A { + fun foo() +} + +interface C: A +interface B: A + +fun test(x: T) where T : C?, T : B? { + x?.foo() + if (x != null) { + x.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/validTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/validTypeParameters.fir.kt new file mode 100644 index 00000000000..dec6653fa20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/multipleBoundsMemberScope/validTypeParameters.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +interface A { + fun foo(): E +} + +interface B { + fun foo(): W +} + +fun test(x: T) where T : B, T : A { + x.foo().checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.fir.kt new file mode 100644 index 00000000000..fe61ad8e7a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.fir.kt @@ -0,0 +1,17 @@ +// FILE: First.java + +public class First { + public static void bind(First first) {} +} + +// FILE: SubFirst.java + +public class SubFirst extends First {} + +// FILE: test.kt + +interface Sample + +fun test(s: SubFirst<*>) { + First.bind(s) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt new file mode 100644 index 00000000000..cd7358e05ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.fir.kt @@ -0,0 +1,6 @@ +// !LANGUAGE: +NewInference + +inline fun foo(x: T?, y: T): T { + if (x is S) return x + return y +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.fir.kt new file mode 100644 index 00000000000..c2f2f51f2ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: JClass.java + +public class JClass { + public void foo(Key key, K value) {} +} + +// FILE: test.kt + +class Key + +fun select(x: S, y: S): S = x + +fun setValue(key: Key, value: T, j: JClass) { + j.foo(key, select(value, null)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/declarationsBoundsViolation.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/declarationsBoundsViolation.fir.kt new file mode 100644 index 00000000000..3e4dd070b0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/declarationsBoundsViolation.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A + +fun foo1(a: A) {} + +class B1 : A +class B2 : A +class B3 : A + +class B4 : A + +fun foo(a: A, b: A, c: A) {} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/expressionsBoundsViolation.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/expressionsBoundsViolation.fir.kt new file mode 100644 index 00000000000..03e3a5d44db --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/expressionsBoundsViolation.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A(x: T) + +fun foo1(x: E) {} +fun E.foo2() {} + +fun bar(x: F) { + A(x) + A(x) + + foo1(x) + foo1(x) + + x.foo2() + x.foo2() +} + diff --git a/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.fir.kt new file mode 100644 index 00000000000..24faa0a169e --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +fun Unit)?> foo(x: E, y: T) { + if (x != null) { + y(x) + } + + if (y != null) { + y(x) + } + + if (x != null && y != null) { + y(x) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/inferNotNullTypeFromIntersectionOfNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/inferNotNullTypeFromIntersectionOfNullableTypes.fir.kt new file mode 100644 index 00000000000..0a8e1644657 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/inferNotNullTypeFromIntersectionOfNullableTypes.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +NewInference + +fun simpleTypeAndNumberType(b: Comparable<*>?) { + if (b is Byte?) { + b!!.dec() + } +} + +fun typeParmeterAndNumberType(b: T?) { + if (b is Byte?) { + b!!.dec() + } +} + +fun anyAndNumberType(b: Any?) { + if (b is Byte?) { + b!!.dec() + } +} + +fun comparableAndNumberType(b: Comparable?) { + if (b is Byte?) { + b!!.dec() + } +} + +object SeparateTypes { + interface A + interface B { + fun foo() {} + } + + fun separate(a: A?) { + if (a is B?) { + a!!.foo() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/kt25182.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/kt25182.fir.kt new file mode 100644 index 00000000000..3ed6a5ebf86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/kt25182.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +abstract class Expr + +class Sum(val e: Expr) : Expr() + +private fun times(e: Expr, element: V): Expr = TODO() + +private fun foo(e: Expr) {} + +fun test(intExpression: Expr) { + foo(Sum(times(intExpression, 42))) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.fir.kt new file mode 100644 index 00000000000..dd0d6de0461 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A +interface B { + fun test() {} +} + +fun select(a: K, b: K): K = a + +fun test(a: A?, b: B?) { + b as A? + a as B? + val c = select(a, b) + if (c != null) { + c.test() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt new file mode 100644 index 00000000000..09fe0b3722a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE + +fun bar(x: E) {} + +fun foo(): T { + val x1: T = null + val x2: T? = null + + bar(null) + bar(null) + + return null +} + +fun baz(): T? = null + +fun foobar(): T = null + +class A { + fun xyz(x: F) {} + + fun foo(): F { + val x1: F = null + val x2: F? = null + + xyz(null) + bar(null) + + return null + } + + fun baz(): F? = null + + fun foobar(): F = null +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCastRefinedClass.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCastRefinedClass.fir.kt new file mode 100644 index 00000000000..914151e3715 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCastRefinedClass.fir.kt @@ -0,0 +1,13 @@ +fun foo(x: T) { + if (x is String?) { + x.length + + if (x != null) { + x.length + } + } + + if (x is String) { + x.length + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt new file mode 100644 index 00000000000..ba669aa51d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt @@ -0,0 +1,46 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE + +fun T.bar1() {} +fun CharSequence?.bar2() {} + +fun T.bar3() {} +fun CharSequence.bar4() {} + +fun foo(x: T) { + + if (x != null) { + if (x != null) {} + + x.length + x?.length + + x.bar1() + x.bar2() + x.bar3() + x.bar4() + + + x?.bar1() + } + + x.length + + if (x is String) { + x.length + x?.length + + x.bar1() + x.bar2() + x.bar3() + } + + if (x is CharSequence) { + x.length + x?.length + + x.bar1() + x.bar2() + x.bar3() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCastsOnThis.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCastsOnThis.fir.kt new file mode 100644 index 00000000000..afd4d5b9a6a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCastsOnThis.fir.kt @@ -0,0 +1,36 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE + +fun T.bar1() {} +fun CharSequence?.bar2() {} + +fun T.bar3() {} +fun CharSequence.bar4() {} + +fun T.foo() { + if (this != null) { + if (this != null) {} + + length + this?.length + + bar1() + bar2() + bar3() + bar4() + + + this?.bar1() + } + + length + + if (this is String) { + length + this?.length + + bar1() + bar2() + bar3() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCastsValueArgument.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCastsValueArgument.fir.kt new file mode 100644 index 00000000000..7a9fb30501c --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCastsValueArgument.fir.kt @@ -0,0 +1,52 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE,-UNUSED_PARAMETER,-ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE,-UNUSED_VALUE + +fun bar1(x: T) {} +fun bar2(x: CharSequence) {} +fun bar3(x: String) {} + +fun foo(x: T) { + var y1: CharSequence = "" + var y2: String = "" + if (x != null) { + if (x != null) {} + + y1 = x + y2 = x + + bar1(x) + bar1(x) + bar2(x) + bar3(x) + } + + if (x is String) { + y1 = x + y2 = x + + bar1(x) + bar2(x) + bar3(x) + } + + if (x is CharSequence) { + y1 = x + y2 = x + + bar1(x) + bar2(x) + bar3(x) + } + + if (1 == 1) { + val y = x!! + bar1(x) + bar1(x) + bar2(x) + bar3(x) + + bar1(y) + bar2(y) + bar3(y) + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolation.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolation.fir.kt new file mode 100644 index 00000000000..5bfe4abd488 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolation.fir.kt @@ -0,0 +1,49 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE + +class A { + fun foo1(x: E) = x + fun foo2(x: E) = x + + fun bar(x: F, y: F?, z: Z, w: W) { + foo1(x) + + val x1 = foo1(x) + x1.checkType { _() } + + foo2(x) + + val x2 = foo2(x) + x2.checkType { _() } + + foo1(y) + foo1(y) + foo2(y) + + val x3 = foo2(y) + x3.checkType { _() } + + foo1(y) + foo2(y) + + foo1(z) + + val x4 = foo1(z) + x4.checkType { _() } + + foo2(z) + + val x5 = foo2(z) + x4.checkType { _() } + + foo1(w) + foo1(w) + foo2(w) + + val x6 = foo2(w) + x6.checkType { _() } + + foo1(w) + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.fir.kt new file mode 100644 index 00000000000..24fb210b617 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.fir.kt @@ -0,0 +1,67 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE + +class A { + class Inv + fun > fooInv1(x: E) = x + fun > fooInv2(x: E) = x + + class In + fun > fooIn1(x: E) = x + fun > fooIn2(x: E) = x + + class Out + fun > fooOut1(x: E) = x + fun > fooOut2(x: E) = x + + fun bar() { + // F + fooInv1>(Inv()) + fooInv2>(Inv()) + fooInv1(Inv()) + fooInv2(Inv()) + + fooIn1>(In()) + fooIn2>(In()) + fooIn1(In()) + fooIn2(In()) + + fooOut1>(Out()) + fooOut2>(Out()) + fooOut1(Out()) + fooOut2(Out()) + + // Z + fooInv1>(Inv()) + fooInv2>(Inv()) + fooInv1(Inv()) + fooInv2(Inv()) + + fooIn1>(In()) + fooIn2>(In()) + fooIn1(In()) + fooIn2(In()) + + fooOut1>(Out()) + fooOut2>(Out()) + fooOut1(Out()) + fooOut2(Out()) + + // W + fooInv1>(Inv()) + fooInv2>(Inv()) + fooInv1(Inv()) + fooInv2(Inv()) + + fooIn1>(In()) + fooIn2>(In()) + fooIn1(In()) + fooIn2(In()) + + fooOut1>(Out()) + fooOut2>(Out()) + fooOut1(Out()) + fooOut2(Out()) + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/tpInBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/tpInBounds.fir.kt new file mode 100644 index 00000000000..3e24720fdd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/tpInBounds.fir.kt @@ -0,0 +1,40 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VALUE,-UNUSED_VARIABLE,-ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE,-VARIABLE_WITH_REDUNDANT_INITIALIZER + +class A { + fun T.bar() {} + + fun foo(x: E1, y: E2) { + x.bar() + + if (1 == 1) { + y.bar() + } + + x?.bar() + y?.bar() + + + var t: T = x + var tN: T? = y + + // condition needed to make smart cast on tN impossible + if (1 == 1) { + tN = x + } + + if (1 == 1) { + t = tN + } + + t = y + + if (y != null) { + t = y + } + + if (tN != null) { + t = tN + } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/useAsReceiver.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/useAsReceiver.fir.kt new file mode 100644 index 00000000000..c8f52d3f8cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/useAsReceiver.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE + +fun T.bar1() {} +fun CharSequence?.bar2() {} + +fun T.bar3() {} + +fun foo(x: T) { + x.length + x?.length + + if (1 == 1) { + x!!.length + } + + + x.bar1() + x.bar2() + + x?.bar1() + x?.bar2() + + x.bar3() + + x?.let { it.length } +} diff --git a/compiler/testData/diagnostics/tests/generics/nullability/useAsValueArgument.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/useAsValueArgument.fir.kt new file mode 100644 index 00000000000..7892ecac4e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/nullability/useAsValueArgument.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE + +fun bar1(x: T) {} + +fun bar2(x: CharSequence?) {} + +fun bar3(x: T) {} + +fun bar4(x: String) {} + +fun foo(x: T) { + bar1(x) + bar2(x) + + bar3(x) + bar4(x) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/MLOut.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/MLOut.fir.kt new file mode 100644 index 00000000000..082106edebe --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/MLOut.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +// FILE: A.java +public class A { + public java.util.List foo() {} +} + +// FILE: main.kt + +fun foo2(x: A, y: MutableList) { + x.foo().isEmpty() + x.foo().get(0) checkType { _() } + x.foo().iterator() checkType { _>() } + + y.isEmpty() + y.get(0) checkType { _() } + y.iterator() checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.fir.kt new file mode 100644 index 00000000000..f5fc027d2df --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface C +interface MC : C { + fun addAll(x: C): Boolean + fun addAllMC(x: MC): Boolean + fun addAllInv(x: MC): Boolean +} + +interface Open +class Derived : Open + +fun mc(): MC = null!! +fun c(): C = null!! + +fun foo(x: MC) { + x.addAll(x) + x.addAllMC(x) + + x.addAll(mc()) + x.addAllMC(mc()) + + x.addAll(mc()) + x.addAllMC(mc()) + + x.addAll(c()) + x.addAll(c()) + + x.addAllInv(mc()) + x.addAll(1) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/approximateDispatchReceiver.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/approximateDispatchReceiver.fir.kt new file mode 100644 index 00000000000..7c3a4681b6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/approximateDispatchReceiver.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +public abstract class A { + fun bar(): String = "" +} + +public class B : A>() + +fun test(b: B<*>) { + // Here `bar` could have dispatch receiver parameter type 'A>', but it wouldn't work as + // since 'b' has type 'A>', so we should approximate dispatch receiver PARAMETER type to make it accept original receiver + b.bar() + b.bar() checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.fir.kt new file mode 100644 index 00000000000..69cd0e36317 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionReceiverTypeMismatch.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +class A { + fun T.foo() {} + fun Out.bar() {} +} +class Out + +fun test(x: A, y: Out) { + with(x) { + // TODO: this diagnostic could be replaced with TYPE_MISMATCH_DUE_TO_TYPE_PROJECTION + "".foo() + y.bar() + + with(y) { + bar() + } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionResultSubstitution.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionResultSubstitution.fir.kt new file mode 100644 index 00000000000..a200e8f6eee --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/extensionResultSubstitution.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun foo() = 1 +} + +interface B + +public fun E.bar() : A = null!! + +fun baz(x: B) { + x.bar().foo() +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.fir.kt new file mode 100644 index 00000000000..1556a5dd960 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +// !CHECK_TYPE + +// FILE: Clazz.java +public class Clazz { + public java.util.Collection foo() { return null; } +} + +// FILE: main.kt + +public fun > Iterable.filterTo(destination: C, predicate: (T) -> Boolean) {} + +fun test(clazz: Clazz) { + val result = java.util.ArrayList() + clazz.foo().filterTo(result) { x -> true } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/inValueParameter.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/inValueParameter.fir.kt new file mode 100644 index 00000000000..860f65e3b75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/inValueParameter.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +interface A +interface B { + fun foo(x: A) +} + +fun foo(x: B, y: A) { + x.foo(y) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/iterateOnExtension.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/iterateOnExtension.fir.kt new file mode 100644 index 00000000000..28aa35be026 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/iterateOnExtension.fir.kt @@ -0,0 +1,11 @@ +class A +fun A.foo(): Collection = null!! + +fun main(a: A<*>, a1: A) { + // see KT-9571 + for (i in a.foo()) { } + for (i: Any? in a.foo()) { } + + for (i in a1.foo()) { } + for (i: CharSequence in a1.foo()) { } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/kt7296.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/kt7296.fir.kt new file mode 100644 index 00000000000..c609458644b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/kt7296.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !CHECK_TYPE +import java.util.ArrayList + +class ListOfLists(public val x : ArrayList>) + +fun main() { + val a : ArrayList> = ArrayList() + val b : ListOfLists = ListOfLists(a) + val c : ListOfLists<*> = b + val d : ArrayList> = c.x + + c.x checkType { _>>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/kt8647.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/kt8647.fir.kt new file mode 100644 index 00000000000..0873de21fd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/kt8647.fir.kt @@ -0,0 +1,8 @@ +interface Subscriber + +interface Observable { + fun subscribe(s: Subscriber) +} + +fun foo(o: Observable, y: Subscriber) = o.subscribe(y) // type safe + diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/lambdaArgument.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/lambdaArgument.fir.kt new file mode 100644 index 00000000000..35247f1b5d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/lambdaArgument.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +class A { + fun foo(f: (T) -> Unit) {} +} + +fun test(a: A, b: A) { + a.foo { + it checkType { _() } + } + + b.foo { + it checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/leakedApproximatedType.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/leakedApproximatedType.fir.kt new file mode 100644 index 00000000000..a5262457bdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/leakedApproximatedType.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Out +class In { + fun invoke1(x: T) {} + fun invoke2(x: Out) {} +} + +interface A { + fun foo(): In +} + +fun test(a: A, y: Out) { + val i = a.foo() + // TODO: These diagnostic are wrong, type of 'i' --- 'In' is not projected itself, + // but it's approximation result caused by 'a' projection + i.invoke1("") + i.invoke2(y) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/multipleArgumentProjectedOut.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/multipleArgumentProjectedOut.fir.kt new file mode 100644 index 00000000000..e7dd1a5f2e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/multipleArgumentProjectedOut.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun foo(x: T, y: T) {} +} + +fun test(a: A) { + a.foo("", "") +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/platformSuperClass.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/platformSuperClass.fir.kt new file mode 100644 index 00000000000..f44f0a6ed53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/platformSuperClass.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +// FILE: Clazz.java +public class Clazz { + public T getT() { return null; } + public Clazz getSuperClass() { return null; } +} + +// FILE: main.kt +fun test(clazz: Clazz<*>) { + clazz.t checkType { _() } + clazz.getSuperClass() checkType { _?>() } + clazz.getSuperClass().t checkType { _() } + + clazz.superClass checkType { _?>() } + clazz.superClass.t checkType { _() } + + // See KT-9294 + if (clazz.superClass == null) { + throw NullPointerException() + } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutConventions.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutConventions.fir.kt new file mode 100644 index 00000000000..aeeb144c0bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutConventions.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + operator fun plus(x: T): A = this + operator fun set(x: Int, y: T) {} + operator fun get(x: T) = 1 +} + +fun test(a: A) { + a + "" + a[1] = "" + a[""] +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutSmartCast.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutSmartCast.fir.kt new file mode 100644 index 00000000000..7b905950ad9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/projectedOutSmartCast.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +class Inv +class C { + fun bindTo(property: Inv) {} +} + +fun foo(x: Any?, y: C<*>) { + y.bindTo("") + + if (x is C<*>) { + x.bindTo("") + with(x) { + bindTo("") + } + } + + with(x) { + if (this is C<*>) { + bindTo("") + } + } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStar.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStar.fir.kt new file mode 100644 index 00000000000..c2abfc7d52e --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStar.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// See KT-7296 +interface A +interface B : A> + +fun foo(x : B<*>) { + bar1(x) // this should not be valid + bar2(x) + bar3(x) +} + +fun bar1(x : A>) { } +fun bar2(x : A>) { } +fun bar3(x : A<*>) { } diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStarOut.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStarOut.fir.kt new file mode 100644 index 00000000000..80c221107c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStarOut.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// See KT-7296 +interface Out +interface B : Out> + +fun foo(x : B<*>) { + bar1(x) + bar2(x) +} + +fun bar1(x : Out>) { } +fun bar2(x : Out<*>) { } diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullability.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullability.fir.kt new file mode 100644 index 00000000000..26ff7f50583 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullability.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// See KT-9893 +open class A + +public interface I { + public fun foo(): T? +} + +fun acceptA(a: A) { +} + +fun main(i: I<*>) { + i.foo() checkType { _() } + acceptA(i.foo()) // i.foo() should be nullable but isn't +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullabilityRecursive.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullabilityRecursive.fir.kt new file mode 100644 index 00000000000..ed7aedae6a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/starNullabilityRecursive.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +interface A?> { + fun foo(): T? +} +fun testA(a: A<*>) { + a.foo() checkType { _?>() } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/superClass.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/superClass.fir.kt new file mode 100644 index 00000000000..e0963df5033 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/superClass.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +interface Clazz { + val t: T + fun getSuperClass(): Clazz +} + +fun test(clazz: Clazz<*>) { + clazz.t checkType { _() } + clazz.getSuperClass() checkType { _>() } + clazz.getSuperClass().t checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchConventions.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchConventions.fir.kt new file mode 100644 index 00000000000..f976f1248d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchConventions.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + operator fun plus(x: Out): A = this + operator fun set(x: Int, y: Out) {} + operator fun get(x: Out) = 1 +} + +class Out + +fun test(a: A, y: Out) { + a + y + a[1] = y + a[y] + + a + Out() + a[1] = Out() + a[Out()] +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt new file mode 100644 index 00000000000..a16b1db7271 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +class Out { + fun id() = this + fun foobar(x: Any) {} +} + +class A { + inline fun foo(block: () -> E) {} + inline fun bar(block: () -> Out) {} +} + +fun test(a: A, z: Out) { + a.foo { + val x: String = 1 // Should be no TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS + "" + } + a.bar { Out() } + a.bar { Out() } + a.bar { z.id() } + + a.foo { + z.foobar(if (1 > 2) return@foo "" else "") + "" + } +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.fir.kt new file mode 100644 index 00000000000..de0ef7c1b87 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.fir.kt @@ -0,0 +1,44 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Out +class In +class Inv + +class A { + fun > foo1(x: E) = 1 + fun > foo2(x: F) = 1 + fun > foo3(x: G) = 1 +} + +fun foo2(a: A, b: A) { + a.foo1(Out()) + a.foo1>(Out()) + + a.foo1(Out()) + a.foo1(Out()) + + a.foo2(Inv()) + a.foo2(Inv()) + a.foo2>(Inv()) + + a.foo3(In()) + a.foo3(In()) + a.foo3>(In()) + + b.foo1(Out()) + b.foo1(Out()) + b.foo1>(Out()) + + b.foo2(Inv()) + b.foo2(Inv()) + b.foo2>(Inv()) + + + b.foo3(In()) + b.foo3>(In()) + + b.foo3(In()) + b.foo3(In()) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.fir.kt new file mode 100644 index 00000000000..10f4635a1d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE + +interface A { + fun foo(x: @UnsafeVariance K): Unit +} + +fun test(a: A<*>) { + a.foo(null) + a.foo(Any()) +} diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.fir.kt new file mode 100644 index 00000000000..bb2deafe59f --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun foo(vararg x: T) {} +} + +fun test(a: A, y: Array) { + a.foo("", "", "") + a.foo(*y) + // TODO: TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS probably redundant + a.foo(*y, "") +} diff --git a/compiler/testData/diagnostics/tests/generics/protectedSuperCall.fir.kt b/compiler/testData/diagnostics/tests/generics/protectedSuperCall.fir.kt new file mode 100644 index 00000000000..7b2439480e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/protectedSuperCall.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// FILE: GA.kt + +package test.x + +open class GA protected constructor() + +// FILE: Main.kt +package test + +import test.x.GA + +class C : GA() { + companion object { + fun bar() = GA() // Should be error + } +} + +fun main(args: Array) { + C.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/recursive.fir.kt b/compiler/testData/diagnostics/tests/generics/recursive.fir.kt new file mode 100644 index 00000000000..690c18b7f65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/recursive.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE + +interface Rec +class A : Rec +class B : Rec + +fun test(a: A, b: B, c: Boolean) { + var ab = if (c) a else b + ab = a + ab = b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/resolveGenericBoundsBeforeSupertypes.fir.kt b/compiler/testData/diagnostics/tests/generics/resolveGenericBoundsBeforeSupertypes.fir.kt new file mode 100644 index 00000000000..543e3f9646b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/resolveGenericBoundsBeforeSupertypes.fir.kt @@ -0,0 +1,7 @@ +// Tests that generic bounds in the object supertype are resolved prior to the supertype itself + +object O : Tr> + +interface Tr + +class V diff --git a/compiler/testData/diagnostics/tests/generics/sameTypeParameterUse.fir.kt b/compiler/testData/diagnostics/tests/generics/sameTypeParameterUse.fir.kt new file mode 100644 index 00000000000..319b5bc8737 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/sameTypeParameterUse.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(x: R, y: String) {} +fun foo(x: R, y: R) { + foo(x, "") // ok, resolved foo(x: R, y: String) + foo(x, "") // ok, foo(x: R, y: String) + foo(x, x) // ok, resolved foo(x: R, y: R) + foo(x, x) // ok, resolved foo(x: R, y: R) +} + +class Q(x: R) { + fun foo() { + Q("") + } +} +fun Q(x: String) {} diff --git a/compiler/testData/diagnostics/tests/generics/starProjections/checkBounds.fir.kt b/compiler/testData/diagnostics/tests/generics/starProjections/checkBounds.fir.kt new file mode 100644 index 00000000000..17f1e033cf6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/starProjections/checkBounds.fir.kt @@ -0,0 +1,3 @@ +class A> +fun > foo() {} +class B> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/starProjections/collectionInheritedFromJava.fir.kt b/compiler/testData/diagnostics/tests/generics/starProjections/collectionInheritedFromJava.fir.kt new file mode 100644 index 00000000000..5e09012121d --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/starProjections/collectionInheritedFromJava.fir.kt @@ -0,0 +1,14 @@ +// FILE: p/Base.java + +package p; + +import java.util.*; + +public class Base { + void coll(Collection r) {} +} + +// FILE: k.kt +package p + +class Derived: p.Base() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromJava.fir.kt b/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromJava.fir.kt new file mode 100644 index 00000000000..caf29f2990a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromJava.fir.kt @@ -0,0 +1,14 @@ +// FILE: p/Base.java + +package p; + +public class Base { + void foo(R r) {} +} + +// FILE: k.kt +package p + +class R> + +class Derived: p.Base() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromKotlin.fir.kt b/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromKotlin.fir.kt new file mode 100644 index 00000000000..bcf02a0e721 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/starProjections/inheritedFromKotlin.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class R> + +open class Base { + fun foo(r: R<*>) {} +} + +class Derived: Base() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/starProjections/invalid.fir.kt b/compiler/testData/diagnostics/tests/generics/starProjections/invalid.fir.kt new file mode 100644 index 00000000000..068e1c105b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/starProjections/invalid.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: main.kt +class Inv(val x: T) + +class A> { + fun foo(): T = null!! +} + +class Inv2>(val x: T) + +fun main(a: A<*>, j: JavaClass<*>, i2: Inv2<*>) { + // Probably it's too restrictive to suppose star projection type here as Any?, + // but looks like we can refine it later + a.foo() checkType { _() } + j.foo() checkType { _() } + i2.x checkType { _() } + + j.bar(1, 2, Any()) + j.bar(null) +} + +// FILE: JavaClass.java +public class JavaClass> { + public void bar(T... x) {} + public T foo() {} +} diff --git a/compiler/testData/diagnostics/tests/generics/suppressVarianceConflict.fir.kt b/compiler/testData/diagnostics/tests/generics/suppressVarianceConflict.fir.kt new file mode 100644 index 00000000000..553af5275bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/suppressVarianceConflict.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +class A { + fun foo(x: @UnsafeVariance T) {} + fun foo(x: @UnsafeVariance T, y: List<@UnsafeVariance T>): @UnsafeVariance E = null!! + + fun bar(): List<@UnsafeVariance E> = null!! +} + +fun foo(x: A, cs: CharSequence, ls: List) { + val y: A = x + + y.foo(cs) + val s: String = y.foo(cs, ls) + + val ls2: List = y.bar() +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt new file mode 100644 index 00000000000..8402c98cef4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A + +inline fun foo(x: A) {} + +fun test(x: A) { + foo(x) +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/ClassDereference.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/ClassDereference.fir.kt new file mode 100644 index 00000000000..758753b3116 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/ClassDereference.fir.kt @@ -0,0 +1,3 @@ + +fun dereferenceClass(): Any = + T::class diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.fir.kt new file mode 100644 index 00000000000..377d73d3998 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline operator fun T.plus(p: T): T = this + +inline operator fun T.invoke(): T = this + +fun main(tp: A, any: Any) { + tp + tp + any + any + + tp() + any() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgument.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgument.fir.kt new file mode 100644 index 00000000000..cff415b6311 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgument.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +ProhibitNonReifiedArraysAsReifiedTypeArguments +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo() {} + +fun bar() { + foo() + foo>() + foo>>() + foo>() + foo>>() + foo() + foo>() + foo>>() +} + +fun test(x: Array, y: Array<*>) { + bar() +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgumentWarning.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgumentWarning.fir.kt new file mode 100644 index 00000000000..ae665ca8b29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericArrayAsReifiedArgumentWarning.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -ProhibitNonReifiedArraysAsReifiedTypeArguments +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo() {} + +fun bar() { + foo() + foo>() + foo>>() + foo>() + foo>>() + foo() + foo>() + foo>>() +} + +fun test(x: Array, y: Array<*>) { + bar() +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericAsReifiedArgument.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericAsReifiedArgument.fir.kt new file mode 100644 index 00000000000..b201042e828 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/GenericAsReifiedArgument.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo() {} + +inline fun bar() { + foo>() + foo>() +} + +inline fun baz(x: E) {} + +fun test(x: Array, y: Array<*>) { + foo>() + foo>() + foo>() + foo>() + + foo>() + foo>() + + baz(x) + baz(y) +} + diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InConstructor.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InConstructor.fir.kt new file mode 100644 index 00000000000..241f164149f --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InConstructor.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +class C + +fun id(p: T): T = p + +fun main() { + C() + + val a: C = C() + C() + + val b: C = C() + C() + + // TODO svtk, uncomment when extensions are called for nested calls! + //val < !UNUSED_VARIABLE!>с< !>: C = id(< !TYPE_PARAMETER_AS_REIFIED!>C< !>()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.fir.kt new file mode 100644 index 00000000000..bdac536027a --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun f(): T = throw UnsupportedOperationException() + +fun id(p: T): T = p + +fun main() { + f() + + val a: A = f() + f() + + val b: Int = f() + f() + + val с: A = id(f()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InProperty.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InProperty.fir.kt new file mode 100644 index 00000000000..b1f7e802c2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InProperty.fir.kt @@ -0,0 +1,2 @@ +val T.v: T + get() = throw UnsupportedOperationException() diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InType.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InType.fir.kt new file mode 100644 index 00000000000..6f5cac1d5c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InType.fir.kt @@ -0,0 +1,4 @@ +class C + +fun main(p1: C, p2: C) { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InlineableReified.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InlineableReified.fir.kt new file mode 100644 index 00000000000..d8c35c93cd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InlineableReified.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun bar(x: T1, y: T2): T2 = y +inline fun foo(z: R): R = bar(1, z) + +fun box() { + foo("abc") +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/LocalFun.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/LocalFun.fir.kt new file mode 100644 index 00000000000..e984a060a04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/LocalFun.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NOT_YET_SUPPORTED_IN_INLINE + +inline fun foo(x: T) { + fun bar() { + + } + + bar() +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/NotInlineableReified.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/NotInlineableReified.fir.kt new file mode 100644 index 00000000000..c9a6bc6c2ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/NotInlineableReified.fir.kt @@ -0,0 +1,4 @@ + +fun foo() { + +} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/ReifiedClass.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/ReifiedClass.fir.kt new file mode 100644 index 00000000000..d12c8d6b0a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/ReifiedClass.fir.kt @@ -0,0 +1,3 @@ +class A { + fun foo(): T2 = throw UnsupportedOperationException() +} diff --git a/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.fir.kt b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.fir.kt new file mode 100644 index 00000000000..1b8f7fe01eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.fir.kt @@ -0,0 +1,14 @@ +interface I0> +interface I1 where T : Unresolved1 +interface I2> where T : Unresolved3 + +fun > foo0() {} +fun foo1() where E : Unresolved5 {} +fun > foo2() where E : Unresolved7 {} + +val E.p1: Int + get() = 1 +val E.p2: Int where E : Unresolved8 + get() = 1 +val E.p3: Int where E : Unresolved10 + get() = 1 diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.fir.kt b/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.fir.kt new file mode 100644 index 00000000000..9086a1fa476 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE +// !WITH_NEW_INFERENCE +interface Tr { + var v: Tr +} + +fun test(t: Tr<*>) { + t.v = t + t.v checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt new file mode 100644 index 00000000000..fedfb34f531 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE +// t is unused due to KT-4233 +interface Tr { + var v: T +} + +fun test(t: Tr<*>) { + t.v = null!! + t.v = "" + t.v = null + t.v checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.fir.kt b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.fir.kt new file mode 100644 index 00000000000..48d011721fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNREACHABLE_CODE +// !WITH_NEW_INFERENCE +interface Tr { + var v: T +} + +fun test(t: Tr) { + // resolved as t.v = t.v + null!!, where type of right operand is String, + // so TYPE_MISMATCH: String is not <: of Captured(out String) + t.v += null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutPlusAssignDefined.fir.kt b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutPlusAssignDefined.fir.kt new file mode 100644 index 00000000000..612031454d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutPlusAssignDefined.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNREACHABLE_CODE +interface Tr { + var v: T +} + +class C { + operator fun plusAssign(c: C) {} +} + +fun test(t: Tr) { + // No error because no real assignment happens + t.v += null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/wildcardInValueParameter.fir.kt b/compiler/testData/diagnostics/tests/generics/wildcardInValueParameter.fir.kt new file mode 100644 index 00000000000..4cb4e519fcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/wildcardInValueParameter.fir.kt @@ -0,0 +1,14 @@ +// JAVAC_SKIP +// FILE: JavaClass.java +public class JavaClass { + public void foo(? x) {} + + public void bar(? extends String y) { } +} + +// FILE: main.kt +fun foo() { + JavaClass().foo(Any()) + JavaClass().bar(Any()) + JavaClass().bar("") +} diff --git a/compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.fir.kt b/compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.fir.kt new file mode 100644 index 00000000000..84e29cfaf8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/wrongNumberOfTypeArgumentsDiagnostic.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +fun myFun(i : String) {} +fun myFun(i : Int) {} + +fun test1() { + myFun(3) + myFun('a') +} + +fun test2() { + val m0 = java.util.HashMap() + val m1 = java.util.HashMap() + val m2 = java.util.HashMap() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/implicitIntersection.fir.kt b/compiler/testData/diagnostics/tests/implicitIntersection.fir.kt new file mode 100644 index 00000000000..2877bb09372 --- /dev/null +++ b/compiler/testData/diagnostics/tests/implicitIntersection.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// See KT-10244: no intersection types in signatures + +open class B +interface A +interface C + +// Error! +fun foo(b: B) = if (b is A && b is C) b else null + +// Ok: given explicitly +fun gav(b: B): A? = if (b is A && b is C) b else null + +class My(b: B) { + // Error! + val x = if (b is A && b is C) b else null + // Ok: given explicitly + val y: C? = if (b is A && b is C) b else null + // Error! + fun foo(b: B) = if (b is A && b is C) b else null +} + +fun bar(b: B): String { + // Ok: local variable + val tmp = if (b is A && b is C) b else null + // Error: local function + fun foo(b: B) = if (b is A && b is C) b else null + return tmp.toString() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/implicitNestedIntersection.fir.kt b/compiler/testData/diagnostics/tests/implicitNestedIntersection.fir.kt new file mode 100644 index 00000000000..9a7ae4322b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/implicitNestedIntersection.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// NI_EXPECTED_FILE + +interface In +open class A : In +open class B : In + +fun select(x: T, y: T) = x + +fun foo2() = select(A(), B()) // Type "In" is prohibited in return position + + + +open class C : In +open class D : In +open class E : In +open class F : In +open class G : In +open class H : In + +fun select8(a: S, b: S, c: S, d: S, e: S, f: S, g: S, h: S) = a + +fun foo8() = select8(A(), B(), C(), D(), E(), F(), G(), H()) diff --git a/compiler/testData/diagnostics/tests/implicitNothing.fir.kt b/compiler/testData/diagnostics/tests/implicitNothing.fir.kt new file mode 100644 index 00000000000..782f4576e60 --- /dev/null +++ b/compiler/testData/diagnostics/tests/implicitNothing.fir.kt @@ -0,0 +1,52 @@ +fun foo() = throw Exception() + +fun bar() = null!! + +fun baz() = bar() + +fun gav(): Any = null!! + +val x = null!! + +val y: Nothing = throw Exception() + +fun check() { + // Error: KT-10449 + fun local() = bar() + // Unreachable / unused, but not implicit Nothing + val x = null!! +} + +fun nonLocalReturn() = run { return } + +class Klass { + fun bar() = null!! + + val y = null!! + + init { + fun local() = bar() + // Should be unreachable: see KT-5311 + val z = null!! + } + + fun foo() { + fun local() = bar() + + val x = y + } +} + +interface Base { + val x: Int + + fun foo(): String +} + +class Derived : Base { + // Ok for override + + override val x = null!! + + override fun foo() = null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/AllUnderImportsAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/imports/AllUnderImportsAmbiguity.fir.kt new file mode 100644 index 00000000000..3e478bc5576 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/AllUnderImportsAmbiguity.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +package a + +class X + +// FILE: b.kt +package b + +class X + +// FILE: c.kt +package c + +import a.* +import b.* + +class Y : X \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/AllUnderImportsLessPriority.fir.kt b/compiler/testData/diagnostics/tests/imports/AllUnderImportsLessPriority.fir.kt new file mode 100644 index 00000000000..8b2c0dd0003 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/AllUnderImportsLessPriority.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +package a + +open class X + +// FILE: b.kt +package b + +class X + +// FILE: c.kt +package c + +import a.X +import b.* + +class Y : X() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForFunction.fir.kt b/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForFunction.fir.kt new file mode 100644 index 00000000000..6c9eb99bb8f --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForFunction.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt +package a + +fun X(p: Int) {} + +// FILE: b.kt +package b + +fun X(): Int = 1 + +// FILE: c.kt +package c + +import b.* +import a.X + +fun foo() { + val v: Int = X() +} diff --git a/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForProperty.fir.kt b/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForProperty.fir.kt new file mode 100644 index 00000000000..065aaebd11e --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/AllUnderImportsSamePriorityForProperty.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt +package a + +var X: Int = 1 + +// FILE: b.kt +package b + +var X: String = "" + +// FILE: c.kt +package c + +import a.X +import b.* + +fun foo() { + X = 1 +} diff --git a/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.fir.kt b/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.fir.kt new file mode 100644 index 00000000000..efae5022256 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility.fir.kt @@ -0,0 +1,73 @@ +// FILE: j/JavaPublic.java +package j; + +public class JavaPublic { + public static void javaM() {} + public static int javaP = 4; + static int javaPackageLocal = 5; +} + +// FILE: j/JavaPackageLocal.java +package j; + +class JavaPackageLocal { + static void javaMPackage() {} + static int javaPPackage = 4; +} + +// FILE: j/JavaProtected.java +package j; + +public class JavaProtected { + protected static void javaMProtected() {} + protected static int javaPProtected = 4; +} + +// FILE: j/JavaPrivate.java +package j; + +public class JavaPrivate { + private static void javaMPrivate() {} + private static int javaPPrivate = 4; +} + + +// FILE: k1.kt +package k + +import j.JavaPublic +import j.JavaPublic.javaM +import j.JavaPublic.javaP +import j.JavaPublic.javaPackageLocal + +import j.JavaPackageLocal +import j.JavaPackageLocal.javaMPackage +import j.JavaPackageLocal.javaPPackage + +import j.JavaProtected +import j.JavaProtected.javaMProtected +import j.JavaProtected.javaPProtected + +import j.JavaPrivate +import j.JavaPrivate.javaMPrivate +import j.JavaPrivate.javaPPrivate + +// FILE: k2.kt +package j + +import j.JavaPublic +import j.JavaPublic.javaM +import j.JavaPublic.javaP +import j.JavaPublic.javaPackageLocal + +import j.JavaPackageLocal +import j.JavaPackageLocal.javaMPackage +import j.JavaPackageLocal.javaPPackage + +import j.JavaProtected +import j.JavaProtected.javaMProtected +import j.JavaProtected.javaPProtected + +import j.JavaPrivate +import j.JavaPrivate.javaMPrivate +import j.JavaPrivate.javaPPrivate \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.fir.kt b/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.fir.kt new file mode 100644 index 00000000000..bd143fb16da --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/CheckJavaVisibility2.fir.kt @@ -0,0 +1,62 @@ +// FILE: j/JavaPackageLocal.java +package j; + +public class JavaPackageLocal { + static void javaMPackage() {} + static int javaPPackage = 4; +} + +// FILE: j/JavaProtected.java +package j; + +public class JavaProtected { + protected static void javaMProtectedStatic() {} + protected static int javaPProtectedStatic = 4; + protected final int javaPProtectedPackage = 4; +} + +// FILE: k.kt +package k + +import j.JavaProtected +import j.JavaPackageLocal + +class A { + val p1 = JavaPackageLocal.javaPPackage + val p2 = JavaProtected.javaPProtectedStatic + val p3 = JavaProtected().javaPProtectedPackage + + fun test() { + JavaProtected.javaMProtectedStatic() + JavaPackageLocal.javaMPackage() + } +} + +class B : JavaProtected() { + val p1 = JavaPackageLocal.javaPPackage + val p2 = JavaProtected.javaPProtectedStatic + val p3 = javaPProtectedPackage + + fun test() { + JavaProtected.javaMProtectedStatic() + JavaPackageLocal.javaMPackage() + } +} + +// FILE: j.kt +package j + +import j.JavaProtected +import j.JavaPackageLocal + +class C { + val p1 = JavaPackageLocal.javaPPackage + val p2 = JavaProtected.javaPProtectedStatic + val p3 = JavaProtected().javaPProtectedPackage + + fun test() { + JavaProtected.javaMProtectedStatic() + JavaProtected.javaMProtectedStatic() + JavaPackageLocal.javaMPackage() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/CheckVisibility.fir.kt b/compiler/testData/diagnostics/tests/imports/CheckVisibility.fir.kt new file mode 100644 index 00000000000..e7ceab762ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/CheckVisibility.fir.kt @@ -0,0 +1,28 @@ +// MODULE: m1 +// FILE: k1.kt +package k + +private class KPrivate +internal class KInternal +public class KPublic + +class A { + protected class KProtected +} + +// FILE: k2.kt +package k2 + +import k.KPrivate +import k.KInternal +import k.KPublic +import k.A.KProtected + +// MODULE: m2(m1) +// FILE: k3.kt +package k3 + +import k.KPrivate +import k.KInternal +import k.KPublic +import k.A.KProtected \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ClassClash.fir.kt b/compiler/testData/diagnostics/tests/imports/ClassClash.fir.kt new file mode 100644 index 00000000000..810aea57d1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClash.fir.kt @@ -0,0 +1,81 @@ +// MODULE: m1 +// FILE: a.kt +package a + +class B { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class B { + fun m2() {} +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.B + +fun test(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() + + val b_1: a.B = B() + b_1.m1() + + val b_2: B = a.B() + b_2.m1() + + val b_3: B = B() + b_3.m1() + + val b_4: B = a.B() + b_4.m1() +} + + +//----------------------------TOP LEVEL--------------------- +// MODULE: top_m1 +// FILE: top_a.kt +class B { + fun m1() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class B { + fun m2() {} +} + +// MODULE: top_m3(top_m1, top_m2) +// FILE: top_c.kt +import B + +fun test(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() + + val b_2 = B() + b_2.m1() +} + +// FILE: top_d.kt + +fun test2(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() + + val b_2 = B() + b_2.m1() +} diff --git a/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.fir.kt b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.fir.kt new file mode 100644 index 00000000000..73e0517a257 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.fir.kt @@ -0,0 +1,76 @@ +// !WITH_NEW_INFERENCE +// MODULE: m1 +// FILE: a.kt +package a + +class B { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class B { + fun m2() {} +} + +// MODULE: m3(m2, m1) +// FILE: b.kt +import a.* + + +fun test(b: B) { + b.m2() + b.m1() + + val b_: B = B() + b_.m2() + + val b_1: a.B = B() + b_1.m2() + + val b_2: B = a.B() + b_2.m2() + + val b_3 = B() + b_3.m2() + + val b_4 = a.B() + b_4.m2() +} + + +//----------------------------TOP LEVEL--------------------- + +// MODULE: top_m1 +// FILE: top_a.kt +class B { + fun m1() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class B { + fun m2() {} +} + +// MODULE: top_m3(top_m2, top_m1) +// FILE: top_c.kt + +fun test(b: B) { + b.m2() + b.m1() + + val b_: B = B() + b_.m2() + + val b_2 = B() + b_2.m2() + + val b_3 = B() + b_3.m2() + + val b_4 = a.B() + b_4.m2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ClassImportsConflicting.fir.kt b/compiler/testData/diagnostics/tests/imports/ClassImportsConflicting.fir.kt new file mode 100644 index 00000000000..a7c75219a9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassImportsConflicting.fir.kt @@ -0,0 +1,15 @@ +//FILE:a.kt +package a + +import b.O +import c.O + +//FILE:b.kt +package b + +object O {} + +//FILE:c.kt +package c + +object O {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/CurrentPackageAndAllUnderImport.fir.kt b/compiler/testData/diagnostics/tests/imports/CurrentPackageAndAllUnderImport.fir.kt new file mode 100644 index 00000000000..a9fe67145a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/CurrentPackageAndAllUnderImport.fir.kt @@ -0,0 +1,16 @@ +// FILE: a.kt +package a + +class X + +// FILE: b.kt +package b + +open class X + +// FILE: b1.kt +package b + +import a.* + +class Y : X() // class from the current package should take priority diff --git a/compiler/testData/diagnostics/tests/imports/CurrentPackageAndExplicitImport.fir.kt b/compiler/testData/diagnostics/tests/imports/CurrentPackageAndExplicitImport.fir.kt new file mode 100644 index 00000000000..75a66d31fdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/CurrentPackageAndExplicitImport.fir.kt @@ -0,0 +1,16 @@ +// FILE: a.kt +package a + +open class Y + +// FILE: b.kt +package b + +class X + +// FILE: b1.kt +package b + +import a.Y as X + +class Y : X() // class from explicit import should take priority diff --git a/compiler/testData/diagnostics/tests/imports/DefaultImportsPriority.fir.kt b/compiler/testData/diagnostics/tests/imports/DefaultImportsPriority.fir.kt new file mode 100644 index 00000000000..dcd261d0336 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/DefaultImportsPriority.fir.kt @@ -0,0 +1,6 @@ +import java.lang.reflect.* +import java.util.List + +fun foo( + p1: Array /* should be resolved to kotlin.Array */, + p2: List /* should be resolved to java.util.List */) { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ExplicitImportsAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/imports/ExplicitImportsAmbiguity.fir.kt new file mode 100644 index 00000000000..905fd270bb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ExplicitImportsAmbiguity.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +package a + +class X + +// FILE: b.kt +package b + +class X + +// FILE: c.kt +package c + +import a.X +import b.X + +class Y : X \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ExplicitImportsUnambiguityForFunction.fir.kt b/compiler/testData/diagnostics/tests/imports/ExplicitImportsUnambiguityForFunction.fir.kt new file mode 100644 index 00000000000..35903947784 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ExplicitImportsUnambiguityForFunction.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt +package a + +fun X(p: Int) {} + +// FILE: b.kt +package b + +fun X(): Int = 1 + +// FILE: c.kt +package c + +import b.X +import a.X + +fun foo() { + val v: Int = X() +} diff --git a/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.fir.kt new file mode 100644 index 00000000000..770dd1bcc1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +package a.x + +class X + +// FILE: b.kt +package b.x + +class X + +// FILE: c.kt +package c + +import a.x +import b.x + +class Y : x.X \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportClassClash.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportClassClash.fir.kt new file mode 100644 index 00000000000..ecab6f23f24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportClassClash.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: 1.kt +package a + +class someFun() {} +fun someFun(i: Int) {} + +class someVal() {} +val Int.someVal: Int get() = 3 + +class A + +class B + +// FILE: 2.kt +package b + +class someFun +class someVal +class someAll + +fun A() {} + +class B + + +// FILE: 3.kt +import a.someFun +import b.someFun + +import a.someVal +import b.someVal + +import a.A +import b.A + +// FILE: 4.kt +import b.* +import a.B + +// FILE: 5.kt +package b + +import a.B + +// FILE: 6.kt +import a.B +import b.B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromCompanionObject.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportFromCompanionObject.fir.kt new file mode 100644 index 00000000000..6c01868ec0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportFromCompanionObject.fir.kt @@ -0,0 +1,138 @@ +// FILE: a.kt +package a + +class C1 { + companion object O { + class A + object B + + fun bar() {} + } +} + + +class C2 { + companion object S { + + val prop: String = "" + + fun o(s: String) = Unit + fun o(i: Int) = Unit + + fun Int.ext() = Unit + var String.ext: Int + get() = 3 + set(i) { + } + + fun A(c: Int) = A() + + class A() + + fun genericFun(t: T, t2: T): T = t + } +} + +open class Base { + fun f() { + } + + fun g(t: T) { + } + + val p = 1 + val Int.ext: Int + get() = 4 +} + +interface BaseI { + fun fromI(): Int = 3 + + fun genericFromI(t: T) = t +} + +class C3 { + companion object K: Base(), BaseI { + val own: String = "" + } +} + +// FILE: b.kt +package b + +import a.C1.O.* + +fun testErroneusAllUnderImportFromObject() { + A() + B + bar() +} + +// FILE: c.kt +package c + +import a.C2.S.prop +import a.C2.S.o +import a.C2.S.ext +import a.C2.S.A +import a.C2.S.genericFun +import a.C2.S.ext as extRenamed + +fun testImportFromObjectByName() { + prop + o("a") + o(3) + 3.ext() + "".ext = 3 + val c: Int = "".ext + + 3.extRenamed() + "".extRenamed = 3 + val c2: Int = "".extRenamed + + A() + A(3) + + val a: Int = genericFun(3, 3) + val s: String = genericFun("A", "b") + val b: Boolean = genericFun(true, false) +} + +fun t(t: T): T { + return genericFun(t, t) +} + +// FILE: d.kt +package d + +import a.C2.S.prop as renamed + +fun testFunImportedFromObjectHasNoDispatchReceiver(l: a.C2.S) { + l.renamed + l.prop + renamed +} + +// FILE: e.kt + +package e + +import a.C3.K.f +import a.C3.K.g +import a.C3.K.p +import a.C3.K.own +import a.C3.K.fromI +import a.C3.K.genericFromI +import a.C3.K.ext + +fun testMembersFromSupertypes() { + f() + g("") + p + fromI() + + genericFromI(3) + genericFromI("a") + + own +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.fir.kt new file mode 100644 index 00000000000..08d4242283a --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.fir.kt @@ -0,0 +1,8 @@ +package a + +import a.A as ER + +interface A { + val a: A + val b: ER +} diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromObject.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportFromObject.fir.kt new file mode 100644 index 00000000000..8da9103fbc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportFromObject.fir.kt @@ -0,0 +1,132 @@ +// FILE: a.kt +package a + +object O { + class A + object B + + fun bar() {} +} + + +object S { + + val prop: String = "" + + fun o(s: String) = Unit + fun o(i: Int) = Unit + + fun Int.ext() = Unit + var String.ext: Int + get() = 3 + set(i) { + } + + fun A(c: Int) = A() + + class A() + + fun genericFun(t: T, t2: T): T = t +} + +open class Base { + fun f() { + } + + fun g(t: T) { + } + + val p = 1 + val Int.ext: Int + get() = 4 +} + +interface BaseI { + fun fromI(): Int = 3 + + fun genericFromI(t: T) = t +} + +object K: Base(), BaseI { + val own: String = "" +} + +// FILE: b.kt +package b + +import a.O.* + +fun testErroneusAllUnderImportFromObject() { + A() + B + bar() +} + +// FILE: c.kt +package c + +import a.S.prop +import a.S.o +import a.S.ext +import a.S.A +import a.S.genericFun +import a.S.ext as extRenamed + +fun testImportFromObjectByName() { + prop + o("a") + o(3) + 3.ext() + "".ext = 3 + val c: Int = "".ext + + 3.extRenamed() + "".extRenamed = 3 + val c2: Int = "".extRenamed + + A() + A(3) + + val a: Int = genericFun(3, 3) + val s: String = genericFun("A", "b") + val b: Boolean = genericFun(true, false) +} + +fun t(t: T): T { + return genericFun(t, t) +} + +// FILE: d.kt +package d + +import a.S.prop as renamed + +fun testFunImportedFromObjectHasNoDispatchReceiver(l: a.S) { + l.renamed + l.prop + renamed +} + +// FILE: e.kt + +package e + +import a.K.f +import a.K.g +import a.K.p +import a.K.own +import a.K.fromI +import a.K.genericFromI +import a.K.ext + +fun testMembersFromSupertypes() { + f() + g("") + p + fromI() + + genericFromI(3) + genericFromI("a") + + own +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromRootPackage.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportFromRootPackage.fir.kt new file mode 100644 index 00000000000..1c31f98ab46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportFromRootPackage.fir.kt @@ -0,0 +1,32 @@ +// FILE: rootPackage.kt +class Klass { + class Nested +} + +class NotImported + +fun function() = "" + +val property = "" + +// FILE: anotherFromRootPackage.kt +fun foo(): Klass { + function() + property + return Klass() +} + +// FILE: anotherFromRootPackage.kt +package pkg + +import Klass +import Klass.Nested +import function +import property + +fun foo(): Klass { + function() + property + return Klass() +} + +val v: Nested = Nested() +val x: NotImported = NotImported() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportHidingDefinitionInTheSameFile.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportHidingDefinitionInTheSameFile.fir.kt new file mode 100644 index 00000000000..3f3a6226ebc --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportHidingDefinitionInTheSameFile.fir.kt @@ -0,0 +1,9 @@ +// ResolveSession.resolveToDescriptor used to crash on such code, so we just check that it's ok now +import kotlin.Double +import kotlin.collections.List +import kotlin.arrayOfNulls + +class List {} + +fun arrayOfNulls(){} +val arrayOfNulls: Int = 0 diff --git a/compiler/testData/diagnostics/tests/imports/ImportNestedWithDifferentName.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportNestedWithDifferentName.fir.kt new file mode 100644 index 00000000000..f5d156292aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportNestedWithDifferentName.fir.kt @@ -0,0 +1,10 @@ +package a + +import a.A.Nested as X + +interface A { + class Nested + + val a: Nested + val b: X +} diff --git a/compiler/testData/diagnostics/tests/imports/ImportObjectAndUseAsSupertype.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportObjectAndUseAsSupertype.fir.kt new file mode 100644 index 00000000000..4b4b9306d5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportObjectAndUseAsSupertype.fir.kt @@ -0,0 +1,19 @@ +// FILE: a.kt + +package foo + +object Bar { + fun bar() {} +} + +// FILE: b.kt + +package baz + +import foo.Bar + +class C: Bar + +fun test() { + Bar.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportObjectHidesCurrentPackage.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportObjectHidesCurrentPackage.fir.kt new file mode 100644 index 00000000000..677f6f9f383 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportObjectHidesCurrentPackage.fir.kt @@ -0,0 +1,12 @@ +//FILE:a.kt +package a + +// no error is reported +import b.a + +fun foo() = a + +//FILE:b.kt +package b + +object a {} diff --git a/compiler/testData/diagnostics/tests/imports/ImportOverloadFunctions.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportOverloadFunctions.fir.kt new file mode 100644 index 00000000000..9e93dd8d3d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportOverloadFunctions.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// FILE: 1.kt +package k + +private fun zero() {} +private fun zero(a: Int) {} +private fun zero(a: String) {} + +fun one() {} +private fun one(a: Int) {} +private fun one(a: String) {} + +fun two() {} +fun two(a: Int) {} +private fun two(a: String) {} + +fun all() {} +fun all(a: Int) {} +fun all(a: String) {} + +// FILE: 2.kt + +import k.zero +import k.one +import k.two +import k.all + +fun test() { + zero() + zero(1) + zero("") + + one() + one(1) + one("") + + two() + two(1) + two("") + + all() + all(1) + all("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt new file mode 100644 index 00000000000..434a8a9cf82 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt @@ -0,0 +1,37 @@ +package test + +import test.TopLevelClass.NestedClass +import test.TopLevelClass.NestedClass.InNested +import test.TopLevelEnum.NestedEnum.NestedEntry +import test.TopLevelObject.inObject +import test.TopLevelEnum.E1 + +private class TopLevelClass { + private class NestedClass { + class InNested + } + + fun test() { + InNested() + } +} + +private enum class TopLevelEnum(private val e: NestedEnum) { + E1(NestedEntry); + + private enum class NestedEnum { + NestedEntry; + } +} + +private object TopLevelObject { + fun inObject() {} +} + +fun testAccess() { + NestedClass() + E1 + InNested() + NestedEntry + inObject() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt new file mode 100644 index 00000000000..af6f1c5e93f --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt @@ -0,0 +1,26 @@ +// FILE: A.kt + +class A { + private class Nested { + object O1 + } +} + +// FILE: B.java + +public class B { + private static class JC { + public static class JC1 { + } + } +} + +// FILE: C.kt + +import A.Nested.* +import B.JC.JC1 + +fun test() { + O1 + JC1() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt new file mode 100644 index 00000000000..ca8d7b91a77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt @@ -0,0 +1,32 @@ +package test + +import test.TopLevelClass.NestedClass.* +import test.TopLevelEnum.NestedEnum.* +import test.TopLevelEnum.* + +private class TopLevelClass { + private class NestedClass { + class A1 + object A2 + } + + fun test() { + A1() + A2 + } +} + +private enum class TopLevelEnum(private val e: NestedEnum) { + E1(NestedEntry); + + private enum class NestedEnum { + NestedEntry; + } +} + +fun testAccess() { + E1 + NestedEntry + A1() + A2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.fir.kt new file mode 100644 index 00000000000..bad5d7c283b --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportProtectedClass.fir.kt @@ -0,0 +1,14 @@ +package p + +import p.Foo.Nested + +open class Foo { + protected class Nested +} + +class Bar: Foo() { + protected fun foo(): Nested? = null +} + +private fun foo(): Nested? = null +private fun bar(): p.Foo.Nested? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.fir.kt new file mode 100644 index 00000000000..d93874eb976 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.fir.kt @@ -0,0 +1,23 @@ +// FILE: b.kt +// KT-355 Resolve imports after all symbols are built + +package a + import b.* + val x : X = X() + +// FILE: b.kt +package b + class X() { + + } + +// FILE: b.kt +package c + import d.X + val x : X = X() + +// FILE: b.kt +package d + class X() { + + } diff --git a/compiler/testData/diagnostics/tests/imports/ImportTwoTimes.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportTwoTimes.fir.kt new file mode 100644 index 00000000000..75aba1ca39c --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportTwoTimes.fir.kt @@ -0,0 +1,14 @@ +// FILE: a.kt + +package weatherForecast + +fun weatherToday() = "snow" + +// FILE: b.kt + +package myApp + +import weatherForecast.weatherToday +import weatherForecast.weatherToday + +fun needUmbrella() = weatherToday() == "rain" diff --git a/compiler/testData/diagnostics/tests/imports/ImportTwoTimesStar.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportTwoTimesStar.fir.kt new file mode 100644 index 00000000000..83e6d3f3e28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportTwoTimesStar.fir.kt @@ -0,0 +1,14 @@ +// FILE: a.kt + +package weatherForecast + +fun weatherToday() = "snow" + +// FILE: b.kt + +package myApp + +import weatherForecast.* +import weatherForecast.* + +fun needUmbrella() = weatherToday() == "rain" diff --git a/compiler/testData/diagnostics/tests/imports/Imports.fir.kt b/compiler/testData/diagnostics/tests/imports/Imports.fir.kt new file mode 100644 index 00000000000..e0d485a9252 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/Imports.fir.kt @@ -0,0 +1,102 @@ +// !WITH_NEW_INFERENCE +// FILE:a.kt +package a + +import b.B //class +import b.foo //function +import b.ext //extension function +import b.value //property +import b.C.Companion.bar //function from companion object +import b.C.Companion.cValue //property from companion object +import b.constant.fff //function from val +import b.constant.dValue //property from val +import b.constant +import b.E.Companion.f //val from companion object +import smth.illegal +import b.C.smth.illegal +import b.bar.smth +import b.bar.* +import b.unr.unr.unr +import unr.unr.unr + +fun test(arg: B) { + foo(value) + arg.ext() + + bar() + foo(cValue) + + fff(dValue) + + constant.fff(constant.dValue) + + f.f() +} + +// FILE:b.kt +package b + +class B() {} + +fun foo(i: Int) = i + +fun B.ext() {} + +val value = 0 + +class C() { + companion object { + fun bar() {} + val cValue = 1 + } +} + +class D() { + fun fff(s: String) = s + val dValue = "w" +} + +val constant = D() + +class E() { + companion object { + val f = F() + } +} + +class F() { + fun f() {} +} + +fun bar() {} + +//FILE:c.kt +package c + +import c.C.* + +object C { + fun f() { + } + val i = 348 +} + +fun foo() { + if (i == 3) f() +} + +//FILE:d.kt +package d + +import d.A.Companion.B +import d.A.Companion.C + +val b : B = B() +val c : B = C + +class A() { + companion object { + open class B() {} + object C : B() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ImportsConflicting.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportsConflicting.fir.kt new file mode 100644 index 00000000000..32368bda9c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ImportsConflicting.fir.kt @@ -0,0 +1,15 @@ +//FILE:a.kt +package a + +import b.foo +import c.foo // TODO: need warning here + +//FILE:b.kt +package b + +fun foo() = 2 + +//FILE:c.kt +package c + +fun foo() = 1 diff --git a/compiler/testData/diagnostics/tests/imports/InaccessiblePrivateClass.fir.kt b/compiler/testData/diagnostics/tests/imports/InaccessiblePrivateClass.fir.kt new file mode 100644 index 00000000000..5a7a9668d1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/InaccessiblePrivateClass.fir.kt @@ -0,0 +1,18 @@ +// FILE: a.kt +package p1 + +private class X +private class Y + +// FILE: b.kt +package p2 + +class X + +// FILE: c.kt +package p1 + +import p2.* + +val x: X = X() +val y: Y = Y() diff --git a/compiler/testData/diagnostics/tests/imports/JavaPackageLocalClassNotImported.fir.kt b/compiler/testData/diagnostics/tests/imports/JavaPackageLocalClassNotImported.fir.kt new file mode 100644 index 00000000000..db191bd4cda --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/JavaPackageLocalClassNotImported.fir.kt @@ -0,0 +1,12 @@ +// FILE: File.kt +package pack + +public open class InetAddressImpl + +// FILE: Main.kt +package a + +import java.net.* // should not import java.net.InetAddressImpl because it's package local +import pack.* + +class X : InetAddressImpl() // should resolve to our pack.InetAddressImpl diff --git a/compiler/testData/diagnostics/tests/imports/MalformedImports.fir.kt b/compiler/testData/diagnostics/tests/imports/MalformedImports.fir.kt new file mode 100644 index 00000000000..9b3737637de --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/MalformedImports.fir.kt @@ -0,0 +1,9 @@ +package test + +import some. +import .some +import .kotlin +import kotlin. +import +import . +import * \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt b/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt new file mode 100644 index 00000000000..520a6fd70bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: a.kt +package a + +class A { + class B +} + +// FILE: b.kt +package a + +class D { + class B +} + +// FILE: c.kt +import a.A.B +import a.D.B + +fun test(b: B) { + B() +} + +// FILE: d.kt +import a.A.* +import a.D.* + +// todo ambiguvity here +fun test2(b: B) { + B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/OperatorRenameOnImport.fir.kt b/compiler/testData/diagnostics/tests/imports/OperatorRenameOnImport.fir.kt new file mode 100644 index 00000000000..46466062ea0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/OperatorRenameOnImport.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: a.kt +package a + +interface A + +operator fun A.plus(other: A): A = this + +// FILE: b.kt +package b + +import a.A +import a.plus as minus + +fun test(a1: A, a2: A) = + a1 - a2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.fir.kt b/compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.fir.kt new file mode 100644 index 00000000000..bea3b640a56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.fir.kt @@ -0,0 +1,17 @@ +// FILE: File1.kt +package pack1 + +private class SomeClass + +// FILE: File2.kt +package pack2 + +public open class SomeClass + +// FILE: Main.kt +package a + +import pack1.* +import pack2.* + +class X : SomeClass() diff --git a/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.fir.kt b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.fir.kt new file mode 100644 index 00000000000..20803950834 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PackageLocalClassReferencedError.fir.kt @@ -0,0 +1,11 @@ +// FILE: File1.kt +package pack1 + +private open class SomeClass + +// FILE: Main.kt +package a + +import pack1.* + +private class X : SomeClass() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PackageVsClass.fir.kt b/compiler/testData/diagnostics/tests/imports/PackageVsClass.fir.kt new file mode 100644 index 00000000000..a333f14b679 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PackageVsClass.fir.kt @@ -0,0 +1,152 @@ +// MODULE: m1 +// FILE: a.kt +package a.b + +fun ab_fun() {} + +class c { + fun ab_c() {} + + class d { + fun ab_cd() {} + } +} + +// MODULE: m2 +// FILE: b.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.a_fun +import a.b + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + val a_bc2 = b.c() + a_bc2.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + val ab_cd2 = c.d() + ab_cd2.ab_cd() + + ab_fun() +} + +// FILE: d.kt +package a + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + val a_bc2 = b.c() + a_bc2.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + val ab_cd2 = c.d() + ab_cd2.ab_cd() + + ab_fun() +} + +//---- Changed dependence order +// MODULE: m4(m2, m1) +// FILE: c.kt +import a.a_fun +import a.b + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + val a_bc2 = b.c() + a_bc2.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + val ab_cd2 = c.d() + ab_cd2.ab_cd() + + ab_fun() +} + +// FILE: d.kt +package a + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + val a_bc2 = b.c() + a_bc2.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + val ab_cd2 = c.d() + ab_cd2.ab_cd() + + ab_fun() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.fir.kt b/compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.fir.kt new file mode 100644 index 00000000000..7510fdfe1bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.fir.kt @@ -0,0 +1,21 @@ +// FILE: File1.kt +package pack1 + +public class SomeClass { + private class N + public open class PublicNested +} + +// FILE: File2.kt +package pack2 + +public open class N + +// FILE: Main.kt +package a + +import pack1.SomeClass.* +import pack2.* + +class X : N() +class Y : PublicNested() diff --git a/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.fir.kt b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.fir.kt new file mode 100644 index 00000000000..a6fda12428f --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PrivateClassReferencedError.fir.kt @@ -0,0 +1,14 @@ +// FILE: File1.kt +package pack1 + +public class SomeClass { + private class N + public open class PublicNested +} + +// FILE: Main.kt +package a + +import pack1.SomeClass.* + +private class X : N() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/RenameOnImport.fir.kt b/compiler/testData/diagnostics/tests/imports/RenameOnImport.fir.kt new file mode 100644 index 00000000000..7e82d721032 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/RenameOnImport.fir.kt @@ -0,0 +1,22 @@ +// FILE: a.kt +package a + +val x = 1 +val y = 1 + +// FILE: b.kt +package b + +val x = "" + +// FILE: c.kt +package c + +import a.x as AX +import a.* +import b.* +import a.y as AY + +val v1: Int = AX +val v2: String = x +val v3 = y diff --git a/compiler/testData/diagnostics/tests/imports/StarImportFromObject.fir.kt b/compiler/testData/diagnostics/tests/imports/StarImportFromObject.fir.kt new file mode 100644 index 00000000000..8302d8698ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/StarImportFromObject.fir.kt @@ -0,0 +1,47 @@ +package a + +import a.A.* +import a.A.C +import a.A.C.* +import a.A.D.* +import a.A.C.* +import a.A.C.G +import a.A.E.J.* +import a.A.CO.* +import a.A.CO + +import a.B.C.* +import a.B.C.A.* +import a.B.C.D.* + +import a.E.* +import a.E.E1 +import a.E.E2.* + +class A { + object C { + object G + } + object D { + + } + + class E { + object J + } + + companion object CO { + object H + } +} + +enum class E { + E1, E2 +} + +object B { + class C { + object A + object D + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/SyntaxError.fir.kt b/compiler/testData/diagnostics/tests/imports/SyntaxError.fir.kt new file mode 100644 index 00000000000..1dd3c4ec94c --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/SyntaxError.fir.kt @@ -0,0 +1,60 @@ +// FILE:a.kt +package a + +val foo = 2 +fun bar() {} + +class B { + val foo = 2 + fun bar() {} + + class C +} + +// FILE:b.kt +package a.b.c + +class D { + class E { + + } +} + + +// FILE:c.kt +import ; +import . +import a. ; +import .a. ; +import .a.b ; +import .a.B ; +import a.B. ; +import a.B.C. ; +import a.B.foo. ; +import a.B.bar. ; +import a.b. ; +import a.b.c. ; +import a.%.b.c. ; +import a.b.c.D. ; +import a.b.c.D.E. ; + +// FILE:d.kt +import +import . +import a. +import .a. +import .a.b +import .a.B +import a.B. as +import a.B. as A +import a.B. +import a.B.C. +import a.B.foo. +import a.B.bar. +import a.b. +import a.b.c. +import a.%.b.c. +import a.b.c.D. +import a.b.c.D.E. + +import a?.b \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.fir.kt b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.fir.kt new file mode 100644 index 00000000000..4317d323edc --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.fir.kt @@ -0,0 +1,68 @@ +// MODULE: m1 +// FILE: a.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: m2 +// FILE: b.kt +fun _fun() {} + +class a { + fun _a() {} + + class b { + fun _ab() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.a_fun +import a.b + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +// FILE: d.kt +fun test2(_a: a) { + _a._a() + + val _ab: a.b = a.b() + _ab._ab() + + val _ab2 = a.b() + _ab2._ab() + + _fun() +} + +// FILE: e.kt +import a +import _fun + +fun test3(_a: a) { + _a._a() + + val _ab: a.b = a.b() + _ab._ab() + + val _ab2 = a.b() + _ab2._ab() + + _fun() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/WrongImport.fir.kt b/compiler/testData/diagnostics/tests/imports/WrongImport.fir.kt new file mode 100644 index 00000000000..5cd8ecce24e --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/WrongImport.fir.kt @@ -0,0 +1,78 @@ +// FILE:a.kt +package a.b + +// FILE:a.kt +package a + +val foo = object { + fun bar() {} +} + +fun bar() = object { + val foo = 239 +} + +class B { + val foo = object { + fun bar() {} + } + + fun bar() = object { + val foo = 239 + } +} + +object C { + val foo = object { + fun bar() {} + } + + fun bar() = object { + val foo = 239 + } + + class Nested +} + +class D { + companion object { + val foo = object { + fun bar() {} + } + + fun bar() = object { + val foo = 239 + } + } +} + + +// FILE:b.kt +import a +import a.b + +import a.foo +import a.foo.bar +import a.bar +import a.bar.foo + +import a.B.foo +import a.B.foo.bar +import a.B.bar +import a.B.bar.foo + +import a.C.foo +import a.C.foo.bar +import a.C.bar +import a.C.bar.foo +import a.C.Nested + +import a.D.foo +import a.D.foo.bar +import a.D.bar +import a.D.bar.foo + +import a.D.Companion.foo +import a.D.Companion.foo.bar +import a.D.Companion.bar +import a.D.Companion.bar.foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImport.fir.kt b/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImport.fir.kt new file mode 100644 index 00000000000..3fd65fd6d42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImport.fir.kt @@ -0,0 +1,13 @@ +// FILE: importFunctionWithAllUnderImport.kt +package test + +import testOther.* + +class B: A() +val inferTypeFromImportedFun = testFun() + +// FILE: importFunctionWithAllUnderImportOther.kt +package testOther + +open class A +fun testFun() = 1 diff --git a/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImportAfterNamedImport.fir.kt b/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImportAfterNamedImport.fir.kt new file mode 100644 index 00000000000..d5f7005f3bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImportAfterNamedImport.fir.kt @@ -0,0 +1,22 @@ +//FILE:mainFile.kt +//---------------------------------------------------------------------------------- +package test + +import testing.other.* +import testing.TestFun + +// Resolve shouldn't be ambiguous +val a = TestFun() + + +//FILE:testing.kt +//---------------------------------------------------------------------------------- +package testing + +class TestFun + +//FILE:testingOther.kt +//---------------------------------------------------------------------------------- +package testing.other + +fun TestFun() = 12 diff --git a/compiler/testData/diagnostics/tests/imports/invisibleFakeReferenceInImport.fir.kt b/compiler/testData/diagnostics/tests/imports/invisibleFakeReferenceInImport.fir.kt new file mode 100644 index 00000000000..1f21b6bb9aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/invisibleFakeReferenceInImport.fir.kt @@ -0,0 +1,16 @@ +// FILE: A.kt + +import B.foo + +fun test() { + foo +} + +// FILE: B.kt +object B : C() + +// FILE: C.kt + +open class C { + private var foo: String = "abc" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/kt13112.fir.kt b/compiler/testData/diagnostics/tests/imports/kt13112.fir.kt new file mode 100644 index 00000000000..2443edbe356 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/kt13112.fir.kt @@ -0,0 +1,46 @@ +// FILE: 1.kt + +package anotherpackage + +interface IInterfaceInput { + fun doSomething(input: T) +} + +// FILE: 2.kt + +package anotherpackage + +interface IInterfaceOutput { + fun doSomething(): T? +} + +// FILE: 3.kt + +package mypackage.nestedpackage + +import mypackage.nestedpackage.Bar.Baz +import anotherpackage.IInterfaceInput +import anotherpackage.IInterfaceOutput + +class Foo() { + class FooNest { + val bar = Bar() + + fun myFun(): List { + return listOf(bar.doSomething()) + } + } +} + +class Bar() : IInterfaceInput, IInterfaceOutput { + override fun doSomething(input: Baz) { + throw UnsupportedOperationException("not implemented") + } + + override fun doSomething(): Baz { + throw UnsupportedOperationException("not implemented") + } + +} + +data class Baz(val myField: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/propertyClassFileDependencyRecursion.fir.kt b/compiler/testData/diagnostics/tests/imports/propertyClassFileDependencyRecursion.fir.kt new file mode 100644 index 00000000000..92a05929628 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/propertyClassFileDependencyRecursion.fir.kt @@ -0,0 +1,17 @@ +// FILE: propertyClassFileDependencyRecursion.kt +package test + +import other.prop + +// Note: "prop" is expected to be unresolved and replaced to Any +class PropType: prop + +// Note: this time "prop" should be resolved and type should be inferred for "checkTypeProp" +val checkTypeProp = prop + +// FILE: propertyClassFileDependencyRecursionOther.kt +package other + +import test.PropType + +val prop: PropType? = null diff --git a/compiler/testData/diagnostics/tests/imports/twoImportLists.fir.kt b/compiler/testData/diagnostics/tests/imports/twoImportLists.fir.kt new file mode 100644 index 00000000000..ac3a130affe --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/twoImportLists.fir.kt @@ -0,0 +1,105 @@ +// !WITH_NEW_INFERENCE +// FILE:a.kt +package a + +<<< FOOO +import b.B //class +import b.foo //function +import b.ext //extension function +import b.value //property +import b.C.Companion.bar //function from companion object +import b.C.Companion.cValue //property from companion object +import b.constant.fff //function from val +import b.constant.dValue //property from val +import smth.illegal +import b.C.smth.illegal + +<<<HEAD +import b.bar.smth +import b.bar.* +import b.unr.unr.unr +import unr.unr.unr +import b.constant +import b.E.Companion.f //val from companion object + +fun test(arg: B) { + foo(value) + arg.ext() + + bar() + foo(cValue) + + fff(dValue) + + constant.fff(constant.dValue) + + f.f() +} + +// FILE:b.kt +package b + +class B() {} + +fun foo(i: Int) = i + +fun B.ext() {} + +val value = 0 + +class C() { + companion object { + fun bar() {} + val cValue = 1 + } +} + +class D() { + fun fff(s: String) = s + val dValue = "w" +} + +val constant = D() + +class E() { + companion object { + val f = F() + } +} + +class F() { + fun f() {} +} + +fun bar() {} + +//FILE:c.kt +package c + +import c.C.* + +object C { + fun f() { + } + val i = 348 +} + +fun foo() { + if (i == 3) f() +} + +//FILE:d.kt +package d + +import d.A.Companion.B +import d.A.Companion.C + +val b : B = B() +val c : B = C + +class A() { + companion object { + open class B() {} + object C : B() {} + } +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/NoSenselessComparisonForErrorType.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/NoSenselessComparisonForErrorType.fir.kt new file mode 100644 index 00000000000..cb1263a3d90 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/NoSenselessComparisonForErrorType.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo() { + val a = getErrorType() + if (a == null) { //no senseless comparison + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/SupertypeOfErrorType.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/SupertypeOfErrorType.fir.kt new file mode 100644 index 00000000000..f821e212a64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/SupertypeOfErrorType.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +package a + +import java.util.Date +import java.util.Comparator + +fun foo() { + + val c: Comparator = comparator { date1, date2 -> + if (date1 != null && date2 != null) { + date1.compareTo(date2) * -11 + } else { + 11 + } + } +} + +fun bar(i: Int, a: U) { + val r = if (true) i else a + val b: Any = r +} + +//from standard library +public inline fun comparator(fn: (T,T) -> Int): Comparator {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.fir.kt new file mode 100644 index 00000000000..28f07365aa7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.fir.kt @@ -0,0 +1,9 @@ +package b + +fun main() { + var ints : Array = arrayOfNulls(31) + + ints[0] = 4; ints[11] = 5; ints[2] =7 + for(i in 0..ints.size) + ints[i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.fir.kt new file mode 100644 index 00000000000..6a13250ac61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +package d + +interface A + +fun infer(a: A) : T {} + +fun test(nothing: Nothing?) { + val i = infer(nothing) +} + +fun sum(a : IntArray) : Int { +for (n +return "?" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt new file mode 100644 index 00000000000..5b570ea91e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE + +fun test1() { + if (rr) { + if (l) { + a.q() + } + else { + a.w() + } + } + else { + if (n) { + a.t() + } + else { + a.u() + } + } +} + +fun test2(l: List) { + l.map { + it!! + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/arrayExpression.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/arrayExpression.fir.kt new file mode 100644 index 00000000000..d25e0ca5648 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/arrayExpression.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +package bar + +fun main() { + class Some + + Some[] names = ["ads"] +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.fir.kt new file mode 100644 index 00000000000..439724d5a0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/checkBackingFieldException.fir.kt @@ -0,0 +1,17 @@ +package h + +class Square() { + var size : Double = + set(value) { + $area = size * size + } + + var area : Double + private set +} + +fun main() { + val s = Square() + + s.size = 2.0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/completeFunctionArgumentsOfNestedCalls.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/completeFunctionArgumentsOfNestedCalls.fir.kt new file mode 100644 index 00000000000..96dadd79db6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/completeFunctionArgumentsOfNestedCalls.fir.kt @@ -0,0 +1,8 @@ +package c + +fun demo() { + val bar = 51 + fun map(f : fun + val foo = 3; + bar + map { foo } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterDotSelectorExpected.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterDotSelectorExpected.fir.kt new file mode 100644 index 00000000000..c983234e53f --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterDotSelectorExpected.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo(x: Any) { + x. + val foo = 1 + + x. + fun bar() = 2 + + x. + fun String.() = 3 + + var a = 24. + var b = 42.0 +} + +class A { + val z = "a". + val x = 4 + + val y = "b". + fun baz() = 5 + + val q = "c". + fun String.() = 6 + + var a = 24. + var b = 42.0 +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterIncompleteElvis.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterIncompleteElvis.fir.kt new file mode 100644 index 00000000000..1ddc5f31308 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/declarationAfterIncompleteElvis.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +fun foo(x: Any?) { + x ?: + val foo = 1 + + x ?: + fun bar() = 2 + + val res: String.() -> Int = null ?: + fun String.() = 3 +} + +class A { + val z = null ?: + val x = 4 + + val y = null ?: + fun baz() = 5 + + val q = null ?: + fun String.() = 6 +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.fir.kt new file mode 100644 index 00000000000..b397ef72dc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.fir.kt @@ -0,0 +1 @@ +fun foo() = diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.fir.kt new file mode 100644 index 00000000000..f773d983a7d --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.fir.kt @@ -0,0 +1 @@ +fun \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.fir.kt new file mode 100644 index 00000000000..36c7d2ced15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.fir.kt @@ -0,0 +1 @@ +class A : (categoryName: ) { \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteEnumReference.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteEnumReference.fir.kt new file mode 100644 index 00000000000..ef56e1ca39a --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteEnumReference.fir.kt @@ -0,0 +1,11 @@ +enum class E { + A, + B, + C +} + +fun foo() { + val e = E. +} + + diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.fir.kt new file mode 100644 index 00000000000..f64b8ae0cff --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.fir.kt @@ -0,0 +1,3 @@ +package c + +val i = diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.fir.kt new file mode 100644 index 00000000000..400320515ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.fir.kt @@ -0,0 +1,3 @@ +package c + +val i : String get() = \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.fir.kt new file mode 100644 index 00000000000..e169c711d74 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.fir.kt @@ -0,0 +1,3 @@ +fun test(a: Any) { + when (a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.fir.kt new file mode 100644 index 00000000000..b0c6be61c67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.fir.kt @@ -0,0 +1 @@ +fun bar() diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt new file mode 100644 index 00000000000..859e1d1b28f --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +package b + +fun foo(map: Map) : R = throw Exception() + +fun getMap() : Map = throw Exception() + +fun bar123() { + foo(getMap( +} + diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt new file mode 100644 index 00000000000..d611ecb41b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt @@ -0,0 +1,3 @@ +package typeReferenceError + +class Pair<:(val c: fun main() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.fir.kt new file mode 100644 index 00000000000..054ff973a76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.fir.kt @@ -0,0 +1,43 @@ +// VAL +class A( + val + val x: Int, + val + private val z: Int, + val +) + +val +fun foo() {} + +class B { + val + fun foo() {} + + fun bar() { + val + fun foo() {} + } +} + +// VAR +class C( + var + val x: Int, + var + private val z: Int, + var +) + +var +fun baz() {} + +class D { + var + fun foo() {} + + fun bar() { + var + fun foo() {} + } +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameBeforeNextDeclarationWithModifiers.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameBeforeNextDeclarationWithModifiers.fir.kt new file mode 100644 index 00000000000..0b315e01230 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameBeforeNextDeclarationWithModifiers.fir.kt @@ -0,0 +1,15 @@ +abstract class A { + private val + // private is parsed as val's identifier + private fun foo1() { + } + + private val + protected abstract fun foo2() + + private val + fun foo3() { + } + + private val private fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameInBlock.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameInBlock.fir.kt new file mode 100644 index 00000000000..f444cae9c97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valWithNoNameInBlock.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun println(x: String) { +} + +fun run(block: () -> Unit) {} + +val propertyNameOnTheNextLine = 1 + +fun foo() { + val + println("abc") + + val + run { + println("abc") + } + + val + if (1 == 1) { + + } + + val + (1 + 2) + + // `propertyNameOnTheNextLine` parsed as simple name expression + val + propertyNameOnTheNextLine + + val + // comment + propertyNameOnTheNextLine + + val /* comment */ + propertyNameOnTheNextLine + + // Correct properties + val + property1 = 1 + + val + propertyWithBy by lazy { 1 } + + val + propertyWithType: Int + + val + (a, b) = 1 +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/illegalSelectorCallableReference.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/illegalSelectorCallableReference.fir.kt new file mode 100644 index 00000000000..3ed64132ea1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/illegalSelectorCallableReference.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun test() { + "a"."b"::foo + "a"."b"::class + "a"."b"."c"::foo + "a"."b"."c"::class +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/inExpr.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/inExpr.fir.kt new file mode 100644 index 00000000000..e53e01564df --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/inExpr.fir.kt @@ -0,0 +1,5 @@ +package l + +fun test(a: Int) { + if (a in ) {} //a is not unresolved +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.fir.kt new file mode 100644 index 00000000000..aa121282304 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.fir.kt @@ -0,0 +1,30 @@ +package sum + +import java.util.* +fun sum(a : IntArray) : Int { + // Write your solution here + res = 0 + for (e in a) + res += +} +fun main() { + test(0) + test(1, 1) + test(-1, -1, 0) + test(6, 1, 2, 3) + test(6, 1, 1, 1, 1, 1, 1) +} +// HELPER FUNCTIONS +fun test(expectedSum : Int, vararg data : Int) { + val actualSum = sum(data) + assertEquals(actualSum, expectedSum, "\ndata = ${Arrays.toString(data)}\n" + + "sum(data) = ${actualSum}, but must be $expectedSum ") +} +fun assertEquals(actual : T?, expected : T?, message : Any? = null) { + if (actual != expected) { + if (message == null) + throw AssertionError() + else + throw AssertionError(message) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.fir.kt new file mode 100644 index 00000000000..bd83db1679b --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.fir.kt @@ -0,0 +1,3 @@ +package a + +fun foo(a: Any) = a == \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.fir.kt new file mode 100644 index 00000000000..9144e6fee12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.fir.kt @@ -0,0 +1,14 @@ +fun test1() { + try { + + } catch () +} + +fun test2() { + try { } +} + +fun test3() { + try { + } catch ({}) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/kt1955.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/kt1955.fir.kt new file mode 100644 index 00000000000..b7aff9093fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/kt1955.fir.kt @@ -0,0 +1,8 @@ +//KT-1955 Half a file is red on incomplete code + +package b + +fun foo() { + val a = 1 + + diff --git a/compiler/testData/diagnostics/tests/incompleteCode/kt2014.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/kt2014.fir.kt new file mode 100644 index 00000000000..0d63fefe59b --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/kt2014.fir.kt @@ -0,0 +1,20 @@ +//KT-2014 Better diagnostic when using property syntax to call a method +package c + +class Foo { + fun prop() : Int = 1 + fun bar(i: Int) : Int = i + + val a : Int = 1 +} + +fun x(f : Foo) { + f.prop + f.bar + + f.a() + c() + R() +} + +object R {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/kt4866UnresolvedArrayAccess.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/kt4866UnresolvedArrayAccess.fir.kt new file mode 100644 index 00000000000..63e21a0e0a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/kt4866UnresolvedArrayAccess.fir.kt @@ -0,0 +1,5 @@ +//KT-4866 Resolve does not work inside brackets with unresolved reference before + +fun test(i: Int, j: Int) { + foo[i, j] +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/plusOnTheRight.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/plusOnTheRight.fir.kt new file mode 100644 index 00000000000..7022fa3623b --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/plusOnTheRight.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +//EA-35646 +package a + +class MyClass1 { + public operator fun unaryPlus() {} +} + +fun main(arg: MyClass1) { + arg+ +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/pseudocodeTraverseNextInstructions.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/pseudocodeTraverseNextInstructions.fir.kt new file mode 100644 index 00000000000..b79f12bebde --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/pseudocodeTraverseNextInstructions.fir.kt @@ -0,0 +1,8 @@ +package b + +fun foo() { + for (i in collection) { + { + break + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/senselessComparisonWithNull.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/senselessComparisonWithNull.fir.kt new file mode 100644 index 00000000000..21e0e292f51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/senselessComparisonWithNull.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +package d + +fun foo(a : IntArray) { + if (null == a() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/typeParameterOnLhsOfDot.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/typeParameterOnLhsOfDot.fir.kt new file mode 100644 index 00000000000..f4e1f12e1ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/typeParameterOnLhsOfDot.fir.kt @@ -0,0 +1,8 @@ +package bar + +class S { + fun foo() { + T + T.create() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/unresolvedArguments.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedArguments.fir.kt new file mode 100644 index 00000000000..0eb8580efed --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedArguments.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +//!DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(i: Int, t: T) {} +fun foo(s: String, t: T) {} + +fun bar(i: Int) {} +fun bar(s: String) {} + +fun test() { + foo(rrr, 1) + bar(rrr) +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.fir.kt new file mode 100644 index 00000000000..c314de08b1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.fir.kt @@ -0,0 +1,4 @@ +fun foo(a: Int) { + !bbb + bbb + a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/variableDeclarationInSelector.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/variableDeclarationInSelector.fir.kt new file mode 100644 index 00000000000..fdd9b6d8b09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/variableDeclarationInSelector.fir.kt @@ -0,0 +1,4 @@ +fun foo(s: String) { + s. + val b = 42 +} diff --git a/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.fir.kt b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.fir.kt new file mode 100644 index 00000000000..90f47681aa7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +fun fooT22() : T? { + return null +} + +fun foo1() { + fooT22() +} + +val n : Nothing = null.sure() + +fun T?.sure() : T = this!! diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveAmbiguity.fir.kt new file mode 100644 index 00000000000..c719e53bab0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveAmbiguity.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +package f + +fun g(i: Int, a: Any): List {throw Exception()} +fun g(a: Any, i: Int): Collection {throw Exception()} + +fun test() { + val c: List = g(1, 1) +} diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.fir.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.fir.kt new file mode 100644 index 00000000000..8058e01af53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +package f + +fun h(i: Int, a: Any, r: R, f: (Boolean) -> Int) = 1 +fun h(a: Any, i: Int, r: R, f: (Boolean) -> Int) = 1 + +fun test() = h(1, 1, 1, { b -> 42 }) diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.fir.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.fir.kt new file mode 100644 index 00000000000..59123b0ae4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +package f + +fun f(i: Int, c: Collection): List {throw Exception()} +fun f(a: Any, l: List): Collection {throw Exception()} + +fun test(l: List) { + f(1, emptyList()) +} + +fun emptyList(): List {throw Exception()} diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoneApplicable.fir.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoneApplicable.fir.kt new file mode 100644 index 00000000000..ae5b852f858 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoneApplicable.fir.kt @@ -0,0 +1,8 @@ +package f + +fun f(i: Int, t: T, c: MutableCollection) {} +fun f(a: Any, t: T, l: MutableList) {} + +fun test(l: List) { + f(1, "", l) +} diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.fir.kt new file mode 100644 index 00000000000..f35f4fc87e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS +package f + +fun h(f: (Boolean) -> R) = 1 +fun h(f: (String) -> R) = 2 + +fun test() = h{ i -> getAnswer() } + +fun getAnswer() = 42 + diff --git a/compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.fir.kt new file mode 100644 index 00000000000..6c51937918d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedInProjectedFlexibleType.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public A getSuperA() { return null; } +} + +// FILE: main.kt + +fun foo(x: T?, func: (T) -> T?) {} + +fun test(a: A<*>) { + foo(a) { it.superA } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt new file mode 100644 index 00000000000..d8f3fda3b6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt @@ -0,0 +1,8 @@ + +fun Array.intersect(other: Iterable) { + val set = toMutableSet() + set.retainAll(other) +} + +fun Array.toMutableSet(): MutableSet = TODO() +fun MutableCollection.retainAll(elements: Iterable) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.fir.kt new file mode 100644 index 00000000000..a62783a1480 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !CHECK_TYPE + +fun bar(a: Array): Array = null!! + +fun test1(a: Array) { + val r: Array = bar(a) + bar(a) +} + +fun foo(l: Array): Array> = null!! + +fun test2(a: Array) { + val r: Array> = foo(a) + foo(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForNullableTypes.fir.kt new file mode 100644 index 00000000000..019da0ed399 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForNullableTypes.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !CHECK_TYPE + +fun bar(a: Array): Array = null!! + +fun test1(a: Array) { + val r: Array = bar(a) + val t = bar(a) + t checkType { _>() } +} + +fun foo(l: Array): Array> = null!! + +fun test2(a: Array) { + val r: Array> = foo(a) + val t = foo(a) + t checkType { _>>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.fir.kt new file mode 100644 index 00000000000..fe976e17094 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.fir.kt @@ -0,0 +1,27 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + public static Class foo(Class clazz) { + return clazz; + } + + public static Class> bar(Class clazz) { + throw new Exception(); + } +} + +// FILE: b.kt +fun test1(clazz: Class) { + val foo0: Class = A.foo(clazz) + val foo1 = A.foo(clazz) + foo1 checkType { _< Class >() } + foo1 checkType { _< Class >() } +} + +fun tes2t(clazz: Class) { + val foo0: Class> = A.bar(clazz) + val foo1 = A.bar(clazz) + foo1 checkType { _< Class> >() } + foo1 checkType { _< Class> >() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeVariable.fir.kt new file mode 100644 index 00000000000..177d1f8c10f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeVariable.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun Array.filterNotNull(): List = throw Exception() + +fun test1(a: Array) { + val list = a.filterNotNull() + list checkType { _>() } +} + +fun test2(vararg a: Int?) { + val list = a.filterNotNull() + list checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromSubtyping.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromSubtyping.fir.kt new file mode 100644 index 00000000000..6af1a91db5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromSubtyping.fir.kt @@ -0,0 +1,9 @@ +fun > mapKeysTo(destination: M): Inv3 { + val foo = associateByTo(destination) + + return foo +} + +fun < Y, Z, T : MutableMap> associateByTo(destination: T): Inv3 = TODO() + +interface Inv3 diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt new file mode 100644 index 00000000000..b0672c7516a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromTypeParameterUpperBound.fir.kt @@ -0,0 +1,11 @@ +interface Inv + +fun > foo(x: X, y: Y) { + val rX = bar(x) + rX.length + + val rY = bar(y) + rY.length +} + +fun bar(l: Inv): Y = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.fir.kt new file mode 100644 index 00000000000..1d437d55c57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo(array: Array>): Array> = array + +fun test(array: Array>) { + foo(array) + + val f: Array> = foo(array) +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.fir.kt new file mode 100644 index 00000000000..a032a30b87e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(array: Array): Array = array + +fun test1(a1: Array) { + val b1: Array = foo(a1) + val c1 = foo(a1) + c1 checkType { _>() } +} + +fun test2(a2: Array) { + val b2: Array = foo(a2) + val c2 = foo(a2) + c2 checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeAndApproximation.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeAndApproximation.fir.kt new file mode 100644 index 00000000000..b0cc77cfab5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeAndApproximation.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(a: Array): Array> = throw Exception() + +fun test1(a1: Array) { + val b1: Array> = foo(a1) + val c1 = foo(a1) + c1 checkType { _>>() } +} + +fun test2(a2: Array) { + val b2: Array> = foo(a2) + val c2 = foo(a2) + c2 checkType { _>>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.fir.kt new file mode 100644 index 00000000000..8d039702800 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo1(a1: Array, a2: Array): T = null!! + +fun test1(a1: Array, a2: Array) { + foo1(a1, a2) checkType { _() } +} + +fun foo2(a1: Array, a2: Array): T = null!! + +fun test2(a1: Array, a2: Array) { + foo2(a1, a2) checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.fir.kt new file mode 100644 index 00000000000..f5a9613e048 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference + +import kotlin.reflect.KClass + +typealias MyString = String + +fun test(k: KClass) { + k::class.java +} + +@Suppress("UPPER_BOUND_VIOLATED") +public val KClass.java: Class get() = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.fir.kt new file mode 100644 index 00000000000..bd4e8035bb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun takeCovArray(a: Array) {} +fun takeInArray(a: Array) {} + +fun foo(): Array = TODO() +fun bar(): Array = TODO() + +fun id(x: X): X = x +fun arrayInId(z: Array): Array = z +fun arrayOutId(z: Array): Array = z + +fun test() { + takeCovArray(foo()) + takeInArray(bar()) + + takeCovArray(id(foo())) + takeInArray(id(bar())) + + takeCovArray(arrayOutId(foo())) + takeInArray(arrayInId(bar())) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/expectedTypeMismatchWithInVariance.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/expectedTypeMismatchWithInVariance.fir.kt new file mode 100644 index 00000000000..3408e5adfd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/expectedTypeMismatchWithInVariance.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun foo(a1: Array, a2: Array): T = null!! + +fun test(a1: Array, a2: Array) { + + val c: Int = foo(a1, a2) + +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/invokeCallWithCapturedReceiver.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/invokeCallWithCapturedReceiver.fir.kt new file mode 100644 index 00000000000..7d205289439 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/invokeCallWithCapturedReceiver.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Inv1 + +operator fun Inv1.invoke(action: T.() -> Unit) {} + +fun test(inv: Inv1) { + inv { } + inv.invoke { } +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt25302.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt25302.fir.kt new file mode 100644 index 00000000000..3096c1eefca --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt25302.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface CollectorMock + +interface StreamMock { + fun collect(collector: CollectorMock): R +} + +fun accept(s: T) {} +fun ofK(t: String): StreamMock = TODO() +fun toSetK(): CollectorMock<*, T> = TODO() + +class KotlinCollectionUser1 { + fun use() { + accept(ofK("").collect(toSetK())) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2570.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2570.fir.kt new file mode 100644 index 00000000000..505d3dbbefa --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2570.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo(l: MutableList): MutableList = l +fun test(l: MutableList) { + val a: MutableList = foo(l) + val b = foo(l) + b checkType { _< MutableList >() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.fir.kt new file mode 100644 index 00000000000..6888e73ef5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +fun Array.foo() {} + +fun test(array: Array) { + array.foo() + array.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt new file mode 100644 index 00000000000..c09a56415ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +class A { + fun foo(): T = null!! +} + +fun A.bar(): A = this + +fun baz(x: A) { + x.bar() checkType { _>() } + x.bar().foo() checkType { _() } // See KT-10448 +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/noCaptureTypeErrorForNonTopLevel.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/noCaptureTypeErrorForNonTopLevel.fir.kt new file mode 100644 index 00000000000..29dc2d569ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/noCaptureTypeErrorForNonTopLevel.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A +class B + +fun foo(b: B>) {} +fun baz(b: B>) {} + +// See KT-13950 +fun bar(b: B>, bOut: B>, bOut2: B>) { + foo(b) + foo(b) + + baz(bOut) + baz(bOut) + + baz(bOut2) + baz(bOut2) +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.fir.kt new file mode 100644 index 00000000000..7b4046ca94a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.fir.kt @@ -0,0 +1,7 @@ +class Bar + +fun Bar.foo() = 42 + +object MyObject { + fun foo(bar: Bar) = bar.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.fir.kt new file mode 100644 index 00000000000..b14d2498fd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(a: Array): T = null!! + +fun test(a: Array) { + foo(a) checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForOutCaptured.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForOutCaptured.fir.kt new file mode 100644 index 00000000000..9c9fa4e59fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForOutCaptured.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(a: Array): T = null!! + +fun test(a: Array) { + foo(a) checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/propagateNullailityOnSupertypesWhenCaptureTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/propagateNullailityOnSupertypesWhenCaptureTypes.fir.kt new file mode 100644 index 00000000000..e4be6048e32 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/propagateNullailityOnSupertypesWhenCaptureTypes.fir.kt @@ -0,0 +1,23 @@ +open class Inv(val value: String) + +fun ?, F: Inv?, G : Inv<*>> test1(t: T, f: F, g: G?) { + if (t != null && f != null && g != null) { + t.value + f.value + g.value + } +} + +// Actually, this behavior is very questional as capturing shouldn't be performed deeper than for 1 level +// But we preserve behavior of old inference here for now +fun ?> test2(t: T) { + if (t != null) { + t.value + } +} + +fun ?, K : Inv<*>?> test3(t: T) { + if (t != null) { + t.value + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/starProjectionRegression.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/starProjectionRegression.fir.kt new file mode 100644 index 00000000000..bfee91bf948 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/starProjectionRegression.fir.kt @@ -0,0 +1,17 @@ +// See KT-14453 +val KClass1.primaryConstructor: KFunction1? get() = null!! + +interface KClass1 +interface KFunction1 +fun f(type: KClass1<*>): KFunction1? = + // What happens here: + // 1. Create captured type for type argument T (it's built upon star-projection from `KClass<*>` that's argument is <: Any) + // 2. Approximate resulting descriptor, now it 'KClass1<*>.primaryConstructor: KFunction1<*>' + // Note that star-projection in 'KFunction1<*>' is obtained from KClass and its `projectionType` is Any (not-nullable). + // Of course that situation is already strange + // 3. When checking subtyping after call completion we get that 'KFunction1<*>' is not a subtype of 'KFunction1' in new type checker. + // The answer is correct, but this old type checker used `projectionType` for this and it was resulting in KFunction1<*> <: KFunction1 + // + // So to fix the issue we use 'out starProjectionType' instead of star-projection itself in approximation + // Note that in new inference there should be no approximation for IN-position types (they must remain captured) + type.primaryConstructor diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/topLevelCapturingInsideReturnType.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/topLevelCapturingInsideReturnType.fir.kt new file mode 100644 index 00000000000..215df989c84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/topLevelCapturingInsideReturnType.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Inv2 + +fun createInv(): Inv2<*, K> = TODO() + +fun foo(i: Inv2) {} + +fun foo() { + foo(createInv()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.fir.kt b/compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.fir.kt new file mode 100644 index 00000000000..6bd6ab8fb68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun fail1(c: suspend () -> Unit) {} + +fun fail2(c: () -> Unit) {} + +fun success1(c: suspend () -> Unit) {} + +fun test1() { + fail1(fun () {}) + fun fail2(c: suspend () -> Unit) {} + fail2(fun () {}) + fun success1(c: () -> Unit) {} + success1(fun() {}) +} + +suspend fun fail3(c: suspend () -> Unit) {} + +suspend fun fail4(c: () -> Unit) {} + +suspend fun success2(c: suspend () -> Unit) {} + +suspend fun test2() { + fail3(fun () {}) + fun fail4(c: suspend () -> Unit) {} + fail4(fun () {}) + fun success2(c: () -> Unit) {} + success2(fun() {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt new file mode 100644 index 00000000000..f911a70bde1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +NewInference + +class Obj + +fun foo(): String? { + run { + if (true) return@run + + if (true) Obj() + } + + run { + if (true) return@run + + if (true) return Obj() // correct error, type check against return type of function "foo" + } + + run { + if (true) + return@run + else + if (true) 42 + } + + run { + if (true) + 42 + else + if (true) 42 + } + + run { + if (true) return@run + + if (true) { + Obj() + } else + if (true) return null + } + + return "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForLastLambdaInLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForLastLambdaInLambda.fir.kt new file mode 100644 index 00000000000..07288febcce --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForLastLambdaInLambda.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun coerceToUnit(f: () -> Unit) {} + +class Inv + +fun builder(block: Inv.() -> Unit): K = TODO() + +fun test() { + coerceToUnit { + builder {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt new file mode 100644 index 00000000000..a06dcfc4b07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE + +fun materialize(): T = TODO() + +val a: () -> Unit = l@{ + // Expected type 'Unit' is used here for inference + if (true) return@l materialize() + + // Expected type here is Unit, but it also implies coercion, + // so we can end lambda body with statement + if (true) 42 +} + +val b: () -> Unit = l@{ + // Error, coercion can't be applied at this position! + if (true) return@l "hello" + + // However, this is OK, because here coercion is applied + "hello" +} + +val c: () -> Unit = { + // Interesting enough, for such expessions we use expected type Unit + // (compare that with the previous case, where we didn't used expected type Unit for "hello") + materialize() +} diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt new file mode 100644 index 00000000000..fd1e8bfd4cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE + +fun materializeNumber(): T = TODO() + +fun a(): Unit = run { + materializeNumber() +} + +fun b(): Unit = run { + run { + materializeNumber() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.fir.kt new file mode 100644 index 00000000000..d676c39e012 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE + +fun foo() { + val f = myRun { + 123 + } +} + +fun myRun(block: () -> R): R = block() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.fir.kt new file mode 100644 index 00000000000..ff5fd940d7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithoutExpectedType.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE + +fun materialize(): T = TODO() + +fun implicitCoercion() { + val a = { + // Block is implicitly Unit-coerced, so it is allowed to place statement at the end of lambda + if (true) 42 + } + + val b = l@{ + return@l + } + + val c = l@{ + // Error: block doesn't have an expected type, so call can't be inferred! + return@l materialize() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/indirectCoercionWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/indirectCoercionWithExpectedType.fir.kt new file mode 100644 index 00000000000..692bf78d0c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/indirectCoercionWithExpectedType.fir.kt @@ -0,0 +1,36 @@ +// !WITH_NEW_INFERENCE + +fun materialize(): T = TODO() + +fun a(): Unit = run { + run { + // Ok, block is coerced, because it has (indirectly) Unit-expected type + "hello" + } +} + +fun b(): Unit = run { + // Ok, expected type is applied + materialize() +} + +fun c(): Unit = run { + run { + // Attention! + // In OI expected type 'Unit' isn't applied here because of implementation quirks (note that OI still applies Unit in case 'e') + // In NI, it is applied and call is correctly inferred, which is consistent with the previous case + materialize() + } +} + +fun d(): Unit = run outer@{ + run inner@{ + return@inner materialize() + } +} + +fun e(): Unit = run outer@{ + run inner@{ + return@outer materialize() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt new file mode 100644 index 00000000000..0ad0a0b5f99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt @@ -0,0 +1,64 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-30242 + +class A + +fun println(s: String = "") {} + +fun foo(f: () -> Any) {} + +fun test1(b: Boolean) { + foo { + if (b) { + println("meh") + } + } +} + +fun test2(b: Boolean) { + foo { + when { + b -> println("meh") + } + } +} + +fun test3(b: Boolean) { + foo { + if (b) { + return@foo A() + } + } +} + +fun test4(b: Boolean) { + foo { + if (b) { + return@foo println("meh") + } + + if (b) { + println() + } + } +} + +fun bar(block: () -> String) {} + +fun test_5(b: Boolean) { + bar { + if (b) { + println("meh") + } + } +} + +fun test_6(b: Boolean) { + foo { + if (b) { + return@foo Unit + } + if (b) {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/noCoercion.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/noCoercion.fir.kt new file mode 100644 index 00000000000..25ebd6d5781 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/noCoercion.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun noCoercionLastExpressionUsedAsReturnArgument() { + val a = { + 42 + } + + a checkType { _<() -> Int>() } +} + +fun noCoercionBlockHasExplicitType() { + val b: () -> Int = { + if (true) 42 + } +} + +fun noCoercionBlockHasExplicitReturn() { + val c = l@{ + if (true) return@l 42 + + if (true) 239 + } +} + +fun noCoercionInExpressionBody(): Unit = "hello" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.fir.kt new file mode 100644 index 00000000000..6adfb804c0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/nonPropagationOfCoercionToUnitInsideNestedLambda.fir.kt @@ -0,0 +1,52 @@ +// !LANGUAGE: +NewInference + +class Obj + +fun foo(): String? { + run { + if (true) return@run + + run { + if (true) { + Obj() + } else + if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas + } + + if (true) { + Obj() + } else + if (true) return null // OK, no error + } + + run { + if (true) return@run + + run { + if (true) { + Obj() + } else + if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas + } + } + + run { + if (true) return@run + + run nestedRun@{ + if (true) return@nestedRun + + if (true) { + Obj() + } else + if (true) return null // OK, additional empty labeled return helps + } + + if (true) { + Obj() + } else + if (true) return null // OK, no error + } + + return "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.fir.kt new file mode 100644 index 00000000000..72afc526eaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/boundOnNullableVariable.fir.kt @@ -0,0 +1,6 @@ +fun test(f: (T) -> T?) { + doFun(f.ext()) +} + +fun Function1.ext(): Function0 = throw Exception() +fun doFun(f: () -> R?) = f diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.fir.kt new file mode 100644 index 00000000000..5f8200ffa51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/cstFromNullableChildAndNonParameterizedType.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Base + +class ParameterizedChild : Base +class Child : Base + +fun elvis(x: K?, y: K): K = TODO() +fun select(x: K, y: K): K = TODO() + +fun myRun(f: () -> V): V = f() + +fun test1(a: ParameterizedChild?, b: Child): Base = myRun { + elvis(a, b) +} + +fun test2(a: S?, b: S): S = myRun { + select(a, b) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.fir.kt new file mode 100644 index 00000000000..6190d21fa8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.fir.kt @@ -0,0 +1,88 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +fun select(x: T, y: T): T = x +open class Inv +class SubInv : Inv() + +fun testSimple() { + val a0 = select(Inv(), SubInv()) + + a0 + + val a1 = select(SubInv(), Inv()) + + a1 +} + +fun testNullability() { + val n1 = select(Inv(), SubInv()) + + n1 + + val n2 = select(SubInv(), Inv()) + + n2 +} + +fun testNested() { + val n1 = select(Inv>(), SubInv()) + + n1 + + val n2 = select(SubInv>(), Inv()) + + n2 + + fun createInvInv(): Inv> = TODO() + + val n3 = select(SubInv>(), createInvInv()) + + n3 +} + +fun testCaptured(cSub: SubInv, cInv: Inv) { + val c1 = select(cInv, SubInv()) + + c1 + + val c2 = select(cSub, Inv()) + + c2 +} + +fun testVariableWithBound() { + fun createWithNumberBound(): Inv = TODO() + fun createWithIntBound(): Inv = TODO() + + val c1 = select(SubInv(), createWithNumberBound()) + + c1 + + val c2 = select(SubInv(), createWithNumberBound()) + + c2 + + val c3 = select(SubInv(), createWithIntBound()) + + c3 +} + +fun testCapturedVariable() { + fun createInvOut(): Inv = TODO() + fun createSubInvOut(): SubInv = TODO() + + fun createInvIn(): Inv = TODO() + + val c1 = select(SubInv(), createInvOut()) + + c1 + + val c2 = select(createSubInvOut(), createInvOut()) + + c2 + + val c3 = select(SubInv(), createInvIn()) + + c3 +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.fir.kt new file mode 100644 index 00000000000..56b7f5657a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/dontCaptureTypeVariable.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.* + +fun test(list: ArrayList, comparatorFun: (Int, Int) -> Int) { + sort(list, Comparator(comparatorFun)) +} + + +public fun sort(list: List, c: Comparator) { +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/fixVariablesInRightOrder.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/fixVariablesInRightOrder.fir.kt new file mode 100644 index 00000000000..1e3724fee47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/fixVariablesInRightOrder.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class GenericClass + +public fun GenericClass>.foo() {} + +public fun bar(t: T, ext: GenericClass.() -> Unit) {} + +fun test() { + bar(mapOf(2 to 3)) { foo() } +} + +// from library +class Pair +fun mapOf(keyValuePair: Pair): Map = throw Exception() +infix fun A.to(that: B): Pair = throw Exception() + diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.fir.kt new file mode 100644 index 00000000000..dc882ec4d8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class GenericClass(val value: T) { + public fun

foo(extension: T.() -> P) {} +} + +public fun GenericClass>.bar() { + foo( { listIterator() }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.fir.kt new file mode 100644 index 00000000000..7ab48bdff17 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.* + +interface Foo +class Bar(val list: MutableList) {} + +fun test(map: MutableMap>) { + + map.getOrPut1("", { Bar(ArrayList()) }) +} + +fun MutableMap.getOrPut1(key: K, defaultValue: () -> V): V = throw Exception() diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/kt30300.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/kt30300.fir.kt new file mode 100644 index 00000000000..7d100e7d50e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/kt30300.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// Issue: KT-30300 + +class Inv +class InvOut + +class Sample + +fun select(x: T, y: T): T = x +fun selectInvOut(a: InvOut, b: InvOut): InvOut = TODO() +fun emptyInvOut(): InvOut = TODO() +fun create(element: S): InvOut, S> = TODO() + +fun test(s: Sample, b: InvOut, Any?>) { + selectInvOut( + b, + select(create(s), emptyInvOut()) + ) +} + diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/kt31969.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/kt31969.fir.kt new file mode 100644 index 00000000000..6477411e023 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/kt31969.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +open class View + +fun test() { + val target = foo() ?: foo() ?: run {} +} + +fun foo(): T? { + return null +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/kt32818.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/kt32818.fir.kt new file mode 100644 index 00000000000..58e4ad63617 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/kt32818.fir.kt @@ -0,0 +1,5 @@ +// !WITH_NEW_INFERENCE + +fun nullable(): T? = null + +val value = nullable() ?: nullable() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/kt33197.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/kt33197.fir.kt new file mode 100644 index 00000000000..c36a9aa4909 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/kt33197.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun test(condition: Boolean) { + val list1 = + if (condition) mutableListOf() + else emptyList() + + list1 + + val list2 = + if (condition) mutableListOf() + else emptyList() + + list2 +} + +fun mutableListOf(): MutableList = TODO() +fun emptyList(): List = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/kt3372toCollection.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/kt3372toCollection.fir.kt new file mode 100644 index 00000000000..18cd4edb8d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/kt3372toCollection.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// KT-3372 Use upper bound in type argument inference + +import java.util.HashSet + +fun > Iterable.toCollection(result: C) : C = throw Exception() + +fun test(list: List) { + val set = list.toCollection(HashSet()) + set checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation.fir.kt new file mode 100644 index 00000000000..f34eb010880 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: -NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A +interface B : A +interface C : A + +@Suppress("INVISIBLE_REFERENCE") +fun select(x: K, y: K): @kotlin.internal.Exact K = x + +fun foo(a: Any) {} + +fun test(b: B, c: C) { + foo( + select(b, c) + ) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation_ni.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation_ni.fir.kt new file mode 100644 index 00000000000..004d8442034 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/lessSpecificTypeForArgumentCallWithExactAnnotation_ni.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A +interface B : A +interface C : A + +@Suppress("INVISIBLE_REFERENCE") +fun select(x: K, y: K): @kotlin.internal.Exact K = x + +fun foo(a: Any) {} + +fun test(b: B, c: C) { + foo( + select(b, c) + ) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/manyArgumentsForVararg.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/manyArgumentsForVararg.fir.kt new file mode 100644 index 00000000000..ad37f1b3559 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/manyArgumentsForVararg.fir.kt @@ -0,0 +1,178 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +val prop = mapOf( + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b"), + to("a", "b") +) + +fun to(a: A, b: B): Pair = TODO() +fun mapOf(vararg pairs: Pair): Map = TODO() + +class Pair \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.fir.kt new file mode 100644 index 00000000000..3e81b84763c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/nestedLambdas.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun Collection.map(transform : (T) -> R) : List = throw Exception() + +fun test(list: List>) { + + val list1 = list.map { it.map { "$it" } } + list1 checkType { _>>() } +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.fir.kt new file mode 100644 index 00000000000..03c5bcddc2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableFromBothBranches.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: JavaTest.java + +public class JavaTest { + public static Number[] createNumberArray() { return null; } +} + +// FILE: test.kt + +fun select(x: K, y: K): K = x + +fun foo(f: () -> R): R = f() + +fun test(n: Number) { + val a = select(foo { JavaTest.createNumberArray() }, emptyArray()) + + a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.fir.kt new file mode 100644 index 00000000000..a354fea3d48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: Inv2.java + +public class Inv2 {} + +// FILE: JavaSet.java + +public class JavaSet { + public static java.util.Set newIdentityHashSet() { return null; } + + public static V get(Inv2 slice, K key) { return null; } +} + +// FILE: test.kt + +fun select(x: K, y: K): K = x + +fun addElementToSlice( + slice: Inv2>, + key: K, + element: T +) { + val a = select(JavaSet.get(slice, key), JavaSet.newIdentityHashSet()) + + a + + a.add(element) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/outProjectedTypeToOutProjected.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/outProjectedTypeToOutProjected.fir.kt new file mode 100644 index 00000000000..fdc80f2c532 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/outProjectedTypeToOutProjected.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class Inv + +fun select(x: K, y: K): K = x + +fun outToOut(x: Inv): Inv = TODO() + +fun test(invOutAny: Inv, invAny: Inv) { + val a: Inv = select(invAny, outToOut(invOutAny)) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation.fir.kt new file mode 100644 index 00000000000..b5ee5094fca --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: -NewInference + +interface ISample + +fun elvisSimple(x: K?, y: K): K = y + +@Suppress("INVISIBLE_REFERENCE") +fun elvisExact(x: K?, y: K): @kotlin.internal.Exact K = y + +fun materialize(): T? = TODO() + +fun test(nullableSample: ISample, any: Any) { + elvisSimple( + nullableSample, + materialize() + ) + + elvisSimple( + elvisSimple(nullableSample, materialize()), + any + ) + + elvisSimple( + elvisExact(nullableSample, materialize()), + any + ) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation_ni.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation_ni.fir.kt new file mode 100644 index 00000000000..0b352bb01f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation_ni.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST + +interface ISample + +fun elvisSimple(x: K?, y: K): K = y + +@Suppress("INVISIBLE_REFERENCE") +fun elvisExact(x: K?, y: K): @kotlin.internal.Exact K = y + +fun materialize(): T? = null +fun Any?.materialize(): T = null as T + +fun test(nullableSample: ISample, any: Any) { + elvisSimple( + nullableSample, + materialize() + ) + + elvisSimple( + elvisSimple(nullableSample, materialize()), + any + ) + + elvisSimple( + elvisExact(nullableSample, materialize()), + any + ) + + val a: String? = null + + val x1: String? = run { + a ?: a?.materialize() + } + + val x2 = run { + a ?: a?.materialize() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt new file mode 100644 index 00000000000..5dfa6d056e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class In +class Out + +class A +class B + +fun select(x: K, y: K): K = x +fun genericIn(x: In) {} +fun genericOut(x: Out) {} + +fun test1(a: In, b: In) { + genericIn(select(a, b)) +} + +fun test2(a: Out, b: Out) { + genericOut(select(a, b)) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromTwoIncompatibleTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromTwoIncompatibleTypes.fir.kt new file mode 100644 index 00000000000..11ce49a6588 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromTwoIncompatibleTypes.fir.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Inv + +class A +class B + +fun select(x: K, y: K): K = x +fun generic(x: Inv) {} + +fun test1(a: Inv, b: Inv) { + generic(select(a, b)) +} + +fun test2(a: Inv<*>?, b: Inv<*>) { + generic(a ?: b) + generic(if (a != null) a else b) + generic(a!!) +} + +fun test3(a: Inv, b: Inv) { + generic(select(a, b)) +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/selectIntegerValueTypeFromIf.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/selectIntegerValueTypeFromIf.fir.kt new file mode 100644 index 00000000000..c213e5b51a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/selectIntegerValueTypeFromIf.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun takeLong(i: Long) {} + +fun test() { + takeLong(if (true) 1 else 0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/theSameFunctionInArgs.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/theSameFunctionInArgs.fir.kt new file mode 100644 index 00000000000..87ce95e3651 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/theSameFunctionInArgs.fir.kt @@ -0,0 +1,6 @@ +// !CHECK_TYPE + +fun test() { + val array = arrayOf(arrayOf(1)) + array checkType { _>>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.fir.kt b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.fir.kt new file mode 100644 index 00000000000..a63377b4fdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package d + +fun joinT(x: Int, vararg a: T): T? { + return null +} + +fun joinT(x: Comparable<*>, y: T): T? { + return null +} + +fun test() { + val x2 = joinT(Unit, "2") + checkSubtype(x2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/conflictingSubstitutions.fir.kt b/compiler/testData/diagnostics/tests/inference/conflictingSubstitutions.fir.kt new file mode 100644 index 00000000000..650d75a29c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/conflictingSubstitutions.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +package conflictingSubstitutions +//+JDK + +import java.util.* + +fun elemAndList(r: R, t: MutableList): R = r +fun R.elemAndListWithReceiver(r: R, t: MutableList): R = r + +fun test() { + val s = elemAndList(11, list("72")) + + val u = 11.elemAndListWithReceiver(4, list("7")) +} + +fun list(value: T) : ArrayList { + val list = ArrayList() + list.add(value) + return list +} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.fir.kt new file mode 100644 index 00000000000..17b3ea6aa8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Out +class In +class Inv + +fun choose1(c: Out>) {} +fun choose2(c: In>) {} +fun choose3(c: Inv>) {} + +fun f(o: Out>, i: In>, inv: Inv>) { + choose1(o) + choose2(i) + choose3(inv) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.fir.kt new file mode 100644 index 00000000000..b77422491e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +package c + +import java.util.ArrayList + +fun Array.toIntArray(): IntArray = this.mapTo(IntArray(size), {it}) + +fun Array.toArrayList(): ArrayList = this.mapTo(ArrayList(size), {it}) + +public fun > Array.mapTo(result: C, transform : (T) -> R) : C = + throw Exception("$result $transform") + diff --git a/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInvariantPosition.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInvariantPosition.fir.kt new file mode 100644 index 00000000000..8b1bbe80eb4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInvariantPosition.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +class Inv(val x: T?) + +fun create(y: K) = Inv(y) +fun createPrivate(y: K) = Inv(y) + +fun takeInvInt(i: Inv) {} + +fun test(i: Int, s: S) { + val a = Inv(s) + + a + + val b = create(i) + + b + + val c = createPrivate(i) + + c + + takeInvInt(create(i)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/earlyCompletionForCalls.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/earlyCompletionForCalls.fir.kt new file mode 100644 index 00000000000..5213966e75c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/earlyCompletionForCalls.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Parent +interface Inv + +object Child : Parent + +fun wrapper(): Inv = TODO() +fun consume(wrapper: Inv) {} + +fun select(x: S, y: S): S = x + +fun error(f: Inv, w: Inv) { + consume(select(f, wrapper())) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.fir.kt new file mode 100644 index 00000000000..c9e1f3c8eab --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE +interface A + +fun foo(a: A, aN: A): T = throw Exception("$a $aN") + +fun doA(a: A): T = throw Exception("$a") + +fun test(a: A, aN: A) { + val aa = doA(aN) + aa checkType { _() } + + val nullable = foo(aN, aN) + //T = Int?, T? = Int? => T = Int? + nullable checkType { _() } + + val notNullable = foo(a, aN) + //T = Int, T? = Int? => T = Int + notNullable checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt new file mode 100644 index 00000000000..79934290420 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NewInference + +// FILE: Sam.java + +public interface Sam { + Sam.Result compute(); + + public static class Result { + public static Sam.Result create(V value) {} + } +} + +// FILE: Foo.java + +public class Foo { + public static void foo(Sam var1) { + } +} + +// FILE: test.kt + +fun test(e: ErrorType) { + Foo.foo { + Sam.Result.create(e) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/fixTypeVariableWithNothingConstraintEarlierThanComplexVariable.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/fixTypeVariableWithNothingConstraintEarlierThanComplexVariable.fir.kt new file mode 100644 index 00000000000..210a2d9d3ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/fixTypeVariableWithNothingConstraintEarlierThanComplexVariable.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Inv + +fun foo(t: K?) = Inv() + +fun bar(t: T) = foo(t) +fun bar1(t: V1): Inv = foo(t) +fun bar2(t: V2): Inv = foo(t) + +fun select(x: S, y: S): S = x + +fun fail(t: T?) = if (t == null) bar(t) else bar(t) +fun fail1(t: F?, n: Nothing?) = select(bar1(n), bar2(t!!)) +fun fail2(t: F?, n: Nothing?) = if (t == null) bar1(t) else bar2(t) +fun fail3(t: F?) = select(bar1(null), bar2(t?.let { it })) diff --git a/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.fir.kt new file mode 100644 index 00000000000..62b443f333a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +class Foo + +fun foo1(f: (T) -> Unit): Foo = Foo() +inline fun foo2(f: (T) -> Unit): Foo = Foo() + +fun test1() { + val f1: Foo = foo1 { it checkType { _() } } + val f2: Foo = foo1 { it checkType { _() } } + + val f3: Foo = foo2 { it checkType { _() } } + val f4: Foo = foo2 { it checkType { _() } } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt new file mode 100644 index 00000000000..5daaf882c68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt @@ -0,0 +1,5 @@ +interface Box +fun List>.choose(): Box? = TODO() +fun list(): List> = TODO() + +fun f() = list().choose() diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt6320.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.fir.kt new file mode 100644 index 00000000000..14a5aea2e24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// AssertionError in ConstraintSystem(The constraint shouldn't contain different type variables on both sides: Y <: X) + +class A + +class B(foo: A) { + fun test1(a: A) { + B(a) + val b: B = B(a) + // crash here + } +} + +class C + +class D(foo: C) { + fun test(a: C) { + val d: D = D(a) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt7351ConstraintFromUnitExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt7351ConstraintFromUnitExpectedType.fir.kt new file mode 100644 index 00000000000..d49d4c3a0bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt7351ConstraintFromUnitExpectedType.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +package kt7351 + +interface Node + +interface Source { + fun f() : T +} +fun > S.woo() : T = this.f() + +fun Node.append(block : Source.() -> Unit) { +} + +fun crashMe(node : Node) { + node.append { + woo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt7433.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt7433.fir.kt new file mode 100644 index 00000000000..1c9ad2d2e1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt7433.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +public inline fun Iterable.reduce1(operation: (S, T) -> S): S = throw Exception() + +fun test(ints: List) { + val f: () -> Unit = { + ints.reduce1 { a, b -> a + b } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt new file mode 100644 index 00000000000..3aa989f59b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Inv +interface Inv2 + +fun > foo(klass: Inv): String? = null + +fun bar(): Inv = null!! + +fun test() { + foo(bar()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.fir.kt new file mode 100644 index 00000000000..85124e82e7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// SKIP_JAVAC + +// FILE: MySettings.java + +import java.util.Collection; + +public class MySettings< + SS extends MySettings, + PS extends MyComparableSettings, + L extends MySettingsListener + > +{ + public Collection getLinkedProjectsSettings() { + return null; + } + + public static MySettings getSettings() { + return null; + } +} + +abstract class MyComparableSettings implements Comparable {} +abstract class MySettingsListener {} + +// FILE: test.kt + +fun test() { + val a = MySettings.getSettings() + a.getLinkedProjectsSettings() + a.linkedProjectsSettings +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.fir.kt new file mode 100644 index 00000000000..499b2716ebd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// SKIP_JAVAC + +// FILE: MySettings.java + +import java.util.Collection + +class MySettings< + SS extends MySettings, + PS extends MyComparableSettings, + L extends MySettingsListener + > +{ + public Collection getLinkedProjectsSettings() { + return null; + } + + public static MySettings getSettings() { + return null; + } +} + +abstract class MyComparableSettings implements Comparable {} +abstract class MySettingsListener {} + +// FILE: test.kt + +fun test() { + val a = MySettings.getSettings() + a.getLinkedProjectsSettings() + a.linkedProjectsSettings +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.fir.kt new file mode 100644 index 00000000000..ac3cc49aa4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +interface A + +interface In + +interface Out + +fun doT(t: T?): T = throw Exception("$t") +fun doOut(o: Out): T { throw Exception("$o") } +fun doIn(i: In) { throw Exception("$i") } +fun doA(i: A) { throw Exception("$i") } + +fun test(out: Out, i: In, inv: A) { + // T? >: Int => T = Int + doT(1) + val r = doOut(out) + r checkType { _() } + + // T? <: Int => error + doIn(i) + + // T? >: Int => error + doA(inv) +} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/operationsOnIntegerValueTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/operationsOnIntegerValueTypes.fir.kt new file mode 100644 index 00000000000..de4197dadcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/operationsOnIntegerValueTypes.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test() { + generateException(Data(1), { Data(it.x + 2) }) +} + +fun generateException(a: T, next: (T) -> T) {} + +class Data(val x: K) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt new file mode 100644 index 00000000000..730fdd640d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: +NewInference + +// FILE: MenuItemBase.java + +public class MenuItemBase, I extends MenuItemBase, S extends SubMenuBase> { + public String getText() { return null; } +} + +// FILE: ContextMenuBase.java + +public class ContextMenuBase, I extends MenuItemBase, S extends SubMenuBase> {} + +// FILE: SubMenuBase.java + +public class SubMenuBase, I extends MenuItemBase, S extends SubMenuBase> {} + +// FILE: test.kt + +fun test(m: MenuItemBase<*, *, *>) { + m.text +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/remainConstraintContainingTypeWithoutProjection.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/remainConstraintContainingTypeWithoutProjection.fir.kt new file mode 100644 index 00000000000..c3add8bad9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/remainConstraintContainingTypeWithoutProjection.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS +// SKIP_TXT + +// FILE: Test.java +import java.util.Collection; + +public class Test { + static Inv> bar() { + return null; + } +} + +// FILE: main.kt +class Inv + +fun foo(x: R, y: Inv) {} + +fun main() { + val values: List = null as List + /* + * Before the fix, there was type mismatch during checking `Test.bar()` to pass to `foo`: + * Required: Inv> + * Found: Inv<(MutableCollection..Collection?)> + * Constraint `(MutableCollection..Collection?)` from 'Found' (for TypeVariable(R)) has been removed + * during fixation TypeVariable(T) due to the constraint for R contained TypeVariable(T). + * The problem was that TypeVariable(T) wan't substituted due to `containsConstrainingTypeWithoutProjection` optimization. + */ + foo(values, Test.bar()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt new file mode 100644 index 00000000000..0f100c7b735 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun testLambda() { + val basicTest: (Int) -> Int = myRun { + val x: Any? = null + if (x is String) return@myRun { it -> x.length + it } + if (x !is Int) return@myRun { it -> it } + + { it -> x + it } + } + + val twoLambda: (Int) -> Int = myRun { + val x: Int = 1 + run { + val y: Int = 2 + { x + y } + } + } + +} + +inline fun myRun(block: () -> R): R = block() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.fir.kt new file mode 100644 index 00000000000..a4459ec1777 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE +interface A + +interface Out + +fun foo(a: A, o: Out): T = throw Exception("$a $o") + +fun doOut(o: Out): T = throw Exception("$o") + +fun test(a: A, aN: A, o: Out) { + val out = doOut(o) + //T? >: Int? => T >: Int + out checkType { _() } + + val nullable = foo(aN, o) + //T = Int?, T? >: Int? => T = Int? + nullable checkType { _() } + + val notNullable = foo(a, o) + //T = Int, T? >: Int? => T = Int + notNullable checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.fir.kt new file mode 100644 index 00000000000..8eecd698e16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE +interface A + +interface In + +fun foo(a: A, i: In): T = throw Exception("$a $i") + +fun doIn(i: In): T = throw Exception("$i") + +fun test(a: A, aN: A, i: In) { + val _in = doIn(i) + //T? <: Int? => T <: Int? + _in checkType { _() } + + val notNullable = foo(a, i) + //T = Int, T? <: Int? => T = Int + notNullable checkType { _() } + + val nullable = foo(aN, i) + //T = Int?, T? <: Int? => T = Int? + nullable checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.fir.kt new file mode 100644 index 00000000000..e64a8ec1c4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class Foo { + var test: String by refreshOnUpdate("str") + + fun refreshOnUpdate(initialValue: T) = RefreshDelegate(initialValue) + + class RefreshDelegate(initialValue: T?) { + operator fun getValue(thisRef: Foo, property: KProperty<*>): T = TODO() + + operator fun setValue(thisRef: Foo, property: KProperty<*>, value: T) {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/dependOnExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/dependOnExpectedType.fir.kt new file mode 100644 index 00000000000..bae7a552814 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dependOnExpectedType.fir.kt @@ -0,0 +1,53 @@ +// !CHECK_TYPE + +package h +//+JDK +import java.util.* + +fun id(t: T) : T = t + +fun id1(t: T) = t + +fun elem(t: List): R = t.get(0) + +fun elemAndList(r: R, t: List): R = t.get(0) + +fun both(t1: T, t2: T) : T = t1 + +fun test1() { + val a = elem(list(2)) + val b = id(elem(list(2))) + val c = id(id1(id(id1(list(33))))) + checkSubtype(a) + checkSubtype(b) + checkSubtype>(c) + + val d : ArrayList = newList() + val e : ArrayList = id(newList()) + val f : ArrayList = id(id1(id(id1(newList())))) + + checkSubtype>(d) + checkSubtype>(e) + checkSubtype>(f) + + val g = elemAndList("", newList()) + val h = elemAndList(1, newList()) + + checkSubtype(g) + checkSubtype(h) + + val i = both(1, "") + val j = both(id(1), id("")) + checkSubtype(i) + checkSubtype(j) +} + +fun list(value: T) : ArrayList { + val list = ArrayList() + list.add(value) + return list +} + +fun newList() : ArrayList { + return ArrayList() +} diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVariance.fir.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.fir.kt new file mode 100644 index 00000000000..14f7068d274 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.fir.kt @@ -0,0 +1,69 @@ +// !WITH_NEW_INFERENCE +package a + +class MyList(t: T) {} + +fun getMyList(t: T) : MyList< T> = MyList(t) +fun getMyListToWriteTo(t: T) : MyList< in T> = MyList(t) +fun getMyListToReadFrom(t: T) : MyList = MyList(t) + +fun useMyList (l: MyList< T>, t: T) {} +fun writeToMyList (l: MyList< in T>, t: T) {} +fun readFromMyList(l: MyList, t: T) {} + +fun test1(int: Int, any: Any) { + val a0 : MyList = getMyList(int) + + val a1 : MyList = getMyList(any) + + val a2 : MyList = getMyList(int) + + val a3 : MyList = getMyListToReadFrom(int) + + val a4 : MyList = getMyList(any) + + val a5 : MyList = getMyListToWriteTo(any) + + + val a6 : MyList = getMyList(int) + val a7 : MyList = getMyList(int) + + val a8 : MyList = getMyListToReadFrom(int) + val a9 : MyList = getMyListToReadFrom(int) + + val a10 : MyList = getMyList(any) + val a11 : MyList = getMyList(any) + + val a12 : MyList = getMyListToWriteTo(any) + val a13 : MyList = getMyListToWriteTo(any) + + useMyList(getMyList(int), int) + useMyList(getMyList(any), int) + useMyList(getMyList(int), any) + + readFromMyList(getMyList(int), any) + readFromMyList(getMyList(any), int) + readFromMyList(getMyList(any), int) + + readFromMyList(getMyListToReadFrom(any), int) + readFromMyList(getMyListToReadFrom(any), int) + + readFromMyList(getMyListToReadFrom(int), any) + + + writeToMyList(getMyList(any), int) + writeToMyList(getMyList(int), any) + writeToMyList(getMyList(int), any) + writeToMyList(getMyList(int), any) + + writeToMyList(getMyListToWriteTo(any), int) + writeToMyList(getMyListToWriteTo(int), any) + + readFromMyList(getMyListToWriteTo(any), any) + + writeToMyList(getMyListToReadFrom(any), any) + + use(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) +} + +fun use(vararg a: Any) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.fir.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.fir.kt new file mode 100644 index 00000000000..f066b72e302 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.fir.kt @@ -0,0 +1,14 @@ +package b +//+JDK + +import java.util.* +import java.util.Collections.* + +fun foo(list: List) : String { + val w : String = max(list, comparator {o1, o2 -> 1 + }) + return w +} + +//from library +fun comparator(fn: (T,T) -> Int): Comparator {} diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt new file mode 100644 index 00000000000..1dac5d3aeb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeAdditionalTest.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast + +fun foo() = 1 + +fun foo() = foo() as T + +fun foo2(): T = TODO() + +val test = foo2().plus("") as String + +fun T.bar() = this +val barTest = "".bar() as Number \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeDoubleReceiver.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeDoubleReceiver.fir.kt new file mode 100644 index 00000000000..a0ef0081b76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeDoubleReceiver.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast + +fun foo(): T = TODO() + +class A { + fun fooA(): T = TODO() +} + +fun id(value: V) = value + +val asA = foo().fooA() as A + +val receiverParenthesized = (foo()).fooA() as A +val no2A = A().fooA().fooA() as A + +val correct1 = A().fooA() as A +val correct2 = foo().fooA() as A +val correct3 = A().fooA().fooA() as A + diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt new file mode 100644 index 00000000000..ba4bafed1a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast + +fun foo(): T = TODO() + +fun id(value: V) = value + +val asString = foo() as String + +val viaId = id(foo()) as String + +val insideId = id(foo() as String) + +val asList = foo() as List + +val asStarList = foo() as List<*> + +val safeAs = foo() as? String + +val fromIs = foo() is String +val fromNoIs = foo() !is String diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastComplexExpression.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastComplexExpression.fir.kt new file mode 100644 index 00000000000..ce51ae98727 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastComplexExpression.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +ExpectedTypeFromCast + +package pp + +class A { + fun foo(): T = TODO() + + companion object { + fun foo2(): T = TODO() + } +} + +val x = A().foo() as String +val y = A.foo2() as String +val z = pp.A.foo2() as String + diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt new file mode 100644 index 00000000000..0bdaa750a1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +ExpectedTypeFromCast + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class bar + +fun foo(): T = TODO() + +fun id(value: V) = value + +val par1 = (foo()) as String +val par2 = ((foo())) as String + +val par3 = (dd@ (foo())) as String + +val par4 = ( @bar() (foo())) as String + +object X { + fun foo(): T = TODO() +} + +val par5 = ( @bar() X.foo()) as String \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.fir.kt new file mode 100644 index 00000000000..c1054a13671 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast + +class X { + fun foo(): T = TODO() +} + +fun test(x: X) { + val y = x.foo() as Int +} + +fun g() { + fun foo(): T = TODO() + + val y = foo() as Int + + val y2 = foo() as D +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/findViewById.fir.kt b/compiler/testData/diagnostics/tests/inference/findViewById.fir.kt new file mode 100644 index 00000000000..37c59b36098 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/findViewById.fir.kt @@ -0,0 +1,59 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast +// !DIAGNOSTICS: -UNUSED_VARIABLE -DEBUG_INFO_LEAKING_THIS + +// FILE: a/View.java +package a; + +public class View { + +} + +// FILE: a/Test.java +package a; + +public class Test { + public T findViewById(int id); +} + +// FILE: 1.kt +package a + + +class X : View() + +class Y : View() + +val xExplicit: X = Test().findViewById(0) +val xCast = Test().findViewById(0) as X + +val xCastExplicitType = Test().findViewById(0) as X +val xSafeCastExplicitType = Test().findViewById(0) as? X + +val yExplicit: Y = Test().findViewById(0) +val yCast = Test().findViewById(0) as Y + + +class TestChild : Test() { + val xExplicit: X = findViewById(0) + val xCast = findViewById(0) as X + + val yExplicit: Y = findViewById(0) + val yCast = findViewById(0) as Y +} + +fun test(t: Test) { + val xExplicit: X = t.findViewById(0) + val xCast = t.findViewById(0) as X + + val yExplicit: Y = t.findViewById(0) + val yCast = t.findViewById(0) as Y +} + +fun test2(t: Test?) { + val xSafeCallSafeCast = t?.findViewById(0) as? X + val xSafeCallSafeCastExplicitType = t?.findViewById(0) as? X + + val xSafeCallCast = t?.findViewById(0) as X + val xSafeCallCastExplicitType = t?.findViewById(0) as X +} diff --git a/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt b/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt new file mode 100644 index 00000000000..3e1d827150f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt @@ -0,0 +1,15 @@ + +// completion order here: X, Y, WHEN_VARIABLE +fun List.optimizeReadOnlyList() = when (size) { + 0 -> emptyList() // here type variable Y will be fixed to Nothing + 1 -> listOf(this[0]) + else -> this +} +fun listOf(element: X): List = TODO() +fun emptyList(): List = TODO() + + +fun test(l: List): List { + val foo = l.optimizeReadOnlyList() + return foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.fir.kt b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.fir.kt new file mode 100644 index 00000000000..705e7193760 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/fixationOrderForProperConstraints.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +fun foo(f: (Y) -> Z, g: (X) -> Y, x: X): Z = f(g(x)) + +// TODO: Actually, this is a bug and will work when new inference is enabled +// see ([NI] Select variable with proper non-trivial constraint first) for more details +fun test() = foo({ it + 1 }, { it.length }, "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.fir.kt new file mode 100644 index 00000000000..dc0f951ef84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.fir.kt @@ -0,0 +1,13 @@ +// FILE: 1.kt +fun Array.plus(): Array { + val result = Arrays.copyOf(this, 3) + // result type is Array<(out) (S&Any)!>! + return result +} + +// FILE: Arrays.java +public class Arrays { + public static T[] copyOf(T[] original, int newLength) { + return (T[]) null; + } +} diff --git a/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt b/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt new file mode 100644 index 00000000000..790d98a513a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package a + +fun emptyList(): List = throw Exception() + +fun foo(f: T.() -> Unit, l: List): T = throw Exception("$f$l") + +fun test() { + val q = foo(fun Int.() {}, emptyList()) //type inference no information for parameter error + checkSubtype(q) + + foo({}, emptyList()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.fir.kt b/compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.fir.kt new file mode 100644 index 00000000000..c35eb35f310 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.fir.kt @@ -0,0 +1,9 @@ +class R + +fun f(): R = R() + +operator fun Int.plusAssign(y: R) {} + +fun box() { + 1 += f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.fir.kt new file mode 100644 index 00000000000..61e2939c97d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.fir.kt @@ -0,0 +1,8 @@ +package n + +fun foo(t: T, t1: T) {} + +fun test() { + //no type inference error + foo(aaab, bbb) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/immutableArrayList.fir.kt b/compiler/testData/diagnostics/tests/inference/immutableArrayList.fir.kt new file mode 100644 index 00000000000..6b8be3fbbdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/immutableArrayList.fir.kt @@ -0,0 +1,17 @@ +// FILE: p/J.java +package p; + +public interface J { + public interface Super {} + public interface Sub extends Super {} +} + +// FILE: k.kt + +import p.J.* + +class Foo: Sub { + fun foo(): Super { + return Foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.fir.kt new file mode 100644 index 00000000000..9dad1baf906 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeExtensionWithFunctionalArgument.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +class AbstractSelector +class SelectorFor + +inline operator fun SelectorFor.invoke(f: S.() -> I): AbstractSelector = TODO() + +class State(val p1: Double, val p2: () -> Int, val p3: String?) + +fun test(s: SelectorFor): Double { + val a = s { p1 } + a checkType { _>() } + + val b = s { p2 } + b checkType { _ Int>>()} + + val c = s { p3 } + c checkType { _>() } + + val d = s { } + d checkType { _>() } + + val e = s { return p1 } + e checkType { _>() } + + return null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.fir.kt new file mode 100644 index 00000000000..e1b9948e568 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeInCompanionObjectWithFunctionalArgument.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +class TestClass { + companion object { + inline operator fun invoke(task: () -> T) = task() + } +} + +fun test(s: String): String { + val a = TestClass { "K" } + a checkType { _() } + + val b = TestClass { return s } + b checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.fir.kt new file mode 100644 index 00000000000..88ee2013734 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeInObjectWithFunctionalArgument.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +object TestClass { + inline operator fun invoke(task: () -> T) = task() +} + +fun test(s: String): String { + val a = TestClass { TestClass { TestClass } } + a checkType { _() } + + val b = TestClass { return s } + b checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.fir.kt new file mode 100644 index 00000000000..cc6a8ce84ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.fir.kt @@ -0,0 +1,38 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +class TestClass { + inline operator fun invoke(task: () -> T) = task() +} + +fun test(value: T, test: TestClass): T { + val x = test { return value } + x checkType { _() } + + return value +} + +// --- + +class Future + +interface FutureCallback { + operator fun invoke(f: (E) -> T): Future +} + +fun test(cb: FutureCallback) { + val a = cb { it[0] } + a checkType { _>() } + + val b = cb { it } + b checkType { _>() } + + val c = cb {} + c checkType { _>() } + + cb.let { callback -> + val d = callback { it.length } + d checkType { _>() } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/inferInFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/inference/inferInFunctionLiterals.fir.kt new file mode 100644 index 00000000000..bee6cb003df --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/inferInFunctionLiterals.fir.kt @@ -0,0 +1,12 @@ +package n + +//+JDK +import java.util.* + +fun expected(t: T, f: () -> T) : T = t + +fun test(arrayList: ArrayList, list: List) { + val t = expected(arrayList, { list.reverse() }) +} + +fun List.reverse() : List = this \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/inferInFunctionLiteralsWithReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/inferInFunctionLiteralsWithReturn.fir.kt new file mode 100644 index 00000000000..c4415224ee0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/inferInFunctionLiteralsWithReturn.fir.kt @@ -0,0 +1,12 @@ +package n + +//+JDK +import java.util.* + +fun expected(t: T, f: () -> T) : T = t + +fun test(arrayList: ArrayList, list: List) { + val t = expected(arrayList, l@ {return@l list.reverse() }) +} + +fun List.reverse() : List = this \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.fir.kt b/compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.fir.kt new file mode 100644 index 00000000000..8c58629b05c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.fir.kt @@ -0,0 +1,13 @@ +interface Foo +interface Bar + +class Baz : Foo, Bar + +fun S.bip(): String where S : Foo, S: Bar { + return "OK" +} + +fun box(): String { + val baz = Baz() + return baz.bip() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt new file mode 100644 index 00000000000..5bdbf9a10cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/invokeLambdaAsFunction.fir.kt @@ -0,0 +1,7 @@ +fun test1(i: Int) = { i -> + i +}(i) + +fun test2() = { i -> i }() + +fun test3() = { i -> i }(1) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt new file mode 100644 index 00000000000..dcefaaae47b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/knownTypeParameters.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +NewInference + +open class A { + open inner class A1(val a1: T1) + open inner class A2(val a2: T2) + + open fun f1(arg: T1) = arg + open fun f2(arg: T2) = arg +} + +open class B : A() { + open inner class B1(b1: T) : A1(b1) + open inner class B2(b2: Int) : A2(b2) + + fun variableToKnownParameter(p: T): Int = + p as? Int ?: 0 + + inner class B3(b3: T) : A2(variableToKnownParameter(b3)) + + override fun f1(arg: T) = arg + override fun f2(arg: Int) = arg +} + +class C : B() { + inner class C1(c1: String): B1(c1) + inner class C2 : B2(15) + + override fun f1(arg: String) = arg + override fun f2(arg: Int) = arg +} diff --git a/compiler/testData/diagnostics/tests/inference/kt11963.fir.kt b/compiler/testData/diagnostics/tests/inference/kt11963.fir.kt new file mode 100644 index 00000000000..e68a9995bba --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt11963.fir.kt @@ -0,0 +1 @@ +val .something> abc \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt b/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt new file mode 100644 index 00000000000..7bd744df578 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt12399.fir.kt @@ -0,0 +1,3 @@ +fun foo(a: Any) { + foo({ index -> } { }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt1293.fir.kt b/compiler/testData/diagnostics/tests/inference/kt1293.fir.kt new file mode 100644 index 00000000000..17db113b303 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt1293.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +//KT-1293 Compiler doesn't show error when element of Array is assigned to Int + +package kt1293 + +fun main() { + val intArray = arrayOfNulls(10) + val i : Int = intArray[0] + requiresInt(intArray[0]) +} + +fun requiresInt(i: Int) {} diff --git a/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt b/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt new file mode 100644 index 00000000000..288e3733bc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt @@ -0,0 +1,85 @@ +// !WITH_NEW_INFERENCE +// !IDIAGNOSTICS: -UNUSED_EXPRESSION + +fun case_1(a: MutableList?>?>?>?>?>?>?) { + if (a != null) { + val b = a[0] // no SMARTCAST diagnostic + if (b != null) { + val c = b[0] + if (c != null) { + val d = c[0] + if (d != null) { + val e = d[0] + if (e != null) { + val f = e[0] + if (f != null) { + val g = f[0] + if (g != null) { + val h = g[0] + if (h != null) { + h.inc() + } + } + } + } + } + } + } + } +} + + +fun case_2(a: MutableList?>?>?>?>?>?>?) { + if (a != null) { + val b = a[0] // no SMARTCAST diagnostic + if (b != null) { + val c = b[0] + if (c != null) { + val d = c[0] + if (d != null) { + val e = d[0] // no SMARTCAST diagnostic + if (e != null) { + val f = e[0] + if (f != null) { + val g = f[0] + if (g != null) { + val h = g[0] // no SMARTCAST diagnostic + if (h != null) { + h.inc() + } + } + } + } + } + } + } + } +} + + +fun case_3(a: MutableList?>?>?>?>?>?>?) { + if (a != null) { + val b = a[0] + if (b != null) { + val c = b[0] + if (c != null) { + val d = c[0] + if (d != null) { + val e = d[0] + if (e != null) { + val f = e[0] + if (f != null) { + val g = f[0] + if (g != null) { + val h = g[0] + if (h != null) { + h.inc() + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt b/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt new file mode 100644 index 00000000000..d9bf315a610 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// Related issue: KT-28654 + +fun select(): K = run { } + +fun test() { + val x: Int = select() + val t = select() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt30405.fir.kt b/compiler/testData/diagnostics/tests/inference/kt30405.fir.kt new file mode 100644 index 00000000000..b769cf1ff57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt30405.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ExpectedTypeFromCast +// !CHECK_TYPE +// Issue: KT-30405 + +inline fun foo(): T { + TODO() +} + +fun test() { + val fooCall = foo() as String // T in foo should be inferred to String + fooCall checkType { _() } + + val safeFooCall = foo() as? String + safeFooCall checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt b/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt new file mode 100644 index 00000000000..db51502b046 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt @@ -0,0 +1,26 @@ +//KT-3184 Type inference seems partially broken +package a + +import java.util.HashMap + +private fun test(value: T, extf: String.(value: T)->Unit) { + "".extf(value) +} + +fun main() { + test(1, {value -> println(value)}) +} + +fun tests() { + val dict = HashMap Unit>() + dict["0"] = { str -> println(str) } + dict["1"] = { println(it) } + + dict.set("1", { println(it) }) + dict["1"] = { r -> println(r) } +} + +// from standard library +operator fun MutableMap.set(key : K, value : V) : V? = this.put(key, value) + +fun println(message : Any?) = System.out.println(message) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt b/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt new file mode 100644 index 00000000000..8aa20cb4c2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt32415.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +NewInference + +abstract class TestType { + open inner class Inner(val item: V) +} + +class Derived: TestType() { + inner class DerivedInner(item: Long): Inner(item) +} diff --git a/compiler/testData/diagnostics/tests/inference/kt32434.fir.kt b/compiler/testData/diagnostics/tests/inference/kt32434.fir.kt new file mode 100644 index 00000000000..72c785a37e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt32434.fir.kt @@ -0,0 +1,32 @@ +// FULL_JDK +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// Issue: KT-32434 + +// FILE: CacheMonoJava.java + +public class CacheMonoJava { + public static Mono lookup(java.util.Map> map, K key) { + throw new UnsupportedOperationException(); + } +} + +// FILE: main.kt + +interface Cache { + fun asMap(): MutableMap +} + +interface Mono +interface Signal : Mono + +interface AttributeDefinition + +val cache: Cache> = TODO() + +object CacheMonoKotlin { + fun lookup(map: MutableMap>, key: K): Mono = TODO() +} + +fun findByName_java(name: String): Mono = CacheMonoJava.lookup(cache.asMap(), name) +fun findByName_kotlin(name: String): Mono = CacheMonoKotlin.lookup(cache.asMap(), name) diff --git a/compiler/testData/diagnostics/tests/inference/kt6175.fir.kt b/compiler/testData/diagnostics/tests/inference/kt6175.fir.kt new file mode 100644 index 00000000000..ec110cd53a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt6175.fir.kt @@ -0,0 +1,49 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER + +fun foo(body: (R?) -> T): T = fail() + +fun test1() { + foo { + true + } + foo { x -> + true + } +} + + +fun bar(body: (R) -> T): T = fail() + +fun test2() { + bar { + true + } + bar { x -> + true + } +} + +fun baz(body: (List) -> T): T = fail() + +fun test3() { + baz { + true + } + baz { x -> + true + } +} + +fun brr(body: (List) -> T): T = fail() + +fun test4() { + brr { + true + } + brr { x -> + true + } +} + +fun fail(): Nothing = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt619.fir.kt b/compiler/testData/diagnostics/tests/inference/kt619.fir.kt new file mode 100644 index 00000000000..34abe88e155 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt619.fir.kt @@ -0,0 +1,4 @@ +class A(t : Int) : Comparable { + var i = t + override fun compareTo(other : A) = (this.i - other.i) +} diff --git a/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.fir.kt b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.fir.kt new file mode 100644 index 00000000000..399d26ddc54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/lambdaInValInitializerWithAnonymousFunctions.fir.kt @@ -0,0 +1,9 @@ +typealias SuspendFn = suspend () -> Unit + +val test1f: suspend () -> Unit = fun () {} +val test2f: suspend Any.() -> Unit = fun Any.() {} + +// This is a bug in the old inference and should be fixed in new inference +// see "Fix anonymous function literals handling in type checker" for more details +val test3f: suspend Any.(Int) -> Int = fun (k: Int) = k + 1 +val test4f: SuspendFn = fun Any.() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/listConstructor.fir.kt b/compiler/testData/diagnostics/tests/inference/listConstructor.fir.kt new file mode 100644 index 00000000000..af1c0fc71be --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/listConstructor.fir.kt @@ -0,0 +1,30 @@ +// !CHECK_TYPE + +package a +//+JDK +import java.util.* + +fun cons(x: A, xs: List): List = xs + +fun nil(): List = arrayList() + +fun test() { + val xs = cons(1, nil()) + val xs1 = cons("", nil()) + val xs2 = cons(1, nil()) + + checkSubtype>(xs) + checkSubtype>(xs1) + checkSubtype>(xs2) +} + + +// --------------------- +// copy from kotlin util + +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) + +fun > Array.toCollection(result: C) : C { + for (element in this) result.add(element) + return result +} diff --git a/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.fir.kt b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.fir.kt new file mode 100644 index 00000000000..a713982a29e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference + +fun bar() { + if (true) { + fun local() { + } + } else { + + } +} diff --git a/compiler/testData/diagnostics/tests/inference/mapFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/mapFunction.fir.kt new file mode 100644 index 00000000000..b9232a4cf5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/mapFunction.fir.kt @@ -0,0 +1,35 @@ +// !CHECK_TYPE + +package a + +//+JDK +import java.util.* + +fun foo() { + val v = array(1, 2, 3) + + val u = v map { it * 2 } + + checkSubtype>(u) + + val a = 1..5 + + val b = a.map { it * 2 } + + checkSubtype>(b) + + //check for non-error types + checkSubtype(u) + checkSubtype(b) +} + + +// --------------------- +// copy from kotlin util (but with `infix` modifier on `map`) + +@Suppress("UNCHECKED_CAST") +fun array(vararg t : T) : Array = t as Array + +infix fun Array.map(transform : (T) -> R) : List {} + +infix fun Iterable.map(transform : (T) -> R) : List {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.fir.kt b/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.fir.kt new file mode 100644 index 00000000000..5907bf98364 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.fir.kt @@ -0,0 +1,24 @@ +// !CHECK_TYPE + +package i + +//+JDK +import java.util.* + +fun Collection.map1(f : (T) -> R) : List {} +fun java.lang.Iterable.map1(f : (T) -> R) : List {} + +fun test(list: List) { + val res = list.map1 { it } + //check res is not of error type + checkSubtype(res) +} + +fun Collection.foo() {} +fun java.lang.Iterable.foo() {} + +fun test1(list: List) { + val res = list.foo() + //check res is not of error type + checkSubtype(res) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/arrayAccess.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/arrayAccess.fir.kt new file mode 100644 index 00000000000..2657debff59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/arrayAccess.fir.kt @@ -0,0 +1,11 @@ +package b + +class A { + operator fun get(i: Int): List = throw Exception("$i") +} + +fun bar(l: List) = l + +fun test(a: A) { + bar(a[12]) +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt new file mode 100644 index 00000000000..8abe5806286 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt @@ -0,0 +1,72 @@ +// !WITH_NEW_INFERENCE +package h + +interface A {} + +fun newA(): A = throw Exception() + +interface Z + +fun id(t: T): T = t + +//binary expressions +//identifier +infix fun Z.foo(a: A): A = a + +fun test(z: Z) { + z foo newA() + val a: A = id(z foo newA()) + val b: A = id(z.foo(newA())) + use(a, b) +} + +//binary operation expression +operator fun Z.plus(a: A): A = a + +fun test1(z: Z) { + id(z + newA()) + val a: A = z + newA() + val b: A = z.plus(newA()) + val c: A = id(z + newA()) + val d: A = id(z.plus(newA())) + use(a, b, c, d) +} + +//comparison operation +operator fun Z.compareTo(a: A): Int { use(a); return 1 } + +fun test2(z: Z) { + val a: Boolean = id(z < newA()) + val b: Boolean = id(z < newA()) + use(a, b) +} + +//'equals' operation +fun Z.equals(any: Any): Int { use(any); return 1 } + +fun test3(z: Z) { + z == newA() + z == newA() + id(z == newA()) + id(z == newA()) + + id(z === newA()) + id(z === newA()) +} + +//'in' operation +fun test4(collection: Collection>) { + id(newA() in collection) + id(newA() in collection) +} + +//boolean operations +fun toBeOrNot(): Boolean = throw Exception() + +fun test5() { + if (toBeOrNot() && toBeOrNot()) {} + if (toBeOrNot() && toBeOrNot()) {} +} + +//use +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.fir.kt new file mode 100644 index 00000000000..ef4e3dfba39 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.fir.kt @@ -0,0 +1,9 @@ +package a + +fun test(c: C) { + foo(c.b) +} + +fun foo(s: String) = s + +class C(val b: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsForArraySetExpression.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsForArraySetExpression.fir.kt new file mode 100644 index 00000000000..583ec9f7104 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsForArraySetExpression.fir.kt @@ -0,0 +1,8 @@ +fun foo(t: T) = t + +fun test(map: MutableMap, t: Int) { + map [t] = foo(t) // t was marked with black square +} + +//from library +operator fun MutableMap.set(key : K, value : V) : V? = this.put(key, value) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsInference.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsInference.fir.kt new file mode 100644 index 00000000000..eea79c7bf82 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsInference.fir.kt @@ -0,0 +1,19 @@ +package a + +import java.util.ArrayList + +public fun Iterable.withIndices(): List> { + val answer = ArrayList>() + var nextIndex = 1 + for (e in this) { + answer.add(Pair(nextIndex, e)) + nextIndex++ + } + return answer +} + +//from standard library +public class Pair( + public val first: A, + public val second: B +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedForVariableAsFunctionCall.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedForVariableAsFunctionCall.fir.kt new file mode 100644 index 00000000000..93fafdcf02d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedForVariableAsFunctionCall.fir.kt @@ -0,0 +1,16 @@ +package j + +interface MyFunc {} + +class A(val b: B) { +} + +class B { + operator fun invoke(f: (T) -> T): MyFunc = throw Exception() +} + +fun id(r: R) = r + +fun foo(a: A) { + val r : MyFunc = id (a.b { x -> x + 14 }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/externalTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/externalTypeParameter.fir.kt new file mode 100644 index 00000000000..f2f16c4c3b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/externalTypeParameter.fir.kt @@ -0,0 +1,6 @@ +class A { + fun foo(s: S): S = s + fun bar(s: U): List = null!! + + fun test() = foo(bar("")) +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/inferenceForNestedBinaryCall.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/inferenceForNestedBinaryCall.fir.kt new file mode 100644 index 00000000000..df887b2f1c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/inferenceForNestedBinaryCall.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +package aaa + +infix fun T.foo(t: T) = t + +fun id(t: T) = t + +fun a() { + val i = id(2 foo 3) + checkSubtype(i) // i shouldn't be resolved to error element +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3395.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3395.fir.kt new file mode 100644 index 00000000000..41a96b8a2eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3395.fir.kt @@ -0,0 +1,35 @@ +//KT-3395 mapOf function can't be used as literal +package b + +import java.util.ArrayList + +public fun query(t: T, args: Map): List { + return ArrayList() +} + +fun test(pair: Pair) { + val id = "Hello" // variable is marked as unused + + println("Some" + query(0, mapOf(id to 1))) + + println("Some" + query(0, mapOf(pair))) +} + + +//from standard library +fun mapOf(vararg values: Pair): Map { throw Exception() } + +infix fun A.to(that: B): Pair { throw Exception() } + +fun println(message : Any?) { throw Exception() } + +class Pair () {} + +//short example +fun foo(t: T) = t + +fun test(t: String) { + + println("Some" + foo(t)) // t was marked with black square +} + diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3461checkTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3461checkTypes.fir.kt new file mode 100644 index 00000000000..ec9c0298aeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/kt3461checkTypes.fir.kt @@ -0,0 +1,15 @@ +//KT-3461 Nullable argument allowed where shouldn't be +package a + +class F { + fun p(): String? = null +} + +fun foo(s: String) {} + +fun r(): Int? = null + +fun test() { + foo(F().p()) + foo(r()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt new file mode 100644 index 00000000000..7c4b7fe3e78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/makeNullableIfSafeCall.fir.kt @@ -0,0 +1,41 @@ +package a + +interface A { + val b: B + val nb: B? +} + +interface B { + fun foo(): Int +} + +fun test(u: A?, x: A?, y: A?, z: A?, w: A, v: A?) { + u?.b?.foo()!! // was UNNECESSARY_SAFE_CALL everywhere, because result type (of 'foo()') wasn't made nullable + u!!.b?.foo()!! + x?.b!!.foo()!! + // x?.b is not null + x!!.b!!.foo()!! + + y?.nb?.foo()!! + y!!.nb?.foo()!! + z?.nb!!.foo()!! + // z?.nb is not null + z!!.nb!!.foo()!! + + w.b?.foo()!! + w.b!!.foo()!! + w.nb?.foo()!! + w.nb!!.foo()!! + + v!!.b.foo()!! +} + +fun B?.bar(): Int = 1 +fun B?.baz(): Int? = 1 + +fun doInt(i: Int) = i + +fun test(a: A?) { + doInt(a?.b.bar()!!) + doInt(a?.b.baz()!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.fir.kt new file mode 100644 index 00000000000..8ca1f233a12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/nontrivialCallExpression.fir.kt @@ -0,0 +1,18 @@ +package a + +fun foo(l: List): Int = l.get(0) + +fun emptyList(): List = throw Exception() + +fun makeNullable(t: T): T? = null + +fun bar(i: Int) = i +fun bar(a: Any) = a + +fun test(array: Array) { + bar(array[foo(emptyList())]) + + bar(foo(emptyList()) + foo(a.emptyList())) + + bar(makeNullable(foo(emptyList())) ?: 0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/noInformationForParameter.fir.kt b/compiler/testData/diagnostics/tests/inference/noInformationForParameter.fir.kt new file mode 100644 index 00000000000..1c9eed8c115 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/noInformationForParameter.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +package noInformationForParameter +//+JDK + +import java.util.* + +fun test() { + val n = newList() + + val n1 : List = newList() +} + +fun newList() : ArrayList { + return ArrayList() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/complexDependancyOnVariableWithTrivialConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/complexDependancyOnVariableWithTrivialConstraint.fir.kt new file mode 100644 index 00000000000..6e5b1719e8f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/complexDependancyOnVariableWithTrivialConstraint.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// Validation test. +// Check that type variable is fixed to Data as it's used in input types for lambda + +class Data(val x: T) { + fun dataMethod() {} +} + +fun bar(x: K, y: (K) -> Unit) {} + +fun test() { + bar(Data(null)) { it.dataMethod() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.fir.kt new file mode 100644 index 00000000000..e387e3f09bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Out(val o: T) + +interface Base +class Inv : Base + +fun select(x: S, y: S): S = x + +fun test(a1: Inv, a2: Inv): Out { + return select(Out(a1), Out(a2)) +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.fir.kt new file mode 100644 index 00000000000..35389378196 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/implicitNothingConstraintFromReturn.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Simple + +fun test(s: Simple?): Simple? { + myRun { + s?.let { return it } + } + + return s +} + +inline fun myRun(block: () -> R): R = TODO() +inline fun K.let(block: (K) -> V): V = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt24490.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt24490.fir.kt new file mode 100644 index 00000000000..e51d9a63070 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt24490.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun bar(i: T): T = i +fun foo(i: Int) = i + +fun dontRun(body: () -> Unit) = Unit + +class Case1 { + fun test() { + dontRun { val x = bar(bar { -> bar { -> 2} }) } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt32051.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt32051.fir.kt new file mode 100644 index 00000000000..7bd6b74bcd0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt32051.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +interface LevelA +interface LevelB : LevelA + +class BiType { + fun pullXb(x: X): BiType = TODO() + fun pullYb(y: Y): BiType = TODO() + fun pullXn(x: X): BiType = TODO() + fun pullYn(y: Y): BiType = TODO() +} + +fun adjustIt(fn: () -> X): X = TODO() +fun adjustIt(f1: () -> X, f2: () -> X): X = TODO() + +fun callAdjustIt(t: BiType<*, *>, x: X, level: LevelA) { + val x1 = adjustIt({ t.pullXb(x) }) + + x1 + + val x2 = adjustIt({ t.pullXn(x) }) + + x2 + + val x3 = adjustIt({ t.pullXb(x) }, { t.pullYb(level) }) + + x3 + + val x4 = adjustIt({ t.pullXn(x) }, { t.pullYn(level) }) + + x4 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt32081.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt32081.fir.kt new file mode 100644 index 00000000000..005db4646cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt32081.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun select(x: T, y: T): T = x + +fun foo(x: Int, stringNothing: Out2): Out2 = + select(x.right(), stringNothing) + +fun R.right(): Out2 = TODO() + +class Out2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt32207.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt32207.fir.kt new file mode 100644 index 00000000000..aff2fa3512d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt32207.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Test { + fun hereIdeaFail(values : List, others : List): List> { + return values.map { left(it) }.plus(others.map { right(it) }) + } + + companion object { + fun left(left: L): Test = TODO() + fun right(right: R): Test = TODO() + } +} + +fun Iterable.map(transform: (T) -> R): List = TODO() +operator fun Collection.plus(elements: Iterable): List = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.fir.kt new file mode 100644 index 00000000000..8a83e051a21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/kt32388.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE + +fun Either.recover(f: (A) -> B): Either = when (this) { + is Either.Left -> f(this.a).right() + is Either.Right -> this +} + +fun A.right(): Either = Either.Right(this) + +sealed class Either { + class Left constructor(val a: A) : Either() + class Right constructor(val b: B) : Either() +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.fir.kt new file mode 100644 index 00000000000..f2eec49bdec --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/lambdaNothingAndExpectedType.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun select2(x: K, y: K): K = TODO() +fun select3(x: K, y: K, z: K): K = TODO() + +fun test2(f: ((String) -> Int)?) { + val a0: ((Int) -> Int)? = select2({ it -> it }, null) + val b0: ((Nothing) -> Unit)? = select2({ it -> it }, null) + + select3({ it.length }, f, null) +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/nestedLambdaInferenceWithIncorporationOfVariables.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/nestedLambdaInferenceWithIncorporationOfVariables.fir.kt new file mode 100644 index 00000000000..f784b2bae38 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/nestedLambdaInferenceWithIncorporationOfVariables.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference + +fun id1(k: K): K = k +fun id2(v: V): V = v + +fun test() { + id1 { + id2 { + 3 + } + } +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.fir.kt new file mode 100644 index 00000000000..5f2cd7c5e9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/nothingWithCallableReference.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun select2(x: K, y: K): K = TODO() +fun select3(x: K, y: K, z: K): K = TODO() + +fun dependantSelect2(x: K, y: S) {} +fun dependantSelect3(x: K, y: K, z: S) {} + +fun foo() {} +fun cloneFoo() {} +fun bar(x: Int) {} + +fun test(f1: (Int) -> Unit, f2: kotlin.Function1) { + select2(null, ::foo) + select3(null, f1, ::bar) + select3(null, f2, ::bar) + + select3(null, f1, ::foo) + select3(null, f2, ::foo) + + dependantSelect2(null, ::foo) + dependantSelect3(null, ::foo, ::cloneFoo) + dependantSelect3(null, f1, ::bar) + dependantSelect3(null, ::bar, f1) + + dependantSelect3(null, ::foo, ::bar) + dependantSelect3(null, ::bar, ::foo) + dependantSelect3(null, f1, ::foo) + dependantSelect3(null, ::foo, f1) +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.fir.kt new file mode 100644 index 00000000000..caa0b712e6a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.fir.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: Tasks.java + +public class Tasks { + public static Inv call(JSam f) { + return null; + } +} + +// FILE: JSam.java + +public interface JSam { + V call(); +} + +// FILE: test.kt + +fun withLock(g: () -> K): K = g() + +class Out +class Inv + +fun Inv.asOut(): Out = TODO() + +fun test() { + val o: Out = Tasks.call { + withLock { TODO() } + }.asOut() + + Tasks.call { + withLock { TODO() } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nullableTypeArgumentWithNotNullUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/nullableTypeArgumentWithNotNullUpperBound.fir.kt new file mode 100644 index 00000000000..94716e1b394 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nullableTypeArgumentWithNotNullUpperBound.fir.kt @@ -0,0 +1,11 @@ +fun foo(x: Array, y: Array) { + val xo = outA(x) + val yo = inA(y) + + var f: Array = xo + f = yo +} + + +fun outA(x: Array): Array = TODO() +fun inA(x: Array): Array = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/nullableUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/nullableUpperBound.fir.kt new file mode 100644 index 00000000000..c5cc05a8612 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nullableUpperBound.fir.kt @@ -0,0 +1,9 @@ +package o + +fun foo(): String? { + return accept(JV()) +} + +fun accept(v: JV): R? = null + +open class JV() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/opposite.fir.kt b/compiler/testData/diagnostics/tests/inference/opposite.fir.kt new file mode 100644 index 00000000000..842dfeb34d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/opposite.fir.kt @@ -0,0 +1,11 @@ +package a + +interface Persistent +interface PersistentFactory + +class Relation( + val sources: PersistentFactory, + val targets: PersistentFactory +) { + fun opposite() = Relation(targets, sources) +} diff --git a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt new file mode 100644 index 00000000000..9a3c0019831 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +package a + +import java.util.* + +fun g (f: () -> List) : T {} + +fun test() { + //here possibly can be a cycle on constraints + val x = g { Collections.emptyList() } + + val y = g { Collections.emptyList() } + val z : List = g { Collections.emptyList() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.fir.kt new file mode 100644 index 00000000000..8c06c32ec28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +class Scope + +fun simpleAsync0(block: Scope.() -> T) {} +fun simpleAsync1(block: suspend Scope.() -> T) {} +suspend fun simpleAsync2(block: Scope.() -> T) {} +suspend fun simpleAsync3(block: suspend Scope.() -> T) {} + +fun insideJob0() = doTheJob0() +fun insideJob1() = doTheJob1() +suspend fun insideJob2() = doTheJob2() +suspend fun insideJob3() = doTheJob3() + +fun doTheJob0() = simpleAsync0 { insideJob0() } +fun doTheJob1() = simpleAsync1 { insideJob1() } +suspend fun doTheJob2() = simpleAsync2 { insideJob2() } +suspend fun doTheJob3() = simpleAsync3 { insideJob3() } diff --git a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/localFactorial.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/localFactorial.fir.kt new file mode 100644 index 00000000000..f74f7cd9f22 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/localFactorial.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// See KT-6271 +fun foo() { + fun fact(n: Int) = { + if (n > 0) { + fact(n - 1) * n + } + else { + 1 + } + } +} diff --git a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveFun.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveFun.fir.kt new file mode 100644 index 00000000000..def59b45ae8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveFun.fir.kt @@ -0,0 +1,4 @@ +// !WITH_NEW_INFERENCE +fun foo() { + fun bar() = (fun() = bar()) +} diff --git a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveLambda.fir.kt new file mode 100644 index 00000000000..ffe65d1b70d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/recursiveLambda.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +fun foo() { + fun bar() = { + bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.fir.kt new file mode 100644 index 00000000000..4bddc08a208 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +fun foo() { + fun bar1() = bar1() + + fun bar2() = 1 + bar2() + fun bar3() = id(bar3()) +} + +fun id(x: T) = x diff --git a/compiler/testData/diagnostics/tests/inference/recursiveTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveTypes.fir.kt new file mode 100644 index 00000000000..b8aabee4db1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/recursiveTypes.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION +// !WITH_NEW_INFERENCE + +interface RecursiveGeneric, U> + +class A : RecursiveGeneric +class B : RecursiveGeneric +class C : RecursiveGeneric + +fun select(x: K, y: K): K = x + +fun foo(a: A, b: B, c: C) { + select(a, b) + select(a, c) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/compareBy.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/compareBy.fir.kt new file mode 100644 index 00000000000..cb18881e8f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/compareBy.fir.kt @@ -0,0 +1,9 @@ +class Item(val name: String, val rating: Int): Comparable { + public override fun compareTo(other: Item): Int { + return compareBy(this, other, { rating }, { name }) + } +} + +// from standard library +fun compareBy(a: T?, b: T?, + vararg functions: T.() -> Comparable<*>?): Int = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1029.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1029.fir.kt new file mode 100644 index 00000000000..3d020b79bfd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1029.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +//KT-1029 Wrong type inference +package i + +public fun from(yielder: ()->Iterable) : Iterable { +} + +public infix fun Iterable.where(predicate : (T)->Boolean) : ()->Iterable { +} + +fun a() { + val x = 0..200 + val odd = from (x where {it%2==0}) // I believe it should infer here + + checkSubtype>(odd) +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1031.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1031.fir.kt new file mode 100644 index 00000000000..5574b422d33 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1031.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +//KT-1031 Can't infer type of `it` with two lambdas +package i + +import java.util.ArrayList + +public infix fun Iterable.where(predicate : (TItem)->Boolean) : ()->Iterable { +} + +public fun select(yielder: ()->Iterable, selector : (TItem)->TResult) : ()->Iterable { +} + +fun a() { + val x = 0..200 + val z = x where { i: Int -> i % 2 == 0 } + val yielder = select(x where { it%2==0 }, { it.toString() }) + + checkSubtype<() -> Iterable>(z) + checkSubtype<() -> Iterable>(yielder) +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1127.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.fir.kt new file mode 100644 index 00000000000..bef26ff67bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +//KT-1127 Wrong type computed for Arrays.asList() + +package d + +fun asList(t: T) : List? {} + +fun main() { + val list : List = asList("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1145.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1145.fir.kt new file mode 100644 index 00000000000..c4a1ff3b486 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1145.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +//KT-1145 removing explicit generics on a call to Iterable.map(...) seems to generate an odd bytecode/runtime error + +package d + +fun test(numbers: Iterable) { + val s = numbers.map{it.toString()}.fold(""){it, it2 -> it + it2} + checkSubtype(s) +} + +//from library +fun Iterable.map(transform : (T) -> R) : List {} + +fun Iterable.fold(initial: T, operation: (T, T) -> T): T {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1358.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.fir.kt new file mode 100644 index 00000000000..47f48ec856f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.fir.kt @@ -0,0 +1,12 @@ +//KT-1358 Overload resolution ambiguity with smartcast and generic function +package d + +fun bar(a: Any?) { + if (a != null) { + a.foo() //overload resolution ambiguity + a.sure() //overload resolution ambiguity + } +} + +fun T?.foo() {} +fun T?.sure() : T = this!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1410.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1410.fir.kt new file mode 100644 index 00000000000..56da5d551cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1410.fir.kt @@ -0,0 +1,26 @@ +// !CHECK_TYPE + +// KT-1410 Compiler does automatically infer type argument when using variance +//+JDK +package d + +public fun MutableCollection.filterToMy(result : MutableList, filter : (T) -> Boolean) : MutableCollection { + for (t in this){ + if (filter(t)){ + result.add(t) + } + } + return this +} + +fun foo(result: MutableList, collection: MutableCollection, prefix : String){ + collection.filterToMy(result, {it.startsWith(prefix)}) +} + +fun test(result: MutableList, collection: MutableCollection, prefix : String){ + val c = collection.filterToMy(result, {it.startsWith(prefix)}) + checkSubtype>(c) +} + +//from library +fun String.startsWith(prefix: String) : Boolean {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1718.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1718.fir.kt new file mode 100644 index 00000000000..1fbdb53e7c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1718.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +//KT-1718 compiler error when not using temporary variable +package n + +import java.util.ArrayList + +fun test() { + val list = arrayList("foo", "bar") + arrayList("cheese", "wine") + checkSubtype>(list) + //check it's not an error type + checkSubtype(list) +} + +//from library +fun arrayList(vararg values: T) : ArrayList {} +operator fun Iterable.plus(elements: Iterable): List {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1944.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1944.fir.kt new file mode 100644 index 00000000000..518a6096516 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1944.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +//KT-1944 Inference fails on run() +package j + +class P { + var x : Int = 0 + private set + + fun foo() { + val r = run {x = 5} // ERROR + checkSubtype(r) + } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2057.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.fir.kt new file mode 100644 index 00000000000..27e53675870 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.ArrayList + +fun foo(a : T, b : Collection, c : Int) { +} + +fun arrayListOf(vararg values: T): ArrayList = throw Exception("$values") + +val bar = foo("", arrayListOf(), ) +val bar2 = foo("", arrayListOf(), ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2179.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2179.fir.kt new file mode 100644 index 00000000000..5e0aa34d03d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2179.fir.kt @@ -0,0 +1,46 @@ +// !CHECK_TYPE + +//KT-2179 Nested function literal breaks compiler +package i + +//+JDK +import java.util.* + +fun test() { + val sample1: List> = arrayList(arrayList(1, 7, null, 8)) + + //breaks compiler + val sample2 = sample1.map({it.map({it})}) + checkSubtype>>(sample2) + + //breaks compiler + val sample3 = sample1.map({row -> row.map({column -> column})}) + checkSubtype>>(sample3) + + //doesn't break compiler + val identity: (Int?) -> Int? = {column -> column} + val sample4 = sample1.map({row -> row.map(identity)}) + checkSubtype>>(sample4) +} + +//------------ + +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) + +fun Collection.map(transform : (T) -> R) : List { + return mapTo(java.util.ArrayList(this.size), transform) +} + +fun > Collection.mapTo(result: C, transform : (T) -> R) : C { + for (item in this) + result.add(transform(item)) + return result +} + +fun > Array.toCollection(result: C) : C { + for (element in this) result.add(element) + return result +} + +val Collection<*>.size : Int + get() = size diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2200.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2200.fir.kt new file mode 100644 index 00000000000..ce35fed156d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2200.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +//KT-2200 array(array()) breaks compiler +package n + +fun main() { + val a = array(array()) + val a0 : Array> = array(array()) + val a1 = array(array()) + checkSubtype>>(a1) + val a2 = array>(array()) + checkSubtype>>(a2) +} + +//from library +@Suppress("UNCHECKED_CAST") +fun array(vararg t : T) : Array = t as Array \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2283.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.fir.kt new file mode 100644 index 00000000000..e64755422b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +//KT-2283 Bad diagnostics of failed type inference +package a + + +interface Foo + +fun Foo.map(f: (A) -> B): Foo = object : Foo {} + + +fun foo() { + val l: Foo = object : Foo {} + val m: Foo = l.map { ppp -> 1 } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt new file mode 100644 index 00000000000..dc8b9a5cb70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// KT-2286 Improve error message for nullability check failure for extension methods + +package n + +abstract class Buggy { + + abstract val coll : Collection + + fun getThree(): Int? { + return coll.find{ it > 3 } // works fine + } + + val anotherThree : Int + get() = coll.find{ it > 3 } // does not work here + + val yetAnotherThree : Int + get() = coll.find({ v:Int -> v > 3 }) // neither here + + val extendedGetter : Int + get() { + return coll.find{ it > 3 } // not even here! + } + +} + +//from library +fun Iterable.find(predicate: (T) -> Boolean) : T? {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2294.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2294.fir.kt new file mode 100644 index 00000000000..c5e4fa5eb02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2294.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +//KT-2294 Type inference infers DONT_CARE instead of correct type +package a + +public fun foo(array: Array): Array = array + +public fun test() +{ + val x = foo(array(1, 2, 3, 4, 5)) // Should infer type 'Int' + // ^--- public final fun array(vararg t : DONT_CARE) : kotlin.Array defined in Kotlin + // ^--- public final fun foo(items t : kotlin.Array) : kotlin.Array defined in root package + checkSubtype>(x) +} + +//-------------------- +@Suppress("UNCHECKED_CAST") +fun array(vararg t : T) : Array = t as Array diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2320.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2320.fir.kt new file mode 100644 index 00000000000..b132028c344 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2320.fir.kt @@ -0,0 +1,13 @@ +//KT-2320 failure of complex case of type inference +package i + +interface NotMap + +interface Entry { + fun getValue(): B +} + + +fun NotMap.mapValuesOriginal(ff: (Entry) -> R): NotMap = throw Exception() + +fun NotMap.mapValuesOnly(f: (B) -> C) = mapValuesOriginal { e -> f(e.getValue()) } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2324.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2324.fir.kt new file mode 100644 index 00000000000..5ff13eabd11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2324.fir.kt @@ -0,0 +1,35 @@ +// !CHECK_TYPE + +//KT-2324 Can't resolve generic by type of function result +package i + +//+JDK +import java.util.* + +fun someFunction(list: List, transform: (T) -> K): List { + val result = arrayList() + for (i in list) { + result.add(transform(i)) + } + return result +} + +fun testSomeFunction() { + val result1 = someFunction(arrayList(1, 2), {checkSubtype(it)}) //type of result1 is List + assertEquals(1, result1.get(0)); //OK + + val result2 = someFunction(arrayList(1, 2), {it}) // type of result2 is List + checkSubtype>(result2) + assertEquals(1, result2.get(0)); //resolved to error element +} + +//--------------------------------- +fun assertEquals(expected: Any?, actual: Any?, message: String = "") { +} + +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) + +fun > Array.toCollection(result: C) : C { + for (element in this) result.add(element) + return result +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2407.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2407.fir.kt new file mode 100644 index 00000000000..836e667aec3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2407.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +package n + +import java.util.* + +fun test() { + val foo = arrayList("").map { it -> it.length }.fold(0, { x, y -> Math.max(x, y) }) + checkSubtype(foo) + checkSubtype(foo) +} + +//from library +fun arrayList(vararg values: T) : ArrayList {} + +fun Collection.map(transform : (T) -> R) : List {} + +fun Iterable.fold(initial: T, operation: (T, T) -> T): T {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2445.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2445.fir.kt new file mode 100644 index 00000000000..2cef6dc4105 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2445.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNREACHABLE_CODE +//KT-2445 Calling method with function with generic parameter causes compile-time exception +package a + +fun main() { + test { + + } +} + +fun test(callback: (R) -> Unit):Unit = callback(null!!) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2459.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2459.fir.kt new file mode 100644 index 00000000000..4e0e772278b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2459.fir.kt @@ -0,0 +1,10 @@ +//KT-2459 Type inference error +package b + +import java.util.* + +class B(val x: List) +fun f(x: T): B = B(arrayList(x)) + +// from standard library +fun arrayList(vararg values: T) : ArrayList {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2484.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2484.fir.kt new file mode 100644 index 00000000000..6071cfac1b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2484.fir.kt @@ -0,0 +1,18 @@ +//KT-2484 Type inferred for function literal is (...) -> Int instead of (...) -> Unit, when function literal parameter is explicit + +package a +//+JDK + +fun Array.forEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) } + +fun bar(operation: (String) -> Unit) = operation("") + +fun main(args: Array) { + args.forEach { a : String -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { a -> a.length } // Type mismatch: (String) -> Unit required, (String) -> Int found + args.forEach { it.length } // This works! + + bar { a: String -> a.length } + bar { a -> a.length } + bar { it.length } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2505.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2505.fir.kt new file mode 100644 index 00000000000..510d55c6d3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2505.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE + +//KT-2505 Type mismatch: inferred type is T but T was expected + +package a + +interface MyType {} +class MyClass : MyType {} + +public open class HttpResponse() { + public open fun parseAs(dataClass : MyClass) : T { + throw Exception() + } + public open fun parseAs(dataType : MyType) : Any? { + return null + } +} + +fun test (httpResponse: HttpResponse, rtype: MyClass) { + val res = httpResponse.parseAs( rtype ) + checkSubtype(res) //type mismatch: required R, found T +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2514.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2514.fir.kt new file mode 100644 index 00000000000..1dff03baa7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2514.fir.kt @@ -0,0 +1,16 @@ +//KT-2514 Type inference fails when using extension function literal +package kt2514 + +//+JDK +import java.io.Closeable + +fun Thread.use(block: Thread.() -> T): T = block() + +fun T.use(block: (T)-> R) : R = block(this) + +fun main() { + Thread().use { } // compilation error: Type inference failed + Thread().use { 5 + 5 } // compilation error: Type inference failed + Thread().use { } // compiles okay + Thread().use { 5 + 5 } // compiles okay +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2588.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.fir.kt new file mode 100644 index 00000000000..bfe802621b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//T-2588 Allow to specify exact super type (expected) in inference if many + +import java.util.HashSet + +class MyClass() + +interface A +interface D +class B : A, D +class C : A, D + +fun hashSetOf(vararg values: T): HashSet = throw Exception("$values") + +fun foo(b: MyClass, c: MyClass) { + val set1 : Set> = hashSetOf(b, c) //type inference expected type mismatch + val set2 = hashSetOf(b, c) //Set> is inferred +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2741.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.fir.kt new file mode 100644 index 00000000000..f08cf948b9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.fir.kt @@ -0,0 +1,11 @@ +//KT-2741 Compiler can't infer a type of a function literal parameter when its body contains errors +package a + +fun > Iterable._sortBy(f: (T) -> R): List = throw Exception() +fun _arrayList(vararg values: T) : List = throw Exception() + +class _Pair(val a: A) + +fun test() { + _arrayList(_Pair(1))._sortBy { it -> xxx } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2754.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.fir.kt new file mode 100644 index 00000000000..3fb056c4e15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// T is the immutable type +interface Builder { + fun build(): T +} + +// T is the immutable type, U is the builder +interface Copyable> { + fun builder(): U +} + +fun , U : Builder> T.copy(fn: U.() -> Unit): T = throw Exception() + +open class Foo(val x: Int, val y: Int) : Copyable { + override fun builder(): FooBuilder = FooBuilder(x, y) + + open class FooBuilder(var x: Int, var y: Int): Builder { + override fun build(): Foo = Foo(x, y) + } +} + +fun test() { + val foo1 = Foo(x = 1, y = 2) + val foo2 = foo1.copy { y = 3 } // this doesn't work + foo2 checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt new file mode 100644 index 00000000000..8d580c9bef0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNREACHABLE_CODE +//KT-2838 Type inference failed on passing null as a nullable argument +package a + +fun foo(a: T, b: Map?) = b?.get(a) +fun bar(a: T, b: Map) = b.get(a) + +fun test(a: Int) { + foo(a, null) + bar(a, null) +} +fun test1(a: Int) { + foo(a, throw Exception()) +} + +fun test2(a: Int) { + bar(a, throw Exception()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.fir.kt new file mode 100644 index 00000000000..1864a243328 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.fir.kt @@ -0,0 +1,15 @@ +package a + +interface Closeable {} +class C : Closeable {} + +public inline fun T.use1(block: (T)-> R) : R { + return block(this) +} + +fun main() { + C().use1 { + w -> // ERROR here + x + } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.fir.kt new file mode 100644 index 00000000000..71a2754783b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.fir.kt @@ -0,0 +1,18 @@ +package a + +interface Closeable { + fun close() {} +} + +class C : Closeable + +public inline fun T.use(block: (t: T)-> R) : R { + return block(this) +} + +fun test() { + C().use { + it.close() + x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.fir.kt new file mode 100644 index 00000000000..b245c6ccfb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.fir.kt @@ -0,0 +1,19 @@ +package a + +interface Closeable { + fun close() {} +} + +class C : Closeable + +public inline fun use(t: T, block: T.(T)-> R) : R { + return t.block(t) +} + +fun test() { + use(C()) { + this.close() + it.close() + xx + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.fir.kt new file mode 100644 index 00000000000..166765b55a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.fir.kt @@ -0,0 +1,18 @@ +package a + +interface Closeable { + fun close() {} +} + +class C : Closeable + +public inline fun T.use(block: T.()-> R) : R { + return this.block() +} + +fun test() { + C().use { + this.close() + x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2842.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2842.fir.kt new file mode 100644 index 00000000000..958e980bed9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2842.fir.kt @@ -0,0 +1,27 @@ +package c + +interface A + +fun test(a: A?) { + a.foo() //no error +} + +fun A.foo() {} + +//------------ +fun test(nullabilityInfoMap: Map?) { + nullabilityInfoMap.iterator() //no error +} + +//resolves to +public fun Map.iterator(): Iterator> {} + + +//------------- +fun foo() : Boolean { + val nullableList = getNullableList() + return nullableList.contains("") + +} + +fun getNullableList(): List? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2883.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2883.fir.kt new file mode 100644 index 00000000000..6e9756905d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2883.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +//KT-2883 Type inference fails due to non-Unit value returned +package a + +public fun doAction(action : () -> Unit){ +} + +class Y(val itemToString: (TItem) -> String){ +} + +fun bar(context : Y) : TItem{ +} + +fun foo(){ + val stringToString : (String) -> String = { it } + doAction({bar(Y(stringToString))}) +} + +fun bar(t: T): T = t + +fun test() { + + doAction { bar(12) } + + val u: Unit = bar(11) +} + +fun testWithoutInference(col: MutableCollection) { + + doAction { col.add(2) } + + val u: Unit = col.add(2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3007.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3007.fir.kt new file mode 100644 index 00000000000..495431f6f60 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3007.fir.kt @@ -0,0 +1,43 @@ +//KT-3007 Kotlin plugin 0.4.126 does not compile KAnnotator revision ba0a93eb +package a + +enum class SomeEnum { + FIRST, + SECOND +} + +// Doesn't work +fun Iterable.some() { + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + if (res == SomeEnum.FIRST) SomeEnum.FIRST else SomeEnum.SECOND + }) +} + +fun tempFun() : SomeEnum { + return SomeEnum.FIRST +} + +// Doesn't work +fun Iterable.someSimpleWithFun() { + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + tempFun() + }) +} + + +// Works +fun Iterable.someSimple() { + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + SomeEnum.FIRST + }) +} + +// Works +fun Iterable.someInt() { + this.fold(0, {res : Int, value -> + if (res == 0) 1 else 0 + }) +} + +//from standard library +fun Iterable.fold(initial: R, operation: (R, T) -> R): R {} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3038.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3038.fir.kt new file mode 100644 index 00000000000..dc958bd113c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3038.fir.kt @@ -0,0 +1,22 @@ +//KT-3038 Wrong type inference for enum entry +package a + +enum class TestEnum { + FIRST, + SECOND +} + +fun inferenceTest(a: T) : T = a + +fun hello() { + var enumElemFirst = inferenceTest(TestEnum.FIRST) + enumElemFirst = TestEnum.SECOND // Type mismatch: inferred type is testDebug.TestEnum..SECOND but testDebug.TestEnum..FIRST was expected + + var enumElemSecond : TestEnum = inferenceTest(TestEnum.FIRST) + enumElemSecond = TestEnum.SECOND // Ok + + use(enumElemFirst, enumElemSecond) +} + + +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3150.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.fir.kt new file mode 100644 index 00000000000..64ae0ce8d10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.fir.kt @@ -0,0 +1,24 @@ +package aa + +class Some + +class SomeTemplate { + fun query(some: Class) = some + + + // Uncomment this to get CANNOT_COMPLETE_RESOLVE error + fun query1(some: Class) = some + fun query1(some: Some) = some +} + +fun SomeTemplate.query(f: (i: Int) -> Unit) = f +fun SomeTemplate.query1(f: (i: Int) -> Unit) = f + +fun test() { + val mapperFunction = { i: Int -> } + SomeTemplate().query(mapperFunction) + + // TYPE_MISMATCH: Required Class<[ERROR: CANT_INFER]>, Found (kotlin.Int) -> Unit + SomeTemplate().query { i: Int -> } + SomeTemplate().query1 { i: Int -> } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3174.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3174.fir.kt new file mode 100644 index 00000000000..48bb892a997 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3174.fir.kt @@ -0,0 +1,12 @@ +//KT-3174 Call resolver doesn't understand type is not-nullable after ?. safe call +package a + +fun T.test(): T = this +fun foo(a: Any?) = a?.test() // Error + +fun T.fff(l: MutableList) = l.add(this) + +fun test(s: String?, l: MutableList) { + s?.fff(l) + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.fir.kt new file mode 100644 index 00000000000..5f41403ca68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +interface G { + fun build(): G +} +class V1(val value: V) +class V2(val value: V) +fun G.foo(vararg values: V1) = build() +fun G.foo(vararg values: V2) = build() + +fun forReference(ref: Any?) {} + +fun test() { + forReference(G::foo) +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.fir.kt new file mode 100644 index 00000000000..1a40bd0ff89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +fun foo(s: String) {} +fun foo(i: Long) {} + +fun bar(f: (Boolean) -> Unit) {} + +fun test() { + bar(::foo) +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3301.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3301.fir.kt new file mode 100644 index 00000000000..2f2ba646a29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3301.fir.kt @@ -0,0 +1,20 @@ +//KT-3301 Inference with several supertypes fails + +package arrays + +interface A +interface B + +object CAB : A, B +object DAB : A, B + +fun m(args : Array) { + +} + +fun test122() { + m(array(CAB, DAB)) // Wrong error here: Array is inferred while expected Array is satisfied +} + +//from library +fun array(vararg t: T): Array {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3344.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3344.fir.kt new file mode 100644 index 00000000000..5202a4dcf65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3344.fir.kt @@ -0,0 +1,16 @@ +//KT-3344 InternalError in compiler when type arguments are not specified + +package i + +import java.util.HashMap +import java.util.ArrayList + +class Foo(val attributes: Map) + +class Bar { + val foos = ArrayList() + + fun bar11(foo: Foo) { + foos.add(Foo(HashMap(foo.attributes))) // foo.attributes is unresolved but not marked + } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt34029.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.fir.kt new file mode 100644 index 00000000000..98284406d5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.fir.kt @@ -0,0 +1,6 @@ +open class MyClass { + object MyObject : MyClass() { } +} + +val foo1 = MyClass.MyObject // it's ok +val foo2 = MyClass.MyObject // here's stofl diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt34282.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt34282.fir.kt new file mode 100644 index 00000000000..3697a669688 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt34282.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun bar(y: (Int) -> Int) = 1 +fun foo(x: Float) = 10f +fun foo(x: String) = "" + +fun main() { + bar(::foo) // no report about unresolved callable reference for `foo` +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.fir.kt new file mode 100644 index 00000000000..9468733e750 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// KT-3496 Type inference bug on y[""] + +class B { + fun x (y: B>) { + val z: S = y[""] // does not work with [], but works with .get() + } + operator fun get(s : String): S = throw Exception() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.fir.kt new file mode 100644 index 00000000000..1fc2f31cf73 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import java.util.ArrayList + +class F { + fun x (y: F>, w: ArrayList) { + val z: ArrayList = y["", w] + } +} +operator fun Any.get(s: String, w: ArrayList): ArrayList = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3559.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.fir.kt new file mode 100644 index 00000000000..c1bf2ddfa18 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.fir.kt @@ -0,0 +1,10 @@ +// KT-3559 Strange inference failure error message + +public inline fun let(subj: T?, body: (T) -> R): R? { + return if (subj != null) body(subj) else null +} + + +fun test(s: String?): String? { + return let(s) {s} // Reports: "Inference failed. Expected jet.String? but found jet.String?" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt4420.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.fir.kt new file mode 100644 index 00000000000..8952e6ff724 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE +//KT-4420 Type inference with type projections + +class Foo +fun Foo.bar(): T = throw Exception() + +fun main() { + val f: Foo = Foo() + f.bar() checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt702.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt702.fir.kt new file mode 100644 index 00000000000..8cd37411b95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt702.fir.kt @@ -0,0 +1,20 @@ +//KT-702 Type inference failed +package a +//+JDK + +fun getJavaClass() : java.lang.Class { } + +public class Throwables() { + companion object { + public fun propagateIfInstanceOf(throwable : Throwable?, declaredType : Class?) : Unit { + if (((throwable != null) && declaredType?.isInstance(throwable)!!)) + { + throw declaredType?.cast(throwable)!! + } + } + public fun propagateIfPossible(throwable : Throwable?) : Unit { + propagateIfInstanceOf(throwable, getJavaClass()) // Type inference failed: Mismatch while expanding constraints + propagateIfInstanceOf(throwable, getJavaClass()) // Type inference failed: Mismatch while expanding constraints + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt731.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt731.fir.kt new file mode 100644 index 00000000000..566f5cef041 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt731.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +//KT-731 Missing error from type inference +package a + +class A(x: T) { + val p = x +} + +fun A.foo(x: (T)-> G): G { + return x(this.p) +} + +fun main() { + val a = A(1) + val t: String = a.foo({p -> p}) + checkSubtype(t) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt742.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt742.fir.kt new file mode 100644 index 00000000000..2fedc1e6b87 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt742.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +//KT-742 Stack overflow in type inference +package a + +fun T?.sure() : T = this!! + +class List(val head: T, val tail: List? = null) + +fun List.map1(f: (T)-> Q): List? = tail!!.map1(f) + +fun List.map2(f: (T)-> Q): List? = tail.sure().map2(f) + +fun List.map3(f: (T)-> Q): List? = tail.sure().map3(f) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt8132.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt8132.fir.kt new file mode 100644 index 00000000000..6304e603450 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt8132.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER +// KT-8132 Can't omit lambda parameter types + +fun test(foo: List): T { + return if (true) + throw IllegalStateException() + else + foo.reduce { left, right -> left } // error: inferred type T is not subtype Nothing +} + +fun Iterable.reduce(operation: (S, T) -> S): S = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt832.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt832.fir.kt new file mode 100644 index 00000000000..d7f6d23d92a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt832.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +//KT-832 Provide better diagnostics when type inference fails for an expression that returns a function +package a + +fun fooT2() : (t : T) -> T { + return {it} +} + +fun test() { + fooT2()(1) // here 1 should not be marked with an error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt943.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt943.fir.kt new file mode 100644 index 00000000000..6d899167b02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt943.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE + +//KT-943 Type inference failed +package maze + +//+JDK +import java.util.Collections.* +import java.util.* + +fun foo(lines: List) { + val w = max(lines, comparator {o1, o2 -> + val l1 : Int = o1.length // Types of o1 and o2 are ERROR + val l2 = o2.length + l1 - l2 + }).sure() + checkSubtype(w) +} + +//standard library +fun T?.sure() : T = this!! + +public inline fun comparator(fn: (T,T) -> Int): Comparator {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt9461.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.fir.kt new file mode 100644 index 00000000000..67c205e8bbe --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.fir.kt @@ -0,0 +1,17 @@ +interface In + +interface B : In + +interface C + +fun In.foo(f: () -> C) {} +fun > Self.foo2(f: () -> C) {} + +class E : B // e <: In <: In + +fun test(c: C, e: E) { + e.foo { c } + e.foo { c } // error here: expected C but must be C + e.foo2 { c } + e.foo2 ({ c }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt new file mode 100644 index 00000000000..8d783455714 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +//KT-948 Make type inference work with sure()/!! + +package a + +import java.util.* + +fun emptyList() : List? = ArrayList() + +fun foo() { + // type arguments shouldn't be required + val l : List = emptyList()!! + val l1 = emptyList()!! + + checkSubtype>(emptyList()!!) + checkSubtype?>(emptyList()) + + doWithList(emptyList()!!) +} + +fun doWithList(list: List) = list \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt new file mode 100644 index 00000000000..ffd7499b218 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/noRecursionOnCallingPureKotlinFunctionAsSyntheticJavaAccessor.fir.kt @@ -0,0 +1,3 @@ +class B { + fun getA() = a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportAboutUnresolvedReferenceAsUnresolved.fir.kt b/compiler/testData/diagnostics/tests/inference/reportAboutUnresolvedReferenceAsUnresolved.fir.kt new file mode 100644 index 00000000000..c54efbeda12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportAboutUnresolvedReferenceAsUnresolved.fir.kt @@ -0,0 +1,7 @@ +fun T.map(f: (T) -> U) = f(this) + +fun consume(s: String) {} + +fun test() { + consume(1.map(::foo)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.fir.kt new file mode 100644 index 00000000000..297a148019c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.fir.kt @@ -0,0 +1,9 @@ +package a + +fun foo(block: (T)-> R, second: (T)-> S) = block + +fun main() { + val fff = { x: Int -> aaa } + foo(fff, { x -> x + 1 }) +} + diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.fir.kt new file mode 100644 index 00000000000..b2ae4f1fe28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/FunctionPlaceholder.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +//For testing error messages text see DiagnosticMessageTest.testFunctionPlaceholder +package a + +class A +fun foo(a: A) = a +fun bar(f: (T) -> R) = f + +fun test() { + foo { it } + foo { x -> x} + foo { x: Int -> x} + + bar { it + 1 } + bar { x -> x + 1} + bar { x: Int -> x + 1} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.fir.kt new file mode 100644 index 00000000000..1a875004b90 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.fir.kt @@ -0,0 +1,16 @@ +package a + +interface Closeable {} +class C : Closeable {} + +fun T.foo(block: (T)-> R) = block + +fun T.foo(block: (T, T)-> R) = block + +fun main() { + C().foo { // no ambiguity here + www -> + xs + } +} + diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.fir.kt new file mode 100644 index 00000000000..2196201049b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +package aa + +fun foo(block: (T)-> R) = block + +fun test1() { + foo { + x -> // here we have 'cannot infer parameter type' error + 43 + } +} + +fun bar(f: (A)->Unit) {} + +fun test2() { + bar { a -> } // here we don't have 'cannot infer parameter type' error +} diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/inferTypeFromUnresolvedArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/inferTypeFromUnresolvedArgument.fir.kt new file mode 100644 index 00000000000..14ef9857089 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/inferTypeFromUnresolvedArgument.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun id2(x: K, s: String): K = x +fun ret(s: String): K = TODO() + +fun test() { + id2(unresolved, "foo") + id2(unresolved, 42) + + ret("foo") + ret(42) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.fir.kt new file mode 100644 index 00000000000..15f474ac9b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.fir.kt @@ -0,0 +1,8 @@ +fun test() { + val a = -false +} + +operator fun A.unaryMinus() {} +operator fun B.unaryMinus() {} +class A +class B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.fir.kt new file mode 100644 index 00000000000..984f1fee42b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo (f: ()->R, r: MutableList) = r.add(f()) +fun bar (r: MutableList, f: ()->R) = r.add(f()) + +fun test() { + val a = foo({1}, arrayListOf("")) //no type inference error on 'arrayListOf' + val b = bar(arrayListOf(""), {1}) +} + +// from standard library +fun arrayListOf(vararg values: T) : MutableList {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnComponentN.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnComponentN.fir.kt new file mode 100644 index 00000000000..2a4bbf399ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnComponentN.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class X + +operator fun X.component1(): T = TODO() + +fun test() { + val (y) = X() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnIteratorCall.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnIteratorCall.fir.kt new file mode 100644 index 00000000000..065818b1da8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/typeInferenceFailedOnIteratorCall.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +class X + +operator fun X.iterator(): Iterable = TODO() + +fun test() { + for (i in X()) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.fir.kt new file mode 100644 index 00000000000..5b3f5b533e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +fun A.fn(b: Int): Nothing = TODO() + +fun A.run() { + "".apply { fn("") } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt new file mode 100644 index 00000000000..3a3c8c81dea --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// WITH_RUNTIME + +fun Runnable.test(f: Runnable.(Int) -> Unit) { + f("") +} + +fun test(f: Runnable.(Int) -> Unit, runnable: Runnable) { + with (runnable) { + f("") + } +} + +fun Int.test(f: String.(Int) -> Unit) { + f("", 0) + f("") + with("") { + f(0) + f(0.0) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/delegationAndInference.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/delegationAndInference.fir.kt new file mode 100644 index 00000000000..bac19086767 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/delegationAndInference.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +class A(val map: MutableMap) { + + var a: String by map.withDefault1 { "foo" } +} + +operator fun MutableMap.getValue(thisRef: Any?, property: KProperty<*>): G = throw Exception() + +operator fun MutableMap.setValue(thisRef: Any?, property: KProperty<*>, value: S) {} + +fun MutableMap.withDefault1(default: (key: K) -> V): MutableMap = this diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt new file mode 100644 index 00000000000..18c5e2a05e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class B { + class Builder +} + +typealias ApplyRestrictions = B.Builder.() -> B.Builder + +fun applyRestrictions1(): ApplyRestrictions = TODO() +fun applyRestrictions2() = applyRestrictions1() +fun applyRestrictions3(e: K) = applyRestrictions1() + +fun buildB() { + val a1 = applyRestrictions1() + val a2 = applyRestrictions2() + val a3 = applyRestrictions3("foo") + + B.Builder().a1() + B.Builder().a2() + B.Builder().a3() +} diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitutionOldInference.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitutionOldInference.fir.kt new file mode 100644 index 00000000000..cf0a40467b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitutionOldInference.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class B { + class Builder +} + +typealias ApplyRestrictions = B.Builder.() -> B.Builder + +fun applyRestrictions1(): ApplyRestrictions = TODO() +fun applyRestrictions2() = applyRestrictions1() +fun applyRestrictions3(e: K) = applyRestrictions1() + +fun buildB() { + val a1 = applyRestrictions1() + val a2 = applyRestrictions2() + val a3 = applyRestrictions3("foo") + + B.Builder().a1() + B.Builder().a2() + B.Builder().a3() +} diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/kt6081SubstituteIntoClassCorrectly.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/kt6081SubstituteIntoClassCorrectly.fir.kt new file mode 100644 index 00000000000..e8976cb2bbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/kt6081SubstituteIntoClassCorrectly.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +//KT-6081 Chained generic method calls: wrong type inference + +class Bar + +fun bar(): Bar = null!! + +class Foo { + fun add(bar: Bar): Foo {return this} +} + +fun doesNotWork(bi: Bar, bs: Bar) { + Foo().add(bi).add(bs) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/simpleSubstitutionCheckTypeArgumentsNotTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/simpleSubstitutionCheckTypeArgumentsNotTypeParameters.fir.kt new file mode 100644 index 00000000000..5f9f2718b55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/simpleSubstitutionCheckTypeArgumentsNotTypeParameters.fir.kt @@ -0,0 +1,10 @@ +class A { + fun useT(t: T) = t + + fun newA(): A = A() +} + +fun test1() { + A().newA().useT("") + A().newA().useT(1) +} diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoAnonymousClass.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoAnonymousClass.fir.kt new file mode 100644 index 00000000000..718e458fe96 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoAnonymousClass.fir.kt @@ -0,0 +1,25 @@ +class Test { + private fun T.self() = object { + fun bar(): T { + return this@self + } + } + fun test() { + 1.self().bar() + 1 + } +} + +class Foo { + private fun bar() = object { + fun baz(): Foo { + return this@Foo + } + } + + fun getR(r: R) = r + + fun test() { + Foo().bar().baz().getR(1) + Foo().bar().baz().getR("") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoInnerClass.fir.kt new file mode 100644 index 00000000000..394619704fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoInnerClass.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Outer { + inner class Inner { + fun getOuter(): Outer = this@Outer + fun genericFun(r: R): Outer = this@Outer + } + fun useOuterParam(t: T) {} +} + +fun test1() { + Outer().Inner().getOuter().useOuterParam(22) + Outer().Inner().getOuter().useOuterParam("") +} + + +class A +class B + +fun test1(a: A, b: B) { + Outer().Inner().genericFun(a).Inner().genericFun(b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.fir.kt b/compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.fir.kt new file mode 100644 index 00000000000..0254636798a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.fir.kt @@ -0,0 +1,6 @@ +public fun iterate(initialValue: T, nextFunction: (T) -> T?): Iterator = + throw Exception("$initialValue $nextFunction") + +fun foo() { + iterate(3) { n -> if (n > 0) n - 1 else null } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/typeConstructorMismatch.fir.kt b/compiler/testData/diagnostics/tests/inference/typeConstructorMismatch.fir.kt new file mode 100644 index 00000000000..d6f97330e59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/typeConstructorMismatch.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +package typeConstructorMismatch +//+JDK + +import java.util.* + +fun test(set: Set) { + elemAndList("2", set) + + "".elemAndListWithReceiver("", set) +} + +fun elemAndList(r: R, t: List): R = r +fun R.elemAndListWithReceiver(r: R, t: List): R = r diff --git a/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.fir.kt new file mode 100644 index 00000000000..e620f3720a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.fir.kt @@ -0,0 +1,42 @@ +// !WITH_NEW_INFERENCE +package typeInferenceExpectedTypeMismatch + +import java.util.* + +fun test() { + val s : Set = newList() + use(s) +} + +fun newList() : ArrayList { + return ArrayList() +} + +interface Out +interface In + +interface Two + +interface A +interface B: A +interface C: A + +fun foo(o: Out, i: In): Two = throw Exception("$o $i") + +fun test1(outA: Out, inB: In) { + foo(outA, inB) + + val b: Two = foo(outA, inB) + use(b) +} + +fun bar(o: Out, i: In): Two = throw Exception("$o $i") + +fun test2(outA: Out, inC: In) { + bar(outA, inC) + + val b: Two = bar(outA, inC) + use(b) +} + +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.fir.kt b/compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.fir.kt new file mode 100644 index 00000000000..d6aa122b339 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +NewInference + +class B(val obj: O) { + val v = B(obj) +} diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.fir.kt new file mode 100644 index 00000000000..5f534de1211 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/conflictingSubstitutionsFromUpperBound.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE + +package g + +import java.util.HashSet +fun > convert(src: Collection, dest: C): C = throw Exception("$src $dest") + +fun test(l: List) { + //todo should be inferred + val r = convert(l, HashSet()) + r checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.fir.kt new file mode 100644 index 00000000000..e9d910c26bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.fir.kt @@ -0,0 +1,68 @@ +// !WITH_NEW_INFERENCE +package a + +interface A + +fun emptyList(): List = throw Exception() + +fun test1() { + emptyList() +} + +//-------------- + +fun emptyListOfA(): List = throw Exception() + +fun test2() { + emptyListOfA() +} + +//-------------- + +fun emptyStrangeMap(): Map = throw Exception() + +fun test3() { + emptyStrangeMap() +} + +//-------------- + +fun emptyStrangeMap1(t: T): Map = throw Exception("$t") + +fun test4() { + emptyStrangeMap1(1) +} + +//-------------- + +fun emptyStrangeMap2(t: T): Map where R: T = throw Exception("$t") + +fun test5(a: A) { + emptyStrangeMap2(a) +} + +//-------------- + +fun emptyStrangeMap3(r: R): Map = throw Exception("$r") + +fun test6(a: A) { + emptyStrangeMap3(a) +} + +//-------------- + +fun emptyStrangeMap4(l: MutableList): Map = throw Exception("$l") + +fun test7(list: MutableList) { + emptyStrangeMap4(list) +} + +//-------------- + +fun test7() : Map = emptyStrangeMap() + +//-------------- + +fun foo(): U = throw Exception() + +fun test8(): Int = foo() diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.fir.kt new file mode 100644 index 00000000000..3569deeff8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package s + +interface In + +interface A +interface B +interface C: A, B + +fun foo(in1: In, in2: In): T = throw Exception("$in1 $in2") + +fun test(inA: In, inB: In, inC: In) { + + foo(inA, inB) + + val r = foo(inA, inC) + checkSubtype(r) + + val c: C = foo(inA, inB) + + use(c) +} + +fun bar(in1: In): T = throw Exception("$in1") + +fun test(inA: In) { + val r = bar(inA) + checkSubtype(r) +} + +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.fir.kt new file mode 100644 index 00000000000..6688ff60d29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.fir.kt @@ -0,0 +1,20 @@ +//KT-2856 Fix the getOrElse signature to be able to return any supertype of V +package d + +import java.util.HashMap + +public inline fun Map.getOrElse1(key: K, defaultValue: ()-> V1) : V1 { + if (this.containsKey(key)) { + return this.get(key) as V + } else { + return defaultValue() + } +} + +fun main() { + val map = HashMap() + println(map.getOrElse1(2, { null })) // Error +} + +//from standard library +fun println(message : Any?) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.fir.kt new file mode 100644 index 00000000000..21379475c41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.fir.kt @@ -0,0 +1,13 @@ +fun unescape(value: Any): R? = throw Exception("$value") + +fun foo(v: Any): T? = unescape(v) + +//-------------- + +interface A + +fun unescapeA(value: Any): R? = throw Exception("$value") + + +fun fooA(v: Any): T? = unescapeA(v) + diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/typeParameterAsUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/typeParameterAsUpperBound.fir.kt new file mode 100644 index 00000000000..a88eaaa611f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/typeParameterAsUpperBound.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + + +@kotlin.internal.InlineOnly +public inline fun C.ifEmpty(f: () -> R): R where C : Collection<*>, C : R = if (isEmpty()) f() else this + +public fun listOf(t: T): List = TODO() + + +fun usage(c: List) { + val cn = c.ifEmpty { null } + cn checkType { _?>() } + + val cs = c.ifEmpty { listOf("x") } + cs checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.fir.kt new file mode 100644 index 00000000000..05c1fbf9520 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +package Hello + +open class Base +class StringBase : Base() + +class Client>(x: X) + +fun test() { + val c = Client(StringBase()) // Type inference fails here for T. + val i : Int = c +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.fir.kt new file mode 100644 index 00000000000..17a39c6633e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo(v: V, u: U) = u +fun bar(v: V, u: U) = u + +fun test(a: Any, s: String) { + val b = foo(a, s) + checkItIsExactlyAny(a, arrayListOf(b)) + val c = bar(a, s) + checkItIsExactlyAny(a, arrayListOf(c)) +} + +fun checkItIsExactlyAny(t: T, l: MutableList) {} + +fun baz(v: V, u: MutableSet) = u + +fun test(a: Any, s: MutableSet) { + baz(a, s) +} + +//from standard library +fun arrayListOf(vararg t: T): MutableList {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/useFunctionLiteralsToInferType.fir.kt b/compiler/testData/diagnostics/tests/inference/useFunctionLiteralsToInferType.fir.kt new file mode 100644 index 00000000000..9a8a8632d35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/useFunctionLiteralsToInferType.fir.kt @@ -0,0 +1,16 @@ +package m + +import java.util.HashSet + +// ---------------------------------- +fun testGetOrPut(result : MutableMap>, key: K) { + result.getOrPut(key) { HashSet() } +} + +fun MutableMap.getOrPut(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue") + +// ---------------------------------- +class Property>(val name: String, val default: () -> T) {} + +fun testProperty() = Property("", { -1.toLong() }) +fun testProperty1() = Property("", { "" }) diff --git a/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.fir.kt b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.fir.kt new file mode 100644 index 00000000000..6e63b72af36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.fir.kt @@ -0,0 +1,59 @@ +abstract class Test() { + abstract val x : Int + abstract val x1 : Int get + abstract val x2 : Int get() = 1 + + val a : Int + val b : Int get + val c = 1 + + val c1 = 1 + get + val c2 : Int + get() = 1 + val c3 : Int + get() { return 1 } + val c4 : Int + get() = 1 + val c5 : Int + get() = field + 1 + + abstract var y : Int + abstract var y1 : Int get + abstract var y2 : Int set + abstract var y3 : Int set get + abstract var y4 : Int set get() = 1 + abstract var y5 : Int set(x) {} get() = 1 + abstract var y6 : Int set(x) {} + + var v : Int + var v1 : Int get + var v2 : Int get set + var v3 : Int get() = 1; set + var v4 : Int get() = 1; set(x){} + + var v5 : Int get() = 1; set(x){field = x} + var v6 : Int get() = field + 1; set(x){} + + abstract val v7 : Int get + abstract var v8 : Int get set + var v9 : Int set + var v10 : Int get + abstract val v11 : Int abstract get + abstract var v12 : Int abstract get abstract set + +} + +open class Super(i : Int) + +class TestPCParameters(w : Int, x : Int, val y : Int, var z : Int) : Super(w) { + + val xx = w + + init { + w + 1 + } + + fun foo() = x + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt b/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt new file mode 100644 index 00000000000..091aaf5a166 --- /dev/null +++ b/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt @@ -0,0 +1,228 @@ +// !WITH_NEW_INFERENCE +open class A() { + fun foo() {} +} + +class B() : A() { + fun bar() {} +} + +fun f9(init : A?) { + val a : A? = init + a?.foo() + a?.bar() + if (a is B) { + a.bar() + a.foo() + } + a?.foo() + a?.bar() + if (!(a is B)) { + a?.bar() + a?.foo() + } + if (!(a is B) || a.bar() == Unit) { + a?.bar() + } + if (!(a is B)) { + return; + } + a.bar() + a.foo() +} + +fun f10(init : A?) { + val a : A? = init + if (!(a is B)) { + return; + } + if (!(a is B)) { + return; + } +} + +class C() : A() { + fun bar() { + + } +} + +fun f101(a : A?) { + if (a is C) { + a.bar(); + } +} + +fun f11(a : A?) { + when (a) { + is B -> a.bar() + is A -> a.foo() + is Any -> a.foo() + is Any? -> a.bar() + else -> a?.foo() + } +} + +fun f12(a : A?) { + when (a) { + is B -> a.bar() + is A -> a.foo() + is Any -> a.foo(); + is Any? -> a.bar() + is C -> a.bar() + else -> a?.foo() + } + + if (a is Any?) { + a?.bar() + } + if (a is B) { + a.foo() + a.bar() + } +} + +fun f13(a : A?) { + if (a is B) { + a.foo() + a.bar() + } + else { + a?.foo() + c.bar() + } + + a?.foo() + if (!(a is B)) { + a?.foo() + c.bar() + } + else { + a.foo() + c.bar() + } + + a?.foo() + if (a is B && a.foo() == Unit) { + a.foo() + a.bar() + } + else { + a?.foo() + c.bar() + } + + if (!(a is B) || !(a is C)) { + } + else { + } + + if (!(a is B) || !(a is C)) { + } + + if (!(a is B)) return + a.bar() +} + +fun f14(a : A?) { + while (!(a is B)) { + } + a.bar() +} +fun f15(a : A?) { + do { + } while (!(a is B)) + a.bar() +} + +fun getStringLength(obj : Any) : Char? { + if (obj !is String) + return null + return obj.get(0) // no cast to String is needed +} + +fun toInt(i: Int?): Int = if (i != null) i else 0 +fun illegalWhenBody(a: Any): Int = when(a) { + is Int -> a + is String -> a +} +fun illegalWhenBlock(a: Any): Int { + when(a) { + is Int -> return a + is String -> return a + } +} +fun declarations(a: Any?) { + if (a is String) { + val p4: String = a + } + if (a is String?) { + if (a != null) { + val s: String = a + } + } + if (a != null) { + if (a is String?) { + val s: String = a + } + } +} +fun vars(a: Any?) { + var b: Int = 0 + if (a is Int) { + b = a + } +} +fun returnFunctionLiteralBlock(a: Any?): Function0 { + if (a is Int) return { a } + else return { 1 } +} +fun returnFunctionLiteral(a: Any?): Function0 { + if (a is Int) return { -> a } + else return { -> 1 } +} + +fun returnFunctionLiteralExpressionBody(a: Any?): Function0 = + if (a is Int) { -> a } + else { -> 1 } + + +fun mergeSmartCasts(a: Any?) { + if (a is String || a is Int) { + a.compareTo("") + a.toString() + } + if (a is Int || a is String) { + a.compareTo("") + } + when (a) { + is String, is Any -> a.compareTo("") + } + if (a is String && a is Any) { + val i: Int = a.compareTo("") + } + if (a is String && a.compareTo("") == 0) {} + if (a is String || a.compareTo("") == 0) {} +} + +//mutability +fun f(): String { + var a: Any = 11 + if (a is String) { + // a is a string, despite of being a variable + val i: String = a + a.compareTo("f") + // Beginning from here a is captured in a closure but nobody modifies it + val f: Function0 = { a } + return a + } + return "" +} + +fun foo(aa: Any?): Int { + var a = aa + if (a is Int?) { + return a + } + return 1 +} diff --git a/compiler/testData/diagnostics/tests/inline/anonymousObjects.fir.kt b/compiler/testData/diagnostics/tests/inline/anonymousObjects.fir.kt new file mode 100644 index 00000000000..af6c62677c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/anonymousObjects.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -NON_LOCAL_RETURN_NOT_ALLOWED + +inline fun inlineFun(p: () -> R) { + val s = object { + + val z = p() + + fun a() { + p() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/assignment.fir.kt b/compiler/testData/diagnostics/tests/inline/assignment.fir.kt new file mode 100644 index 00000000000..3e04fcb9ef6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/assignment.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + var d = s + d = s + + var e = ext + e = ext +} + + +inline fun Function1.inlineExt() { + var d = this + d = this +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/andOr.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/andOr.fir.kt new file mode 100644 index 00000000000..8d7a1cd5fb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/andOr.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -TYPE_MISMATCH + +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + s && ext + s || s +} + +inline fun inlineFunWithInvokeNonInline(noinline s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + s && ext + s || s +} + +inline fun Function1.inlineExt() { + invoke(11) + this && this + this || this +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/arrayAccess.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/arrayAccess.fir.kt new file mode 100644 index 00000000000..697bc552738 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/arrayAccess.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE +operator inline fun Function1.get(index : Int) { + +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + s[1] +} + +//noinline +operator fun Function2.get(index : Int) { + +} + +operator fun @ExtensionFunctionType Function3.get(index : Int) { + +} + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) { + s[1] + ext[1] +} diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/assignment.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/assignment.fir.kt new file mode 100644 index 00000000000..7ec7960bb2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/assignment.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -NON_LOCAL_RETURN_NOT_ALLOWED + +operator fun Function1.minusAssign(p: Function1) {} + +inline operator fun Function1.modAssign(p: Function1) = { + this += p + p += this +} + +inline operator fun Function1.plusAssign(p: Function1) { + this -= p + p -= this +} + +operator fun @ExtensionFunctionType Function2.minusAssign(ext : @ExtensionFunctionType Function2) {} + +inline operator fun @ExtensionFunctionType Function2.modAssign(ext : @ExtensionFunctionType Function2) = { + this += ext + ext += this +} + +inline operator fun @ExtensionFunctionType Function2.plusAssign(ext : @ExtensionFunctionType Function2) { + this -= ext + ext -= this +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) { + s += s + ext += ext +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/comparison.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/comparison.fir.kt new file mode 100644 index 00000000000..af0da08e58c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/comparison.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE + +inline operator fun Function1.compareTo(p: Function1) = 1 + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + s < s + s <= s + s > s + s >= s +} + +//noinline +operator fun Function2.compareTo(index : Function2) = 1 +operator fun @ExtensionFunctionType Function3.compareTo(index : @ExtensionFunctionType Function3) = 1 + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) { + s < s + s <= s + s > s + s >= s + + ext < ext + ext > ext + ext <= ext + ext >= ext +} diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/componentAccess.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/componentAccess.fir.kt new file mode 100644 index 00000000000..d57da8784d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/componentAccess.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE +inline operator fun Function1.component1() = 1 +inline operator fun Function1.component2() = 2 + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + val (d1, e1) = s +} + +operator fun Function2.component1() = 1 +operator fun Function2.component2() = 2 + +operator fun @ExtensionFunctionType Function3.component1() = 1 +operator fun @ExtensionFunctionType Function3.component2() = 2 + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) { + val (d1, e1) = s + val (d2, e2) = ext +} diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.fir.kt new file mode 100644 index 00000000000..d74c5d90803 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE +operator inline fun Function1.contains(p: Function1): Boolean { + this in p + p in this + return false +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + s in s + s !in s +} + + +operator fun Function2.contains(p: Function2): Boolean = false + +operator fun @ExtensionFunctionType Function3.contains(ext: @ExtensionFunctionType Function3): Boolean = false + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> U, ext: T.(p: U, l: U) -> V) { + s in s + s !in s + + ext in ext + ext !in ext +} diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/mathOperations.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/mathOperations.fir.kt new file mode 100644 index 00000000000..d641299f7b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/mathOperations.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -CONFLICTING_JVM_DECLARATIONS -CONFLICTING_OVERLOADS +operator fun Function1.minus(p: Function1) { + +} + +operator fun @ExtensionFunctionType Function2.minus(p: T.(p: U) -> V) { + +} + +inline operator fun Function1.plus(p: Function1) { + this - p +} + +inline operator fun @ExtensionFunctionType Function2.plus(p: T.(p: U) -> V) { + this - p +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) { + s + s + ext + ext +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) { + s + s + ext + ext +} + +inline fun Function1.submit() { + this + this +} + +inline fun @ExtensionFunctionType Function2.submit() { + this + this +} diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.fir.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.fir.kt new file mode 100644 index 00000000000..fca75c38907 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE + +inline operator fun Function1.rangeTo(p: Function1): ClosedRange { + this..p + p..this + return 1..2 +} + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + s..s + s..s +} + + +operator fun Function2.rangeTo(p: Function2): ClosedRange { + return 1..2 +} + +operator fun @ExtensionFunctionType Function3.rangeTo(ext: @ExtensionFunctionType Function3): ClosedRange { + return 1..2 +} + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> U, ext: T.(p: U, l: U) -> V) { + s..s + s..s + + ext..ext + ext..ext +} diff --git a/compiler/testData/diagnostics/tests/inline/capture.fir.kt b/compiler/testData/diagnostics/tests/inline/capture.fir.kt new file mode 100644 index 00000000000..57dbe1cc45f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/capture.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -NON_LOCAL_RETURN_NOT_ALLOWED + +infix fun Function1.noInlineExt(p: Int) {} + +inline infix fun Function1.inlineExt2(p: Int) { + { + noInlineExt(11) + this.noInlineExt(11) + this noInlineExt 11 + this + }() +} + + +inline fun Function1.inlineExt() { + { + inlineExt2(1) + this.inlineExt2(1) + this inlineExt2 1 + this(11) + }() +} + +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit) { + { + s(11) + s.invoke(11) + s invoke 11 + }() +} + +inline fun inlineFunWithInvokeNonInline(noinline s: (p: Int) -> Unit) { + { + s(11) + s.invoke(11) + s invoke 11 + }() +} + + +inline fun testExtension(s: (p: Int) -> Unit) { + { + s.inlineExt() + } () +} + +inline fun inlineFunWrongExtension(s: (p: Int) -> Unit) { + { + s.noInlineExt(11) + } () +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/constructor.fir.kt b/compiler/testData/diagnostics/tests/inline/constructor.fir.kt new file mode 100644 index 00000000000..288bd2417ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/constructor.fir.kt @@ -0,0 +1,7 @@ +class Z(s: (Int) -> Int) { + +} + +public inline fun test(s : (Int) -> Int) { + Z(s) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/default.fir.kt b/compiler/testData/diagnostics/tests/inline/default.fir.kt new file mode 100644 index 00000000000..6a0b5067607 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/default.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun default(s : Int = 10) { + +} + +inline fun default2(p: Int, s : String = "OK") { + +} + +open class Base { + inline final fun foo(a: Int = 1) {} + + inline final fun foo2(a: Int = 1, s: String = "OK") {} +} diff --git a/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineDisable.fir.kt b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineDisable.fir.kt new file mode 100644 index 00000000000..303a77830d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineDisable.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +// !LANGUAGE: -InlineDefaultFunctionalParameters + +fun test() = "OK" + +val prop = "OK" + +class Foo { + fun test() = "OK" + val prop = "OK" +} + +object FooObject { + fun test() = "OK" + val prop = "OK" +} + +inline fun default1(s : () -> String = { "OK" }) {} +inline fun default2(s : () -> String = ::test) {} +inline fun default3(s : () -> String = ::prop) {} +inline fun default4(s : () -> String = FooObject::test) {} +inline fun default5(s : () -> String = FooObject::prop) {} +inline fun default6(s : (a: Foo) -> String = Foo::test) {} +inline fun default7(s : (a: Foo) -> String = Foo::prop) {} + +val a = Foo() + +inline fun default8(s : () -> String = a::test) {} +inline fun default9(s : () -> String = a::prop) {} + +inline fun default10(s : () -> String = object : Function0 { + override fun invoke(): String { + return "FAIL" + } +}) {} + + +abstract class Base { + abstract fun foo(f: () -> Unit = { }) +} + +class Derived : Base() { + override final inline fun foo(f: () -> Unit) { + f() + } +} + +inline fun default11(s : () -> Derived = ::Derived) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineSuspend.fir.kt b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineSuspend.fir.kt new file mode 100644 index 00000000000..03209ab4197 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlineSuspend.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE -NOTHING_TO_INLINE +// SKIP_TXT + +suspend inline fun test1(s : suspend () -> String = { "OK" }) {} +suspend inline fun test2(s : () -> String = { "OK" }) {} +suspend inline fun test3(crossinline s : suspend () -> String = { "OK" }) {} +suspend inline fun test4(crossinline s : () -> String = { "OK" }) {} +suspend inline fun test5(noinline s : suspend () -> String = { "OK" }) {} +suspend inline fun test6(noinline s : () -> String = { "OK" }) {} + diff --git a/compiler/testData/diagnostics/tests/inline/defaultLambdaInlining.fir.kt b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlining.fir.kt new file mode 100644 index 00000000000..0836ab9ef8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/defaultLambdaInlining.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +// !LANGUAGE: +InlineDefaultFunctionalParameters + +fun test() = "OK" + +val prop = "OK" + +class Foo { + fun test() = "OK" + val prop = "OK" +} + +object FooObject { + fun test() = "OK" + val prop = "OK" +} + +inline fun default1(s : () -> String = {"OK"}) {} +inline fun default2(s : () -> String = ::test) {} +inline fun default3(s : () -> String = ::prop) {} +inline fun default4(s : () -> String = FooObject::test) {} +inline fun default5(s : () -> String = FooObject::prop) {} +inline fun default6(s : (a: Foo) -> String = Foo::test) {} +inline fun default7(s : (a: Foo) -> String = Foo::prop) {} + +val a = Foo() + +inline fun default8(s : () -> String = a::test) {} +inline fun default9(s : () -> String = a::prop) {} + +inline fun default10(s : () -> String = object : Function0 { + override fun invoke(): String { + return "FAIL" + } +}) {} + +abstract class Base { + abstract fun foo(f: () -> Unit = { }) +} + +class Derived : Base() { + override final inline fun foo(f: () -> Unit) { + f() + } +} + +inline fun default11(s : () -> Derived = ::Derived) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/extensionOnFunction.fir.kt b/compiler/testData/diagnostics/tests/inline/extensionOnFunction.fir.kt new file mode 100644 index 00000000000..6ab76240945 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/extensionOnFunction.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +infix fun Function1.noInlineExt(p: Int) {} + +inline infix fun Function1.inlineExt2(p: Int) { + noInlineExt(11) + this.noInlineExt(11) + this noInlineExt 11 + this +} + +inline fun Function1.inlineExt() { + inlineExt2(1) + this.inlineExt2(1) + this inlineExt2 1 +} + +inline fun testExtension(s: (p: Int) -> Unit) { + s.inlineExt() +} + +inline fun inlineFunWrongExtension(s: (p: Int) -> Unit) { + s.noInlineExt(11) +} + +inline fun inlineFunNoInline(noinline s: (p: Int) -> Unit) { + s.noInlineExt(11) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.fir.kt b/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.fir.kt new file mode 100644 index 00000000000..065f4c26ceb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.fir.kt @@ -0,0 +1,7 @@ +inline fun onlyLocal(p: () -> R) { + inlineAll(p) +} + +inline fun inlineAll(noinline p: () -> R) { + p() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/functions.fir.kt b/compiler/testData/diagnostics/tests/inline/functions.fir.kt new file mode 100644 index 00000000000..41bb698bd4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/functions.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -UNNECESSARY_NOT_NULL_ASSERTION -UNNECESSARY_SAFE_CALL + +fun getFun(s: (p: Int) -> Unit): Function1 = {11} + +inline fun getInlineFun(s: (p: Int) -> Unit): Function1 = {11} + +inline fun testExtension(s: (p: Int) -> Unit) { + getFun(s).invoke(10) + getInlineFun(s).invoke(10) + getInlineFun(s)!!.invoke(10) + getInlineFun(s)?.invoke(10) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameter.fir.kt b/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameter.fir.kt new file mode 100644 index 00000000000..3ad7a5dce69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameter.fir.kt @@ -0,0 +1,58 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +// !LANGUAGE: +InlineDefaultFunctionalParameters + +inline fun inlineFun(lambda: () -> String) = lambda() + +fun noInlineFun(lambda: () -> String) = lambda() + + +inline fun default0_1(lambda: () -> String, dlambda: () -> String = { lambda; "OK" }) { + lambda() + dlambda() +} + +inline fun default0_2(lambda: () -> String, dlambda: () -> String = { noInlineFun (lambda) }) { + lambda() + dlambda() +} + + + +inline fun default0(lambda: () -> String, dlambda: () -> String = { noInlineFun (lambda) }) { + lambda() + dlambda() +} + +inline fun default1_0(lambda: () -> String, dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_1(lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_1crossinline(crossinline lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_2(noinline lambda: () -> String, dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_3(noinline lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + + +inline fun default2_1(lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_1crossinline(crossinline lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_2(noinline lambda: () -> String, dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_3(noinline lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} diff --git a/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameterDisabled.fir.kt b/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameterDisabled.fir.kt new file mode 100644 index 00000000000..8a831f8e5c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/inlineLambdaInDefaultInlineParameterDisabled.fir.kt @@ -0,0 +1,61 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +// !LANGUAGE: -InlineDefaultFunctionalParameters + +inline fun inlineFun(lambda: () -> String) = lambda() + +fun noInlineFun(lambda: () -> String) = lambda() + + +inline fun default0_1(lambda: () -> String, dlambda: () -> String = { lambda }) { + lambda() + dlambda() +} + +inline fun default0_2(lambda: () -> String, dlambda: () -> String = { noInlineFun (lambda) }) { + lambda() + dlambda() +} + + + +inline fun default1_0(lambda: () -> String, dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_1(lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_1crossinline(crossinline lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_2(noinline lambda: () -> String, dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + +inline fun default1_3(noinline lambda: () -> String, noinline dlambda: () -> String = { lambda() }) { + lambda() + dlambda() +} + + + + +inline fun default2_0(lambda: () -> String, dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_1(lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_1crossinline(crossinline lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_2(noinline lambda: () -> String, dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} + +inline fun default2_3(noinline lambda: () -> String, noinline dlambda: () -> String = { inlineFun(lambda) }) { + lambda() + dlambda() +} diff --git a/compiler/testData/diagnostics/tests/inline/inlineReified.fir.kt b/compiler/testData/diagnostics/tests/inline/inlineReified.fir.kt new file mode 100644 index 00000000000..c6a4332e529 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/inlineReified.fir.kt @@ -0,0 +1,2 @@ +inline fun foo(): T3 = null!! + diff --git a/compiler/testData/diagnostics/tests/inline/invoke.fir.kt b/compiler/testData/diagnostics/tests/inline/invoke.fir.kt new file mode 100644 index 00000000000..45b96b57bbe --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/invoke.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + s(11) + s.invoke(11) + s invoke 11 + + 11.ext(11) + 11 ext 11 +} + +inline fun inlineFunWithInvokeNonInline(noinline s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + s(11) + s.invoke(11) + s invoke 11 + + 11.ext(11) + 11 ext 11 +} + +inline fun Function1.inlineExt() { + invoke(11) + this.invoke(11) + this invoke 11 + this(11) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/isCheck.fir.kt b/compiler/testData/diagnostics/tests/inline/isCheck.fir.kt new file mode 100644 index 00000000000..e5c021a89dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/isCheck.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +inline public fun reg(converter: (Any) -> Any, flag: Boolean) { + flag + converter("") +} + +public inline fun register(converter: (Any) -> Any) { + converter is (Any) -> Any + reg(converter, converter is (Any) -> Any) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/kt15410.fir.kt b/compiler/testData/diagnostics/tests/inline/kt15410.fir.kt new file mode 100644 index 00000000000..5ab655383bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt15410.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Foo protected constructor() + +inline fun foo(f: () -> Unit) = object: Foo() {} + +class A : Foo() { + inline fun foo(f: () -> Unit) = Foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/kt19679.fir.kt b/compiler/testData/diagnostics/tests/inline/kt19679.fir.kt new file mode 100644 index 00000000000..4138c154f28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt19679.fir.kt @@ -0,0 +1,4 @@ +inline fun test(s: () -> Unit, p: (() -> Unit)?) { + s() + p?.invoke() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/kt4869.fir.kt b/compiler/testData/diagnostics/tests/inline/kt4869.fir.kt new file mode 100644 index 00000000000..5fc9d07399f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt4869.fir.kt @@ -0,0 +1,6 @@ +inline fun foo(f: () -> Unit) { + val ff = { f: () -> Unit -> + f.invoke() + } + ff(f) +} diff --git a/compiler/testData/diagnostics/tests/inline/labeled.fir.kt b/compiler/testData/diagnostics/tests/inline/labeled.fir.kt new file mode 100644 index 00000000000..b991c098c68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/labeled.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +inline fun foo(bar1: (String.() -> Int) -> Int, bar2: (()->Int) -> Int) { + bar1 label@ { + this@label.length + } + + bar1 { + this.length + } + //unmute after KT-4247 fix + //bar1 { + // this@bar1.length + //} + + bar2 l@ { + 11 + } + + bar2 { + 12 + } + +} + +inline fun foo2(bar1: (String.() -> Int) -> Int) { + l1@ bar1 + + l2@ bar1 { + 11 + } + + (l3@ bar1) { + 11 + } + + (l5@ (l4@ bar1)) { + 11 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/lambdaCast.fir.kt b/compiler/testData/diagnostics/tests/inline/lambdaCast.fir.kt new file mode 100644 index 00000000000..af524ecd3c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/lambdaCast.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNCHECKED_CAST -USELESS_CAST +inline public fun reg(convertFunc: (Any) -> Any) { + convertFunc("") +} + +public inline fun register(converter: (T) -> R) { + converter as (Any) -> Any + reg(converter as (Any) -> Any) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/localFun.fir.kt b/compiler/testData/diagnostics/tests/inline/localFun.fir.kt new file mode 100644 index 00000000000..7b15da005a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/localFun.fir.kt @@ -0,0 +1,4 @@ +fun main() { + inline fun a(){ + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/messagesForUnsupportedInInline.fir.kt b/compiler/testData/diagnostics/tests/inline/messagesForUnsupportedInInline.fir.kt new file mode 100644 index 00000000000..0c368ac56ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/messagesForUnsupportedInInline.fir.kt @@ -0,0 +1,18 @@ +inline fun inlineFun() { + fun localFun() {} + class LocalClass {} +} + +fun outerFun() { + inline fun localInlineFun() {} +} + +abstract class Base { + abstract fun withDefault(f: () -> Unit = { -> }) +} + +class Derived : Base() { + override final inline fun withDefault( + f: () -> Unit + ) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjects.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjects.fir.kt new file mode 100644 index 00000000000..39a8ec3d9cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjects.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunOnlyLocal(crossinline p: () -> R) { + val s = object { + + val z = p() + + fun a() { + p() + } + } +} + +inline fun inlineFun(p: () -> R) { + val s = object { + + val z = p() + + fun a() { + p() + } + } +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.fir.kt new file mode 100644 index 00000000000..e068f2a91d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunOnlyLocal(crossinline p: () -> R) { + val s = object { + + val z = p(); + + init { + doCall { + p() + } + } + + fun a() { + doCall { + p() + } + + p() + } + } +} + +inline fun inlineFun(p: () -> R) { + val s = object { + + val z = p() + + init { + doCall { + p() + } + } + + + fun a() { + doCall { + p() + } + + p() + } + } +} + +inline fun doCall(p: () -> R) { + p() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/explicitReturnType.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/explicitReturnType.fir.kt new file mode 100644 index 00000000000..e11a8fc6dcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/explicitReturnType.fir.kt @@ -0,0 +1,41 @@ +fun inlineCallExplicitError(): String { + inlineFun lamba@ { + if (true) { + return@lamba 2 + } + 1 + } + + return "x" +} + +fun inlineCall(): String { + inlineFun lamba@ { + if (true) { + return@lamba 2 + } + 1 + } + + return "x" +} + +inline fun inlineFun(s: () -> Int) { + s() +} + + +fun noInlineCall(): String { + noInline lambda@ { + if (true) { + return@lambda 2 + } + 1 + } + return "x" +} + + +fun noInline(s: () -> Int) { + s() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/fromOnlyLocal.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/fromOnlyLocal.fir.kt new file mode 100644 index 00000000000..d6c0ad89ff2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/fromOnlyLocal.fir.kt @@ -0,0 +1,8 @@ + +inline fun onlyLocal(crossinline p: () -> R) { + inlineAll(p) +} + +inline fun inlineAll(p: () -> R) { + p() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/inlineLambda.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/inlineLambda.fir.kt new file mode 100644 index 00000000000..094bfabab41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/inlineLambda.fir.kt @@ -0,0 +1,16 @@ + +inline fun inlineFunWithAnnotation(crossinline p: () -> R) { + inlineFun { + p() + } +} + +inline fun inlineFun2(p: () -> R) { + inlineFun { + p() + } +} + +inline fun inlineFun(p: () -> R) { + p() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/labeledReturn.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/labeledReturn.fir.kt new file mode 100644 index 00000000000..4b290879ed1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/labeledReturn.fir.kt @@ -0,0 +1,31 @@ +fun inlineCall(): String { + inlineFun { + if (true) { + return@inlineCall "" + } + 1 + } + + return "x" +} + +inline fun inlineFun(s: ()->Int) { + s() +} + + +fun noInlineCall(): String { + noInline { + if (true) { + return@noInlineCall "" + } + 1 + } + + return "x" +} + + +fun noInline(s: ()->Int) { + s() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.fir.kt new file mode 100644 index 00000000000..acb2535e663 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE + +fun box() : String { + test { + return@box "123" + } + + return "OK" +} + +inline fun test(p: T) { + p.toString() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.fir.kt new file mode 100644 index 00000000000..438220488c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.fir.kt @@ -0,0 +1,11 @@ +fun box() : String { + test { + return@box "123" + } + + return "OK" +} + +inline fun test(p: Any) { + p.toString() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaWithGlobalReturnsInsideOnlyLocalOne.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaWithGlobalReturnsInsideOnlyLocalOne.fir.kt new file mode 100644 index 00000000000..37a7935c201 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaWithGlobalReturnsInsideOnlyLocalOne.fir.kt @@ -0,0 +1,9 @@ + +inline fun testSameCaptured(lambdaWithResultCaptured: () -> Unit) : String { + doWork({lambdaWithResultCaptured()}) + return "OK" +} + +inline fun doWork(crossinline job: ()-> R) : R { + return job() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/localFun.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/localFun.fir.kt new file mode 100644 index 00000000000..63f60ab4e35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/localFun.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunOnlyLocal(crossinline p: () -> R) { + fun a() { + val z = p() + } + a() +} + +inline fun inlineFun(p: () -> R) { + fun a() { + p() + } + a() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nestedNonLocals.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nestedNonLocals.fir.kt new file mode 100644 index 00000000000..023306d08b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nestedNonLocals.fir.kt @@ -0,0 +1,41 @@ +import Kind.EXT_RETURN +import Kind.GLOBAL_RETURN + +enum class Kind { + LOCAL, + EXT_RETURN, + GLOBAL_RETURN +} + +class Internal(val value: String) + +class External(val value: String) + +class Global(val value: String) + +fun test1(intKind: Kind, extKind: Kind): Global { + + var externalResult = doCall ext@ { + + val internalResult = doCall int@ { + if (intKind == Kind.LOCAL) { + return@test1 Global("internal to global") + } else if (intKind == EXT_RETURN) { + return@ext External("internal to external") + } + return@int Internal("internal to local") + } + + if (extKind == GLOBAL_RETURN || extKind == EXT_RETURN) { + return Global("external to global") + } + + External(internalResult.value + " to local"); + } + + return Global(externalResult.value + " to exit") +} + +public inline fun doCall(block: ()-> R) : R { + return block() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineAnnotation.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineAnnotation.fir.kt new file mode 100644 index 00000000000..f6a5b2ec051 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineAnnotation.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE +fun main() { + test { + return + } +} + +inline fun test(noinline lambda: () -> Unit) { + lambda() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineLambda.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineLambda.fir.kt new file mode 100644 index 00000000000..bc5293f974d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/noInlineLambda.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunOnlyLocal(crossinline p: () -> R) { + { + p() + }() +} + +inline fun inlineFun(p: () -> R) { + { + p() + }() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nonInlinedClass.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nonInlinedClass.fir.kt new file mode 100644 index 00000000000..df9dbafb8d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/nonInlinedClass.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFunOnlyLocal(crossinline p: () -> R) { + class A { + + val z = p() + + fun a() { + p() + } + } +} + +inline fun inlineFun(p: () -> R) { + class A { + + val z = p() + + fun a() { + p() + } + } +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambda.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambda.fir.kt new file mode 100644 index 00000000000..c4419fdb152 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambda.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +fun fun1(p: () -> R) { + inlineFun { + p() + } +} + +fun fun1ValueArgument(p: () -> R) { + inlineFun ({ + p() + }) +} + +fun fun3(p: () -> R) { + inlineFun { + return; + } +} + +fun fun3ValueArgument(p: () -> R) { + inlineFun ({ + return; + }) +} + + +fun fun4(p: () -> R) { + inlineFun lambda@ { + return@lambda p(); + } +} + +fun fun4ValueArgument(p: () -> R) { + inlineFun (lambda@ { + return@lambda p(); + }) +} + + +inline fun inlineFun(crossinline p: () -> R) { + p() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambdaBinaryExpr.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambdaBinaryExpr.fir.kt new file mode 100644 index 00000000000..5a0533c202b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/onlyLocalReturnLambdaBinaryExpr.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +class Z { + inline infix fun inlineFun(crossinline p: () -> R) { + p() + } +} + +fun fun1(p: () -> R) { + Z() inlineFun { + p() + } +} + +fun fun3(p: () -> R) { + Z() inlineFun { + return; + } +} + +fun fun4(p: () -> R) { + Z() inlineFun lambda@ { + return@lambda p(); + } +} diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/propertyAccessorsAndConstructor.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/propertyAccessorsAndConstructor.fir.kt new file mode 100644 index 00000000000..d5449715989 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/propertyAccessorsAndConstructor.fir.kt @@ -0,0 +1,24 @@ +inline fun doCall(p: () -> R) { + p() +} + +inline fun doCallInt(p: () -> R): R { + return p() +} + +class A { + var result: Int = doCallInt { return this }; + + var field: Int + get() { + doCall { return 1 } + return 2 + } + set(v: Int) { + doCall { + result = v / 2 + return + } + result = v + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/toOnlyLocal.fir.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/toOnlyLocal.fir.kt new file mode 100644 index 00000000000..8970e751c2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/toOnlyLocal.fir.kt @@ -0,0 +1,8 @@ + +inline fun toOnlyLocal(crossinline p: () -> R) { + p() +} + +inline fun inlineAll(p: () -> R) { + toOnlyLocal(p) +} diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicClass.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicClass.fir.kt new file mode 100644 index 00000000000..850af038fae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicClass.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -PRIVATE_CLASS_MEMBER_FROM_INLINE +private class Z public constructor(){ + public val publicProperty:Int = 12 + public fun publicFun() {} +} + +public inline fun test() { + Z().publicProperty + Z().publicFun() +} + +internal inline fun testInternal() { + Z().publicProperty + Z().publicFun() +} + +internal class Z2 { + private val privateProperty = 11; + + public val publicProperty:Int = 12 + + private fun privateFun() {} + + public fun publicFun() {} + + public inline fun test() { + privateProperty + privateFun() + publicProperty + publicFun() + Z2().publicProperty + Z2().publicFun() + Z2().privateProperty + Z2().privateFun() + } + + internal inline fun testInternal() { + privateProperty + privateFun() + publicProperty + publicFun() + Z2().publicProperty + Z2().publicFun() + Z2().privateProperty + Z2().privateFun() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicInnerClass.fir.kt new file mode 100644 index 00000000000..78f956bd84c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inNonPublicInnerClass.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +internal class Z2 { + private val privateProperty = 11; + + public val publicProperty:Int = 12 + + private fun privateFun() {} + + public fun publicFun() {} + + internal inner class ZInner { + public inline fun test() { + privateProperty + privateFun() + publicFun() + publicProperty + + Z2().publicProperty + Z2().publicFun() + Z2().privateProperty + Z2().privateFun() + } + + internal inline fun testInternal() { + privateProperty + privateFun() + publicFun() + publicProperty + + Z2().publicProperty + Z2().publicFun() + Z2().privateProperty + Z2().privateFun() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPackage.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPackage.fir.kt new file mode 100644 index 00000000000..4278490afdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPackage.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +private val privateProperty = 11; +private fun privateFun() {} + +internal val internalProperty = 11; +internal fun internalFun() {} + +public inline fun test() { + privateFun() + privateProperty +} + +public inline fun test2() { + internalFun() + internalProperty +} + +internal inline fun testInternal() { + privateFun() + privateProperty +} + +internal inline fun test2Internal() { + internalFun() + internalProperty +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPublicClass.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPublicClass.fir.kt new file mode 100644 index 00000000000..b58a7e8d0ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/inPublicClass.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +public class Z { + internal val privateProperty = 11; + + internal fun privateFun() { + + } +} + +public inline fun test() { + Z().privateProperty + Z().privateFun() +} + +internal inline fun testInternal() { + Z().privateProperty + Z().privateFun() +} + + +public class Z2 { + private val privateProperty = 11; + + private fun privateFun() { + + } + + public inline fun test() { + privateProperty + privateFun() + } + + internal inline fun testInternal() { + privateProperty + privateFun() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/kt14887.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/kt14887.fir.kt new file mode 100644 index 00000000000..60b03648e04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/kt14887.fir.kt @@ -0,0 +1,8 @@ +inline fun foo() { + unresolved().another + unresolved().another() +} + +fun main() { + foo() +} diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass.fir.kt new file mode 100644 index 00000000000..5f3c49341f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -NOTHING_TO_INLINE + +public class Z { + private val privateProperty = 11; + + public fun privateFun() { + + class Local { + public inline fun a() { + privateProperty + } + } + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass2.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass2.fir.kt new file mode 100644 index 00000000000..9c8142c5777 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localClass2.fir.kt @@ -0,0 +1,13 @@ +public fun test() { + + class Z { + public fun localFun() { + + } + } + + inline fun localFun2() { + Z().localFun() + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/localFun.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localFun.fir.kt new file mode 100644 index 00000000000..513803471a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/localFun.fir.kt @@ -0,0 +1,11 @@ +public fun test() { + + fun localFun() { + + } + + inline fun localFun2() { + localFun() + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonPublicMember/publishedApi.fir.kt b/compiler/testData/diagnostics/tests/inline/nonPublicMember/publishedApi.fir.kt new file mode 100644 index 00000000000..0848d0d9506 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonPublicMember/publishedApi.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE + + +inline fun call(a: A) { + a.test() + + privateFun() + + internalFun() +} + +@PublishedApi +internal inline fun callFromPublishedApi(a: A) { + a.test() + + privateFun() + + internalFun() +} + +internal class A { + @PublishedApi + internal fun test() { + test() + + privateFun() + + internalFun() + } + + @PublishedApi + internal fun testInline() { + test() + + privateFun() + + internalFun() + } +} + + +private fun privateFun() { + +} + +internal fun internalFun() { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.fir.kt b/compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.fir.kt new file mode 100644 index 00000000000..fb437750c26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline private fun a() {} + +inline fun b() {} + +inline public fun c() {} + +abstract class A { + inline private fun good1() {} + inline public final fun good2() {} + inline protected final fun good3() {} + inline final fun good4() {} + + + inline open protected fun wrong1() {} + + inline open public fun wrong2() {} + + inline open fun wrong3() {} + + inline abstract protected fun wrong4() + + inline abstract public fun wrong5() + + inline abstract fun wrong6() +} + + +interface B { + + inline private fun good1() {} + + inline fun wrong1() {} + + inline open fun wrong2() {} + + inline open public fun wrong3() {} + + inline open fun wrong4() {} + + inline fun wrong5() + + inline public fun wrong6() + + inline fun wrong7() +} diff --git a/compiler/testData/diagnostics/tests/inline/nothingToInline.fir.kt b/compiler/testData/diagnostics/tests/inline/nothingToInline.fir.kt new file mode 100644 index 00000000000..69f22f45b25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nothingToInline.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NULLABLE_INLINE_PARAMETER -CONFLICTING_JVM_DECLARATIONS + +inline fun test() { + +} + +inline fun test2(s : (Int) -> Int) { + +} + +inline fun test3(noinline s : (Int) -> Int) { + +} + +inline fun test4(noinline s : Int.() -> Int) { + +} + +inline fun Function1?.test5() { + +} + +inline fun Function1?.test6() { + +} + +inline fun test2(s : ((Int) -> Int)?) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nullabilityOperations.fir.kt b/compiler/testData/diagnostics/tests/inline/nullabilityOperations.fir.kt new file mode 100644 index 00000000000..176f08f96ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nullabilityOperations.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNNECESSARY_SAFE_CALL -UNNECESSARY_NOT_NULL_ASSERTION -CONFLICTING_JVM_DECLARATIONS +inline fun String.submit(action: Function1) { + +} + +inline fun Function1.submit() { + this?.invoke(11) + this!!.invoke(11) + + submit(this!!) +} + +inline fun submit(action: Function1) { + action?.invoke(10) + action!!.invoke(10) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nullableFunction.fir.kt b/compiler/testData/diagnostics/tests/inline/nullableFunction.fir.kt new file mode 100644 index 00000000000..5d81a507901 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/nullableFunction.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -CONFLICTING_JVM_DECLARATIONS + +public inline fun Function1?.submit(action: ()->T) { + this?.invoke(11) +} + +public inline fun submit(action: Function1?, s: () -> Int) { + action?.invoke(10) +} + +public inline fun submitNoInline(noinline action: Function1?, s: () -> Int) { + action?.invoke(10) +} + +public inline fun Function1?.submit() { + +} + +public inline fun submit(action: Function1?) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/overrideWithInline.fir.kt b/compiler/testData/diagnostics/tests/inline/overrideWithInline.fir.kt new file mode 100644 index 00000000000..ee3753a83a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/overrideWithInline.fir.kt @@ -0,0 +1,60 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER + +interface IBase { + fun foo() + fun bar() + fun qux(x: T) +} + +class CDerived : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + + class CNested : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + + val anObject = object : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + + fun aMethod() { + class CLocal : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + } +} + +open class COpen : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + + open class COpenNested : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + + val anObject = object : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + + fun aMethod() { + open class COpenLocal : IBase { + override inline final fun foo() {} + override inline fun bar() {} + override inline final fun qux(x: T) {} + } + } +} + diff --git a/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt b/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt new file mode 100644 index 00000000000..fd3aaf8e3ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt @@ -0,0 +1,27 @@ +// !CHECK_TYPE + +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit) { + (s)(11) + (s).invoke(11) + (s) invoke 11 + (s) +} + +inline fun Function1.inlineExt() { + (this).invoke(11) + (this) invoke 11 + (this)(11) + (this) +} + +inline fun inlineFunWithInvoke2(s: (p: Int) -> Unit) { + (((s)))(11) + (((s))).invoke(11) + (((s))) invoke 11 + (((s))) +} + +inline fun propagation(s: (p: Int) -> Unit) { + inlineFunWithInvoke((label@ s)) + inlineFunWithInvoke((label2@ label@ s)) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/privateClass.fir.kt b/compiler/testData/diagnostics/tests/inline/privateClass.fir.kt new file mode 100644 index 00000000000..34c743b800b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/privateClass.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE + +private class S public constructor() { + fun a() { + + } +} + +internal inline fun x(s: S, z: () -> Unit) { + z() + S() + s.a() + test() +} + +private inline fun x2(s: S, z: () -> Unit) { + z() + S() + s.a() + test() +} + +private fun test(): S { + return S() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/propagation.fir.kt b/compiler/testData/diagnostics/tests/inline/propagation.fir.kt new file mode 100644 index 00000000000..3faba489acd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/propagation.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -NON_LOCAL_RETURN_NOT_ALLOWED + +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + subInline(s, ext) + subNoInline(s, ext) +} + +inline fun inlineFunWithInvokeClosure(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + subInline({p: Int -> s(p)}, { p -> this.ext(p)}) + subNoInline({p: Int -> s(p)}, { p -> this.ext(p)}) +} + +//No inline +inline fun inlineFunWithInvokeNonInline(noinline s: (p: Int) -> Unit, noinline ext: Int.(p: Int) -> Unit) { + subInline(s, ext) + subNoInline(s, ext) +} + +inline fun inlineFunWithInvokeClosureNoinline(noinline s: (p: Int) -> Unit, noinline ext: Int.(p: Int) -> Unit) { + subInline({p: Int -> s(p)}, { p -> this.ext(p)}) + subNoInline({p: Int -> s(p)}, { p -> this.ext(p)}) +} + +//ext function +inline fun Function1.inlineExt(ext: Int.(p: Int) -> Unit) { + subInline(this, ext) + subNoInline(this, ext) +} + +inline fun Function1.inlineExtWithClosure(ext: Int.(p: Int) -> Unit) { + subInline({p: Int -> this(p)}, { p -> this.ext(p)}) + subNoInline({p: Int -> this(p)}, { p -> this.ext(p)}) +} + +inline fun subInline(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {} + +fun subNoInline(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {} diff --git a/compiler/testData/diagnostics/tests/inline/property/invoke.fir.kt b/compiler/testData/diagnostics/tests/inline/property/invoke.fir.kt new file mode 100644 index 00000000000..f0f11d69994 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/property/invoke.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -INFIX_MODIFIER_REQUIRED + +inline var value: (p: Int) -> String + get() = {"123" } + set(s: (p: Int) -> String) { + s(11) + s.invoke(11) + s invoke 11 + + val z = s + } + +inline var value2: Int.(p: Int) -> String + get() = {"123" } + set(ext: Int.(p: Int) -> String) { + 11.ext(11) + 11.ext(11) + + val p = ext + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/property/propertyWithBackingField.fir.kt b/compiler/testData/diagnostics/tests/inline/property/propertyWithBackingField.fir.kt new file mode 100644 index 00000000000..d857444247e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/property/propertyWithBackingField.fir.kt @@ -0,0 +1,21 @@ +// WITH_REFLECT + +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int = 1 +} + +open class A { + inline val z1 = 1 + + val z1_1 = 1 + inline get() = field + 1 + + inline var z2 = 1 + + var z2_1 = 1 + inline set(p: Int) {} + + inline val z by Delegate() +} diff --git a/compiler/testData/diagnostics/tests/inline/property/unsupportedConstruction.fir.kt b/compiler/testData/diagnostics/tests/inline/property/unsupportedConstruction.fir.kt new file mode 100644 index 00000000000..a97b55cd40a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/property/unsupportedConstruction.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline val z: Int + get() { + + class A { + fun a() { + class AInner {} + } + } + + object B{ + object BInner {} + } + + fun local() { + fun localInner() {} + } + return 1 +} diff --git a/compiler/testData/diagnostics/tests/inline/property/virtualProperty.fir.kt b/compiler/testData/diagnostics/tests/inline/property/virtualProperty.fir.kt new file mode 100644 index 00000000000..e95efd83238 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/property/virtualProperty.fir.kt @@ -0,0 +1,38 @@ +final class FinalProperty { + inline val valProp: Int + get() = 1 + + val valProp_1: Int + inline get() = 1 + + inline var varProp: Int + get() = 1 + set(p: Int) {} + + var varProp_2: Int + get() = 1 + inline set(p: Int) {} +} + + +open class OpenProperty { + inline open val valProp: Int + get() = 1 + + open val valProp_1: Int + inline get() = 1 + + inline open var varProp: Int + get() = 1 + set(p: Int) {} + + open var varProp_2: Int + get() = 1 + inline set(p: Int) {} +} + + +interface AbstractProperty { + inline abstract val valProp: Int + inline abstract var varProp: Int +} diff --git a/compiler/testData/diagnostics/tests/inline/protectedCallDepecation.fir.kt b/compiler/testData/diagnostics/tests/inline/protectedCallDepecation.fir.kt new file mode 100644 index 00000000000..c6137f3ccdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/protectedCallDepecation.fir.kt @@ -0,0 +1,102 @@ +// !LANGUAGE: -ProhibitProtectedCallFromInline +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE + +// FILE: JavaClass.java + + +public abstract class JavaClass { + protected void bind() {} +} + +// FILE: main.kt +open class A { + protected fun test() {} + + protected val z: String = "1" + + public var zVar: String = "1" + protected set(value) {} + + inline fun call() { + test() + z + zVar + zVar = "123" + } + + internal inline fun callFromInternal() { + test() + zVar + zVar = "123" + } + + @PublishedApi + internal inline fun callFromPublished() { + test() + z + zVar + zVar = "123" + } + + protected inline fun callFromProtected() { + test() + zVar + zVar = "123" + } + +} + +class B : A() { + inline fun testB() { + test() + } +} + +class C : JavaClass() { + inline fun call() { + bind() + } + + internal inline fun callFromInternal() { + bind() + } + + protected inline fun callFromProtected() { + bind() + } + + @PublishedApi + internal inline fun callFromPublished() { + bind() + } +} + + +internal class AInternal { + protected fun test() {} + + protected val z: String = "1" + + public var zVar: String = "1" + protected set(value) {} + + + inline fun call() { + test() + } + + @PublishedApi + internal inline fun call2() { + test() + } +} + +private class X { + + public class Z : A() { + public inline fun effictivelyNonPublic() { + test() + } + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/protectedCallError.fir.kt b/compiler/testData/diagnostics/tests/inline/protectedCallError.fir.kt new file mode 100644 index 00000000000..a3dec4dfa8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/protectedCallError.fir.kt @@ -0,0 +1,102 @@ +// !LANGUAGE: +ProhibitProtectedCallFromInline +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE + +// FILE: JavaClass.java + + +public abstract class JavaClass { + protected void bind() {} +} + +// FILE: main.kt +open class A { + protected fun test() {} + + protected val z: String = "1" + + public var zVar: String = "1" + protected set(value) {} + + inline fun call() { + test() + z + zVar + zVar = "123" + } + + internal inline fun callFromInternal() { + test() + zVar + zVar = "123" + } + + @PublishedApi + internal inline fun callFromPublished() { + test() + z + zVar + zVar = "123" + } + + protected inline fun callFromProtected() { + test() + zVar + zVar = "123" + } + +} + +class B : A() { + inline fun testB() { + test() + } +} + +class C : JavaClass() { + inline fun call() { + bind() + } + + internal inline fun callFromInternal() { + bind() + } + + protected inline fun callFromProtected() { + bind() + } + + @PublishedApi + internal inline fun callFromPublished() { + bind() + } +} + + +internal class AInternal { + protected fun test() {} + + protected val z: String = "1" + + public var zVar: String = "1" + protected set(value) {} + + + inline fun call() { + test() + } + + @PublishedApi + internal inline fun call2() { + test() + } +} + +private class X { + + public class Z : A() { + public inline fun effictivelyNonPublic() { + test() + } + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/publishedApi.fir.kt b/compiler/testData/diagnostics/tests/inline/publishedApi.fir.kt new file mode 100644 index 00000000000..ad214321f3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/publishedApi.fir.kt @@ -0,0 +1,175 @@ +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE +inline fun call(a: A) { + a.test() + publishedTopLevel() + + a.publishedVar + a.publishedVar = 1 + + publishedVarTopLevel + publishedVarTopLevel = 1 +} + +inline var inlineVar: Int + get() { + val a = A() + a.test() + publishedTopLevel() + + a.publishedVar + a.publishedVar = 1 + + publishedVarTopLevel + publishedVarTopLevel = 1 + return 1 + } + set(value) { + val a = A() + a.test() + publishedTopLevel() + + a.publishedVar + a.publishedVar = 1 + + publishedVarTopLevel + publishedVarTopLevel = 1 + } + +@PublishedApi +internal class A { + @PublishedApi + internal fun test() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + + publishedVar + publishedVar = 1 + } + + @PublishedApi + internal inline fun testInline() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + + publishedVar + publishedVar = 1 + } + + + @PublishedApi + internal inline var publishedVar: Int + get() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + return 1 + } + + set(value) { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + } + +} + +@PublishedApi +internal fun publishedTopLevel() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 +} + +@PublishedApi +inline internal fun publishedTopLevelInline() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 +} + +@PublishedApi +inline internal var publishedVarTopLevel: Int + get() { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + return 1 + } + + set(value) { + publicFun() + internalFun() + privateFun() + + publicVarTopLevel + publicVarTopLevel = 1 + internalVarTopLevel + internalVarTopLevel = 1 + privateVarTopLevel + privateVarTopLevel = 1 + } + + +fun publicFun() {} + +internal fun internalFun() {} + +private fun privateFun() {} + + +var publicVarTopLevel = 1 + +internal var internalVarTopLevel = 1 + +private var privateVarTopLevel = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/recursion.fir.kt b/compiler/testData/diagnostics/tests/inline/recursion.fir.kt new file mode 100644 index 00000000000..905e848bcae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/recursion.fir.kt @@ -0,0 +1,24 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -VARIABLE_EXPECTED + +inline fun inlineFun(s: (p: Int) -> Unit) { + inlineFun(s) +} + +inline fun inlineFun(s: T) { + inlineFun(11) +} + + +inline fun Function0.inlineExt() { + (checkSubtype>({11})).inlineExt(); + {11}.inlineExt() +} + +inline operator fun Function1.not() : Boolean { + return !this +} + +inline operator fun Function1.inc() : Function1 { + return this++ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/regressions/kt4341.fir.kt b/compiler/testData/diagnostics/tests/inline/regressions/kt4341.fir.kt new file mode 100644 index 00000000000..ed80d11bd1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/regressions/kt4341.fir.kt @@ -0,0 +1,6 @@ +//KT-4341 No resolved call for right-hand side of equals expression +package g + +inline fun inlineFunWithInvoke(s: (p: T) -> U) { + s == s //resolved call for right-hand side 's' not traced +} diff --git a/compiler/testData/diagnostics/tests/inline/returns.fir.kt b/compiler/testData/diagnostics/tests/inline/returns.fir.kt new file mode 100644 index 00000000000..bdf8c0bd8a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/returns.fir.kt @@ -0,0 +1,20 @@ +inline fun inlineFun(s: (p: Int) -> Unit) : (p: Int) -> Unit { + return s +} + +inline fun inlineFun2(s: (p: Int) -> Unit) : (p: Int) -> Unit = s + + +inline fun inlineFunWithExt(ext: Int.(p: Int) -> Unit) : Int.(p: Int) -> Unit { + return ext +} + +inline fun inlineFunWithExt2(ext: Int.(p: Int) -> Unit) : Int.(p: Int) -> Unit = ext + + + +inline fun Function1.inlineExt(): Function1 { + return this +} + +inline fun Function1.inlineExt2(): Function1 = this \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/sam.fir.kt b/compiler/testData/diagnostics/tests/inline/sam.fir.kt new file mode 100644 index 00000000000..31c5e88ccf4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/sam.fir.kt @@ -0,0 +1,58 @@ +// !DIAGNOSTICS: -NON_LOCAL_RETURN_NOT_ALLOWED +// FILE: Run.java +public interface Run { + public int run(); +} + + +// FILE: Test.java +public class Test { + public void test(Run r) { + + } +} + +// FILE: test.kt +inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + Test().test(){ + s(11) + s.invoke(11) + s invoke 11 + + 11.ext(11) + 11 ext 11 + + s + ext + 11 + } +} + +inline fun inlineFunWithInvokeNonInline(noinline s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) { + Test().test(){ + s(11) + s.invoke(11) + s invoke 11 + + 11.ext(11) + 11 ext 11 + + s + ext + + 11 + } +} + +inline fun Function1.inlineExt() { + Test().test(){ + invoke(11) + this.invoke(11) + this invoke 11 + this(11) + + this + + 11 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/stringTemplate.fir.kt b/compiler/testData/diagnostics/tests/inline/stringTemplate.fir.kt new file mode 100644 index 00000000000..ae1c745c672 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/stringTemplate.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +inline public fun reg(converter: (Any) -> Any, str: String) { + str + converter("") +} + +public inline fun register(converter: (Any) -> Any) { + "123$converter" + reg(converter, "123$converter") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.fir.kt b/compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.fir.kt new file mode 100644 index 00000000000..36ef67bba28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED + +inline operator fun Function1.unaryPlus() = this +operator fun Function1.unaryMinus() = this +inline operator fun Function1.inc() = this +operator fun Function1.dec() = this + +inline operator fun @ExtensionFunctionType Function2.unaryPlus(){} +operator fun @ExtensionFunctionType Function2.unaryMinus(){} +inline operator fun @ExtensionFunctionType Function2.inc() = this +operator fun @ExtensionFunctionType Function2.dec() = this + +inline fun inlineFunWithInvoke(s: (p: T) -> V, ext: T.(p: T) -> V) { + +s + -s + s++ + ++s + s-- + --s + +ext + -ext + ext++ + ++ext + ext-- + --ext +} + +inline fun Function1.inlineFunWithInvoke() { + +this + -this + this++ + ++this + this-- + --this +} diff --git a/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.fir.kt b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.fir.kt new file mode 100644 index 00000000000..2a9f4cda4f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.fir.kt @@ -0,0 +1,3 @@ +public inline fun test(predicate: (Char) -> Boolean) { + !predicate('c') +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.fir.kt b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.fir.kt new file mode 100644 index 00000000000..864423fa3de --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE +inline operator fun Function1.not() : Boolean { + return !this +} + +inline fun inlineFunWithInvoke(s: (p: T) -> V) { + !s +} + +operator fun Function2.not() : Boolean { + return !this +} + +operator fun @ExtensionFunctionType Function3.not() : Boolean { + return !this +} + +inline fun inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: T, l : U) -> V) { + !s + !ext +} diff --git a/compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt b/compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt new file mode 100644 index 00000000000..55269200a9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/unsupportedConstruction.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE +// !LANGUAGE: -InlineDefaultFunctionalParameters + +inline fun unsupported() { + + class A { + fun a() { + class AInner {} + } + } + + object B{ + object BInner {} + } + + fun local() { + fun localInner() {} + } +} + +inline fun unsupportedDefault(s : ()->Unit = {}) { + +} + +open class Base { + open fun foo(a: Int = 1) {} +} + +class Derived: Base() { + inline final override fun foo(a: Int) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/vararg.fir.kt b/compiler/testData/diagnostics/tests/inline/vararg.fir.kt new file mode 100644 index 00000000000..305d27c98cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/vararg.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE + +inline fun inlineFun(s: (p: Int) -> Unit, noinline b: (p: Int) -> Unit) { + subInline(s, b) + subNoInline(s, b) +} + +inline fun Function1.inlineExt(s: (p: Int) -> Unit, noinline b: (p: Int) -> Unit) { + subInline(this, s, b) + subNoInline(this, s, b) +} + + +inline fun subInline(vararg s: (p: Int) -> Unit) {} + +fun subNoInline(vararg s: (p: Int) -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/when.fir.kt b/compiler/testData/diagnostics/tests/inline/when.fir.kt new file mode 100644 index 00000000000..9fb50407b45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/when.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +inline public fun reg(converter: (Any) -> Any) { + converter("") +} + +public inline fun register(converter: (Any) -> Any) { + reg(when(converter) { + is (Any) -> Any -> converter + else -> converter + }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/wrongUsage.fir.kt b/compiler/testData/diagnostics/tests/inline/wrongUsage.fir.kt new file mode 100644 index 00000000000..c2ca220a4b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/wrongUsage.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -NOTHING_TO_INLINE -USELESS_ELVIS + +inline fun inlineFunWrongUsage(s: (p: Int) -> Unit) { + s + + if (true) s else 0 + + s ?: s +} + +inline fun inlineFunWrongUsageExt(ext: Int.(p: Int) -> Unit) { + ext + + if (true) ext else 0 + + ext ?: ext +} + +inline fun inlineFunWrongUsageInClosure(s: (p: Int) -> Unit) { + { + s + + if (true) s else 0 + + s ?: s + }() +} + +inline fun inlineFunWrongUsageInClosureExt(ext: Int.(p: Int) -> Unit) { + { + ext + + if (true) ext else 0 + + ext ?: ext + }() +} + +inline fun inlineFunNoInline(noinline s: (p: Int) -> Unit) { + s + if (true) s else 0 + + s ?: s +} + +inline fun inlineFunNoInline(noinline ext: Int.(p: Int) -> Unit) { + ext + if (true) ext else 0 + + ext ?: ext +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclaration.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclaration.fir.kt new file mode 100644 index 00000000000..fdb6b5bb420 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclaration.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +InlineClasses + +inline class Foo(val x: Int) + +inline interface InlineInterface +inline annotation class InlineAnn +inline object InlineObject +inline enum class InlineEnum diff --git a/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclarationDisabled.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclarationDisabled.fir.kt new file mode 100644 index 00000000000..b3ddad1f098 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/basicInlineClassDeclarationDisabled.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: -InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class Foo(val x: Int) + +inline annotation class InlineAnn +inline object InlineObject +inline enum class InlineEnum + +inline class NotVal(x: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/constructorsJvmSignaturesClash.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/constructorsJvmSignaturesClash.fir.kt new file mode 100644 index 00000000000..c46969ca1e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/constructorsJvmSignaturesClash.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class X(val x: Int) +inline class Z(val x: Int) + +class TestOk1(val a: Int, val b: Int) { + constructor(x: X) : this(x.x, 1) +} + +class TestErr1(val a: Int) { + constructor(x: X) : this(x.x) +} + +class TestErr2(val a: Int, val b: Int) { + constructor(x: X) : this(x.x, 1) + constructor(z: Z) : this(z.x, 2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/delegatedPropertyInInlineClass.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/delegatedPropertyInInlineClass.fir.kt new file mode 100644 index 00000000000..77dd8988c78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/delegatedPropertyInInlineClass.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +InlineClasses + +class Val { + operator fun getValue(thisRef: Any?, kProp: Any?) = 1 +} + +class Var { + operator fun getValue(thisRef: Any?, kProp: Any?) = 2 + operator fun setValue(thisRef: Any?, kProp: Any?, value: Int) {} +} + + +object ValObject { + operator fun getValue(thisRef: Any?, kProp: Any?) = 1 +} + +object VarObject { + operator fun getValue(thisRef: Any?, kProp: Any?) = 2 + operator fun setValue(thisRef: Any?, kProp: Any?, value: Int) {} +} + +inline class Z(val data: Int) { + val testVal by Val() + var testVar by Var() + + val testValBySingleton by ValObject + var testVarBySingleton by VarObject +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesClash.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesClash.fir.kt new file mode 100644 index 00000000000..2269b291aaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesClash.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class X(val x: Int) +inline class Z(val x: Int) +inline class Str(val str: String) +inline class Name(val name: String) +inline class NStr(val str: String?) + +fun testSimple(x: X) {} +fun testSimple(z: Z) {} + +fun testMixed(x: Int, y: Int) {} +fun testMixed(x: X, y: Int) {} +fun testMixed(x: Int, y: X) {} +fun testMixed(x: X, y: X) {} + +fun testNewType(s: Str) {} +fun testNewType(name: Name) {} + +fun testNullableVsNonNull1(s: Str) {} +fun testNullableVsNonNull1(s: Str?) {} + +fun testNullableVsNonNull2(ns: NStr) {} +fun testNullableVsNonNull2(ns: NStr?) {} + +fun testFunVsExt(x: X) {} +fun X.testFunVsExt() {} + +fun testNonGenericVsGeneric(x: X, y: Number) {} +fun testNonGenericVsGeneric(x: X, y: T) {} + +class C { + fun testNonGenericVsGeneric(x: X, y: Number) {} + fun testNonGenericVsGeneric(x: X, y: T) {} + fun testNonGenericVsGeneric(x: X, y: TC) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesConflictOnInheritance.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesConflictOnInheritance.fir.kt new file mode 100644 index 00000000000..4d71d826e72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/functionsJvmSignaturesConflictOnInheritance.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +InlineClasses + +inline class Name(val name: String) +inline class Password(val password: String) + +interface NameVerifier { + fun verify(name: Name) +} + +interface PasswordVerifier { + fun verify(password: Password) +} + +interface NameAndPasswordVerifier : NameVerifier, PasswordVerifier diff --git a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt new file mode 100644 index 00000000000..b4e920e64a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_VARIABLE + +inline class Foo(val x: Int) +inline class Bar(val y: String) + +fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { + val a1 = f1 === f2 || f1 !== f2 + val a2 = f1 === f1 + val a3 = f1 === b1 || f1 !== b1 + + val c1 = fn1 === fn2 || fn1 !== fn2 + val c2 = f1 === fn1 || f1 !== fn1 + val c3 = b1 === fn1 || b1 !== fn1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.fir.kt new file mode 100644 index 00000000000..07970c657c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +InlineClasses + +abstract class AbstractBaseClass + +open class OpenBaseClass + +interface BaseInterface + +inline class TestExtendsAbstractClass(val x: Int) : AbstractBaseClass() + +inline class TestExtendsOpenClass(val x: Int) : OpenBaseClass() + +inline class TestImplementsInterface(val x: Int) : BaseInterface \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.fir.kt new file mode 100644 index 00000000000..fc15d5e7721 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +InlineClasses + +interface IFoo + +object FooImpl : IFoo + +inline class Test1(val x: Any) : IFoo by FooImpl + +inline class Test2(val x: IFoo) : IFoo by x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassConstructorParameterWithDefaultValue.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassConstructorParameterWithDefaultValue.fir.kt new file mode 100644 index 00000000000..14efbfee879 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassConstructorParameterWithDefaultValue.fir.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: +InlineClasses + +inline class Test(val x: Int = 42) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.fir.kt new file mode 100644 index 00000000000..1dc1d59e16d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassDeclarationCheck.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class A0(val x: Int) + +inline class A1 +inline class A2() +inline class A3(x: Int) +inline class A4(var x: Int) +inline class A5(val x: Int, val y: Int) +inline class A6(x: Int, val y: Int) +inline class A7(vararg val x: Int) +inline class A8(open val x: Int) +inline class A9(final val x: Int) + +class B1 { + companion object { + inline class C1(val x: Int) + } + + inline class C2(val x: Int) +} + +object B2 { + inline class C3(val x: Int) +} + +final inline class D0(val x: Int) +open inline class D1(val x: Int) +abstract inline class D2(val x: Int) +sealed inline class D3(val x: Int) + +inline data class D4(val x: String) diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassImplementsCollection.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassImplementsCollection.fir.kt new file mode 100644 index 00000000000..b665afb1e14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassImplementsCollection.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +InlineClasses + +inline class UInt(val x: Int) + +inline class UIntArray(private val storage: IntArray) : Collection { + public override val size: Int get() = storage.size + + override operator fun iterator() = TODO() + override fun contains(element: UInt): Boolean = TODO() + override fun containsAll(elements: Collection): Boolean = TODO() + override fun isEmpty(): Boolean = TODO() +} diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassWithForbiddenUnderlyingType.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassWithForbiddenUnderlyingType.fir.kt new file mode 100644 index 00000000000..650bcb0e190 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassWithForbiddenUnderlyingType.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +InlineClasses + +inline class Foo(val x: T) +inline class FooNullable(val x: T?) + +inline class FooGenericArray(val x: Array) +inline class FooGenericArray2(val x: Array>) + +inline class FooStarProjectedArray(val x: Array<*>) +inline class FooStarProjectedArray2(val x: Array>) + +inline class Bar(val u: Unit) +inline class BarNullable(val u: Unit?) + +inline class Baz(val u: Nothing) +inline class BazNullable(val u: Nothing?) diff --git a/compiler/testData/diagnostics/tests/inlineClasses/inlineClassesInsideAnnotations.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassesInsideAnnotations.fir.kt new file mode 100644 index 00000000000..861f728fed8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/inlineClassesInsideAnnotations.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +InlineClasses + +import kotlin.reflect.KClass + +inline class MyInt(val x: Int) +inline class MyString(val x: String) + +annotation class Ann1(val a: MyInt) +annotation class Ann2(val a: Array) +annotation class Ann3(vararg val a: MyInt) + +annotation class Ann4(val a: KClass) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/lateinitInlineClasses.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/lateinitInlineClasses.fir.kt new file mode 100644 index 00000000000..d81f5b2b0e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/lateinitInlineClasses.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_VARIABLE + +inline class Foo(val x: Int) + +lateinit var a: Foo + +fun foo() { + lateinit var b: Foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/presenceOfInitializerBlockInsideInlineClass.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/presenceOfInitializerBlockInsideInlineClass.fir.kt new file mode 100644 index 00000000000..338b20f53b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/presenceOfInitializerBlockInsideInlineClass.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_VARIABLE + +inline class Foo(val x: Int) { + init {} + + init { + val f = 1 + } +} diff --git a/compiler/testData/diagnostics/tests/inlineClasses/presenceOfPublicPrimaryConstructorForInlineClass.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/presenceOfPublicPrimaryConstructorForInlineClass.fir.kt new file mode 100644 index 00000000000..3d4387b1ec7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/presenceOfPublicPrimaryConstructorForInlineClass.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +InlineClasses + +inline class ConstructorWithDefaultVisibility(val x: Int) +inline class PublicConstructor public constructor(val x: Int) +inline class InternalConstructor internal constructor(val x: Int) +inline class ProtectedConstructor protected constructor(val x: Int) +inline class PrivateConstructor private constructor(val x: Int) diff --git a/compiler/testData/diagnostics/tests/inlineClasses/propertiesWithBackingFieldsInsideInlineClass.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/propertiesWithBackingFieldsInsideInlineClass.fir.kt new file mode 100644 index 00000000000..673b7ba8262 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/propertiesWithBackingFieldsInsideInlineClass.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface A { + val goodSize: Int +} + +interface B { + val badSize: Int +} + +inline class Foo(val x: Int) : A, B { + val a0 + get() = 0 + + val a1 = 0 + + var a2: Int + get() = 1 + set(value) {} + + var a3: Int = 0 + get() = 1 + set(value) { + field = value + } + + override val goodSize: Int + get() = 0 + + override val badSize: Int = 0 + + lateinit var lateinitProperty: String +} diff --git a/compiler/testData/diagnostics/tests/inlineClasses/recursiveInlineClasses.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/recursiveInlineClasses.fir.kt new file mode 100644 index 00000000000..6ebf4f85568 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/recursiveInlineClasses.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +InlineClasses + +inline class Test1(val x: Test1) + +inline class Test2A(val x: Test2B) +inline class Test2B(val x: Test2A) + +inline class Test3A(val x: Test3B) +inline class Test3B(val x: Test3C) +inline class Test3C(val x: Test3A) + +inline class TestNullable(val x: TestNullable?) + +inline class TestRecursionInTypeArguments(val x: List) + +inline class TestRecursionInArray(val x: Array) + +inline class TestRecursionInUpperBounds>(val x: T) + +inline class Id(val x: T) +inline class TestRecursionThroughId(val x: Id) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/reservedMembersAndConstructsInsideInlineClass.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/reservedMembersAndConstructsInsideInlineClass.fir.kt new file mode 100644 index 00000000000..c433e12c85f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/reservedMembersAndConstructsInsideInlineClass.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class IC1(val x: Any) { + fun box() {} + fun box(x: Any) {} + + fun unbox() {} + fun unbox(x: Any) {} + + override fun equals(other: Any?): Boolean = true + override fun hashCode(): Int = 0 +} + +inline class IC2(val x: Any) { + fun box(x: Any) {} + fun box(): Any = TODO() + + fun unbox(x: Any) {} + fun unbox(): Any = TODO() + + fun equals(my: Any, other: Any): Boolean = true + fun hashCode(a: Any): Int = 0 +} + +inline class IC3(val x: Any) { + fun box(x: Any): Any = TODO() + fun unbox(x: Any): Any = TODO() + + fun equals(): Boolean = true +} + +interface WithBox { + fun box(): String +} + +inline class IC4(val s: String) : WithBox { + override fun box(): String = "" +} + +inline class IC5(val a: String) { + constructor(i: Int) : this(i.toString()) { + TODO("something") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/unsignedLiteralsWithoutArtifactOnClasspath.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/unsignedLiteralsWithoutArtifactOnClasspath.fir.kt new file mode 100644 index 00000000000..7fa08d2d9a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/unsignedLiteralsWithoutArtifactOnClasspath.fir.kt @@ -0,0 +1,3 @@ +val u1 = 1u +val u2 = 0xFu +val u3 = 0b1u \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/varargsOnParametersOfInlineClassType.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/varargsOnParametersOfInlineClassType.fir.kt new file mode 100644 index 00000000000..69737965c97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/varargsOnParametersOfInlineClassType.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -UNUSED_ANONYMOUS_PARAMETER + +inline class Foo(val x: Int) + +fun f1(vararg a: Foo) {} +fun f2(vararg a: Foo?) {} + +class A { + fun f3(a0: Int, vararg a1: Foo) { + fun f4(vararg a: Foo) {} + + val g = fun (vararg v: Foo) {} + } +} + +class B(vararg val s: Foo) { + constructor(a: Int, vararg s: Foo) : this(*s) +} + +annotation class Ann(vararg val f: Foo) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/InnerClassNameClash.fir.kt b/compiler/testData/diagnostics/tests/inner/InnerClassNameClash.fir.kt new file mode 100644 index 00000000000..9e9d3cf80ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/InnerClassNameClash.fir.kt @@ -0,0 +1,10 @@ +package test + +class B { + class B { + fun foo(b: B.C) { + } + class C { + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/accessingToJavaNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/accessingToJavaNestedClass.fir.kt new file mode 100644 index 00000000000..efd4caaf9b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/accessingToJavaNestedClass.fir.kt @@ -0,0 +1,64 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// FILE: A.java + +public class A { + static class NC {} + class IC {} + static interface NI {} +} + +// FILE: I.java + +public interface I { + class NC {} + interface NI {} +} + +// FILE: B.java + +public class B extends A { + +} + +// FILE: C.java + +public class C implements I { + +} + +// FILE: D.java + +public class D extends A implements I { + +} + +// FILE: K.kt + +class K : D() + +// FILE: test.kt + +fun test() { + val ac: A.NC = A.NC() + val aic: A.IC = A().IC() + val ai: A.NI? = null + + val ic: I.NC = I.NC() + val ii: I.NI? = null + + val bc: B.NC = B.NC() + val bic: B.IC = B().IC() + val bi: B.NI? = null + + val cc: C.NC = C.NC() + val ci: C.NI? = null + + val dc: D.NC = D.NC() + val dic: D.IC = D().IC() + val di: D.NI? = null + + val kc: K.NC = K.NC() + val kic: K.IC = K().IC() + val ki: K.NI? = null +} diff --git a/compiler/testData/diagnostics/tests/inner/accessingToKotlinNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/accessingToKotlinNestedClass.fir.kt new file mode 100644 index 00000000000..f5dc4fdaad1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/accessingToKotlinNestedClass.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +open class A { + class NC {} + inner class IC {} + interface NI {} +} + +interface I { + class NC {} + interface NI {} +} + +class B : A() { + +} + +class C : I { + +} + +class D : A(), I { + +} + +fun test() { + val ac: A.NC = A.NC() + val aic: A.IC = A().IC() + val ai: A.NI? = null + + val ic: I.NC = I.NC() + val ii: I.NI? = null + + val bc: B.NC = B.NC() + val bic: B.IC = B().IC() + val bi: B.NI? = null + + val cc: C.NC = C.NC() + val ci: C.NI? = null + + val dc: D.NC = D.NC() + val dic: D.IC = D().IC() + val di: D.NI? = null +} diff --git a/compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt new file mode 100644 index 00000000000..903b7c13869 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/annotationInInnerClass.fir.kt @@ -0,0 +1,5 @@ +class Outer { + inner class Inner { + annotation class TestNestedAnnotation + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt b/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt new file mode 100644 index 00000000000..b1e7bc807dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/classesInClassObjectHeader.fir.kt @@ -0,0 +1,11 @@ +class Test { + @`InnerAnnotation` @InnerAnnotation + companion object : StaticClass(), InnerClass() { + + } + + annotation class InnerAnnotation + open class StaticClass + + open inner class InnerClass +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt b/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt new file mode 100644 index 00000000000..959b9a6d0b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt @@ -0,0 +1,32 @@ +class Outer1 { + class Nested + + class C1 { val b = Nested() } + class C2(val b: Any = Nested()) + inner class C3 { val b = Nested() } + inner class C4(val b: Any = Nested()) + + inner class Inner + + class C5 { val b = Inner() } + class C6(val b: Any = Inner()) + inner class C7 { val b = Inner() } + inner class C8(val b: Any = Inner()) +} + + +class Outer2 { + class Nested { + fun foo() = Outer2() + fun bar() = Inner() + } + inner class Inner { + fun foo() = Outer2() + fun bar() = Nested() + } + + fun foo() { + Nested() + Inner() + } +} diff --git a/compiler/testData/diagnostics/tests/inner/deepInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inner/deepInnerClass.fir.kt new file mode 100644 index 00000000000..2431bd87d21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/deepInnerClass.fir.kt @@ -0,0 +1,14 @@ +interface P + +class A { + class B { + fun test() { + class C() : P { + companion object : P { + } + + inner class D : P + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/enumEntries.fir.kt b/compiler/testData/diagnostics/tests/inner/enumEntries.fir.kt new file mode 100644 index 00000000000..dad79e88daa --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/enumEntries.fir.kt @@ -0,0 +1,12 @@ +enum class E { + E1 { + override fun foo() = outerFun() + super.outerFun() + }, + E2 { + override fun foo() = E1.foo() + }; + + abstract fun foo(): Int + + fun outerFun() = 42 +} diff --git a/compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt new file mode 100644 index 00000000000..8ca09096ec6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/enumInInnerClass.fir.kt @@ -0,0 +1,5 @@ +class Outer { + inner class Inner { + enum class TestNestedEnum + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/extensionFun.fir.kt b/compiler/testData/diagnostics/tests/inner/extensionFun.fir.kt new file mode 100644 index 00000000000..f43b8b80566 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/extensionFun.fir.kt @@ -0,0 +1,28 @@ +class Outer { + class Nested + inner class Inner + + fun Inner.foo() { + Outer() + Nested() + Inner() + } + + fun Nested.bar() { + Outer() + Nested() + Inner() + } + + fun Outer.baz() { + Outer() + Nested() + Inner() + } +} + +fun Outer.foo() { + Outer() + Nested() + Inner() +} diff --git a/compiler/testData/diagnostics/tests/inner/extensionLambdaInsideNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/extensionLambdaInsideNestedClass.fir.kt new file mode 100644 index 00000000000..0c6e0e544ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/extensionLambdaInsideNestedClass.fir.kt @@ -0,0 +1,27 @@ +package f + +object A { + class LoginFormPage() : Request({ + val failed = session.get("LOGIN_FAILED") + }) +} + +class B { + companion object { + class LoginFormPage() : Request({ + val failed = session.get("LOGIN_FAILED") + }) + } + + class C { + class LoginFormPage() : Request({ + val failed = session.get("LOGIN_FAILED") + }) + } +} + +open class Request(private val handler: ActionContext.() -> Unit) {} + +interface ActionContext { + val session : Map +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/illegalModifier.fir.kt b/compiler/testData/diagnostics/tests/inner/illegalModifier.fir.kt new file mode 100644 index 00000000000..28c8691442c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/illegalModifier.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: -InnerClassInEnumEntryClass +inner fun foo() {} +inner val prop = 42 + +inner class A +inner interface B +inner object C + +class D { + inner class E + inner interface F + inner object G + inner enum class R + inner annotation class S + inner companion object +} + +enum class H { + I0 { + inner class II0 + }, + inner I { + inner class II + }; + + inner class J +} + +interface K { + inner class L +} + +object N { + inner class O +} + +class P { + companion object { + inner class Q + } +} + +val R = object { + inner class S +} diff --git a/compiler/testData/diagnostics/tests/inner/illegalModifier_lv12.fir.kt b/compiler/testData/diagnostics/tests/inner/illegalModifier_lv12.fir.kt new file mode 100644 index 00000000000..ddc9f30edbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/illegalModifier_lv12.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +InnerClassInEnumEntryClass +inner fun foo() {} +inner val prop = 42 + +inner class A +inner interface B +inner object C + +class D { + inner class E + inner interface F + inner object G + inner enum class R + inner annotation class S + inner companion object +} + +enum class H { + I0 { + inner class II0 + }, + inner I { + inner class II + }; + + inner class J +} + +interface K { + inner class L +} + +object N { + inner class O +} + +class P { + companion object { + inner class Q + } +} + +val R = object { + inner class S +} diff --git a/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClassMemberResolve.fir.kt b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClassMemberResolve.fir.kt new file mode 100644 index 00000000000..36aca591b84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClassMemberResolve.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +InnerClassInEnumEntryClass + +enum class A { + X { + val x = 1 + fun foo() {} + + inner class Inner { + val y = x + fun bar() = foo() + } + } +} diff --git a/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt new file mode 100644 index 00000000000..6391c59d91b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv11.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -InnerClassInEnumEntryClass -NestedClassesInEnumEntryShouldBeInner + +enum class Enum { + ENTRY_WITH_CLASS { + inner class TestInner + + class TestNested + + interface TestInterface + + object TestObject + + enum class TestEnumClass { + OTHER_ENTRY + } + + companion object {} + } +} diff --git a/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt new file mode 100644 index 00000000000..ba98e4a6478 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv12.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +InnerClassInEnumEntryClass -NestedClassesInEnumEntryShouldBeInner + +enum class Enum { + ENTRY_WITH_CLASS { + inner class TestInner + + class TestNested + + interface TestInterface + + object TestObject + + enum class TestEnumClass { + OTHER_ENTRY + } + + companion object {} + } +} diff --git a/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt new file mode 100644 index 00000000000..2f2869d3a40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerClassInEnumEntryClass_lv13.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +InnerClassInEnumEntryClass +NestedClassesInEnumEntryShouldBeInner + +enum class Enum { + ENTRY_WITH_CLASS { + inner class TestInner + + class TestNested + + interface TestInterface + + object TestObject + + enum class TestEnumClass { + OTHER_ENTRY + } + + companion object {} + } +} diff --git a/compiler/testData/diagnostics/tests/inner/innerClassesInStaticParameters.fir.kt b/compiler/testData/diagnostics/tests/inner/innerClassesInStaticParameters.fir.kt new file mode 100644 index 00000000000..c4f1408564d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerClassesInStaticParameters.fir.kt @@ -0,0 +1,11 @@ +class Test { + companion object { + fun test(t: TestInner) = 42 + } + + class TestStatic { + fun test(t: TestInner) = 42 + } + + inner class TestInner +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt new file mode 100644 index 00000000000..4c3dce517eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +// FILE: Outer.kt +package abc +class Outer { + inner class Inner() { + constructor(x: Int) : this() {} + } + + companion object { + + fun baz() { + Inner() + Inner(1) + } + } +} + +fun foo() { + Outer.Inner() + Outer.Inner(1) +} + +// FILE: imported.kt +import abc.Outer +import abc.Outer.Inner + +fun bar() { + Inner() + Inner(1) + + with(Outer()) { + Inner() + Inner(1) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt new file mode 100644 index 00000000000..303bb5a88dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +// FILE: Outer.kt +package abc +class Outer { + inner class Inner() { + constructor(x: Int) : this() {} + } + + companion object { + fun Inner(x: String) {} + + fun baz() { + // Diagnostic here could be better (why can't I call the constructor above?) + Inner() + Inner(1) + Inner("") + } + } +} + +fun foo() { + Outer.Inner() + Outer.Inner(1) + Outer.Inner("") +} + +// FILE: imported.kt +import abc.Outer +import abc.Outer.Inner +import abc.Outer.Companion.Inner + +fun bar() { + Inner() + Inner(1) + Inner("") + + with(Outer()) { + Inner() + Inner(1) + Inner("") + } +} diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt new file mode 100644 index 00000000000..f91ff272ef0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt @@ -0,0 +1,26 @@ +open class SomeClass +class TestSome

{ + companion object : SomeClass

() { + } +} + +class Test { + companion object : InnerClass() { + val a = object: InnerClass() { + } + + fun more(): InnerClass { + val b = InnerClass() + + val testVal = inClass + foo() + + return b + } + } + + val inClass = 12 + fun foo() {} + + open inner class InnerClass +} diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt new file mode 100644 index 00000000000..0e447b286f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt @@ -0,0 +1,27 @@ +open class SomeClass +class TestSome

{ + object Some : SomeClass

() { + } +} + +class Test { + object Some : InnerClass() { + val a = object: InnerClass() { + } + + fun more(): InnerClass { + val b = InnerClass() + + val testVal = inClass + foo() + + return b + } + } + + val inClass = 12 + fun foo() { + } + + open inner class InnerClass +} diff --git a/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt b/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt new file mode 100644 index 00000000000..f6902c9ecda --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt @@ -0,0 +1,22 @@ +// NI_EXPECTED_FILE + +interface Trait { + fun bar() = 42 +} + +class Outer : Trait { + class Nested { + val t = this@Outer.bar() + val s = super@Outer.bar() + + inner class NestedInner { + val t = this@Outer.bar() + val s = super@Outer.bar() + } + } + + inner class Inner { + val t = this@Outer.bar() + val s = super@Outer.bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt b/compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt new file mode 100644 index 00000000000..a93f9f4155a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/interfaceInInnerClass.fir.kt @@ -0,0 +1,5 @@ +class Outer { + inner class Inner { + interface TestNestedInterface + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/kt5854.fir.kt b/compiler/testData/diagnostics/tests/inner/kt5854.fir.kt new file mode 100644 index 00000000000..ae458b800a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/kt5854.fir.kt @@ -0,0 +1,11 @@ +//KT-5854 Incorrect 'Nested class should be qualified' + +class A { + class Nested { + + } + + fun foo() { + Nested(1) //two errors here, the first one is wrong + } +} diff --git a/compiler/testData/diagnostics/tests/inner/kt6026.fir.kt b/compiler/testData/diagnostics/tests/inner/kt6026.fir.kt new file mode 100644 index 00000000000..6a923f74e91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/kt6026.fir.kt @@ -0,0 +1,8 @@ +// KT-6026 Exception on instantiating a nested class in an anonymous object + +val oo = object { + // Forbidden in KT-13510 + class Nested + + fun f1() = Nested(11) +} diff --git a/compiler/testData/diagnostics/tests/inner/localClass.fir.kt b/compiler/testData/diagnostics/tests/inner/localClass.fir.kt new file mode 100644 index 00000000000..0745bfff026 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/localClass.fir.kt @@ -0,0 +1,18 @@ +class Outer { + fun foo(): Int { + if (outerState > 0) return outerState + + class Local { + val localState = outerState + + inner class LocalInner { + val o = outerState + val l = localState + } + } + + return Local().localState + } + + val outerState = 42 +} diff --git a/compiler/testData/diagnostics/tests/inner/localClassInsideNested.fir.kt b/compiler/testData/diagnostics/tests/inner/localClassInsideNested.fir.kt new file mode 100644 index 00000000000..a7eefec3262 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/localClassInsideNested.fir.kt @@ -0,0 +1,11 @@ +class Outer { + class Nested { + fun foo() { + class Local { + val state = outerState + } + } + } + + val outerState = 42 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/localThisSuper.fir.kt b/compiler/testData/diagnostics/tests/inner/localThisSuper.fir.kt new file mode 100644 index 00000000000..78c356415f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/localThisSuper.fir.kt @@ -0,0 +1,23 @@ +interface Trait { + fun bar() = 42 +} + +class Outer : Trait { + fun foo() { + val t = this@Outer + val s = super@Outer.bar() + + class Local : Trait { + val t = this@Outer + val s = super@Outer.bar() + + inner class Inner { + val t = this@Local + val s = super@Local.bar() + + val tt = this@Outer + val ss = super@Outer.bar() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/inner/modality.fir.kt b/compiler/testData/diagnostics/tests/inner/modality.fir.kt new file mode 100644 index 00000000000..461687e2b8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/modality.fir.kt @@ -0,0 +1,17 @@ +class Outer { + open class OpenNested + class FinalNested + + open inner class OpenInner + class FinalInner + + class Nested1 : OpenNested() + class Nested2 : FinalNested() + class Nested3 : OpenInner() + class Nested4 : FinalInner() + + inner class Inner1 : OpenNested() + inner class Inner2 : FinalNested() + inner class Inner3 : OpenInner() + inner class Inner4 : FinalInner() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassAccessedViaInstanceReference.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassAccessedViaInstanceReference.fir.kt new file mode 100644 index 00000000000..72a896dde77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassAccessedViaInstanceReference.fir.kt @@ -0,0 +1,53 @@ +interface N { fun foo() = 1 } + +class WithClassObject { + companion object {} + + class Nested() + class NestedWithClassObject { companion object : N } + enum class NestedEnum { A } + object NestedObj : N { operator fun invoke() = 1 } +} + +class WithoutClassObject { + class Nested() + class NestedWithClassObject { companion object : N } + enum class NestedEnum { A } + object NestedObj : N { operator fun invoke() = 1 } +} + +object Obj { + class Nested() + class NestedWithClassObject { companion object : N } + enum class NestedEnum { A } + object NestedObj : N { operator fun invoke() = 1 } +} + +fun test(with: WithClassObject, without: WithoutClassObject, obj: Obj) { + with.Nested() + with.NestedWithClassObject + with.NestedWithClassObject() + with.NestedWithClassObject.foo() + with.NestedEnum.A + with.NestedObj + with.NestedObj() + with.NestedObj.foo() + + without.Nested() + without.NestedWithClassObject + without.NestedWithClassObject() + without.NestedWithClassObject.foo() + without.NestedEnum.A + without.NestedObj + without.NestedObj() + without.NestedObj.foo() + + obj.Nested() + obj.NestedWithClassObject + obj.NestedWithClassObject() + obj.NestedWithClassObject.foo() + obj.NestedEnum.A + obj.NestedObj + obj.NestedObj() + obj.NestedObj.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuter.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuter.fir.kt new file mode 100644 index 00000000000..991b4ffb543 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuter.fir.kt @@ -0,0 +1,8 @@ +open class Outer { + class Nested : Outer() { + fun bar() = foo() + fun baz() = super.foo() + } + + fun foo() = 42 +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuterGeneric.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuterGeneric.fir.kt new file mode 100644 index 00000000000..11e0d3b9340 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassExtendsOuterGeneric.fir.kt @@ -0,0 +1,12 @@ +open class Outer { + class Nested : Outer() { + fun bar(): U = foo() + fun baz(): U = super.foo() + } + class Nested2 : Outer() { + fun bar(): String = foo() + fun baz(): String = super.foo() + } + + fun foo(): T = null!! +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassInObject.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassInObject.fir.kt new file mode 100644 index 00000000000..1eba5b37b5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassInObject.fir.kt @@ -0,0 +1,16 @@ +object Object { + class NestedClass { + fun test() { + outerFun() + outerVal + OuterObject + OuterClass() + } + } + + fun outerFun() {} + val outerVal = 4 + + object OuterObject + class OuterClass +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt new file mode 100644 index 00000000000..18778d77efb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_after.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NestedClassesInEnumEntryShouldBeInner + +class A { + inner class B { + class C + } + + fun foo() { + class B { + class C + } + } +} + +fun foo() { + class B { + class C + } +} + + +enum class E { + E1 { + class D + } +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt new file mode 100644 index 00000000000..7e718dae2bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedClassNotAllowed_before.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: -NestedClassesInEnumEntryShouldBeInner + +class A { + inner class B { + class C + } + + fun foo() { + class B { + class C + } + } +} + +fun foo() { + class B { + class C + } +} + + +enum class E { + E1 { + class D + } +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt new file mode 100644 index 00000000000..35729b8cae8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedObject.fir.kt @@ -0,0 +1,12 @@ +// SKIP_TXT +class Outer { + inner class Inner1 { + object Obj1 + + companion object Obj2 + + inner class Inner2 { + object Obj3 + } + } +} diff --git a/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt new file mode 100644 index 00000000000..e3806c9636d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt @@ -0,0 +1,27 @@ +// NI_EXPECTED_FILE + +class Outer { + fun function() = 42 + val property = "" + + class Nested { + fun f() = function() + fun g() = property + fun h() = this@Outer.function() + fun i() = this@Outer.property + } + + inner class Inner { + fun innerFun() = function() + val innerProp = property + fun innerThisFun() = this@Outer.function() + val innerThisProp = this@Outer.property + + inner class InnerInner { + fun f() = innerFun() + fun g() = innerProp + fun h() = this@Inner.innerFun() + fun i() = this@Inner.innerProp + } + } +} diff --git a/compiler/testData/diagnostics/tests/inner/outerGenericParam.fir.kt b/compiler/testData/diagnostics/tests/inner/outerGenericParam.fir.kt new file mode 100644 index 00000000000..78778d830f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/outerGenericParam.fir.kt @@ -0,0 +1,13 @@ +class Outer { + class Nested { + fun foo(t: T) = t + } + + class Nested2 { + fun foo(t: T) = t + } + + inner class Inner { + fun foo(t: T) = t + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/outerProtectedMember.fir.kt b/compiler/testData/diagnostics/tests/inner/outerProtectedMember.fir.kt new file mode 100644 index 00000000000..5f0064e9227 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/outerProtectedMember.fir.kt @@ -0,0 +1,13 @@ +// KT-2100 + +interface I { + val x : String +} + +class Foo { + protected val x : String = "" + + inner class Inner : I { + override val x : String = this@Foo.x + } +} diff --git a/compiler/testData/diagnostics/tests/inner/outerSuperClassMember.fir.kt b/compiler/testData/diagnostics/tests/inner/outerSuperClassMember.fir.kt new file mode 100644 index 00000000000..dae32f58c4f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/outerSuperClassMember.fir.kt @@ -0,0 +1,9 @@ +open class Base { + fun foo() {} +} + +class Derived : Base() { + class Nested { + fun bar() = foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/classObjectOfNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/classObjectOfNestedClass.fir.kt new file mode 100644 index 00000000000..fb452a3238a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/classObjectOfNestedClass.fir.kt @@ -0,0 +1,14 @@ +class Outer { + class Nested { + companion object { + fun foo() = 42 + } + } + + companion object { + fun bar() = 239 + } +} + +fun foo() = Outer.Nested.foo() +fun bar() = Outer.bar() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt new file mode 100644 index 00000000000..c0dc2c60a00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt @@ -0,0 +1,17 @@ +class Outer { + class Nested { + class NestedNested + } + + inner class Inner { + inner class InnerInner + } +} + +fun f1() = Outer() +fun f2() = Outer.Nested() +fun f3() = Outer.Nested.NestedNested() +fun f4() = Outer.Inner() +fun f5() = Outer.Inner.InnerInner() +fun f6() = Outer().Inner() +fun f7() = Outer().Inner().InnerInner() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/dataLocalVariable.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/dataLocalVariable.fir.kt new file mode 100644 index 00000000000..07b6d50f09c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/dataLocalVariable.fir.kt @@ -0,0 +1,5 @@ +fun bar(b: Boolean) = b + +fun foo(data: List) { + bar(data.contains("")) +} diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/enumConstant.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/enumConstant.fir.kt new file mode 100644 index 00000000000..431424518a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/enumConstant.fir.kt @@ -0,0 +1,7 @@ +enum class E { + E1, + E2 { }; +} + +fun foo() = E.E1 +fun bar() = E.E2 diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/genericNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/genericNestedClass.fir.kt new file mode 100644 index 00000000000..6ae7ed32c08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/genericNestedClass.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +class Outer { + class Nested +} + +fun nested() = Outer.Nested() +fun noArguments() = Outer.Nested() +fun noArgumentsExpectedType(): Outer.Nested = Outer.Nested() +fun manyArguments() = Outer.Nested() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/importNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/importNestedClass.fir.kt new file mode 100644 index 00000000000..128bdafcc08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/importNestedClass.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +class A { + class B { + class C + } +} + +// FILE: b.kt +import A.B +import A.B.C + +val a = A() +val b = B() +val ab = A.B() +val c = C() +val bc = B.C() +val abc = A.B.C() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedClassInPackage.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedClassInPackage.fir.kt new file mode 100644 index 00000000000..07623cb8350 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedClassInPackage.fir.kt @@ -0,0 +1,8 @@ +package A + +class B { + class C { + } +} + +val a = A.B.C() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedEnumConstant.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedEnumConstant.fir.kt new file mode 100644 index 00000000000..a4f370e65ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedEnumConstant.fir.kt @@ -0,0 +1,9 @@ +class A { + enum class E { + E1, + E2 { }; + } +} + +fun foo() = A.E.E1 +fun bar() = A.E.E2 diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedObjects.fir.kt new file mode 100644 index 00000000000..c764ad234e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/nestedObjects.fir.kt @@ -0,0 +1,7 @@ +object A { + object B { + object C + } +} + +val a = A.B.C diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/typePosition.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/typePosition.fir.kt new file mode 100644 index 00000000000..067bc4df710 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/typePosition.fir.kt @@ -0,0 +1,11 @@ +abstract class Outer { + class Nested { + class NestedNested + } + + abstract val prop1: Nested + abstract val prop2: Nested.NestedNested +} + +fun foo(): Outer.Nested = null!! +val bar: Outer.Nested.NestedNested = null!! diff --git a/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.fir.kt b/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.fir.kt new file mode 100644 index 00000000000..cc02038def3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// KT-4351 Cannot resolve reference to self in init of class local to function + +fun f() { + class MyClass() { + init { + val x: MyClass = MyClass() + } + + fun member() { + val x: MyClass = MyClass() + } + } + + object MyObject { + init { + val obj: MyObject = MyObject + } + } + + val x: MyClass = MyClass() +} + +val closure = { + class MyClass { + init { + val x: MyClass = MyClass() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/resolvePackageClassInObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/resolvePackageClassInObjects.fir.kt new file mode 100644 index 00000000000..6bc832b5785 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/resolvePackageClassInObjects.fir.kt @@ -0,0 +1,9 @@ +open class PackageTest + +class MoreTest() { + companion object: PackageTest() { + + } + + object Some: PackageTest() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inner/selfAnnotationForClassObject.fir.kt b/compiler/testData/diagnostics/tests/inner/selfAnnotationForClassObject.fir.kt new file mode 100644 index 00000000000..825e6eee634 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/selfAnnotationForClassObject.fir.kt @@ -0,0 +1,9 @@ +class Test { + @ClassObjectAnnotation + @NestedAnnotation + companion object { + annotation class ClassObjectAnnotation + } + + annotation class NestedAnnotation +} diff --git a/compiler/testData/diagnostics/tests/inner/traits.fir.kt b/compiler/testData/diagnostics/tests/inner/traits.fir.kt new file mode 100644 index 00000000000..7135bf91889 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/traits.fir.kt @@ -0,0 +1,11 @@ +// KT-1188 + +interface Foo { + val b : Bar + val b1 : Foo.Bar + interface Bar {} +} + +interface Foo2 : Foo { + val bb1 : Foo.Bar +} diff --git a/compiler/testData/diagnostics/tests/inner/visibility.fir.kt b/compiler/testData/diagnostics/tests/inner/visibility.fir.kt new file mode 100644 index 00000000000..9f77c959bb3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inner/visibility.fir.kt @@ -0,0 +1,34 @@ +open class Outer { + private class PrivateNested + private inner class PrivateInner + + protected class ProtectedNested + protected inner class ProtectedInner + + public class PublicNested + public inner class PublicInner +} + +class Derived : Outer() { + fun foo() { + Outer.PrivateNested() + super.PrivateInner() + + Outer.ProtectedNested() + super.ProtectedInner() + + Outer.PublicNested() + super.PublicInner() + } +} + +fun foo() { + Outer.PrivateNested() + Outer().PrivateInner() + + Outer.ProtectedNested() + Outer().ProtectedInner() + + Outer.PublicNested() + Outer().PublicInner() +} diff --git a/compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.fir.kt new file mode 100644 index 00000000000..08fb60a0a99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.fir.kt @@ -0,0 +1,49 @@ +// JAVAC_EXPECTED_FILE +// FILE: p/G.java + +package p; + +public interface G { +} + +// FILE: p/A.kt + +package p; + +public interface A { + fun foo(p: A) +} + +// FILE: p/B.java + +package p; + +public class B implements A { + void foo(A p) {} +} + +// FILE: p/C.java + +package p; + +public class C extends B implements A { +} + +// FILE: p/P.java + +package p; + +public class P { +} + +// FILE: k.kt + +import p.* + +abstract class K: C

() { + +} + +abstract class AL: java.util.ArrayList

() { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/InheritedGenericFunction.fir.kt b/compiler/testData/diagnostics/tests/j+k/InheritedGenericFunction.fir.kt new file mode 100644 index 00000000000..de2cd55d562 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/InheritedGenericFunction.fir.kt @@ -0,0 +1,30 @@ +// FILE: p/A.java + +package p; + +public interface A { + void foo(TA p); +} + +// FILE: p/B.java + +package p; + +public class B implements A { + void foo(TB p) {} +} + +// FILE: p/C.java + +package p; + +public class C extends B implements A { +} + +// FILE: k.kt + +import p.* + +abstract class K: C() { + +} diff --git a/compiler/testData/diagnostics/tests/j+k/InnerClassFromJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/InnerClassFromJava.fir.kt new file mode 100644 index 00000000000..cb9f85d3466 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/InnerClassFromJava.fir.kt @@ -0,0 +1,16 @@ +// FILE: Bar.java +public class Bar implements Foo { +public interface I extends Boo { +} +} + +// FILE: Baz.kt +public interface Foo { + companion object { + public val EMPTY: Foo = object : Foo{} + } +} + +interface Boo + +public class Baz : Bar.I \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/KJKInheritance.fir.kt b/compiler/testData/diagnostics/tests/j+k/KJKInheritance.fir.kt new file mode 100644 index 00000000000..dc8ab1f5d86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/KJKInheritance.fir.kt @@ -0,0 +1,18 @@ +// FILE: K1.kt +open class KFirst() { + fun foo() { + } +} + +// FILE: J1.java +public class J1 extends KFirst { + void baz() {} +} + +// FILE: K2.kt +class K2: J1() { + fun bar() { + foo() + baz() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.fir.kt b/compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.fir.kt new file mode 100644 index 00000000000..2c184f5e70d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.fir.kt @@ -0,0 +1,17 @@ +// FILE: K1.kt +open class KFirst() { + fun foo(t: T): T = t +} + +// FILE: J1.java +public class J1 extends KFirst { + void baz() {} +} + +// FILE: K2.kt +class K2: J1() { + fun bar() { + foo(1) + baz() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/OverrideVararg.fir.kt b/compiler/testData/diagnostics/tests/j+k/OverrideVararg.fir.kt new file mode 100644 index 00000000000..2d26101c4ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/OverrideVararg.fir.kt @@ -0,0 +1,12 @@ +// FILE: Aaa.java +// http://youtrack.jetbrains.com/issue/KT-1694 + +public abstract class Aaa { + public abstract void foo(String... args); +} + +// FILE: bbb.kt + +class Bbb() : Aaa() { + override fun foo(vararg args: String?) = Unit +} diff --git a/compiler/testData/diagnostics/tests/j+k/Simple.fir.kt b/compiler/testData/diagnostics/tests/j+k/Simple.fir.kt new file mode 100644 index 00000000000..c82f272c811 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/Simple.fir.kt @@ -0,0 +1,11 @@ +// FILE: aa/A.java +package aa; + +public class A { + public void f() { } +} + +// FILE: B.kt +import aa.A + +fun foo(a: A) = a.f() diff --git a/compiler/testData/diagnostics/tests/j+k/StaticMembersFromSuperclasses.fir.kt b/compiler/testData/diagnostics/tests/j+k/StaticMembersFromSuperclasses.fir.kt new file mode 100644 index 00000000000..de425b2100f --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/StaticMembersFromSuperclasses.fir.kt @@ -0,0 +1,16 @@ +// FILE: Aaa.java +// http://youtrack.jetbrains.com/issue/KT-1880 + +public class Aaa { + public static final int i = 1; +} + +// FILE: Bbb.java + +public class Bbb extends Aaa { + public static final String i = "s"; +} + +// FILE: b.kt + +fun foo() = Bbb.i diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt new file mode 100644 index 00000000000..842a06b0502 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-SpecialTypes.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// FILE: A.java +public class A {} + +// FILE: X.java +import org.jetbrains.annotations.NotNull; + +public class X { + @NotNull T fooN() {return null;} + void barN(@NotNull T a) {} +} + +// FILE: Y.java +public class Y extends X { + +} + +// FILE: test.kt + +fun main() { + checkSubtype(Y().fooN()) + Y().barN(null); +} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt new file mode 100644 index 00000000000..610836c63f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-NotNull-UserTypes.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// FILE: A.java +public class A {} + +// FILE: X.java +import org.jetbrains.annotations.NotNull; + +public class X { + @NotNull T fooN() {return null;} + void barN(@NotNull T a) {} +} + +// FILE: Y.java +public class Y extends X { + +} + +// FILE: test.kt + +fun main() { + checkSubtype(Y().fooN()) + Y().barN(null); +} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-SpecialTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-SpecialTypes.fir.kt new file mode 100644 index 00000000000..1823253b9b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-SpecialTypes.fir.kt @@ -0,0 +1,20 @@ +// FILE: A.java +public class A {} + +// FILE: X.java +public class X { + T foo() {return null;} + void bar(T a) {} +} + +// FILE: Y.java +public class Y extends X { + +} + +// FILE: test.kt + +fun main() { + Y().foo().length + Y().bar(null) +} diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.fir.kt new file mode 100644 index 00000000000..cc28efdcaa2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.fir.kt @@ -0,0 +1,20 @@ +// FILE: A.java +public class A {} + +// FILE: X.java +public class X { + T foo() {return null;} + void bar(T a) {} +} + +// FILE: Y.java +public class Y extends X { + +} + +// FILE: test.kt + +fun main() { + Y().foo().hashCode() + Y().bar(null) +} diff --git a/compiler/testData/diagnostics/tests/j+k/UnboxingNulls.fir.kt b/compiler/testData/diagnostics/tests/j+k/UnboxingNulls.fir.kt new file mode 100644 index 00000000000..4e69df6f24c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/UnboxingNulls.fir.kt @@ -0,0 +1,13 @@ +// FILE: a/Test.java +package a; + +public class Test { + T t() {return null;} +} +// FILE: b.kt +package a + +fun foo() { + // If this fails, it means that we have broken the rule that Java returns are always nullable + a.Test().t() + 1 +} diff --git a/compiler/testData/diagnostics/tests/j+k/accessClassObjectFromJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/accessClassObjectFromJava.fir.kt new file mode 100644 index 00000000000..af234b504c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/accessClassObjectFromJava.fir.kt @@ -0,0 +1,10 @@ +class Foo { + companion object { + val bar = 1 + + fun test(a: Foo.`object`) { + + } + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.fir.kt b/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.fir.kt new file mode 100644 index 00000000000..4b0edc1fab3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/ambiguousSamAdapters.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java +import java.io.Closeable; + +public class A { + public static void foo(Runnable r) { + } + + public static void foo(Closeable c) { + } +} + +// FILE: test.kt + +fun main() { + A.foo { "Hello!" } + A.foo(Runnable { "Hello!" }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.fir.kt b/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.fir.kt new file mode 100644 index 00000000000..90f3fc6ea16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.fir.kt @@ -0,0 +1,12 @@ +// FILE: A.java +@missing.Ann(x = "") +public class A { + @missing.Ann(1) + public String foo() {} +} + +// FILE: main.kt + +fun main() { + A().foo().length +} diff --git a/compiler/testData/diagnostics/tests/j+k/annotationsInheritance.fir.kt b/compiler/testData/diagnostics/tests/j+k/annotationsInheritance.fir.kt new file mode 100644 index 00000000000..1764b09b343 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/annotationsInheritance.fir.kt @@ -0,0 +1,19 @@ +// FILE: MyAnnotation.java +public @interface MyAnnotation { +} +// FILE: MyAnnoClass.java +public class MyAnnoClass implements MyAnnotation { +//... +} + +// FILE: main.kt + +val ann: MyAnnotation = MyAnnoClass() + +fun foo(x: MyAnnoClass) { + bar(x) +} + +fun bar(y: MyAnnotation) { + y.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/j+k/arrayOfStarParametrized.fir.kt b/compiler/testData/diagnostics/tests/j+k/arrayOfStarParametrized.fir.kt new file mode 100644 index 00000000000..d18fda6e7fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/arrayOfStarParametrized.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +// FILE: A.java +public class A { + public A[] baz() { return null; } +} + + +// FILE: main.kt + +fun foo1(x: A<*>) = x.baz() +fun foo2(x: A<*>) { + x.baz() checkType { _>>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/brokenCode/classDuplicates.fir.kt b/compiler/testData/diagnostics/tests/j+k/brokenCode/classDuplicates.fir.kt new file mode 100644 index 00000000000..928b78be8ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/brokenCode/classDuplicates.fir.kt @@ -0,0 +1,13 @@ +// FILE: Hello.kt +private class Hello() +{ + val a = 4 +} + +fun test() { + // no exception is thrown (see KT-3897) + Hello().a +} + +// FILE: Hello.java +public class Hello {} diff --git a/compiler/testData/diagnostics/tests/j+k/brokenCode/fieldDuplicates.fir.kt b/compiler/testData/diagnostics/tests/j+k/brokenCode/fieldDuplicates.fir.kt new file mode 100644 index 00000000000..857d09668c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/brokenCode/fieldDuplicates.fir.kt @@ -0,0 +1,13 @@ +// FILE: A.java + +public class A { + public String foo; + public String foo = ""; +} + +// FILE: main.kt + +fun foo() { + // no exception is thrown (see KT-3898) + A().foo +} diff --git a/compiler/testData/diagnostics/tests/j+k/callableReferencesStaticMemberClash.fir.kt b/compiler/testData/diagnostics/tests/j+k/callableReferencesStaticMemberClash.fir.kt new file mode 100644 index 00000000000..86149c53609 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/callableReferencesStaticMemberClash.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: A.java +public class A { + public static void foo() {} + public static void foo(String x) {} + + private void foo(int y) {} +} + +// FILE: main.kt + +fun baz(x: (String) -> Unit) {} + +fun bar() { + baz(A::foo) +} diff --git a/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.fir.kt b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.fir.kt new file mode 100644 index 00000000000..f999e6b8e83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.fir.kt @@ -0,0 +1,11 @@ +// FILE: Super.java +public class Super { + void foo(Runnable r) { + } +} + +// FILE: Sub.kt +class Sub() : Super() { + fun foo(r : (() -> Unit)?) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/charBuffer.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/charBuffer.fir.kt new file mode 100644 index 00000000000..1b32d392513 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/charBuffer.fir.kt @@ -0,0 +1,22 @@ +// FILE: CharBuffer.java + +public class CharBuffer implements CharSequence { + public final int length() { + return 0; + } + + public final char charAt(int index) { + return get(position() + checkIndex(index, 1)); + } + + // The key problem here is that `get` has the same signature as kotlin.CharSequence.get but completely different semantics + public abstract char get(int index); + public abstract CharBuffer subSequence(int start, int end); +} + +// FILE: main.kt + +fun test(cb: CharBuffer) { + cb.get(0) + (cb as CharSequence).get(0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/collectionStringImpl.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/collectionStringImpl.fir.kt new file mode 100644 index 00000000000..08b86b53d45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/collectionStringImpl.fir.kt @@ -0,0 +1,85 @@ +// FILE: CollectionStringImpl.java + +import java.util.Collection; +import java.util.Iterator; + +public class CollectionStringImpl implements Collection { + @Override + public int size() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public boolean contains(Object o) { + return false; + } + + + @Override + public Iterator iterator() { + return null; + } + + + @Override + public Object[] toArray() { + return new Object[0]; + } + + + @Override + public T[] toArray(T[] a) { + return null; + } + + @Override + public boolean add(String s) { + return false; + } + + @Override + public boolean remove(Object o) { + return false; + } + + @Override + public boolean containsAll(Collection c) { + return false; + } + + @Override + public boolean addAll(Collection c) { + return false; + } + + @Override + public boolean removeAll(Collection c) { + return false; + } + + @Override + public boolean retainAll(Collection c) { + return false; + } + + @Override + public void clear() { + + } + + public boolean contains(String o) { + return true; + } +} + +// FILE: main.kt + +fun test(x: CollectionStringImpl) { + x.contains("") + (x as Collection).contains("") +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/commonCollections.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/commonCollections.fir.kt new file mode 100644 index 00000000000..2d563de8a26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/commonCollections.fir.kt @@ -0,0 +1,28 @@ +import java.util.* +fun foo() { + val al = ArrayList() + al.size + al.contains(1) + al.contains("") + + al.remove("") + al.removeAt(1) + + val hs = HashSet() + hs.size + hs.contains(1) + hs.contains("") + + hs.remove("") + + + val hm = HashMap() + hm.size + hm.containsKey(1) + hm.containsKey("") + + hm[1] + hm[""] + + hm.remove("") +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/contains.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/contains.fir.kt new file mode 100644 index 00000000000..8caaa33cfd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/contains.fir.kt @@ -0,0 +1,66 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -PARAMETER_NAME_CHANGED_ON_OVERRIDE +// JAVAC_EXPECTED_FILE +// FILE: A.java + +abstract public class A implements java.util.Collection { + public boolean contains(Object x) {return false;} +} + +// FILE: B.java + +abstract public class B implements java.util.Collection { + public boolean contains(Object x) {return false;} +} + +// FILE: IC.java +public interface IC extends java.util.Collection { + public boolean contains(Object x); +} + +// FILE: main.kt +abstract class KA : java.util.AbstractList() { + override fun contains(x: T) = false +} + +abstract class KB : java.util.AbstractList(), IC { + override fun contains(element: String) = false +} + + +// Raw? + +fun foo( + a: A, b: B, ic: IC, + ka: KA, kb: KB, + al: java.util.ArrayList +) { + a.contains("") + a.contains(1) + "" in a + 1 in a + + b.contains("") + b.contains(1) + "" in b + 1 in b + + ic.contains("") + ic.contains(1) + "" in ic + 1 in ic + + ka.contains("") + ka.contains(1) + "" in ka + 1 in ka + + kb.contains("") + kb.contains(1) + "" in kb + 1 in kb + + al.contains("") + al.contains(1) + "" in al + 1 in al +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAll.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAll.fir.kt new file mode 100644 index 00000000000..94b462adcc4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAll.fir.kt @@ -0,0 +1,56 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -PARAMETER_NAME_CHANGED_ON_OVERRIDE +// JAVAC_EXPECTED_FILE +// FILE: A.java +import java.util.*; + +abstract public class A implements java.util.Collection { + public boolean containsAll(Collection x) {return false;} +} + +// FILE: B.java +import java.util.*; + +abstract public class B implements java.util.Collection { + public boolean containsAll(Collection x) {return false;} +} + +// FILE: IC.java +import java.util.*; + +public interface IC extends java.util.Collection { + public boolean containsAll(Collection x); +} + +// FILE: main.kt +abstract class KA : java.util.AbstractList() { + override fun containsAll(x: Collection) = false +} + +abstract class KB : java.util.AbstractList(), IC { + override fun containsAll(elements: Collection) = false +} + +fun foo( + a: A, b: B, ic: IC, + ka: KA, kb: KB, + al: java.util.ArrayList, + cs: Collection, ca: Collection +) { + a.containsAll(cs) + a.containsAll(ca) + + b.containsAll(cs) + b.containsAll(ca) + + ic.containsAll(cs) + ic.containsAll(ca) + + ka.containsAll(cs) + ka.containsAll(ca) + + kb.containsAll(cs) + kb.containsAll(ca) + + al.containsAll(cs) + al.containsAll(ca) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAndOverload.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAndOverload.fir.kt new file mode 100644 index 00000000000..14ba0abc693 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/containsAndOverload.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -PARAMETER_NAME_CHANGED_ON_OVERRIDE + +// FILE: A.java +abstract public class A implements java.util.Collection { + public boolean contains(Object x) {return false;} + public boolean contains(String x) {return false;} +} + +// FILE: main.kt +abstract class KA : A() { + override fun contains(x: String) = false +} + +fun foo(a: A, ka: KA) { + a.contains("") + a.contains(1) + "" in a + 1 in a + + ka.contains("") + ka.contains(1) + "" in ka + 1 in ka +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/getCharSequence.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/getCharSequence.fir.kt new file mode 100644 index 00000000000..40c49d09a1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/getCharSequence.fir.kt @@ -0,0 +1,30 @@ +// FILE: A.java +abstract public class A implements CharSequence { + public char charAt(int x) { } + public int length() { return 1; } +} + +// FILE: C.java +abstract public class C implements CharSequence { + public char get(int x) { } + public int length() { return 1; } +} + +// FILE: main.kt + +abstract class B : A(), CharSequence { + override operator fun get(index: Int) = '1' + override val length: Int get() = 1 +} + +fun main(a: A, b: B, c: C) { + a[0] + b[0] + c[0] + + a.get(0) + b.get(0) + c.get(0) + + a.length + b.length + c.length +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantCharAtAbstract.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantCharAtAbstract.fir.kt new file mode 100644 index 00000000000..8462a985da9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantCharAtAbstract.fir.kt @@ -0,0 +1,19 @@ +// FILE: A.java + +public abstract class A { + abstract public char charAt(int i); +} + +// FILE: B.java + +abstract public class B extends A implements CharSequence { + public char charAt(int i) { return '1'; } +} + +// FILE: main.kt + +abstract class C1 : B() + +abstract class C2 : B() { + override fun get(index: Int) = '1' +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequence.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequence.fir.kt new file mode 100644 index 00000000000..e544b2be1c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequence.fir.kt @@ -0,0 +1,25 @@ +// FILE: AImpl.java + +abstract public class AImpl { + public char charAt(int index) { + return '1'; + } + + public final int length() { return 1; } +} + +// FILE: A.java +public class A extends AImpl implements CharSequence { + public CharSequence subSequence(int start, int end) { + return null; + } +} + +// FILE: X.kt +class X : A() + +fun main() { + val x = X() + x[0] + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequenceKotlin.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequenceKotlin.fir.kt new file mode 100644 index 00000000000..65a03831ee2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplCharSequenceKotlin.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: AImpl.kt + +abstract class AImpl { + fun charAt(index: Int): Char { + return '1' + } + + fun length(): Int { + return 1 + } +} + +// FILE: A.java +public class A extends AImpl implements CharSequence { + public CharSequence subSequence(int start, int end) { + return null; + } +} + +// FILE: X.kt +class X : A() + +fun main() { + val x = X() + x[0] + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableList.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableList.fir.kt new file mode 100644 index 00000000000..68b8dad2acd --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableList.fir.kt @@ -0,0 +1,119 @@ +// FILE: AImpl.java + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +public abstract class AImpl { + public int size() { + return 0; + } + + public boolean isEmpty() { + return false; + } + + public boolean contains(Object o) { + return false; + } + + public Iterator iterator() { + return null; + } + + public Object[] toArray() { + return new Object[0]; + } + + public T[] toArray(T[] a) { + return null; + } + + public boolean add(String s) { + return false; + } + + public boolean remove(Object o) { + return false; + } + + public boolean containsAll(Collection c) { + return false; + } + + public boolean addAll(Collection c) { + return false; + } + + public boolean addAll(int index, Collection c) { + return false; + } + + public boolean removeAll(Collection c) { + return false; + } + + public boolean retainAll(Collection c) { + return false; + } + + public void clear() { + + } + + public String get(int index) { + return null; + } + + public String set(int index, String element) { + return null; + } + + public void add(int index, String element) { + + } + + public String remove(int index) { + return null; + } + + public int indexOf(Object o) { + return 0; + } + + public int lastIndexOf(Object o) { + return 0; + } + + public ListIterator listIterator() { + return null; + } + + public ListIterator listIterator(int index) { + return null; + } + + public List subList(int fromIndex, int toIndex) { + return null; + } +} + + +// FILE: A.java +import java.util.List; + +public class A extends AImpl implements List { + +} + +// FILE: X.kt +class X : A() + +fun main() { + val x = X() + x[0] + x.size + x.remove("") + x.remove(1) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableListKotlin.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableListKotlin.fir.kt new file mode 100644 index 00000000000..4c7f99d2c13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantImplMutableListKotlin.fir.kt @@ -0,0 +1,106 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: AImpl.kt + +public abstract class AImpl { + fun add(element: String): Boolean { + throw UnsupportedOperationException() + } + + fun remove(element: String): Boolean { + throw UnsupportedOperationException() + } + + fun addAll(elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun addAll(index: Int, elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun removeAll(elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun retainAll(elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun clear() { + throw UnsupportedOperationException() + } + + fun set(index: Int, element: String): String { + throw UnsupportedOperationException() + } + + fun add(index: Int, element: String) { + throw UnsupportedOperationException() + } + + fun remove(index: Int): String { + throw UnsupportedOperationException() + } + + fun listIterator(): MutableListIterator { + throw UnsupportedOperationException() + } + + fun listIterator(index: Int): MutableListIterator { + throw UnsupportedOperationException() + } + + fun subList(fromIndex: Int, toIndex: Int): MutableList { + throw UnsupportedOperationException() + } + + val size: Int + get() = throw UnsupportedOperationException() + + fun isEmpty(): Boolean { + throw UnsupportedOperationException() + } + + fun contains(element: Any?): Boolean { + throw UnsupportedOperationException() + } + + fun containsAll(elements: Collection<*>): Boolean { + throw UnsupportedOperationException() + } + + fun get(index: Int): String { + throw UnsupportedOperationException() + } + + fun indexOf(element: String): Int { + throw UnsupportedOperationException() + } + + fun lastIndexOf(element: String): Int { + throw UnsupportedOperationException() + } + + fun iterator(): MutableIterator { + throw UnsupportedOperationException() + } +} + + +// FILE: A.java +import java.util.List; + +public class A extends AImpl implements List { + +} + +// FILE: X.kt +class X : A() + +fun main() { + val x = X() + x[0] + x.size + x.remove("") + x.remove(1) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantMapGetAbstract.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantMapGetAbstract.fir.kt new file mode 100644 index 00000000000..409e6ed8c49 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/irrelevantMapGetAbstract.fir.kt @@ -0,0 +1,19 @@ +// FILE: Dict.java + +public abstract class Dict { + abstract public V get(Object key); +} + +// FILE: MHashtable.java + +abstract public class MHashtable extends Dict implements java.util.Map { + public V get(Object key) { return null; } +} + +// FILE: main.kt + +abstract class C1 : MHashtable() + +abstract class C2 : MHashtable() { + override fun get(key: String) = 1 +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/mapGetOverride.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/mapGetOverride.fir.kt new file mode 100644 index 00000000000..c357b29c46a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/mapGetOverride.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE +// JAVAC_EXPECTED_FILE +// FILE: MyMap.java + +abstract public class MyMap extends java.util.AbstractMap { + String get(Object q) { } +} + +// FILE: main.kt + +fun foo(m: MyMap) { + var x: String? = m.get(1.0) + x = m[2.0] +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/overridesBuiltinNoMagic.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/overridesBuiltinNoMagic.fir.kt new file mode 100644 index 00000000000..a25795d18de --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/overridesBuiltinNoMagic.fir.kt @@ -0,0 +1,163 @@ +// FILE: X.java +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +public class X implements java.util.List { + @Override + public int size() { + return 0; + } + + public int getSize() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } + + public boolean contains(String o) { + return false; + } + + @Override + public boolean contains(Object o) { + return false; + } + + @NotNull + @Override + public Iterator iterator() { + return null; + } + + @NotNull + @Override + public Object[] toArray() { + return new Object[0]; + } + + @NotNull + @Override + public T[] toArray(T[] a) { + return null; + } + + @Override + public boolean add(String s) { + return false; + } + + @Override + public boolean remove(Object o) { + return false; + } + + @Override + public boolean containsAll(Collection c) { + return false; + } + + @Override + public boolean addAll(Collection c) { + return false; + } + + @Override + public boolean addAll(int index, Collection c) { + return false; + } + + @Override + public boolean removeAll(Collection c) { + return false; + } + + @Override + public boolean retainAll(Collection c) { + return false; + } + + @Override + public void clear() { + + } + + @Override + public String get(int index) { + return null; + } + + @Override + public String set(int index, String element) { + return null; + } + + @Override + public void add(int index, String element) { + + } + + @Override + public String remove(int index) { + return null; + } + + public String removeAt(int index) { + return null; + } + + @Override + public int indexOf(Object o) { + return 0; + } + + @Override + public int lastIndexOf(Object o) { + return 0; + } + + @NotNull + @Override + public ListIterator listIterator() { + return null; + } + + @NotNull + @Override + public ListIterator listIterator(int index) { + return null; + } + + @NotNull + @Override + public List subList(int fromIndex, int toIndex) { + return null; + } +} + +// FILE: main.kt + +class Y : X() +class Y2 : X() { + override fun removeAt(index: Int) = "" +} + +fun main() { + X().remove("") + X().removeAt(1) + + val y: MutableList = Y() + y.removeAt(1) + + Y().remove("") + Y().removeAt(1) + + X().remove("") + X().removeAt(1) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.fir.kt new file mode 100644 index 00000000000..bf5a5332a11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.fir.kt @@ -0,0 +1,23 @@ +// JAVAC_EXPECTED_FILE +// FILE: A.java +abstract public class A extends B { + public F remove(int x) { } + public boolean remove(Object x) { } +} + +// FILE: main.kt +import java.util.*; + +abstract class B : MutableList, AbstractList() { + override fun removeAt(index: Int): T = null!! + override fun remove(element: T): Boolean = null!! +} + +fun main(a: A, b: B, c: ArrayList) { + a.remove("") + a.removeAt(0) + b.remove("") + b.removeAt(0) + c.remove("") + c.removeAt(0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt new file mode 100644 index 00000000000..ff15421906f --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt @@ -0,0 +1,23 @@ +// JAVAC_EXPECTED_FILE +// FILE: A.java +abstract public class A extends B { + public Integer removeAt(int x) { } + public boolean remove(Integer x) { } +} + +// FILE: main.kt +import java.util.*; + +abstract class B : MutableList, AbstractList() { + override fun removeAt(index: Int): Int = null!! + override fun remove(element: Int): Boolean = null!! +} + +fun main(a: A, b: B, c: ArrayList) { + a.remove(1) + a.removeAt(0) + b.remove(1) + b.removeAt(0) + c.remove(1) + c.removeAt(0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.fir.kt new file mode 100644 index 00000000000..bd214138ce0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.fir.kt @@ -0,0 +1,13 @@ +// FILE: A.java + +abstract public class A extends MyList { + int getSize() { return 0; } +} + +// FILE: main.kt + +abstract class MyList : Collection {} + +fun main(a: A) { + a.size +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectorInference.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectorInference.fir.kt new file mode 100644 index 00000000000..6ae7cf7606e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectorInference.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// SKIP_TXT +// FULL_JDK + +import java.util.stream.Collectors +import java.util.stream.Stream + +fun test(a: Stream) { + a.collect(Collectors.toList()) checkType { _>() } + // actually the inferred type is platform + a.collect(Collectors.toList()) checkType { _>() } +} + diff --git a/compiler/testData/diagnostics/tests/j+k/computeIfAbsentConcurrent.fir.kt b/compiler/testData/diagnostics/tests/j+k/computeIfAbsentConcurrent.fir.kt new file mode 100644 index 00000000000..abd047b6ccd --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/computeIfAbsentConcurrent.fir.kt @@ -0,0 +1,22 @@ +// FILE: MyFunc.java +public interface MyFunc { + V apply(K String); +} + +// FILE: ConcMap.java +public interface ConcMap { + V computeIfAbsent(K key, MyFunc mappingFunction); +} + +// FILE: ConcHashMap.java +public class ConcHashMap implements ConcMap { + @Override + V computeIfAbsent(K key, MyFunc mappingFunction) { } +} + +// FILE: main.kt + +public fun concurrentMap() { + val map = ConcHashMap() + map.computeIfAbsent("") { "" } // here +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/contravariantIterable.fir.kt b/compiler/testData/diagnostics/tests/j+k/contravariantIterable.fir.kt new file mode 100644 index 00000000000..6a78efd5e2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/contravariantIterable.fir.kt @@ -0,0 +1,20 @@ +// FILE: A.java +import java.util.*; +public class A { + public static void foo(Iterable x) {} + public static void bar(Iterator x) {} +} + +// FILE: main.kt + +fun test(x: List, y: List<*>, z: MutableList<*>, w: MutableList) { + A.foo(x) + A.foo(y) + A.foo(z) + A.foo(w) + + A.bar(x.iterator()) + A.bar(y.iterator()) + A.bar(z.iterator()) + A.bar(w.iterator()) +} diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt new file mode 100644 index 00000000000..2655a46b921 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt @@ -0,0 +1,166 @@ +// FILE: JavaInterface.java + +public interface JavaInterface { + static String testStatic() { + return "OK"; + } + + default String test() { + return "OK"; + } + + default String testOverride() { + return "OK"; + } +} + +// FILE: 1.kt +import JavaInterface.testStatic + +interface KotlinInterface : JavaInterface { + fun fooo() { + testStatic() + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + } + + val propertyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + return "" + } + + override fun testOverride(): String { + return "OK"; + } +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + fun foooo() { + testStatic() + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + } + + val propertyyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + return "" + } +} + +open class KotlinClass : JavaInterface { + fun foo() { + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2(){ + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + } + + val property2: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo() { + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + return "" + } +} + +fun test() { + JavaInterface.testStatic() + KotlinClass().foo() + KotlinClass().property + KotlinClassIndirectInheritance2().foo() + KotlinClassIndirectInheritance2().property + + KotlinClass().test() + KotlinClass().property + KotlinClass().testOverride() + KotlinClassIndirectInheritance().testOverride() +} diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt new file mode 100644 index 00000000000..6aafef0fac0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt @@ -0,0 +1,79 @@ +// FILE: JavaInterfaceBase.java + +public interface JavaInterfaceBase { + default String test() { + return "OK"; + } + + default String testOverride() { + return "OK"; + } +} + +// FILE: JavaInterface.java + +public interface JavaInterface extends JavaInterfaceBase { + static String testStatic() { + return "OK"; + } +} + + +// FILE: 1.kt +import JavaInterface.testStatic + +interface KotlinInterface : JavaInterface { + fun fooo() { + testStatic() + super.test() + test() + testOverride() + } + + override fun testOverride(): String { + return "OK"; + } +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + fun foooo() { + testStatic() + super.test() + testOverride() + super.testOverride() + } +} + +open class KotlinClass : JavaInterface { + fun foo(){ + testStatic() + super.test() + super.testOverride() + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2(){ + testStatic() + super.test() + super.testOverride() + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo(){ + testStatic() + super.test() + super.testOverride() + } +} + +fun test() { + JavaInterface.testStatic() + KotlinClass().foo() + KotlinClassIndirectInheritance2().foo() + + KotlinClass().test() + KotlinClass().testOverride() + KotlinClassIndirectInheritance().testOverride() +} diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt new file mode 100644 index 00000000000..e7b765c005a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt @@ -0,0 +1,168 @@ +//!LANGUAGE: -DefaultMethodsCallFromJava6TargetError +// FILE: JavaInterface.java + +public interface JavaInterface { + static String testStatic() { + return "OK"; + } + + default String test() { + return "OK"; + } + + default String testOverride() { + return "OK"; + } +} + +// FILE: 1.kt + +import JavaInterface.testStatic + +interface KotlinInterface : JavaInterface { + fun fooo() { + testStatic() + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + } + + val propertyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + return "" + } + + override fun testOverride(): String { + return "OK"; + } +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + fun foooo() { + testStatic() + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + } + + val propertyyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + return "" + } +} + +open class KotlinClass : JavaInterface { + fun foo(){ + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2(){ + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + } + + val property2: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo(){ + testStatic() + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + return "" + } +} + +fun test() { + JavaInterface.testStatic() + KotlinClass().foo() + KotlinClass().property + KotlinClassIndirectInheritance2().foo() + KotlinClassIndirectInheritance2().property + + KotlinClass().test() + KotlinClass().property + KotlinClass().testOverride() + KotlinClassIndirectInheritance().testOverride() +} diff --git a/compiler/testData/diagnostics/tests/j+k/deprecations/forFakeOverrides.fir.kt b/compiler/testData/diagnostics/tests/j+k/deprecations/forFakeOverrides.fir.kt new file mode 100644 index 00000000000..6100afe2c4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/deprecations/forFakeOverrides.fir.kt @@ -0,0 +1,36 @@ +// FILE: J.java +public interface J { + @Deprecated + public void foo(); + + @Deprecated + public String bar(); + + @Deprecated + public CharSequence baz(); +} +// FILE: J2.java +public interface J2 extends J, K { +} + +// FILE: main.kt +interface K { + fun bar(): CharSequence + fun baz(): String +} + +interface A : J, K + +fun main(j: J, j2: J2, a: A) { + j.foo() + j2.foo() + a.foo() + + j.bar() + j2.bar() + a.bar() + + j.baz() + j2.baz() + a.baz() +} diff --git a/compiler/testData/diagnostics/tests/j+k/deprecations/forMixedOverride.fir.kt b/compiler/testData/diagnostics/tests/j+k/deprecations/forMixedOverride.fir.kt new file mode 100644 index 00000000000..2caf9e3d1bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/deprecations/forMixedOverride.fir.kt @@ -0,0 +1,27 @@ +// FILE: J.java +public class J { + @Deprecated + public void foo() {} +} +// FILE: J2.java +public class J2 extends J implements WithDeprecation { + @Override + public void foo() {} +} + +// FILE: main.kt +interface WithDeprecation { + @Deprecated("") + fun foo() +} + +class A : J(), WithDeprecation { + override fun foo() {} +} + +fun main() { + J().foo() + + J2().foo() + A().foo() +} diff --git a/compiler/testData/diagnostics/tests/j+k/deprecations/forOverrides.fir.kt b/compiler/testData/diagnostics/tests/j+k/deprecations/forOverrides.fir.kt new file mode 100644 index 00000000000..e06bfaf2060 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/deprecations/forOverrides.fir.kt @@ -0,0 +1,23 @@ +// FILE: J.java +public interface J { + @Deprecated + public void foo(); + +} +// FILE: J2.java +public interface J2 extends J { + @Override + public void foo(); +} + +// FILE: main.kt + +interface A : J { + override fun foo() +} + +fun main(j: J, j2: J2, a: A) { + j.foo() + j2.foo() + a.foo() +} diff --git a/compiler/testData/diagnostics/tests/j+k/differentFilename.fir.kt b/compiler/testData/diagnostics/tests/j+k/differentFilename.fir.kt new file mode 100644 index 00000000000..b0ae18cce3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/differentFilename.fir.kt @@ -0,0 +1,26 @@ +// JAVAC_SKIP +// FILE: A.java +public class A { + public B b() {} + public F f() {} +} + +class B { public void bar() {} } + +// FILE: C.java +class D { + public void baz() {} +} + +// FILE: E.java +class F { + public void foobaz() {} +} + +// FILE: main.kt +fun main(x: A) { + x.b().bar() + x.f().foobaz() + + D().baz() +} diff --git a/compiler/testData/diagnostics/tests/j+k/enumGetOrdinal.fir.kt b/compiler/testData/diagnostics/tests/j+k/enumGetOrdinal.fir.kt new file mode 100644 index 00000000000..e5f13b1d851 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/enumGetOrdinal.fir.kt @@ -0,0 +1,12 @@ +// FILE: MyEnum.java + +public enum MyEnum { + A; + public int getOrdinal() {return "";} +} + +// FILE: main.kt + +fun foo() { + MyEnum.A.getOrdinal() +} diff --git a/compiler/testData/diagnostics/tests/j+k/exceptionMessage.fir.kt b/compiler/testData/diagnostics/tests/j+k/exceptionMessage.fir.kt new file mode 100644 index 00000000000..cbc8640a180 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/exceptionMessage.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// JAVAC_EXPECTED_FILE +// FILE: VcsException.java +import org.jetbrains.annotations.NotNull; + +public class VcsException extends Exception { + @Override + @NotNull + public String getMessage() { + return ""; + } +} + +// FILE: main.kt +fun foo(e: VcsException) { + e.message.contains("") + "" in e.message +} + +public operator fun CharSequence.contains(other: CharSequence): Boolean = true diff --git a/compiler/testData/diagnostics/tests/j+k/fieldOverridesField.fir.kt b/compiler/testData/diagnostics/tests/j+k/fieldOverridesField.fir.kt new file mode 100644 index 00000000000..54d5f50f599 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/fieldOverridesField.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java + +public class A { + public int size = 1; +} + +// FILE: B.java + +public class B implements A { + public int size = 1; +} + +// FILE: main.kt + +fun foo() { + B().size +} diff --git a/compiler/testData/diagnostics/tests/j+k/fieldOverridesFieldOfDifferentType.fir.kt b/compiler/testData/diagnostics/tests/j+k/fieldOverridesFieldOfDifferentType.fir.kt new file mode 100644 index 00000000000..d3ba6713d79 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/fieldOverridesFieldOfDifferentType.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +// FILE: A.java + +public class A { + public int size = 1; +} + +// FILE: B.java + +public class B extends A { + public String size = 1; +} + +// FILE: main.kt + +fun foo() { + B().size.checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.fir.kt b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.fir.kt new file mode 100644 index 00000000000..b5fc8ab03da --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.fir.kt @@ -0,0 +1,19 @@ +// FILE: B.java + +public abstract class B implements A { + public int size = 1; +} + +// FILE: main.kt + +interface A { + val size: Int +} + +class C : B() { + override val size: Int get() = 1 +} + +fun foo() { + C().size +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.fir.kt b/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.fir.kt new file mode 100644 index 00000000000..8eba11c0bc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/finalCollectionSize.fir.kt @@ -0,0 +1,12 @@ +// JAVAC_EXPECTED_FILE +// FILE: A.java + +abstract public class A extends java.util.ArrayList { + public final int size() { return 0; } +} + +// FILE: main.kt + +class B : A() { + override val size: Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/j+k/flexibleNothing.fir.kt b/compiler/testData/diagnostics/tests/j+k/flexibleNothing.fir.kt new file mode 100644 index 00000000000..942b41dd65c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/flexibleNothing.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE + +// FILE: TestClass.java +import org.jetbrains.annotations.Nullable; +public class TestClass { + public T set(@Nullable String key, @Nullable T t) { + return t; + } +} + +// FILE: main.kt +fun run() { + val testClass = TestClass() + // inferred as `set()`, return type is Nothing! + testClass.set("test", null) + + // Should not be unreachable + run() +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.fir.kt new file mode 100644 index 00000000000..bab46b386aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: A.java + +public class A { + public A(E x, java.util.List y) {} +} + +// FILE: main.kt + +fun test(x: List, y: List) { + A("", x) checkType { _>() } + A("", y) checkType { _>() } + + A("", x) + A("", y) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.fir.kt new file mode 100644 index 00000000000..7dc1379b776 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: Outer.java + +public class Outer { + public class Inner { + public Inner(E x, java.util.List y, G z) {} + } +} + +// FILE: main.kt +fun test(x: List, y: List) { + Outer().Inner("", y, 1) checkType { _.Inner>() } + Outer().Inner("", y, 1) checkType { _.Inner>() } + + Outer().Inner("", x, 1) checkType { _.Inner>() } + Outer().Inner("", x, 1) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParameters.fir.kt new file mode 100644 index 00000000000..fd33141f842 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParameters.fir.kt @@ -0,0 +1,18 @@ +// FILE: A.java + +public class A { + public A(T x, java.util.List y) {} +} + +// FILE: main.kt + +fun test(x: List, y: List) { + A("", x) // inferred as Any! + A("", y) + + A("", x) + + A("", x) + A("", y) + A("", y) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.fir.kt new file mode 100644 index 00000000000..b2c873d053b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// FILE: A.java + +public class A { + public A(T x, Inv y) {} +} + +// FILE: main.kt + +class Inv + +fun test(x: Inv, y: Inv) { + A("", x) + A("", y) + + A("", x) + + A("", x) + A("", y) + A("", y) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/recursive.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/recursive.fir.kt new file mode 100644 index 00000000000..d6fae89aa4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/recursive.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// FILE: C.java + +// See KT-10410 +public class C { + public C(T t) { + } +} + +// FILE: main.kt + +fun foo() = C() diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/selfTypes.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/selfTypes.fir.kt new file mode 100644 index 00000000000..b63283686ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/selfTypes.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: R.java +public class R> { + public > R(F x) { + } +} + +// FILE: RImpl.java +public class RImpl extends R { + public RImpl() { + super(null); + } +} + +// FILE: main.kt +fun test() { + val x: R = R(RImpl()) + R(RImpl()) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCall.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCall.fir.kt new file mode 100644 index 00000000000..660e860c347 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCall.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// FILE: A.java + +public class A { + public A(E x, java.util.List y) {} +} + +// FILE: main.kt + +class B1(x: List) : A("", x) +class B2(x: List) : A("", x) + +class C : A { + constructor(x: List) : super("", x) + constructor(x: List, y: Int) : super("", x) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt new file mode 100644 index 00000000000..ce346602671 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// FILE: A.java + +public class A { + public A(E x, java.util.List y) {} +} + +// FILE: main.kt + +// TODO: It's effectively impossible to perform super call to such constructor +// if there is not enough information to infer corresponding arguments +// May be we could add some special syntax for such arguments +class B1(x: List) : A("", x) +class B2(x: List) : A("", x) + +class C : A { + constructor(x: List) : super("", x) + constructor(x: List, y: Int) : super("", x) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/withClassTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/withClassTypeParameters.fir.kt new file mode 100644 index 00000000000..4ff0ddd0b6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/withClassTypeParameters.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE +// FILE: A.java + +public class A { + public A(T x, java.util.List y) {} +} + +// FILE: main.kt + +fun test(x: List, y: List) { + var z: A = A("", x) // E inferred from expected type + z = A("", y) + + z = A("", x) + + z = A("", x) + z = A("", y) + z = A("", y) +} diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructorWithMultipleBounds.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructorWithMultipleBounds.fir.kt new file mode 100644 index 00000000000..dc79ff1dce8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructorWithMultipleBounds.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import java.io.Serializable; + +public class J { + public J(T t) {} +} + +// FILE: K.kt + +import java.io.Serializable + +fun cloneable(c: Cloneable) = J(c) + +fun serializable(s: Serializable) = J(s) + +fun both(t: T) where T : Cloneable, T : Serializable = J(t) diff --git a/compiler/testData/diagnostics/tests/j+k/inheritAbstractSamAdapter.fir.kt b/compiler/testData/diagnostics/tests/j+k/inheritAbstractSamAdapter.fir.kt new file mode 100644 index 00000000000..7ddceb7a976 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/inheritAbstractSamAdapter.fir.kt @@ -0,0 +1,18 @@ +// FILE: A.java +public interface A { + void foo(Runnable r); +} + +// FILE: B.java +public interface B extends A { + public void bar(Runnable r); +} + +// FILE: test.kt +class C: B { + override fun foo(r: Runnable?) { + } + + override fun bar(r: Runnable?) { + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/inheritanceStaticMethodFromInterface.fir.kt b/compiler/testData/diagnostics/tests/j+k/inheritanceStaticMethodFromInterface.fir.kt new file mode 100644 index 00000000000..f1bfbab902d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/inheritanceStaticMethodFromInterface.fir.kt @@ -0,0 +1,32 @@ +// FILE: I.java + +public interface I { + int a = 1; + static void foo() {} +} + +// FILE: C.java + +public class C implements I { + static int b = 1; + static void bar() {} +} + +// FILE: test.kt + +class K : C() + +fun main() { + I.a + I.foo() + + C.a + C.b + C.foo() + C.bar() + + K.a + K.b + K.foo() + K.bar() +} diff --git a/compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.fir.kt new file mode 100644 index 00000000000..22576156bde --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.fir.kt @@ -0,0 +1,32 @@ +// FILE: a/M.java +package a; + +public class M { + public class Inner { + + } + + public static class Nested { + + } + + private class PrInner { + + } + + private static class PrNested { + + } +} + +// FILE: b.kt +package b + +fun f() { + val c1: a.M.Inner + val c2: a.M.Nested + val c3: a.M.PrInner + val c4: a.M.PrNested + +} + diff --git a/compiler/testData/diagnostics/tests/j+k/invisiblePackagePrivateInheritedMember.fir.kt b/compiler/testData/diagnostics/tests/j+k/invisiblePackagePrivateInheritedMember.fir.kt new file mode 100644 index 00000000000..99645d5127a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/invisiblePackagePrivateInheritedMember.fir.kt @@ -0,0 +1,23 @@ +// FILE: a/M.java +package a; + +public class M { + int m; +} + +// FILE: b/F.java +package b; + +import a.M; + +public class F extends M { +} + +// FILE: c.kt +package c + +import b.F + +fun f() { + F().m +} diff --git a/compiler/testData/diagnostics/tests/j+k/javaStaticImport.fir.kt b/compiler/testData/diagnostics/tests/j+k/javaStaticImport.fir.kt new file mode 100644 index 00000000000..72f4f0629bd --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/javaStaticImport.fir.kt @@ -0,0 +1,37 @@ +// JAVAC_EXPECTED_FILE +// FILE: backend/asmutil/AsmUtil.java +package backend.asmutil; + +import org.jetbrains.annotations.NotNull; +import static frontend.JvmDeclarationOrigin.NO_ORIGIN; + +public class AsmUtil { + + @NotNull + public static String doSmth(String s) { + Object or = NO_ORIGIN; + return "OK"; + } +} + +// FILE: First.kt +package frontend +public class JvmDeclarationOrigin { + companion object { + public val NO_ORIGIN: JvmDeclarationOrigin = JvmDeclarationOrigin() + } +} + +// FILE: Second.kt +package backend + +import backend.asmutil.AsmUtil.doSmth + +open public class ECallable { + fun test() { + doSmth("") + } +} + +/* KT-5848 */ + diff --git a/compiler/testData/diagnostics/tests/j+k/kt1402.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt1402.fir.kt new file mode 100644 index 00000000000..40e71ec651e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt1402.fir.kt @@ -0,0 +1,26 @@ +// FILE: a/M.java +package a; + +public class M { + public static class Inner { + private int i; + public Inner(int i) { + this.i = i; + } + + public int getI() { + return i; + } + } +} + +// FILE: b.kt +package b + +import a.M.Inner + +fun foo() { + doSmth(Inner(87)) +} + +fun doSmth(b: Inner) = b diff --git a/compiler/testData/diagnostics/tests/j+k/kt1431.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt1431.fir.kt new file mode 100644 index 00000000000..971257ededc --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt1431.fir.kt @@ -0,0 +1,17 @@ +//FILE: a/C.java +// KT-1431 StackOverflowException in IDE when using JavaFX builders +package a; + +public class C> { + public static C create() { return null; } + public C foo() {return null;} +} + +//FILE: d.kt +package d + +import a.C + +fun test() { + C.create().foo() +} diff --git a/compiler/testData/diagnostics/tests/j+k/kt1730_implementCharSequence.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt1730_implementCharSequence.fir.kt new file mode 100644 index 00000000000..7efe604a0e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt1730_implementCharSequence.fir.kt @@ -0,0 +1,24 @@ +// KT-1730 Method which has been implemented by Java is recognized to be abstract. + +// FILE: C.java +public class C implements java.lang.CharSequence { + @Override + public int length() { + return 3; + } + @Override + public char charAt(int index) { + return 48; + } + @Override + public CharSequence subSequence(int start, int end) { + return "ab"; + } + @Override + public String toString() { + return "abc"; + } +} + +// FILE: T.kt +class T : C() diff --git a/compiler/testData/diagnostics/tests/j+k/kt2152.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2152.fir.kt new file mode 100644 index 00000000000..113ca5b4bb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2152.fir.kt @@ -0,0 +1,10 @@ +//FILE: Bbb.kt +open class Bbb + +//FILE: Ccc.java +public class Ccc extends Bbb { +} + +//FILE: Ddd.kt +import Ccc + diff --git a/compiler/testData/diagnostics/tests/j+k/kt2394.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2394.fir.kt new file mode 100644 index 00000000000..877f140f272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2394.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +//KT-2394 java.lang.Iterable should be visible as kotlin.Iterable +package d + +fun foo(iterable: Iterable, iterator: Iterator, comparable: Comparable) { + checkSubtype>(iterable) + checkSubtype>(iterator) + checkSubtype>(comparable) +} + +fun bar(c: Collection) { + checkSubtype>(c) + checkSubtype>(c.iterator()) +} diff --git a/compiler/testData/diagnostics/tests/j+k/kt2606.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2606.fir.kt new file mode 100644 index 00000000000..f362ec33d42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2606.fir.kt @@ -0,0 +1,11 @@ +//KT-2606 Filter java.util.* import +package n + +import java.util.* +import java.lang.annotation.* + +fun bar() : Iterator? { + val i : Iterable + val a : Annotation + return null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt2619.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2619.fir.kt new file mode 100644 index 00000000000..9613d6f02fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2619.fir.kt @@ -0,0 +1,15 @@ +//FILE: foo.kt +fun main() { + val c: Type + when (c) { + + } +} + + + +//FILE: Type.java +public enum Type { + TYPE, + NO_TYPE; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt2641.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2641.fir.kt new file mode 100644 index 00000000000..ea101ae4fc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2641.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +package a + +import java.util.Iterator +import java.lang.Comparable as Comp + +fun bar(any: Any): java.lang.Iterable? { + val a: java.lang.Comparable? = null + val b: Iterable + val c : Iterator? = null + + if (any is Iterator<*>) { + checkSubtype>(any) + } + any as Iterator<*> + return null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt2890.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt2890.fir.kt new file mode 100644 index 00000000000..c8d0830ef06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2890.fir.kt @@ -0,0 +1,20 @@ +//FILE:_03_collections/CollectionTest.java +package _03_collections; + +import java.util.List; + +public class CollectionTest { + public static void add(List ints) { + ints.add(5); + } +} + +//FILE:n.kt +package _03_collections + +import java.util.ArrayList + +fun test() { + val c = CollectionTest() + CollectionTest.add(ArrayList()) +} diff --git a/compiler/testData/diagnostics/tests/j+k/kt3307.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt3307.fir.kt new file mode 100644 index 00000000000..340842481bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt3307.fir.kt @@ -0,0 +1,21 @@ +// FILE: Bug.java + +public interface Bug { + RET save(); +} + +// FILE: SubBug.java + +public class SubBug implements Bug { + public SubBug save() { + return this; + } +} + +// FILE: Bug.kt + +fun TestBug() { + SubBug().save() // can resolve on subtype + val bug: Bug = SubBug() + bug.save() // can resolve on supertype +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt3311.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt3311.fir.kt new file mode 100644 index 00000000000..080e29b9e9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt3311.fir.kt @@ -0,0 +1,19 @@ +// FILE: Super.java +public class Super { + public boolean foo; + public boolean bar; + + public void setFoo(boolean foo) { + this.foo = foo; + } +} + +// FILE: b.kt +public class Sub: Super() { +} + +fun main() { + val x = Sub() + x.foo = true + x.bar = true +} diff --git a/compiler/testData/diagnostics/tests/j+k/kt6720_abstractProperty.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt6720_abstractProperty.fir.kt new file mode 100644 index 00000000000..988e5ec6549 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt6720_abstractProperty.fir.kt @@ -0,0 +1,18 @@ +// FILE: AC.kt + +interface A { + val a: Int +} + +// FILE: B.java + +public abstract class B implements A { +} + +// FILE: C.kt + +class C : B() + +fun main() { + C().a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt7523.fir.kt b/compiler/testData/diagnostics/tests/j+k/kt7523.fir.kt new file mode 100644 index 00000000000..64e8ab34bc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt7523.fir.kt @@ -0,0 +1,14 @@ +// FILE: A.java +public interface A, S extends A> {} + +// FILE: C.java +public class C +{ + public , S extends A> void f(A x){} +} + +// FILE: main.kt +fun foo() { + // TODO: uncomment when KT-9597 is fixed + // C().f(object : A<*, *> {}) +} diff --git a/compiler/testData/diagnostics/tests/j+k/matchers.fir.kt b/compiler/testData/diagnostics/tests/j+k/matchers.fir.kt new file mode 100644 index 00000000000..4c2bcb72eef --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/matchers.fir.kt @@ -0,0 +1,18 @@ +// FILE: Assert.java + +public class Assert { + public static void assertThat(T actual, Matcher matcher) { + } +} + +// FILE: Matcher.java +public class Matcher { + public static Matcher> hasItem(T item) { + return null; + } +} + +// FILE: main.kt +fun test(x: List) { + Assert.assertThat(x, Matcher.hasItem("abc")) +} diff --git a/compiler/testData/diagnostics/tests/j+k/mutableIterator.fir.kt b/compiler/testData/diagnostics/tests/j+k/mutableIterator.fir.kt new file mode 100644 index 00000000000..9f24f78c48c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/mutableIterator.fir.kt @@ -0,0 +1,29 @@ +//FILE:a/JC.java +package a; + +import java.util.Iterator; + +public interface JC { + public Iterator getIterator(); + + public void setIterator(Iterator iterator); + + public Iterable getIterable(); + + public void setIterable(Iterable iterable); +} + +//FILE:n.kt +package n + +import a.JC + +fun foo(c: JC, iterator: Iterator, iterable: Iterable) { + val mutableIterator: MutableIterator? = c.getIterator() + c.setIterator(mutableIterator) + c.setIterator(iterator) + + val mutableIterable: MutableIterable? = c.getIterable() + c.setIterable(mutableIterable) + c.setIterable(iterable) +} diff --git a/compiler/testData/diagnostics/tests/j+k/nullForOptionalOrElse.fir.kt b/compiler/testData/diagnostics/tests/j+k/nullForOptionalOrElse.fir.kt new file mode 100644 index 00000000000..b3ac1902278 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/nullForOptionalOrElse.fir.kt @@ -0,0 +1,9 @@ +// FULL_JDK + +import java.util.* +import java.util.stream.Stream + +fun Stream?.getIfSingle() = + this?.map { Optional.ofNullable(it) } + ?.reduce(Optional.empty()) { _, _ -> Optional.empty() } + ?.orElse(null) // <<---- should not be an error diff --git a/compiler/testData/diagnostics/tests/j+k/overrideRawType.fir.kt b/compiler/testData/diagnostics/tests/j+k/overrideRawType.fir.kt new file mode 100644 index 00000000000..4772e9a77c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/overrideRawType.fir.kt @@ -0,0 +1,15 @@ +//FILE: Foo.java +public class Foo { +} + +//FILE: Bar.java +public interface Bar { + void f(Foo f); +} + +//FILE: a.kt +class BarImpl: Bar { + override fun f(f: Foo<*>?) { + throw UnsupportedOperationException() + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/overrideWithSamAndTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/overrideWithSamAndTypeParameter.fir.kt new file mode 100644 index 00000000000..8ce4c73cbd9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/overrideWithSamAndTypeParameter.fir.kt @@ -0,0 +1,22 @@ +// FILE: MyFunc.java + +public interface MyFunc { + String apply(String x); +} + +// FILE: A.java +public interface A { + K foo(K key, MyFunc f); +} + +// FILE: B.java +public class B implements A { + @Override + public E foo(E key, MyFunc f) {return null;} +} + +// FILE: main.kt + +fun main() { + B().foo("") { "" } +} diff --git a/compiler/testData/diagnostics/tests/j+k/packagePrivateClassStaticMember.fir.kt b/compiler/testData/diagnostics/tests/j+k/packagePrivateClassStaticMember.fir.kt new file mode 100644 index 00000000000..b93b076994c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/packagePrivateClassStaticMember.fir.kt @@ -0,0 +1,17 @@ +// KT-4021 Java's Package visibilty does not work for static methods + +// FILE: foo/Bar.java + +package foo; + +class Bar { + static void baz() {} +} + +// FILE: main.kt + +package foo + +fun main() { + Bar.baz() +} diff --git a/compiler/testData/diagnostics/tests/j+k/packageVisibility.fir.kt b/compiler/testData/diagnostics/tests/j+k/packageVisibility.fir.kt new file mode 100644 index 00000000000..ff2aed7313b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/packageVisibility.fir.kt @@ -0,0 +1,44 @@ +//FILE: a/MyJavaClass.java +package a; + +class MyJavaClass { + static int staticMethod() { + return 1; + } + + static class NestedClass { + static int staticMethodOfNested() { + return 1; + } + } +} + +//FILE:a.kt +package a + +val mc = MyJavaClass() +val x = MyJavaClass.staticMethod() +val y = MyJavaClass.NestedClass.staticMethodOfNested() +val z = MyJavaClass.NestedClass() + +//FILE: b.kt +package b + +import a.MyJavaClass + +val mc1 = MyJavaClass() + +val x = MyJavaClass.staticMethod() +val y = MyJavaClass.NestedClass.staticMethodOfNested() +val z = MyJavaClass.NestedClass() + +//FILE: c.kt +package a.c + +import a.MyJavaClass + +val mc1 = MyJavaClass() + +val x = MyJavaClass.staticMethod() +val y = MyJavaClass.NestedClass.staticMethodOfNested() +val z = MyJavaClass.NestedClass() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.fir.kt new file mode 100644 index 00000000000..8adec367303 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/kt11140.fir.kt @@ -0,0 +1,24 @@ +// JAVAC_EXPECTED_FILE +// FILE: B.java +public interface B { + double put(int x, double y); + T2 put(T1 x, T2 y); +} +// FILE: A.java +import java.util.HashMap; + +public class A extends HashMap implements B { + public double put(int x, double y) { + return 1.0; + } + + @Override + public Double put(Integer key, Double value) { + return super.put(key, value); + } +} +// FILE: main.kt +fun test(){ + val o = A() + o.put(1, 2.0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt new file mode 100644 index 00000000000..1a501bd20ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt @@ -0,0 +1,22 @@ +// FILE: A.java +import org.jetbrains.annotations.*; + +public class A { + public void foo(int x) {} + public void bar(@NotNull Double x) {} +} + +// FILE: B.java +import org.jetbrains.annotations.*; +public class B extends A { + public void foo(@NotNull Integer x) {} + public void bar(double x) {} +} + +// FILE: main.kt + +fun foo(b: B) { + // See KT-9182 + b.foo(1) + b.bar(2.0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt new file mode 100644 index 00000000000..dad78e433d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt @@ -0,0 +1,113 @@ +// FILE: AbstractSpecializedMap.java +public abstract class AbstractSpecializedMap implements java.util.Map { + public abstract double put(int x, double y); + public abstract double remove(int k); + public abstract double get(int k); + + public abstract boolean containsKey(int k); + public boolean containsKey(Object x) { + return false; + } + + public abstract boolean containsValue(double v); + public boolean containsValue(Object x) { + return false; + } +} + +// FILE: SpecializedMap.java +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public class SpecializedMap extends AbstractSpecializedMap { + public double put(int x, double y) { + return 123.0; + } + + @Override + public Double get(Object key) { + return null; + } + + @Override + public Double put(Integer key, Double value) { + return null; + } + + public double remove(int k) { + return 456.0; + } + + + public Double remove(Object ok) { + return null; + } + + + public double get(int k) { + return 789.0; + } + + public boolean containsKey(int k) { + return true; + } + + public boolean containsValue(double v) { + return true; + } + + @Override + public void putAll(Map m) { + } + + @Override + public void clear() { + + } + + @NotNull + @Override + public Set keySet() { + return null; + } + + @NotNull + @Override + public Collection values() { + return null; + } + + @NotNull + @Override + public Set> entrySet() { + return null; + } + + @Override + public int size() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } +} + +// FILE: main.kt +fun foo(x: SpecializedMap) { + x.containsKey(1) + x.containsKey(null) + + x.get(2) + x.get(null) + + x.remove(3) + x.remove(null) + + x.put(4, 5.0) + x.put(4, null) +} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverridesWithInlineClass/inlineClassErasedToPrimitiveInt.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverridesWithInlineClass/inlineClassErasedToPrimitiveInt.fir.kt new file mode 100644 index 00000000000..c4ff078edd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverridesWithInlineClass/inlineClassErasedToPrimitiveInt.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +InlineClasses +// FILE: kt1.kt +package kt + +inline class Z(val value: Int) + +interface IFoo { + fun foo(): T +} + +open class KFooZ : IFoo { + override fun foo(): Z = Z(42) +} + +// FILE: j/J.java +package j; + +import kt.Z; +import kt.KFooZ; + +public class J extends KFooZ { +} + +// FILE: kt2.kt +package kt + +import j.J + +fun jfoo(x: J) = x.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.fir.kt b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.fir.kt new file mode 100644 index 00000000000..56516cd67e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.fir.kt @@ -0,0 +1,19 @@ +// FILE: B.java + +public abstract class B implements A { + private int size = 1; +} + +// FILE: main.kt + +interface A { + val size: Int +} + +class C : B() { + override val size: Int get() = 1 +} + +fun foo() { + C().size +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt b/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt new file mode 100644 index 00000000000..d0a40b6be97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt @@ -0,0 +1,18 @@ +// KT-4149 static members of Java private nested class are accessible from Kotlin + +// FILE: javaPackage/Foo.java + +package javaPackage; + +public class Foo { + private static class Bar { + public static void doSmth() { + } + } +} + +// FILE: 1.kt + +fun main() { + javaPackage.Foo.Bar.doSmth() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/properties/interface.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/interface.fir.kt new file mode 100644 index 00000000000..7c3c81e57f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/interface.fir.kt @@ -0,0 +1,32 @@ +// FILE: A.java + +public interface A extends B { + public int getFoo(); + public void setFoo(int x); +} + +// FILE: BImpl.java + +public class BImpl implements B { + public int getFoo() {} + public void setFoo(int x) {} +} + +// FILE: main.kt + +interface B { + var foo: Int +} + +interface C1 : A { + override var foo: Int +} + +class D : C1, BImpl() + +fun foo() { + BImpl().foo = BImpl().foo + 1 + D().foo = D().foo + 2 +} + + diff --git a/compiler/testData/diagnostics/tests/j+k/properties/isName.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/isName.fir.kt new file mode 100644 index 00000000000..3e86adc7ca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/isName.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java + +public class A extends B { + public int isFoo() { return 0; } + public void setFoo(int x) {} +} + +// FILE: F.java + +public class F extends B { + public final int isFoo() { return 0; } + public final void setFoo(int x) {} +} + +// FILE: main.kt + +open class B { + open var isFoo: Int = 1 +} + +class C1 : A() { + override var isFoo: Int = 2 +} + +class C2 : F() { + override var isFoo: Int = 3 +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/val.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/val.fir.kt new file mode 100644 index 00000000000..63aa0476c5d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/val.fir.kt @@ -0,0 +1,25 @@ +// FILE: A.java + +public class A extends B { + public int getFoo() { return 0; } +} + +// FILE: F.java + +public class F extends B { + public final int getFoo() { return 0; } +} + +// FILE: main.kt + +open class B { + open val foo: Int = 1 +} + +class C1 : A() { + override val foo: Int = 2 +} + +class C2 : F() { + override val foo: Int = 3 +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/var.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/var.fir.kt new file mode 100644 index 00000000000..41e5c92ff12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/var.fir.kt @@ -0,0 +1,42 @@ +// FILE: A.java + +public class A extends B { + public int getFoo() { return 0; } + public void setFoo(int x) {} +} + +// FILE: F.java + +public class F extends B { + public final int getFoo() { return 0; } + public final void setFoo(int x) {} +} + +// FILE: ConflictingModality.java + +public class ConflictingModality extends B { + public final int getFoo() { return 0; } + public abstract void setFoo(int x) {} +} + +// FILE: ConflictingVisibility.java + +public class ConflictingVisibility extends B { + public int getFoo() { return 0; } + protected void setFoo(int x) {} +} + +// FILE: main.kt + +open class B { + // check that final is not overridden + open protected var foo: Int = 1 +} + +class C1 : A() { + override var foo: Int = 2 +} + +class C2 : F() { + override var foo: Int = 3 +} diff --git a/compiler/testData/diagnostics/tests/j+k/protectedStaticSamePackage.fir.kt b/compiler/testData/diagnostics/tests/j+k/protectedStaticSamePackage.fir.kt new file mode 100644 index 00000000000..e51d7bc5689 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/protectedStaticSamePackage.fir.kt @@ -0,0 +1,20 @@ +// FILE: test/JavaClass.java + +package test; + +public class JavaClass { + protected static int field; + + protected static String method() { + return ""; + } +} + +// FILE: test.kt + +package test + +fun test() { + JavaClass.field + JavaClass.method() +} diff --git a/compiler/testData/diagnostics/tests/j+k/recursionWithJavaSyntheticProperty.fir.kt b/compiler/testData/diagnostics/tests/j+k/recursionWithJavaSyntheticProperty.fir.kt new file mode 100644 index 00000000000..875fa382fa8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/recursionWithJavaSyntheticProperty.fir.kt @@ -0,0 +1,12 @@ +// FILE: X.java + +public class X { + int getFoo() {return 3;} +} + +// FILE: Usage.kt + +class A : X() { + // TODO: DEBUG_INFO_MISSING_UNRESOLVED indicates a bug here + override fun getFoo() = foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.fir.kt b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.fir.kt new file mode 100644 index 00000000000..75a5c2333d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound.fir.kt @@ -0,0 +1,13 @@ +// FILE: Bad.java + +public class Bad {} + +// FILE: X.java + +public class X { + Bad foo() {return null;} +} + +// FILE: Usage.kt + +fun foo(p: X) = p.foo() diff --git a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound2.fir.kt b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound2.fir.kt new file mode 100644 index 00000000000..dfc3e1205f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound2.fir.kt @@ -0,0 +1,8 @@ +// FILE: XYZ.java +public interface XYZ { + XYZ foo() {} +} + +// FILE: main.kt + +fun main(xyz: XYZ<*>) = xyz.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound3.fir.kt b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound3.fir.kt new file mode 100644 index 00000000000..282814ecf53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/recursiveRawUpperBound3.fir.kt @@ -0,0 +1,8 @@ +// FILE: XYZ.java +public interface XYZ { + XYZ foo() {} +} + +// FILE: main.kt + +fun main(xyz: XYZ<*, *, *>) = xyz.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.fir.kt new file mode 100644 index 00000000000..8b236b356e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java +import org.jetbrains.annotations.*; + +public interface J { + @NotNull + String foo(@Nullable String x); +} + +// FILE: J2.java +import org.jetbrains.annotations.Nullable; + +public interface J2 extends J { + String foo(String x); +} + +// FILE: main.kt +fun main() { + J { s: String -> s} // should be prohibited, because SAM value parameter has nullable type + J { "" + it.length } + J { null } + J { it?.length?.toString() } + + J2 { s: String -> s} + J2 { "" + it.length } + J2 { null } + J2 { it?.length?.toString() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/sam/fakeOverrideFunctionForStaticSam.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/fakeOverrideFunctionForStaticSam.fir.kt new file mode 100644 index 00000000000..88ae849b8fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/fakeOverrideFunctionForStaticSam.fir.kt @@ -0,0 +1,20 @@ +// FILE: BehaviorSubject.java +public class BehaviorSubject extends Observable { +} + +// FILE: Observable.java + +public class Observable { + public static Observable create(Observable.OnSubscribe f) { + return null; + } + public interface OnSubscribe { + void call(T t); + } +} + +// FILE: 1.kt +fun main() { + BehaviorSubject.create(null) + BehaviorSubject.create { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/inheritedStaticSam.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/inheritedStaticSam.fir.kt new file mode 100644 index 00000000000..0779d3ced95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/inheritedStaticSam.fir.kt @@ -0,0 +1,13 @@ +// FILE: Statics.java + +public class Statics { + public static void foo(Runnable r) {} +} + +// FILE: test.kt + +class A : Statics() { + fun test() { + foo {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.fir.kt new file mode 100644 index 00000000000..f45fd6988e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.fir.kt @@ -0,0 +1,21 @@ +// JAVAC_EXPECTED_FILE +// FILE: foo/A.java +package foo; + +public class A { + static void f(B b) { + b.g(); + } + + public interface B { + void g(); + } +} + +// FILE: bar/sample.kt + +package bar + +fun main() { + foo.A.f {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.fir.kt new file mode 100644 index 00000000000..6457136dfdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.fir.kt @@ -0,0 +1,28 @@ +// FILE: MyFuture.java + +public interface MyFuture { + MyFuture addListener(MyListener> listener); +} + +// FILE: MyListener.java + +public interface MyListener> { + void operationComplete(F future) throws Exception; +} + +// FILE: test.kt + +typealias Handler = (cause: Throwable?) -> Unit + +fun MyFuture.setup() { + addListener(ListenerImpl>()) + addListener { } +} + +class ListenerImpl> : MyListener, Handler { + override fun operationComplete(future: F) { + } + + override fun invoke(cause: Throwable?) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.fir.kt new file mode 100644 index 00000000000..4b32b73471d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.fir.kt @@ -0,0 +1,17 @@ +// FILE: FormFieldValidatorPresenterTest.java +public class FormFieldValidatorPresenterTest { + + public void setValidationListenerTest(ValidationListenerTest validationListener) { + } + + public interface ValidationListenerTest { + void onValidityChanged(boolean valid); + } +} +// FILE: main.kt +fun

> setValidationListener( + presenter: P, + validationListener: (Boolean) -> Unit +) { + presenter.setValidationListenerTest(validationListener) // Error: Type mismatch: inferred type is (Boolean) -> Unit but FormFieldValidatorPresenterTest.ValidationListenerTest! was expected +} diff --git a/compiler/testData/diagnostics/tests/j+k/sam/staticSamFromImportWithStar.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/staticSamFromImportWithStar.fir.kt new file mode 100644 index 00000000000..b299377a168 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/staticSamFromImportWithStar.fir.kt @@ -0,0 +1,17 @@ +// FILE: a/Statics.java + +package a; + +public class Statics { + public static void foo(Runnable r) {} +} + +// FILE: test.kt + +package b + +import a.Statics.* + +fun test() { + foo {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/staticSamWithExplicitImport.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/staticSamWithExplicitImport.fir.kt new file mode 100644 index 00000000000..8c551eed7b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/staticSamWithExplicitImport.fir.kt @@ -0,0 +1,17 @@ +// FILE: a/Statics.java + +package a; + +public class Statics { + public static void foo(Runnable r) {} +} + +// FILE: test.kt + +package b; + +import a.Statics.foo + +fun test() { + foo {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.fir.kt new file mode 100644 index 00000000000..544d981203a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER +// FILE: A.java +public class A { + public void foo(K key, BiFunction remappingFunction) { + + } +} + +// FILE: BiFunction.java +public interface BiFunction { + R apply(T t, U u); +} + +// FILE: main.kt +fun main() { + val a = A() + a.foo(2, BiFunction { k, v -> null }) + a.foo(2) { k, v -> null } // See KT-12144 +} diff --git a/compiler/testData/diagnostics/tests/j+k/sam/withDefaultMethods.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/withDefaultMethods.fir.kt new file mode 100644 index 00000000000..acc211a1064 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/withDefaultMethods.fir.kt @@ -0,0 +1,22 @@ +// FILE: ALambda.java + +public interface ALambda { + ALambda curried(); + + ALambda tupled(); +} + +// FILE: ACheckedFunction0.java + +public interface ACheckedFunction0 extends ALambda { + + Integer apply(); + + default ALambda curried() { return null; } + default ALambda tupled() { return null; } +} + +// FILE: main.kt +fun test() { + ACheckedFunction0 { 2 } // error: Interface ACheckedFunction0 does not have constructors +} diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInReturnType.fir.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInReturnType.fir.kt new file mode 100644 index 00000000000..1c2ee9979c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInReturnType.fir.kt @@ -0,0 +1,53 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: EventListener.java +public interface EventListener { + E handle(String x); +} + +// FILE: A.java +public class A { + public void foo(EventListener l) { + } + + public static void bar(EventListener l) { + } + + public static void baz(EventListener l) { + } +} + +// FILE: main.kt +fun main() { + A().foo { + x -> x.hashCode() + } + + A.bar { + x -> x.hashCode() + } + + + // baz + A.baz { + x -> x.toString() // OK + } + + A.baz { + x -> x.hashCode() + } + + val block: (String) -> Any? = { + x -> x.hashCode() + } + + A().foo(block) + A.bar(block) + + val block2: (String) -> CharSequence? = { + x -> x.toString() + } + + A.baz(block) + A.baz(block2) +} diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInValueParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInValueParameter.fir.kt new file mode 100644 index 00000000000..1da5559f790 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericInValueParameter.fir.kt @@ -0,0 +1,32 @@ +// !CHECK_TYPE +// FILE: EventListener.java +public interface EventListener { + void handle(E e); +} + +// FILE: A.java +public class A { + public void foo(EventListener l) { + } + + public static void bar(EventListener l) { + } + + public static void baz(EventListener l) { + } +} + +// FILE: main.kt +fun main() { + A().foo { + x -> x checkType { _() } + } + + A.bar { + x -> x checkType { _() } + } + + A.baz { + x -> x checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericSuperWildcard.fir.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericSuperWildcard.fir.kt new file mode 100644 index 00000000000..df6128944c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/genericSuperWildcard.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE +// FILE: EventListener.java +public interface EventListener { + void handle(E e); +} + +// FILE: A.java +public class A { + public void foo(EventListener l) { + } + + public static void bar(EventListener l) { + } +} + +// FILE: main.kt +fun main() { + A().foo { + x -> x checkType { _() } + } + + A.bar { + x -> x checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.fir.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.fir.kt new file mode 100644 index 00000000000..bff8339f4bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: Function.java +public interface Function> { + E handle(F f); +} + +// FILE: A.java +public class A { + public void foo(Function l) { + } + + public static void bar(Function l) { + } +} + +// FILE: main.kt +fun main() { + A().foo { + x -> + "" + } + + A.bar { + x -> + "" + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/starProjectionComplexUpperBound.fir.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/starProjectionComplexUpperBound.fir.kt new file mode 100644 index 00000000000..648e6875297 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/starProjectionComplexUpperBound.fir.kt @@ -0,0 +1,33 @@ +// !CHECK_TYPE +// FILE: Function.java +public interface Function, F extends CharSequence> { + F handle(E e); +} + +// FILE: A.java +public class A { + public void foo(Function l) { + } + + public static void bar(Function l) { + } +} + +// FILE: main.kt +fun main() { + A().foo { + x -> + x checkType { _?>() } + "" + } + + A.bar { + x -> + x checkType { _>() } + "" + } + + val block: (Map) -> CharSequence = { x -> x.toString() } + A().foo(block) + A.bar(block) +} diff --git a/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt new file mode 100644 index 00000000000..f5a5200958b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt @@ -0,0 +1,23 @@ +// FILE: j/OnSubscribe.java +package j; + +public interface OnSubscribe { + void f(); +} + +// FILE: j/Observable.java +package j; + +public class Observable { + + protected Observable(OnSubscribe f) { + } +} + +// FILE: Kotlin.kt + +import j.* + +class K : Observable({}) + +class J : Observable(null) diff --git a/compiler/testData/diagnostics/tests/j+k/samWithConsumer.fir.kt b/compiler/testData/diagnostics/tests/j+k/samWithConsumer.fir.kt new file mode 100644 index 00000000000..6480f97c171 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/samWithConsumer.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// FULL_JDK +// FILE: A.java +import java.util.function.Consumer; + +public class A { + void test(Consumer consumer) {} +} + +// FILE: 1.kt +import java.util.function.Consumer + +fun test(a: A) { + a.test (Consumer { + it checkType { _() } + it.toInt() + }) + + a.test { + it checkType { _() } + it.toInt() + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/selectMoreSpecific.fir.kt b/compiler/testData/diagnostics/tests/j+k/selectMoreSpecific.fir.kt new file mode 100644 index 00000000000..dec7050b358 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/selectMoreSpecific.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE +// FILE: A.java +public class A { + public String foo() {} + public CharSequence foo() {} + + public static String bar() {} + public static CharSequence bar() {} +} + +// FILE: main.kt + +fun foo(a: A) { + a.foo() checkType { _() } + A.bar() checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/serializable.fir.kt b/compiler/testData/diagnostics/tests/j+k/serializable.fir.kt new file mode 100644 index 00000000000..f326daf6c9d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/serializable.fir.kt @@ -0,0 +1,60 @@ +// FILE: B.kt + +import aa.A.use +import aa.A.useList + +fun testPrimitives(b: Byte, ss: Short, i: Int, l: Long, d: Double, s: String, f: Float, bool: Boolean) { + use(b) + use(ss) + use(i) + use(l) + use(s) + use(f) + use(d) + use(bool) +} + +class N +class S: java.io.Serializable + +fun testArrays(ia: IntArray, ai: Array, an: Array, a: Array) { + use(ia) + use(ai) + use(an) + use(a) +} + +fun testLiterals() { + use(1) + use(1.0) + use(11111111111111) + use("Asdsd") + use(true) +} + +fun testNotSerializable(l: List) { + use(l) + use(N()) +} + +enum class C { + E, E2 +} + +fun testEnums(a: Enum<*>) { + use(C.E) + use(C.E2) + use(a) +} + +fun testLists(a: List) { + useList(a) +} + +// FILE: aa/A.java +package aa; + +public class A { + public static void use(java.io.Serializable s) { } + public static void useList(java.util.List s) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/shadowingPrimitiveStaticField.fir.kt b/compiler/testData/diagnostics/tests/j+k/shadowingPrimitiveStaticField.fir.kt new file mode 100644 index 00000000000..54cb9615d6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/shadowingPrimitiveStaticField.fir.kt @@ -0,0 +1,24 @@ +// FILE: B.kt + +import aa.B + +fun use() { + // checking that CONST is of platform type + B.CONST = null + B.CONST?.length + B.CONST.length +} + +// FILE: aa/A.java +package aa; + +public class A { + public static int CONST = 3; +} + +// FILE: aa/B.java +package aa; + +public class B extends A { + public static String CONST = null; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultEnum.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultEnum.fir.kt new file mode 100644 index 00000000000..10f4ab7708b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultEnum.fir.kt @@ -0,0 +1,67 @@ +// FILE: Signs.java +// ANDROID_ANNOTATIONS + +public enum Signs { + HELLO, + WORLD; + + public static final Signs X; + public static final class NOT_ENTRY_EITHER {} +} + +// FILE: Mixed.java +public enum Mixed { + NOT_ENTRY_EITHER; + + public static final class NOT_ENTRY_EITHER {} +} + +// FILE: B.kt +enum class B { + X, + Y; +} + +// FILE: A.java +import kotlin.annotations.jvm.internal.*; + +class A { + public Signs a(@DefaultValue("HELLO") Signs arg) { + return arg; + } + + public B b(@DefaultValue("Y") B arg) { + return arg; + } + + public void foooo(@DefaultValue("ok") B arg) { + } + + public Signs bar(@DefaultValue("X") Signs arg) { + return arg; + } + + public Signs baz(@DefaultValue("NOT_ENTRY_EITHER") Signs arg) { + return arg; + } + + public Mixed bam(@DefaultValue("NOT_ENTRY_EITHER") Mixed arg) { + return arg; + } + +} + +// FILE: test.kt +fun test(){ + val a = A() + a.a() + a.a(Signs.HELLO) + a.b() + a.b(B.X) + a.foooo() + a.foooo(B.Y) + a.bar() + a.baz() + + a.bam() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultLongLiteral.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultLongLiteral.fir.kt new file mode 100644 index 00000000000..78bf0a516ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultLongLiteral.fir.kt @@ -0,0 +1,49 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +public class A { + public void first(@DefaultValue("0x1F") Long value) { + } + + public void second(@DefaultValue("0X1F") Long value) { + } + + public void third(@DefaultValue("0b1010") Long value) { + } + + public void fourth(@DefaultValue("0B1010") Long value) { + } +} + +// FILE: B.java +import kotlin.annotations.jvm.internal.*; + +public class B { + public void first(@DefaultValue("0x") Long value) { + } + + public void second(@DefaultValue("0xZZ") Long value) { + } + + public void third(@DefaultValue("0b") Long value) { + } + + public void fourth(@DefaultValue("0B1234") Long value) { + } +} + +// FILE: test.kt +fun main(a: A, b: B) { + a.first() + a.second() + a.third() + a.fourth() + + b.first() + b.second() + b.third() + b.fourth() +} + diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNull.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNull.fir.kt new file mode 100644 index 00000000000..b492eaa5f6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNull.fir.kt @@ -0,0 +1,31 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +public class A { + public void foo(@DefaultNull Integer x) {} + public void bar(@DefaultNull int x) {} +} + +// FILE: B.java +import kotlin.annotations.jvm.internal.*; + +public class B { + public void foo(@DefaultNull T t) { } +} + +// FILE: test.kt +fun test(a: A, first: B, second: B) { + a.foo() + a.foo(0) + + a.bar() + a.bar(0) + + first.foo() + first.foo(5) + + second.foo() + second.foo(5) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNullAndParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNullAndParameter.fir.kt new file mode 100644 index 00000000000..444e281e4cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultNullAndParameter.fir.kt @@ -0,0 +1,57 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +public class A { + public void foo(@DefaultNull Integer i) {} + + public void bar(@DefaultNull Integer a) {} + + public void bam(@DefaultNull Integer a) {} + + public void baz(@DefaultValue("42") Integer a) {} +} + +// FILE: AInt.java +import kotlin.annotations.jvm.internal.*; + +public interface AInt { + public void foo(@DefaultValue("42") Integer i) {} + public void bar(@DefaultNull Integer a) {} +} + +// FILE: B.java +import kotlin.annotations.jvm.internal.*; + +public class B extends A { + public void foo(Integer i) {} + + public void bar(@DefaultValue("42") Integer a) {} + + public void bam(@DefaultNull @DefaultValue("42") Integer a) {} +} + +// FILE: C.java +public class C extends A implements AInt { +} + +// FILE: test.kt + +fun test(b: B, c: C) { + b.foo() + b.foo(5) + b.bar() + b.bar(5) + b.bam() + b.bam(5) + + c.foo() + c.foo(5) + c.bar() + c.bar(5) + c.bam() + c.bam(5) + c.baz() + c.baz(42) +} diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultParameter.fir.kt new file mode 100644 index 00000000000..230257989ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/defaultParameter.fir.kt @@ -0,0 +1,45 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +class A { + public void first(@DefaultValue("hello") String value) { + } + + public void second(@DefaultValue("first") String a, @DefaultValue("second") String b) { + } + + public void third(@DefaultValue("first") String a, String b) { + } + + public void fourth(String first, @DefaultValue("second") String second) { + } + + public void wrong(@DefaultValue("hello") Integer i) { + } +} + + +// FILE: test.kt +fun main() { + val a = A() + + a.first() + a.first("arg") + + a.second() + a.second("arg") + a.second("first", "second") + + a.third("OK") + a.third("first", "second") + + a.fourth() + a.fourth("first") + a.fourth("first", "second") + + a.wrong() + a.wrong(42) +} + diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/emptyParameterName.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/emptyParameterName.fir.kt new file mode 100644 index 00000000000..f9718064622 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/emptyParameterName.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +class A { + public void emptyName(@ParameterName("") String first, @ParameterName("ok") int second) { + } + + public void missingName(@ParameterName() String first) { + } + + public void numberName(@ParameterName(42) String first) { + } +} + +// FILE: test.kt +fun main() { + val test = A() + test.emptyName("first", 42) + test.emptyName("first", ok = 42) + + test.missingName(`first` = "arg") + test.missingName("arg") + + test.numberName("first") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/notNullVarargOverride.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/notNullVarargOverride.fir.kt new file mode 100644 index 00000000000..338461c1433 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/notNullVarargOverride.fir.kt @@ -0,0 +1,22 @@ +// FILE: BaseClass.java +import org.jetbrains.annotations.NotNull; + +public class BaseClass { + public void loadCache(@NotNull Object... args) {} +} + +// FILE: main.kt + +class A : BaseClass() { + // org.jetbrains.annotations.NotNull has @Target PARAMETER, so it doesn't affect elements type + override fun loadCache(vararg args: Any?) { + super.loadCache(*args) + } +} + +class B : BaseClass() { + // org.jetbrains.annotations.NotNull has @Target PARAMETER, so it doesn't affect elements type + override fun loadCache(vararg args: Any) { + super.loadCache(*args) + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/nullableVarargOverride.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/nullableVarargOverride.fir.kt new file mode 100644 index 00000000000..6d130cdebff --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/nullableVarargOverride.fir.kt @@ -0,0 +1,22 @@ +// FILE: BaseClass.java +import org.jetbrains.annotations.Nullable; + +public class BaseClass { + public void loadCache(@Nullable Object... args) {} +} + +// FILE: main.kt + +class A : BaseClass() { + // org.jetbrains.annotations.Nullable has @Target PARAMETER, so it doesn't affect elements type + override fun loadCache(vararg args: Any?) { + super.loadCache(*args) + } +} + +class B : BaseClass() { + // org.jetbrains.annotations.Nullable has @Target PARAMETER, so it doesn't affect elements type + override fun loadCache(vararg args: Any) { + super.loadCache(*args) + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesDefaultValue.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesDefaultValue.fir.kt new file mode 100644 index 00000000000..a5f9e3e5c1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesDefaultValue.fir.kt @@ -0,0 +1,100 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +class A { + public void first(@DefaultValue("42") int arg) { + } +} + +// FILE: B.java +class B { + public void first(int arg) { + } +} + +// FILE: C.java +import kotlin.annotations.jvm.internal.*; + +class C extends A { + public void first(@DefaultValue("73") int arg) { + } +} + +// FILE: D.java +import kotlin.internal.*; + +class D extends B { + public void first(@DefaultValue("37") int arg) { + } +} + +// FILE: E.java +import kotlin.annotations.jvm.internal.*; + +class E extends A { + public void first(int arg) { + } +} + +// FILE: F.kt +open class F { + open fun foo(x: String = "0") { + } +} + +// FILE: G.java +class G extends F { + public void foo(String y) { + } +} + +// FILE: K.java +import kotlin.annotations.jvm.internal.*; + +public interface K { + public void foo(@DefaultValue("1") String x) { } +} + +// FILE: L.java +import kotlin.annotations.jvm.internal.*; + +public interface L { + public void foo(@DefaultValue("1") String x) { } +} + +// FILE: M.java +public class M implements K, L { + public void foo(String x) { + } +} + +// FILE: main.kt +fun main() { + val a = A() + val c = C() + val d = D() + val e = E() + + val ac: A = C() + val bd: B = D() + + a.first() + c.first() + ac.first() + + d.first() + bd.first() + + e.first() + + val g = G() + g.foo() + g.foo("ok") + + val m = M() + m.foo() + +} + diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesParameterName.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesParameterName.fir.kt new file mode 100644 index 00000000000..3c46406ebaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/overridesParameterName.fir.kt @@ -0,0 +1,98 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +class A { + public void call(@ParameterName("foo") String arg) { + } +} + +// FILE: B.java +import kotlin.annotations.jvm.internal.*; + +class B extends A { + public void call(@ParameterName("bar") String arg) { + } +} + +// FILE: C.java + +class C extends A { + public void call(String arg) { + } +} + +// FILE: D.kt +open class D { + open fun call(foo: String) { + } +} + +// FILE: E.java +import kotlin.annotations.jvm.internal.*; + +class E extends D { + public void call(@ParameterName("baz") String bar) { + } +} + +// FILE: F.java +class F extends D { + public void call(String baaam) { + } +} + + +// FILE: G.java +import kotlin.annotations.jvm.internal.*; + +class G { + public void foo(String bar, @ParameterName("foo") String baz) { + } +} + +// FILE: H.java +class H extends G { + public void foo(String baz, String bam) { + } +} + +// FILE: test.kt +fun main() { + val a = A() + val b = B() + val c = C() + + a.call(foo = "hello") + a.call(arg = "hello") + a.call("hello") + + b.call(foo = "hello") + b.call(arg = "hello") + b.call(bar = "hello") + b.call("hello") + + c.call(foo = "hello") + c.call(arg = "hello") + c.call("hello") + + val e = E() + val f = F() + + e.call(foo = "hello") + e.call(bar = "hello") + e.call(baz = "hello") + e.call("hello") + + f.call(foo = "hello") + f.call(baaam = "hello") + f.call("hello") + + val g = G() + val h = H() + g.foo("ok", foo = "hohoho") + g.foo("ok", "hohoho") + h.foo("ok", foo = "hohoho") + h.foo("ok", "hohoho") +} diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/reorderedParameterNames.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/reorderedParameterNames.fir.kt new file mode 100644 index 00000000000..3b593be43c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/reorderedParameterNames.fir.kt @@ -0,0 +1,17 @@ + +// FILE: A.java +// ANDROID_ANNOTATIONS +import kotlin.annotations.jvm.internal.*; + +public class A { + public void connect(@ParameterName("host") String host, @ParameterName("port") int port) { + } +} + +// FILE: test.kt +fun main() { + val test = A() + test.connect("127.0.0.1", 8080) + test.connect(host = "127.0.0.1", port = 8080) + test.connect(port = 8080, host = "127.0.0.1") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/sameParameterName.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/sameParameterName.fir.kt new file mode 100644 index 00000000000..01a29b0c13c --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/sameParameterName.fir.kt @@ -0,0 +1,17 @@ + +// FILE: A.java +// ANDROID_ANNOTATIONS +import kotlin.annotations.jvm.internal.*; + +public class A { + public void same(@ParameterName("ok") String first, @ParameterName("ok") String second) { + } +} + +// FILE: test.kt +fun main() { + val test = A() + test.same("hello", "world") + test.same(ok = "hello", ok = world) + test.same("hello", ok = "world") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/specialCharsParameterName.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/specialCharsParameterName.fir.kt new file mode 100644 index 00000000000..0070bd9f64e --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/specialCharsParameterName.fir.kt @@ -0,0 +1,24 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS +import kotlin.annotations.jvm.internal.*; +import kotlin.internal.*; + +public class A { + public void dollarName(@ParameterName("$") String host) { + } + + public void numberName(@ParameterName("42") String field) { + } +} + +// FILE: test.kt +fun main() { + val test = A() + test.dollarName(`$` = "hello") + test.dollarName("hello") + test.dollarName(host = "hello") + + test.numberName(`42` = "world") + test.numberName("world") + test.numberName(field = "world") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/stableParameterName.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/stableParameterName.fir.kt new file mode 100644 index 00000000000..44c47d2bfc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/stableParameterName.fir.kt @@ -0,0 +1,20 @@ +// FILE: A.java +// ANDROID_ANNOTATIONS +import kotlin.annotations.jvm.internal.*; + + +public class A { + public void foo(@ParameterName("hello") String world) {} +} + +// FILE: B.kt + +class B : A() { + override fun foo(hello: String) {} +} + +// FILE: C.kt + +class C : A() { +} + diff --git a/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/staticMethodWithDefaultValue.fir.kt b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/staticMethodWithDefaultValue.fir.kt new file mode 100644 index 00000000000..6f101ae561b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/signatureAnnotations/staticMethodWithDefaultValue.fir.kt @@ -0,0 +1,17 @@ +// IGNORE_BACKEND: JS, NATIVE + +// FILE: A.java +// ANDROID_ANNOTATIONS + +import kotlin.annotations.jvm.internal.*; + +class A { + public static String withDefault(@DefaultValue("OK") String arg) { + return arg; + } +} + +// FILE: test.kt +fun box(): String { + return A.withDefault(); +} diff --git a/compiler/testData/diagnostics/tests/j+k/specialBridges.fir.kt b/compiler/testData/diagnostics/tests/j+k/specialBridges.fir.kt new file mode 100644 index 00000000000..f83c28a9a99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/specialBridges.fir.kt @@ -0,0 +1,7 @@ +// JAVAC_EXPECTED_FILE +interface I2 { + val size: Int +} + +class B2 : java.util.ArrayList(), I2 + diff --git a/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.fir.kt b/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.fir.kt new file mode 100644 index 00000000000..3fb99cd2976 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.fir.kt @@ -0,0 +1,6 @@ +// FULL_JDK + +class C1 : java.util.Hashtable() +class C2 : java.util.Hashtable() { + override fun get(key: String) = 123 +} diff --git a/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/securityProvider.fir.kt b/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/securityProvider.fir.kt new file mode 100644 index 00000000000..9a532723211 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/specialBuiltIns/securityProvider.fir.kt @@ -0,0 +1,5 @@ +// FULL_JDK + +import java.security.Provider + +class Example : Provider("A", 1.0, "B") diff --git a/compiler/testData/diagnostics/tests/j+k/staticMethodInClass.fir.kt b/compiler/testData/diagnostics/tests/j+k/staticMethodInClass.fir.kt new file mode 100644 index 00000000000..06c9a89809d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/staticMethodInClass.fir.kt @@ -0,0 +1,16 @@ +// FILE: JavaClass.java + +public class JavaClass { + public static String testStatic() { + return "OK"; + } + +} + +// FILE: 1.kt +import JavaClass.testStatic + +fun test() { + JavaClass.testStatic() + testStatic() +} diff --git a/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt b/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt new file mode 100644 index 00000000000..e49d86b7fc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt @@ -0,0 +1,41 @@ +// FILE: Test.java +public interface Test { + default String test() { + return "123"; + } +} + +// FILE: test.kt +interface KTrait : Test { + fun ktest() { + super.test() + + test() + } +} + + +interface KTrait2 : KTrait { + fun ktest2() { + super.test() + + test() + } +} + +class A : KTrait { + fun a() { + super.test() + + test() + } +} + + +class A2 : KTrait2 { + fun a() { + super.test() + + test() + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt b/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt new file mode 100644 index 00000000000..808122807cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt @@ -0,0 +1,18 @@ +// FILE: OnSubscribe.java +public interface OnSubscribe { + void f(); +} + +// FILE: Observable.java +public class Observable { + public Observable(OnSubscribe f) { + } +} + +// FILE: Kotlin.kt + +typealias ObservableAlias = Observable +typealias ObservableIntAlias = Observable + +class A : ObservableAlias({}) +class B : ObservableIntAlias({}) diff --git a/compiler/testData/diagnostics/tests/j+k/types/arrayList.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/arrayList.fir.kt new file mode 100644 index 00000000000..68825e9c8d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/types/arrayList.fir.kt @@ -0,0 +1,15 @@ +// FILE: k.kt + +interface ML { + public fun foo(): MutableList +} + +class K : J(), ML + +// FILE: J.java + +import java.util.*; + +public class J extends ML { + public List foo() { return null; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/types/returnCollection.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/returnCollection.fir.kt new file mode 100644 index 00000000000..4ead28c1794 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/types/returnCollection.fir.kt @@ -0,0 +1,13 @@ +// FILE: k.kt + +interface K { + fun foo(): List +} + +// FILE: J.java + +import java.util.*; + +interface J extends K { + List foo(); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPosition.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPosition.fir.kt new file mode 100644 index 00000000000..84c8934b225 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPosition.fir.kt @@ -0,0 +1,19 @@ +// FILE: k.kt + +interface G +interface SubG : G + +interface K { + fun foo(): G + fun bar(): G? +} + +// FILE: J.java + +import java.util.*; + +interface J extends K { + SubG foo(); + SubG bar(); + SubG baz(); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPositionGeneric.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPositionGeneric.fir.kt new file mode 100644 index 00000000000..2ab572dca5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/types/shapeMismatchInCovariantPositionGeneric.fir.kt @@ -0,0 +1,19 @@ +// FILE: k.kt + +interface G +interface SubG : G + +interface K { + fun foo(): G + fun bar(): G? +} + +// FILE: J.java + +import java.util.*; + +interface J extends K { + SubG> foo(); + SubG> bar(); + SubG> baz(); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/types/typeParameter.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/typeParameter.fir.kt new file mode 100644 index 00000000000..550b69b506d --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/types/typeParameter.fir.kt @@ -0,0 +1,11 @@ +// FILE: k.kt + +interface K { + fun foo(t: T) +} + +// FILE: J.java + +interface J extends K { + void foo(T t); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt new file mode 100644 index 00000000000..f9f04ca3148 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: A.java + +public class A { + public static Out foo() { return null; } + public static In bar() { return null; } +} + +// FILE: main.kt + +class Out { + fun x(): E = null!! +} + +class In { + fun y(f: F) {} +} + +fun test() { + A.foo().x() checkType { _() } + A.bar().y(null) +} diff --git a/compiler/testData/diagnostics/tests/java8Overrides/abstractBaseClassMemberNotImplemented.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/abstractBaseClassMemberNotImplemented.fir.kt new file mode 100644 index 00000000000..c96d63f07ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/abstractBaseClassMemberNotImplemented.fir.kt @@ -0,0 +1,9 @@ +abstract class ALeft { + abstract fun foo() +} + +interface IRight { + fun foo() {} +} + +class CDerived : ALeft(), IRight \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/abstractVsAbstract.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/abstractVsAbstract.fir.kt new file mode 100644 index 00000000000..e13adb74cea --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/abstractVsAbstract.fir.kt @@ -0,0 +1,13 @@ +interface ILeft { + fun foo() +} + +interface IRight { + fun foo() +} + +interface IDerived : ILeft, IRight + +class CDerived : ILeft, IRight + +abstract class ADerived : ILeft, IRight \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/defaultVsAbstract.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/defaultVsAbstract.fir.kt new file mode 100644 index 00000000000..8dcd1d137ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/defaultVsAbstract.fir.kt @@ -0,0 +1,13 @@ +interface ILeft { + fun foo() {} +} + +interface IRight { + fun foo() +} + +interface IDerived : ILeft, IRight + +class CDerived : ILeft, IRight + +abstract class ADerived : ILeft, IRight \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/hidingMethodOfAny.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/hidingMethodOfAny.fir.kt new file mode 100644 index 00000000000..ef0f562557e --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/hidingMethodOfAny.fir.kt @@ -0,0 +1,5 @@ +interface IA { + fun toString(): String = "IB" + + override fun equals(other: Any?): Boolean +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/implementingMethodOfAny.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/implementingMethodOfAny.fir.kt new file mode 100644 index 00000000000..5c737fc2420 --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/implementingMethodOfAny.fir.kt @@ -0,0 +1,9 @@ +interface IA { + override fun toString(): String = "IA" + + override fun equals(other: Any?): Boolean = super.equals(other) + + override fun hashCode(): Int { + return 42; + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/notAMethodOfAny.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/notAMethodOfAny.fir.kt new file mode 100644 index 00000000000..3c918e0f098 --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/notAMethodOfAny.fir.kt @@ -0,0 +1,3 @@ +interface IC { + fun toString(x: String): String = "IC$x" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyChain.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyChain.fir.kt new file mode 100644 index 00000000000..b1b1f8944d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyChain.fir.kt @@ -0,0 +1,13 @@ +interface IA + +interface IB : IA { + override fun toString(): String = "IB" +} + +interface IC : IB { + override fun toString(): String = "IC" +} + +interface ID : IC { + override fun toString(): String = "ID" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyDiamond.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyDiamond.fir.kt new file mode 100644 index 00000000000..73f6b39202b --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/overridingMethodOfAnyDiamond.fir.kt @@ -0,0 +1,11 @@ +interface ILeft { + override fun toString(): String +} + +interface IRight { + override fun toString(): String +} + +interface IDiamond : ILeft, IRight { + override fun toString(): String = "IDiamond" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/java8Overrides/singleRelevantDefault.fir.kt b/compiler/testData/diagnostics/tests/java8Overrides/singleRelevantDefault.fir.kt new file mode 100644 index 00000000000..9fd93ea94b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/java8Overrides/singleRelevantDefault.fir.kt @@ -0,0 +1,9 @@ +interface ITop { + fun foo() {} +} + +interface ILeft : ITop + +interface IRight : ITop + +interface IDerived : ILeft, IRight \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/kt13401.fir.kt b/compiler/testData/diagnostics/tests/kt13401.fir.kt new file mode 100644 index 00000000000..758d2abddff --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt13401.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// See KT-13401: SOE in VarianceChecker + +interface Rec> { + fun t(): T +} +interface Super { + fun foo(p: Rec<*>) = p.t() +} +// Related variance errors +class Owner { + inner class Inner(val u: U) { + fun getT() = u + } + + fun foo(arg: Inner<*>) = arg.getT() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/kt310.fir.kt b/compiler/testData/diagnostics/tests/kt310.fir.kt new file mode 100644 index 00000000000..9e95191526c --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt310.fir.kt @@ -0,0 +1,5 @@ +// !WITH_NEW_INFERENCE + +fun f(c: LongRange): Int { + return c.start() +} diff --git a/compiler/testData/diagnostics/tests/kt435.fir.kt b/compiler/testData/diagnostics/tests/kt435.fir.kt new file mode 100644 index 00000000000..aec09116fa8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt435.fir.kt @@ -0,0 +1,7 @@ +fun Any.foo1() : (i : Int) -> Unit { + return {} +} + +fun test(a : Any) { + a.foo1()() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/kt53.fir.kt b/compiler/testData/diagnostics/tests/kt53.fir.kt new file mode 100644 index 00000000000..be726999125 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt53.fir.kt @@ -0,0 +1,6 @@ +val T.foo : T? + get() = null + +fun test(): Int? { + return 1.foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.fir.kt b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.fir.kt new file mode 100644 index 00000000000..0e05bbbb547 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.fir.kt @@ -0,0 +1,17 @@ +fun test(x: List): Int { + x myMap { + return@myMap + } + + return 0 +} + +fun myMap(x: List): Int { + x myMap { + return@myMap + } + + return 0 +} + +infix fun List.myMap(x: () -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt1703.fir.kt b/compiler/testData/diagnostics/tests/labels/kt1703.fir.kt new file mode 100644 index 00000000000..e4a6d4eed25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt1703.fir.kt @@ -0,0 +1,15 @@ +//KT-1703 Reference to label is unresolved + +fun test() { + val ints = Array(2, { null }) + ints.forEach lit@ { + if (it == null) return@lit + use(it + 5) + } +} + +fun Array.forEach(operation: (T) -> Unit) { + for (element in this) operation(element) +} + +fun use(a: Any?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt361.fir.kt b/compiler/testData/diagnostics/tests/labels/kt361.fir.kt new file mode 100644 index 00000000000..18f66608df9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt361.fir.kt @@ -0,0 +1,11 @@ +fun nonlocals(b : Boolean) { + a@{ + fun foo() { + if (b) { + return@a 1 // The label must be resolved, but an error should be reported for a non-local return + } + } + + return@a 5 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt3920.fir.kt b/compiler/testData/diagnostics/tests/labels/kt3920.fir.kt new file mode 100644 index 00000000000..9ae310acc38 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt3920.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//KT-3920 Labeling information is lost when passing through some expressions + +fun test() { + run f@{ + val x = if (1 > 2) return@f 1 else 2 + 2 + } +} diff --git a/compiler/testData/diagnostics/tests/labels/kt3988.fir.kt b/compiler/testData/diagnostics/tests/labels/kt3988.fir.kt new file mode 100644 index 00000000000..07dbf238721 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt3988.fir.kt @@ -0,0 +1,21 @@ +//KT-3988 This@label for outer function not resolved + +class Comment() { + var article = "" + +} +class Comment2() { + var article2 = "" +} + +fun new(body: Comment.() -> Unit) = body + +fun new2(body: Comment2.() -> Unit) = body + +fun main() { + new { + new2 { + this@new //UNRESOLVED REFERENCE + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt4247.fir.kt b/compiler/testData/diagnostics/tests/labels/kt4247.fir.kt new file mode 100644 index 00000000000..25b5f2cb56e --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt4247.fir.kt @@ -0,0 +1,11 @@ +//KT-4247 LABEL_NAME_CLASH + +fun foo(bar1: (String.() -> Int) -> Int) { + bar1 { + this.length + } + + bar1 { + this@bar1.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/kt4586.fir.kt b/compiler/testData/diagnostics/tests/labels/kt4586.fir.kt new file mode 100644 index 00000000000..5ac3e300d34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt4586.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//KT-4586 this@ does not work for builders + +fun string(init: StringBuilder.() -> Unit): String{ + val answer = StringBuilder() + answer.init() + return answer.toString() +} + +val str = string l@{ + append("hello, ") + + val sub = string { + append("world!") + this@l.append(this) + } +} diff --git a/compiler/testData/diagnostics/tests/labels/kt4603.fir.kt b/compiler/testData/diagnostics/tests/labels/kt4603.fir.kt new file mode 100644 index 00000000000..31e6bb298fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt4603.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//KT-4603 Labeling information is lost when passing through local classes or objects + +fun foo() { + val s: Int.() -> Unit = l@{ + class Local(val y: Int = this@l) { + fun bar() { + val x: Int = this@l //unresolved + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/labels/kt591.fir.kt b/compiler/testData/diagnostics/tests/labels/kt591.fir.kt new file mode 100644 index 00000000000..0235783feee --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/kt591.fir.kt @@ -0,0 +1,11 @@ +//KT-591 Unresolved label in valid code + +fun test() { + val a: (Int?).() -> Unit = a@{ + if (this != null) { + val b: String.() -> Unit = { + this@a.times(5) // a@ Unresolved + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.fir.kt b/compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.fir.kt new file mode 100644 index 00000000000..cc43ae6d1cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.fir.kt @@ -0,0 +1,27 @@ +interface A { + fun foo() +} + +interface B { + fun bar() +} + +fun B.b() { + object : A { + override fun foo() { + this@b.bar() + } + } +} + + +fun test() { + fun without(f: T.() -> Unit): Unit = (null!!).f() + without() b@ { + object : A { + override fun foo() { + this@b.bar() + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt new file mode 100644 index 00000000000..67361c6adfd --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +val funLit = lambda@ fun String.() { + val d1 = this@lambda +} + +fun test() { + val funLit = lambda@ fun String.(): String { + return this@lambda + } +} + +fun lambda() { + val funLit = lambda@ fun String.(): String { + return this@lambda + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.fir.kt b/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.fir.kt new file mode 100644 index 00000000000..326e7c49271 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.fir.kt @@ -0,0 +1,36 @@ +fun foo(a: Any?): Int { + @{ -> + return@ + } + + @ while(a == null) { + if (true) { + break@ + } + else { + continue@ + } + } + + var b = 1 + + (@ b) = 2 + + return@ 1 +} + +open class A { + fun foo() {} +} + +class B : A() { + fun bar() { + this@.foo() + super@.foo() + } +} + +fun bar(f: () -> Unit) = f +fun test() { + bar @{} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/lateinit/local/inapplicableLateinitModifier.fir.kt b/compiler/testData/diagnostics/tests/lateinit/local/inapplicableLateinitModifier.fir.kt new file mode 100644 index 00000000000..c2be8e1ba95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/local/inapplicableLateinitModifier.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VALUE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE +// !LANGUAGE: +LateinitLocalVariables + +import kotlin.reflect.KProperty + +object Delegate { + operator fun getValue(instance: Any?, property: KProperty<*>) : String = "" + operator fun setValue(instance: Any?, property: KProperty<*>, value: String) {} +} + + +fun test() { + lateinit val test0: Any + lateinit var test1: Int + lateinit var test2: Any? + lateinit var test3: String = "" + lateinit var test4 by Delegate +} diff --git a/compiler/testData/diagnostics/tests/lateinit/local/localLateinit.fir.kt b/compiler/testData/diagnostics/tests/lateinit/local/localLateinit.fir.kt new file mode 100644 index 00000000000..9586a34dfca --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/local/localLateinit.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +LateinitLocalVariables + +fun test() { + lateinit var s: String + s = "" + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/lateinit/local/uninitialized.fir.kt b/compiler/testData/diagnostics/tests/lateinit/local/uninitialized.fir.kt new file mode 100644 index 00000000000..090a7d0cce9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/local/uninitialized.fir.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +LateinitLocalVariables + +fun test1() { + lateinit var s: String + s.length +} + +fun test2() { + lateinit var s: String + run { + s = "" + } + s.length +} + +fun almostAlwaysTrue(): Boolean = true + +fun test3() { + lateinit var s: String + if (almostAlwaysTrue()) { + s = "" + } + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.fir.kt b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.fir.kt new file mode 100644 index 00000000000..fec3fbc5ee7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.fir.kt @@ -0,0 +1,71 @@ +// !LANGUAGE: -LateinitTopLevelProperties -LateinitLocalVariables +import kotlin.reflect.KProperty + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +public abstract class A(lateinit var p2: String) { + + public lateinit val a: String + lateinit val b: T + private lateinit var c: CharSequence + + lateinit val d: String + get + + public lateinit var e: String + get + private set + + fun a() { + lateinit var a: String + } + + lateinit var e1: V + lateinit var e2: String? + lateinit var e3: Int + lateinit var e4: Int? + lateinit var e5 = "A" + + // With initializer, primitive + lateinit var e6 = 3 + + lateinit var e7 by CustomDelegate() + + lateinit var e8: String + get() = "A" + + lateinit var e9: String + set(v) { field = v } + + abstract lateinit var e10: String + + lateinit var String.e11: String + + lateinit var String.e12: String +} + +lateinit val topLevel: String +lateinit var topLevelMutable: String + +public interface Intf { + lateinit var str: String +} + +public abstract class AbstractClass { + abstract var str: String +} + +public class AbstractClassImpl : AbstractClass() { + override lateinit var str: String +} + +public class B { + lateinit var a: String + + init { + a.length + } +} diff --git a/compiler/testData/diagnostics/tests/lateinit/modifierApplicability_lv12.fir.kt b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability_lv12.fir.kt new file mode 100644 index 00000000000..d73c339b13a --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability_lv12.fir.kt @@ -0,0 +1,71 @@ +// !LANGUAGE: +LateinitTopLevelProperties +LateinitLocalVariables +import kotlin.reflect.KProperty + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} +} + +public abstract class A(lateinit var p2: String) { + + public lateinit val a: String + lateinit val b: T + private lateinit var c: CharSequence + + lateinit val d: String + get + + public lateinit var e: String + get + private set + + fun a() { + lateinit var a: String + } + + lateinit var e1: V + lateinit var e2: String? + lateinit var e3: Int + lateinit var e4: Int? + lateinit var e5 = "A" + + // With initializer, primitive + lateinit var e6 = 3 + + lateinit var e7 by CustomDelegate() + + lateinit var e8: String + get() = "A" + + lateinit var e9: String + set(v) { field = v } + + abstract lateinit var e10: String + + lateinit var String.e11: String + + lateinit var String.e12: String +} + +lateinit val topLevel: String +lateinit var topLevelMutable: String + +public interface Intf { + lateinit var str: String +} + +public abstract class AbstractClass { + abstract var str: String +} + +public class AbstractClassImpl : AbstractClass() { + override lateinit var str: String +} + +public class B { + lateinit var a: String + + init { + a.length + } +} diff --git a/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt b/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt new file mode 100644 index 00000000000..18d914f0725 --- /dev/null +++ b/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt @@ -0,0 +1,22 @@ +class My { + + lateinit var x: String + private set + + lateinit var y: String + internal set + + lateinit protected var z: String + private set + + lateinit private var w: String + // Ok, private var / private set + private set + + lateinit protected var v: String + public set + + lateinit public var u: String + // Ok, public var / public set + public set +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/library/Collections.fir.kt b/compiler/testData/diagnostics/tests/library/Collections.fir.kt new file mode 100644 index 00000000000..23fb5dd6f26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/library/Collections.fir.kt @@ -0,0 +1,111 @@ +// !WITH_NEW_INFERENCE +package collections + +fun testCollection(c: Collection, t: T) { + c.size + c.isEmpty() + c.contains(1) + val iterator: Iterator = c.iterator() + c.containsAll(c) + + val mutableIterator: MutableIterator = c.iterator() + c.add(t) + c.remove(1) + c.addAll(c) + c.removeAll(c) + c.retainAll(c) + c.clear() + +} +fun testMutableCollection(c: MutableCollection, t: T) { + c.size + c.isEmpty() + c.contains(1) + val iterator: Iterator = c.iterator() + c.containsAll(c) + + + val mutableIterator: MutableIterator = c.iterator() + c.add(t) + c.remove(1 as T) + c.addAll(c) + c.removeAll(c) + c.retainAll(c) + c.clear() +} + +fun testList(l: List, t: T) { + val t: T = l.get(1) + val i: Int = l.indexOf(t) + val i1: Int = l.lastIndexOf(t) + val listIterator: ListIterator = l.listIterator() + val listIterator1: ListIterator = l.listIterator(1) + val list: List = l.subList(1, 2) + + val value: T = l.set(1, t) + l.add(1, t) + l.remove(1) + val mutableListIterator: MutableListIterator = l.listIterator() + val mutableListIterator1: MutableListIterator = l.listIterator(1) + val mutableList: MutableList = l.subList(1, 2) +} + +fun testMutableList(l: MutableList, t: T) { + val value: T = l.set(1, t) + l.add(1, t) + l.removeAt(1) + val mutableListIterator: MutableListIterator = l.listIterator() + val mutableListIterator1: MutableListIterator = l.listIterator(1) + val mutableList: MutableList = l.subList(1, 2) +} + +fun testSet(s: Set, t: T) { + s.size + s.isEmpty() + s.contains(1) + val iterator: Iterator = s.iterator() + s.containsAll(s) + + val mutableIterator: MutableIterator = s.iterator() + s.add(t) + s.remove(1) + s.addAll(s) + s.removeAll(s) + s.retainAll(s) + s.clear() + +} +fun testMutableSet(s: MutableSet, t: T) { + s.size + s.isEmpty() + s.contains(1) + val iterator: Iterator = s.iterator() + s.containsAll(s) + + + val mutableIterator: MutableIterator = s.iterator() + s.add(t) + s.remove(1 as T) + s.addAll(s) + s.removeAll(s) + s.retainAll(s) + s.clear() +} + +fun testMap(m: Map) { + val set: Set = m.keys + val collection: Collection = m.values + val set1: Set> = m.entries + + val mutableSet: MutableSet = m.keys + val mutableCollection: MutableCollection = m.values + val mutableSet1: MutableSet> = m.entries +} + +fun testMutableMap(m: MutableMap) { + val mutableSet: MutableSet = m.keys + val mutableCollection: MutableCollection = m.values + val mutableSet1: MutableSet> = m.entries +} + +fun array(vararg t: T): Array {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/library/kt828.fir.kt b/compiler/testData/diagnostics/tests/library/kt828.fir.kt new file mode 100644 index 00000000000..f08475a80eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/library/kt828.fir.kt @@ -0,0 +1,12 @@ +fun test() { + var res : Boolean = true + res = (res and false) + res = (res or false) + res = (res xor false) + res = (true and false) + res = (true or false) + res = (true xor false) + res = (!true) + res = (true && false) + res = (true || false) +} diff --git a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt new file mode 100644 index 00000000000..f152deb620b --- /dev/null +++ b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -ProhibitLocalAnnotations + +fun f() { + annotation class Anno + + @Anno class Local { + annotation class Nested + } +} diff --git a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt new file mode 100644 index 00000000000..d8dac02ea1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitLocalAnnotations + +fun f() { + annotation class Anno + + @Anno class Local { + annotation class Nested + } +} diff --git a/compiler/testData/diagnostics/tests/localInterfaces.fir.kt b/compiler/testData/diagnostics/tests/localInterfaces.fir.kt new file mode 100644 index 00000000000..5e5af2f9926 --- /dev/null +++ b/compiler/testData/diagnostics/tests/localInterfaces.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + interface a {} + val b = object { + interface c {} + } + class A { + interface d {} + } + val f = { + interface e {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt new file mode 100644 index 00000000000..39c44dd2189 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt @@ -0,0 +1,163 @@ +@myAnnotation public +package illegal_modifiers + +abstract class A() { + abstract final fun f() + abstract open fun g() + final open fun h() {} + + open var r: String + get + abstract protected set +} + +final interface T {} + +class FinalClass() { + open fun foo() {} + val i: Int = 1 + open get(): Int = field + var j: Int = 1 + open set(v: Int) {} +} + +private public class C +private public object D + +//A sample annotation to check annotation usage in parameters. +annotation class annotated(val text: String = "not given") + +//Check legal modifiers in constructor +class LegalModifier(val a: Int, @annotated private var b: String, @annotated vararg v: Int) + +//Check illegal modifier in constructor parameters +class IllegalModifiers1( + in + out + reified + enum + private + const + a: Int) + +//Check multiple illegal modifiers in constructor +class IllegalModifiers2(private abstract a: Int) + + +//Check annotations with illegal modifiers in constructor +class IllegalModifiers3(@annotated public abstract b: String) + +//Check annotations and vararg with illegal modifiers in constructor +class IllegalModifiers4(val a: Int, @annotated("a text") protected vararg v: Int) + +//Check illegal modifiers for functions and catch block +abstract class IllegalModifiers5() { + + //Check illegal modifier in function parameter + abstract fun foo(public a: Int, vararg v: String) + + //Check multiple illegal modifiers in function parameter + abstract fun bar(public abstract a: Int, vararg v: String) + + //Check annotations with illegal modifiers + abstract fun baz(@annotated("a text") public abstract a: Int) + + private fun qux() { + + //Check illegal modifier in catch block + try {} catch (in out reified enum public e: Exception) {} + + //Check multiple illegal modifiers in catch block + try {} catch (in out reified enum abstract public e: Exception) {} + + //Check annotations with illegal modifiers + try {} catch (@annotated("a text") abstract public e: Exception) {} + } +} + +//Check illegal modifiers on anonymous initializers +abstract class IllegalModifiers6() { + public init {} + private init {} + protected init {} + vararg init {} + abstract init {} + open init {} + final init {} + + public @annotated init {} + + private @IllegalModifiers6() init {} +} + +// strange inappropriate modifiers usages +override +out +in +vararg +reified +class IllegalModifiers7() { + enum + inner + annotation + out + in + vararg + reified + val x = 1 + enum + inner + annotation + out + in + vararg + reified + const + fun foo() {} +} + +// Secondary constructors +class IllegalModifiers8 { + abstract + enum + open + inner + annotation + override + out + in + final + vararg + reified + const + constructor() {} + + constructor(private enum abstract x: Int) {} +} + +class IllegalModifiers9 { + private protected constructor() {} + private internal constructor(x: Int) {} +} + +// Illegal modifiers on primary constructor + +class IllegalModifiers10 +abstract +enum +open +inner +annotation +override +out +in +final +vararg +reified +const constructor() + +class IllegalModifiers11 private protected constructor() + +class Outer { + inner sealed class Inner +} diff --git a/compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.fir.kt b/compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.fir.kt new file mode 100644 index 00000000000..4f23c38669b --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.fir.kt @@ -0,0 +1,6 @@ +fun foo() { + public class A + private class B + protected class C + internal class D +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/annotations.fir.kt b/compiler/testData/diagnostics/tests/modifiers/annotations.fir.kt new file mode 100644 index 00000000000..8b30f2bba45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/annotations.fir.kt @@ -0,0 +1,12 @@ +annotation class My( + public val x: Int, + protected val y: Int, + internal val z: Int, + private val w: Int +) + +open class Your { + open val x: Int = 0 +} + +annotation class His(override val x: Int): Your() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt new file mode 100644 index 00000000000..e122b400edd --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/applicability.fir.kt @@ -0,0 +1,110 @@ +// !DIAGNOSTICS:-UNUSED_VARIABLE,-CAST_NEVER_SUCCEEDS,-DIVISION_BY_ZERO + +import kotlin.reflect.KProperty + +const val topLevel: Int = 0 +const val topLevelInferred = 1 +const var topLeveLVar: Int = 2 + +private val privateTopLevel = 3 + +object A { + const val inObject: Int = 4 +} + +class B(const val constructor: Int = 5) + +abstract class C { + open const val x: Int = 6 + + abstract const val y: Int = 7 + + companion object { + const val inCompaionObject = 8 + } +} + +object D : C() { + override const val x: Int = 9 + + const val inObject = 10 + + final const val final = 11 + + const val withoutInitializer: Int + + init { + withoutInitializer = 12 + } +} + +const val delegated: Int by Delegate() + + +const val withGetter: Int + get() = 13 + +const val withExplicitDefaultGetter: Int = 1 + get + +fun foo(): Int { + const val local: Int = 14 + return 15 +} + +enum class MyEnum { + A { + const val inEnumEntry = 16 + }; + const val inEnum = 17 +} + +class Outer { + inner class Inner { + object C { + const val a = 18 + } + } +} + +const val defaultGetter = 19 + get + +const val nonConstInitializer1 = foo() +const val nonConstInitializer2 = 1 as String +const val nonConstInitializer3 = 1.0 as String +const val nonConstInitializer4 = 1 as Double +const val nonConstInitializer5 = "2" as Int +const val nonConstInitializer6 = 1/0 +const val nonConstInitializer7 = -1/0 +const val nonConstInitializer8 = 1/0 - 1/0 +const val nonConstInitializer9 = 1.0/0.0 - 1/0 +const val nonConstInitializer10 = 0/0 +const val nonConstInitializer11 = 1 % 0 +const val nonConstInitializer12 = 0 % 0 +const val nonConstInitializer13 = 0.mod(0) +const val nonConstInitializer14 = 0.rem(0) +const val nonConstInitializer15 = 0.div(0) + +const val constInitializer1 = 1.0/0 +const val constInitializer2 = 1/0.0 +const val constInitializer3 = 1.0/0.0 +const val constInitializer4 = -1.0/0 +const val constInitializer5 = 0.0/0 +const val constInitializer6 = 42 + 1.0/0 +const val constInitializer7 = 42 - 1.0/0 +const val constInitializer8 = 1.0/0 - 1.0/0 +const val constInitializer9 = 0.0/0 + 1.0/0 +const val constInitializer10 = 1.0 % 0 +const val constInitializer11 = 0.0 % 0 +const val constInitializer12 = (-1.0) % 0 +const val constInitializer13 = 1.0.rem(0) +const val constInitializer14 = 1.0.mod(0) +const val constInitializer15 = 1.0.div(0) + +// ------------------ +class Delegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): Int = 1 + + operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: Int) = Unit +} diff --git a/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.fir.kt new file mode 100644 index 00000000000..1eb5fb247ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.fir.kt @@ -0,0 +1,3 @@ +// !WITH_NEW_INFERENCE +annotation class A(val a: IntArray = arrayOf(1)) +annotation class B(val a: IntArray = intArrayOf(1)) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/constInteraction.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/constInteraction.fir.kt new file mode 100644 index 00000000000..240bd3d3f71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/constInteraction.fir.kt @@ -0,0 +1,18 @@ +const val aConst = 1 +const val bConst = aConst + 1 + +const val boolVal = bConst > 1 || (B.boolVal && A.boolVal) +const val stringInterpolation = "Result: ${B.boolVal}" + +object A { + const val boolVal = bConst + 3 == 5 + + const val recursive1: Int = 1 + B.recursive2 +} + +class B { + companion object { + const val boolVal = A.boolVal + const val recursive2: Int = A.recursive1 + 2 + } +} diff --git a/compiler/testData/diagnostics/tests/modifiers/const/fromJava.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/fromJava.fir.kt new file mode 100644 index 00000000000..7fad716d109 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/fromJava.fir.kt @@ -0,0 +1,26 @@ +// FILE: A.java + +public class A { + public static final int X = 1; + public static final int Y; + + public final int z = 3; + + static { + Y = 2; + } +} + +// FILE: main.kt + +annotation class Ann(val x: Int) + +@Ann(A.X) +fun main1() {} + +@Ann(A.Y) +fun main2() {} + +val q = A() +@Ann(q.z) +fun main3() {} diff --git a/compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.fir.kt new file mode 100644 index 00000000000..bace34caa25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/fromJavaSubclass.fir.kt @@ -0,0 +1,15 @@ +// FILE: A.java + +public class A { + public static final String FOO = "foo"; +} + +// FILE: B.java + +public class B extends A { +} + +// FILE: main.kt + +const val K1 = B.FOO +const val K2 = A.FOO \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kt12248.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/kt12248.fir.kt new file mode 100644 index 00000000000..093c6ca967c --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/kt12248.fir.kt @@ -0,0 +1,19 @@ +// FILE: Bar.java + +public class Bar { + public static final int BAR = Foo.FOO + 1; +} + +// FILE: Test.kt + +class Foo { + companion object { + const val FOO = 1 + } +} + +class Baz { + companion object { + const val BAZ = Bar.BAR + 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/kt15913.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/kt15913.fir.kt new file mode 100644 index 00000000000..13884090354 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/kt15913.fir.kt @@ -0,0 +1,19 @@ +// FILE: Context.java + +public interface Context { + String BEAN = "context"; +} + +// FILE: Test.kt + +annotation class Resource(val name: String) + +class MyController { + companion object { + private const val foo = Context.BEAN + } + + @Resource(name = Context.BEAN) + fun setContext() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/noDivisionByZeroFeature.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/noDivisionByZeroFeature.fir.kt new file mode 100644 index 00000000000..f7f2fb9f75c --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/noDivisionByZeroFeature.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -DivisionByZeroInConstantExpressions +// !DIAGNOSTICS:-DIVISION_BY_ZERO + +const val a = 1 / 0.0 +const val b = 1.0 / 0 +const val c = 0.0 / 0 +const val d = 1.0 % 0 +const val e = 0.0 % 0 +const val f = 0.0.mod(0) +const val g = 0.0.rem(0) +const val h = 0.0.div(0) + +const val i = 1 / 0 + +val nonConst1 = 1.0 / 0 +val nonConst2 = 1 / 0 +val nonConst3 = 1.0 % 0 +val nonConst4 = 1 % 0 +val nonConst5 = 1.mod(0) +val nonConst6 = 1.rem(0) +val nonConst7 = 1.div(0) diff --git a/compiler/testData/diagnostics/tests/modifiers/const/types.fir.kt b/compiler/testData/diagnostics/tests/modifiers/const/types.fir.kt new file mode 100644 index 00000000000..b55bb6d33ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/types.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +const val intConst = 1 +const val longConst: Long = 1 +const val boolConst = true +const val stringConst = "empty" + +enum class MyEnum { A } + +const val enumConst: MyEnum = MyEnum.A +const val arrayConst: Array = arrayOf("1") +const val intArrayConst: IntArray = intArrayOf() + +const val unresolvedConst1 = Unresolved +const var unresolvedConst2 = Unresolved +const val unresolvedConst3 = Unresolved +get() = 10 diff --git a/compiler/testData/diagnostics/tests/modifiers/defaultModifier.fir.kt b/compiler/testData/diagnostics/tests/modifiers/defaultModifier.fir.kt new file mode 100644 index 00000000000..49b79c540d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/defaultModifier.fir.kt @@ -0,0 +1,55 @@ +companion class A { + companion object { + + } +} + +class B { + companion object + + val c: Int = 1 +} + +class C { + companion object A { + + } +} + +class D { + companion object A { + companion object { + } + } +} + +companion object G { + companion object +} + +companion interface H { + companion object +} + +class J { + companion object C { + companion object + } +} + +companion enum class Enum { + E1, + E2; + + companion object +} + +companion fun main() { + +} + +companion var prop: Int = 1 + companion get + companion set + +class Z(companion val c: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/incompatibleVarianceModifiers.fir.kt b/compiler/testData/diagnostics/tests/modifiers/incompatibleVarianceModifiers.fir.kt new file mode 100644 index 00000000000..960ca254855 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/incompatibleVarianceModifiers.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface Foo +interface Foo1 +interface Foo2 + +fun test1(foo: Foo) = foo +fun test2(): Foo = throw Exception() + +fun test3() { + val f: Foo + + class Bzz +} + +class A { + fun bar() { + } +} + +fun test4(a: A) { + a.bar() +} diff --git a/compiler/testData/diagnostics/tests/modifiers/inlineParameters.fir.kt b/compiler/testData/diagnostics/tests/modifiers/inlineParameters.fir.kt new file mode 100644 index 00000000000..311f939d9ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/inlineParameters.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo(noinline x: Int) {} + +inline fun bar(y: Int, crossinline x: String) {} + +fun gav(noinline x: (Int) -> Unit, crossinline y: (String) -> Int) {} + +inline fun correct(noinline x: (Int) -> Unit, crossinline y: (String) -> Int) {} + +inline fun incompatible(noinline crossinline x: () -> String) {} + +class FunctionSubtype : () -> Unit { + override fun invoke() {} +} + +inline fun functionSubtype( + noinline f: FunctionSubtype, + crossinline g: FunctionSubtype +) { } diff --git a/compiler/testData/diagnostics/tests/modifiers/internalInInterface.fir.kt b/compiler/testData/diagnostics/tests/modifiers/internalInInterface.fir.kt new file mode 100644 index 00000000000..5b1a334f17a --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/internalInInterface.fir.kt @@ -0,0 +1,7 @@ +interface My { + internal val x: Int + internal val xxx: Int + get() = 0 + internal fun foo(): Int + internal fun bar() = 42 +} diff --git a/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.fir.kt b/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.fir.kt new file mode 100644 index 00000000000..ae1ccc95eb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.fir.kt @@ -0,0 +1,52 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun f(vararg x: Int) {} + +val inVal: (vararg x: Int)->Unit = {} + +fun inParam(fn: (vararg x: Int)->Unit) {} + +fun inParamNested(fn1: (fn2: (vararg n: Int)->Unit)->Unit) {} + +fun inReturn(): (vararg x: Int)->Unit = {} + +class A : (vararg Int)->Unit { + override fun invoke(p1: Int) { + var lambda: (vararg x: Int)->Unit = {} + } + + val prop: (vararg x: Int)->Unit + get(): (vararg x: Int)->Unit = {} +} + +val allProhibited: (abstract + annotation + companion + const + crossinline + data + enum + external + final + in + inline + inner + internal + lateinit + noinline + open + operator + out + override + private + protected + public + reified + sealed + tailrec + vararg + + x: Int)->Unit = {} + +val valProhibited: (val x: Int)->Unit = {} +val varProhibited: (var x: Int)->Unit = {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/openInInterface.fir.kt b/compiler/testData/diagnostics/tests/modifiers/openInInterface.fir.kt new file mode 100644 index 00000000000..8c9497d874f --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/openInInterface.fir.kt @@ -0,0 +1,10 @@ +interface My { + open fun foo() + open fun bar() {} + open abstract fun baz(): Int + + open val x: Int + open val y: String + get() = "" + open abstract val z: Double +} diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.fir.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.fir.kt new file mode 100644 index 00000000000..69a7f9ebd6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Example + +fun Example.plus(other: Example) = 0 +operator infix fun Example.minus(other: Example) = 0 + +operator infix fun Example.times(other: Example) = 0 +fun Example.div(other: Example) = 0 + +fun a() { + with (Example()) { + operator infix fun Example.plus(other: Example) = "" + fun Example.minus(other: Example) = "" + + operator infix fun Example.times(other: Example) = "" + fun Example.div(other: Example) = "" + + with (Example()) { + val a = Example() + val b = Example() + + consumeString(a + b) + consumeInt(a - b) + + consumeString(a plus b) + consumeInt(a minus b) + + a * b + a / b + + a times b + a div b + } + } +} + +fun consumeInt(i: Int) {} +fun consumeString(s: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.fir.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.fir.kt new file mode 100644 index 00000000000..faa594795d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER + +class Example { + operator infix fun plus(other: Example) = 0 + fun minus(other: Example) = 0 + + operator infix fun times(other: Example) = 0 + fun div(other: Example) = 0 +} + +fun Example.plus(other: Example) = "" +operator infix fun Example.minus(other: Example) = "" + +operator infix fun Example.times(other: Example) = "" +fun Example.div(other: Example) = "" + +fun a() { + val a = Example() + val b = Example() + + a + b + a - b + a * b + a / b + + a plus b + a minus b + a times b + a div b + + with (Example()) { + consumeInt(this + a) + consumeString(this - b) + consumeInt(this * a) + consumeInt(this / b) + + consumeInt(this plus a) + consumeString(this minus b) + consumeInt(this times a) + consumeInt(this div b) + } +} + +fun consumeInt(i: Int) {} +fun consumeString(s: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.fir.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.fir.kt new file mode 100644 index 00000000000..2ecb1895096 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER + +open class Example { + fun invoke() = 0 + fun get(i: Int) = 0 + + fun component1() = 0 + fun component2() = 0 + + fun inc() = Example() + + fun plus(o: Example) = 0 +} + +class Example2 : Example() + +operator fun Example.invoke() = "" +operator fun Example.get(i: Int) = "" + +operator fun Example.component1() = "" +operator fun Example.component2() = "" + +operator fun Example.inc() = Example2() + +infix fun Example.plus(o: Example) = "" + +fun test() { + var a = Example() + val b = Example() + + consumeString(a()) + consumeString(a[1]) + + val (x, y) = Example() + consumeString(x) + consumeString(y) + + consumeExample2(++a) + + consumeString(a plus b) +} + +fun consumeInt(i: Int) {} +fun consumeString(s: String) {} +fun consumeExample2(e: Example2) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingBrackets.fir.kt b/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingBrackets.fir.kt new file mode 100644 index 00000000000..f6b4a247fd1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingBrackets.fir.kt @@ -0,0 +1,2 @@ +class A private constructor { +} diff --git a/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingKeyword.fir.kt b/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingKeyword.fir.kt new file mode 100644 index 00000000000..babb16e5b07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/primaryConstructorMissingKeyword.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +annotation class Ann(val x: Int = 1) +class A private (val x: Int) { +inner class B @Ann(2) (val y: Int) + +fun foo() { + class C private @Ann(3) (args: Int) + } +} diff --git a/compiler/testData/diagnostics/tests/modifiers/privateInInterface.fir.kt b/compiler/testData/diagnostics/tests/modifiers/privateInInterface.fir.kt new file mode 100644 index 00000000000..75878595978 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/privateInInterface.fir.kt @@ -0,0 +1,12 @@ +interface My { + private val x: Int + private abstract val xx: Int + private val xxx: Int + get() = 0 + final val y: Int + final val yy: Int + get() = 1 + private fun foo(): Int + // ok + private fun bar() = 42 +} diff --git a/compiler/testData/diagnostics/tests/modifiers/protected.fir.kt b/compiler/testData/diagnostics/tests/modifiers/protected.fir.kt new file mode 100644 index 00000000000..203b968c732 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/protected.fir.kt @@ -0,0 +1,21 @@ +class My(protected val x: Int) { + class Her(protected val x: Int) + + inner class Its(protected val x: Int) +} + +object Your { + protected fun foo() = 3 +} + +annotation class His(protected val x: Int) + +enum class Our(protected val x: Int) { + FIRST(42) { + protected fun foo() = 13 + } +} + +interface Their { + protected fun foo() = 7 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/redundantTargets.fir.kt b/compiler/testData/diagnostics/tests/modifiers/redundantTargets.fir.kt new file mode 100644 index 00000000000..c2cc1149db6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/redundantTargets.fir.kt @@ -0,0 +1,10 @@ +open interface First +// Now inspection +abstract interface Second +// Now inspection +final enum class Third { + FOURTH, + FIFTH +} +// Now inspection +final object Sixth \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/repeatedModifiers.fir.kt b/compiler/testData/diagnostics/tests/modifiers/repeatedModifiers.fir.kt new file mode 100644 index 00000000000..0ae92441676 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/repeatedModifiers.fir.kt @@ -0,0 +1,41 @@ +abstract abstract class Foo +public public class Bar +open open final class Baz { + private private fun foo() {} +} + +class Bzz(public public val q: Int = 1) { + public public val x: Int = 2 + + public val y: Int + public public get() = 3 + + val z: Int + open final get() = 4 + + public public class B(public public val z: Int = 1) { + public public val y: Int = 2 + + public val x: Int + public public get() = 3 + } + + public public object C { + public public val y: Int = 1 + public public fun z(): Int = 1 + } +} + +public public val bar: Int = 1 + +public public fun foo(): Int = 1 + +fun test() { + public public class B(public public val z: Int = 1) { + public public val y: Int = 2 + + public val x: Int + public public get() = 3 + } +} + diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/collectionMethodStub.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/collectionMethodStub.fir.kt new file mode 100644 index 00000000000..fb8a15bf719 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/collectionMethodStub.fir.kt @@ -0,0 +1,21 @@ +// FILE: f1.kt +// SKIP_TXT + +package kotlin + +class Unit + +// FILE: f2.kt + +class C: MutableIterator { + override fun remove(): Unit { + throw UnsupportedOperationException() + } + override fun next(): Int { + throw UnsupportedOperationException() + } + override fun hasNext(): Boolean { + throw UnsupportedOperationException() + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArguments.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArguments.fir.kt new file mode 100644 index 00000000000..17bd97d27f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArguments.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class M1 { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A + +public fun foo(a: A) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(M1().a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArgumentsReversed.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArgumentsReversed.fir.kt new file mode 100644 index 00000000000..2b2f8bdf6a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArgumentsReversed.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class M1 { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A + +public fun foo(a: A) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(M1().a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateClass.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateClass.fir.kt new file mode 100644 index 00000000000..28bed038c27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateClass.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class B { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A { + val x = 1 +} + +public fun foo(a: A) { + a.x + 1 +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(B().a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateNestedClasses.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateNestedClasses.fir.kt new file mode 100644 index 00000000000..6fc7ff0296c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateNestedClasses.fir.kt @@ -0,0 +1,68 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public class A { + public class B + public object C + companion object { + public class D { + public object E + } + public class G + } + + public inner class F +} + +public class M1 { + public val a: A = A() + public val b: A.B = A.B() + public val c: A.C = A.C + public val d: A.Companion.D = A.Companion.D() + public val e: A.Companion.D.E = A.Companion.D.E + public val f: A.F = A().F() + public val g: A.Companion.G = A.Companion.G() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A { + public class B + public class C + companion object { + public class D { + public class E + } + } + public class G + public inner class F +} + +public fun a(p: A) {} +public fun b(p: A.B) {} +public fun c(p: A.C) {} +public fun d(p: A.Companion.D) {} +public fun e(p: A.Companion.D.E) {} +public fun f(p: A.F) {} +public fun g(p: A.G) {} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test(m1: M1) { + a(m1.a) + b(m1.b) + c(m1.c) + d(m1.d) + e(m1.e) + f(m1.f) + g(m1.g) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateSuperClass.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateSuperClass.fir.kt new file mode 100644 index 00000000000..73f4f212412 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateSuperClass.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public interface A +public class B : A +public class M1 { + public val b: B = B() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public interface A + +public fun foo(a: A) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(M1().b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.fir.kt new file mode 100644 index 00000000000..31e558b93c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class M1 { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A + +public fun foo(a: A) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(M1().a) + foo(1) // error type on the declaration site +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericSuperClass.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericSuperClass.fir.kt new file mode 100644 index 00000000000..a90aa734312 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericSuperClass.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public interface A +public interface C +public interface D +public class B : A, C, D +public class M1 { + public val b: B = B() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public interface A +public interface C +public interface D + +public fun a(a: A) { +} + +public fun c(c: C) { +} + +public fun d(d: D) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + a(M1().b) // Type arguments do not match + c(M1().b) // Type arguments do not match + d(M1().b) // Type arguments do match +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsage.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsage.fir.kt new file mode 100644 index 00000000000..20f29622e77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsage.fir.kt @@ -0,0 +1,23 @@ +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class B { + public val a: A = A() +} + +// MODULE: m2(m1) +// FILE: b.kt + +package p + +class A { + fun foo() {} +} + +fun test() { + val a: A = B().a + a.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsageNoTypeAnnotation.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsageNoTypeAnnotation.fir.kt new file mode 100644 index 00000000000..6dbc4b1496d --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsageNoTypeAnnotation.fir.kt @@ -0,0 +1,23 @@ +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class B { + public val a: A = A() +} + +// MODULE: m2(m1) +// FILE: b.kt + +package p + +class A { + fun foo() {} +} + +fun test() { + val a = B().a + a.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/members.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/members.fir.kt new file mode 100644 index 00000000000..eb795c7bbe0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/members.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// MODULE: m1 +// FILE: a.kt + +package p + +public class A { + public fun m1() {} +} +public class M1 { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A { + public fun m2() {} +} + +public class M2 { + public val a: A = A() +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test(a: A) { + a.m1() + + M1().a.m1() + + M2().a.m2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameClassNameDifferentPackages.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameClassNameDifferentPackages.fir.kt new file mode 100644 index 00000000000..6de2c5bc250 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameClassNameDifferentPackages.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class B { + public val a: A = A() +} + +// MODULE: m2(m1) +// FILE: b.kt + +import p.* + +class A + +fun test() { + val a: A = B().a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameGenericArguments.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameGenericArguments.fir.kt new file mode 100644 index 00000000000..bc4cf46afd4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameGenericArguments.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public class A +public class M1 { + public val a: A = A() +} + +// MODULE: m2 +// FILE: b.kt + +package p + +public class A + +public fun foo(a: A) { +} + +// MODULE: m3(m1, m2) +// FILE: b.kt + +import p.* + +fun test() { + foo(M1().a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParams.fir.kt new file mode 100644 index 00000000000..5b0df4dc633 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParams.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: X) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo("") + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsBoundMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsBoundMismatch.fir.kt new file mode 100644 index 00000000000..4aadd61475a --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsBoundMismatch.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T?) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: X?) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface Tr + +public interface B { + public fun foo(a: T?) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(null) + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsIndexMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsIndexMismatch.fir.kt new file mode 100644 index 00000000000..00da81c4009 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsIndexMismatch.fir.kt @@ -0,0 +1,34 @@ +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T?) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: X?) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T?) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(null) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsNameMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsNameMismatch.fir.kt new file mode 100644 index 00000000000..3a6fd9ff269 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInParamsNameMismatch.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: X) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T1) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?, y: Y) { + if (b is C) { + b?.foo(y) + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt new file mode 100644 index 00000000000..de9a558ecd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(): T +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(): X + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(): T +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classVsFunctionGenericsInParamsMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classVsFunctionGenericsInParamsMismatch.fir.kt new file mode 100644 index 00000000000..0afb87446e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classVsFunctionGenericsInParamsMismatch.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T, b : R) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: Any?, b : R) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T, b: R) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?, c: C) { + b?.foo(1, 1) + c.foo(1, 1) + if (b is C) { + b?.foo(1, 1) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/covariantReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/covariantReturnTypes.fir.kt new file mode 100644 index 00000000000..c3df30c4c78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/covariantReturnTypes.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun getParent(): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun getParent(): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun getParent(): Any? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.getParent() + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differenceInParamNames.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differenceInParamNames.fir.kt new file mode 100644 index 00000000000..5f278c9cf55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differenceInParamNames.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: Int, b: String): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: Int, b: String): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a1: Int, b1: String): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(1, "") + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentGenericsInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentGenericsInParams.fir.kt new file mode 100644 index 00000000000..8dbd7151a07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentGenericsInParams.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m0 +// FILE: a.kt +package p + +public interface G1 +public interface G2 + +// MODULE: m1(m0) +// FILE: a.kt +package p + +public interface B { + public fun foo(a: G1?, b: G2?) +} + +// MODULE: m2(m1, m0) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: G1?, b: G2?) + +} + +// MODULE: m3(m0) +// FILE: b.kt +package p + +public interface B { + public fun foo(a: G1?, b: G2?) +} + +// MODULE: m4(m3, m2, m0) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(null, null) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentNumberOfParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentNumberOfParams.fir.kt new file mode 100644 index 00000000000..59575852fbf --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentNumberOfParams.fir.kt @@ -0,0 +1,34 @@ +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: Int, b: String): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: Int, b: String): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: Int, b: String, c: Int = 0): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(1, "") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentReturnTypes.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentReturnTypes.fir.kt new file mode 100644 index 00000000000..d332b7a100f --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/differentReturnTypes.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun getParent(): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun getParent(): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun getParent(): Int +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.getParent() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/extensionMatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/extensionMatch.fir.kt new file mode 100644 index 00000000000..60d54f8cf72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/extensionMatch.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun String.getParent(): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public class C : B { + override fun String.getParent(): B? = null + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun String.getParent(): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun B.test() { + if (this is C) { + "".getParent() + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParams.fir.kt new file mode 100644 index 00000000000..ff4d22e7a93 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParams.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo("") + } +} + +fun test1(b: B?) { + if (b is C) { + b?.foo("") + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsBoundsMismatch.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsBoundsMismatch.fir.kt new file mode 100644 index 00000000000..f9946ea73d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsBoundsMismatch.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface Tr + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + // hard to find parameters for an ambiguous call, so we rely on NONE_APPLICABLE here + // as opposed to diagnostics for a single unmatched candidate + b?.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsEqNull.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsEqNull.fir.kt new file mode 100644 index 00000000000..664571d7d31 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsEqNull.fir.kt @@ -0,0 +1,52 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b == null) return + b?.foo("") +} + +fun test1(b: B?) { + if (b != null) { + b?.foo("") + } +} + +fun test2(b: B?) { + if (b == null) return + b?.foo("") +} + +fun test3(b: B?) { + if (b != null) { + b?.foo("") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsNotIs.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsNotIs.fir.kt new file mode 100644 index 00000000000..e24aee75faf --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsNotIs.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b !is C) return + b?.foo("") +} + +fun test1(b: B?) { + if (b !is C) return + b?.foo("") +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnFooT.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnFooT.fir.kt new file mode 100644 index 00000000000..5e775bc5e72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnFooT.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface Foo + +public interface B { + public fun foo(a: T): Foo +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): Foo + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface Foo + +public interface B { + public fun foo(a: T): Foo +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b !is C) return + b?.foo("") +} + +fun test1(b: B?) { + if (b !is C) return + b?.foo("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnT.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnT.fir.kt new file mode 100644 index 00000000000..494c865981b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/functionGenericsInParamsReturnT.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T): T +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: T): T + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: T): T +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b !is C) return + b?.foo("") +} + +fun test1(b: B?) { + if (b !is C) return + b?.foo("") +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/incompleteCodeNoNoneApplicable.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/incompleteCodeNoNoneApplicable.fir.kt new file mode 100644 index 00000000000..3bd3957db38 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/incompleteCodeNoNoneApplicable.fir.kt @@ -0,0 +1,20 @@ +// MODULE: m1 +// FILE: a.kt +package p + +fun f(s: String, t: String) = s + t + +// MODULE: m2 +// FILE: b.kt +package p + +fun f(s: String, t: String) = t + s + +// MODULE: m3(m1, m2) +// FILE: c.kt +import p.f + +fun test() { + // There should be no "none applicable" error here + f( +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noGenericsInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noGenericsInParams.fir.kt new file mode 100644 index 00000000000..5a5eb3c618f --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noGenericsInParams.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: Int, b: String): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: Int, b: String): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: Int, b: String): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo(1, "") + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noParams.fir.kt new file mode 100644 index 00000000000..67a86edc2e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/noParams.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun getParent(): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public class C : B { + override fun getParent(): B? = null + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun getParent(): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.getParent() + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sameGenericsInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sameGenericsInParams.fir.kt new file mode 100644 index 00000000000..2e8bfca20f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sameGenericsInParams.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNNECESSARY_SAFE_CALL + +// MODULE: m0 +// FILE: a.kt +package p + +public interface G1 +public interface G2 + +// MODULE: m1(m0) +// FILE: a.kt +package p + +public interface B { + public fun foo(a: G1, b: G2): B? +} + +// MODULE: m2(m1, m0) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: G1, b: G2): B? + +} + +// MODULE: m3(m0) +// FILE: b.kt +package p + +public interface B { + public fun foo(a: G1, b: G2): B? +} + +// MODULE: m4(m3, m2, m0) +// FILE: c.kt +import p.* + +fun test(b: B?, a: G1, b1: G2) { + if (b is C) { + b?.foo(a, b1) + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt new file mode 100644 index 00000000000..4076dbb3560 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt @@ -0,0 +1,38 @@ +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun getParent(): B? +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun getParent(): B? + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun getParent(): B? +} + +public interface D : B { + override fun getParent(): B? +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C && b is D) { + b?.getParent() + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sinceKotlin.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sinceKotlin.fir.kt new file mode 100644 index 00000000000..f3aa06a1cf2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/sinceKotlin.fir.kt @@ -0,0 +1,34 @@ +// !API_VERSION: 1.0 +// MODULE: m1 +// FILE: a.kt + +package p1 + +@SinceKotlin("1.1") +fun foo(s: Int): String = s.toString() + +// MODULE: m2 +// FILE: b.kt + +package p2 + +fun foo(s: Int): Int = s + +// MODULE: m3(m1, m2) +// FILE: severalStarImports.kt +import p1.* +import p2.* + +fun test1(): Int { + val r = foo(42) + return r +} + +// FILE: explicitlyImportP1.kt +import p1.foo // TODO: consider reporting API_NOT_AVAILABLE here +import p2.* + +fun test2(): Int { + val r = foo(42) + return r +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/substitutedGenericInParams.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/substitutedGenericInParams.fir.kt new file mode 100644 index 00000000000..e46d3003573 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/substitutedGenericInParams.fir.kt @@ -0,0 +1,34 @@ +// MODULE: m1 +// FILE: a.kt +package p + +public interface B { + public fun foo(a: T) +} + +// MODULE: m2(m1) +// FILE: b.kt +package p + +public interface C : B { + override fun foo(a: String) + +} + +// MODULE: m3 +// FILE: b.kt +package p + +public interface B { + public fun foo(a: String) +} + +// MODULE: m4(m3, m2) +// FILE: c.kt +import p.* + +fun test(b: B?) { + if (b is C) { + b?.foo("") + } +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/differentSuperTraits.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/differentSuperTraits.fir.kt new file mode 100644 index 00000000000..99450485c7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/differentSuperTraits.fir.kt @@ -0,0 +1,31 @@ +// MODULE: m1 +// FILE: x.kt +package p + +public interface Base { + public fun foo() {} +} + +public interface A : Base { + override fun foo() {} +} + +public interface C : A + + +// MODULE: m2 +// FILE: x.kt +package p + +public interface Base { + public fun foo() {} +} + +public interface B : Base + +// MODULE: m3(m1, m2) +// FILE: x.kt + +import p.* + +class Foo: C, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTrait.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTrait.fir.kt new file mode 100644 index 00000000000..b6d5d833f04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTrait.fir.kt @@ -0,0 +1,26 @@ +// MODULE: m1 +// FILE: x.kt +package p + +public interface Base { + public fun foo() {} +} + +public interface A : Base + +// MODULE: m2 +// FILE: x.kt +package p + +public interface Base { + public fun foo() {} +} + +public interface B : Base + +// MODULE: m3(m1, m2) +// FILE: x.kt + +import p.* + +class Foo: A, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt new file mode 100644 index 00000000000..4c1e52747a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt @@ -0,0 +1,29 @@ +// MODULE: m1 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: Array) {} +} + +public interface A : Base + +// MODULE: m2 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: Array) {} +} + +public interface B : Base + +// MODULE: m3(m1, m2) +// FILE: x.kt + +import p.* + +class Foo: A, B { + override fun foo(t: Array) {} + override fun foo(t: Array) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitGenerics.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitGenerics.fir.kt new file mode 100644 index 00000000000..6fceaf1f9e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitGenerics.fir.kt @@ -0,0 +1,26 @@ +// MODULE: m1 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: T) {} +} + +public interface A : Base + +// MODULE: m2 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: T) {} +} + +public interface B : Base + +// MODULE: m3(m1, m2) +// FILE: x.kt + +import p.* + +class Foo: A, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt new file mode 100644 index 00000000000..b7dca29721c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenImportPriority.fir.kt @@ -0,0 +1,37 @@ +// MODULE: m1 +// FILE: a.kt + +package p1 + +@Deprecated("Use p2.A instead", level = DeprecationLevel.HIDDEN) +class A { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt + +package p2 + +class A { + fun m2() {} +} + +// MODULE: m3(m1, m2) +// FILE: severalStarImports.kt +import p1.* +import p2.* + +fun test(a: A) { + a.m1() + a.m2() +} + +// FILE: explicitlyImportP1.kt +import p1.A +import p2.* + +fun test(a: A) { + a.m1() + a.m2() +} diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt new file mode 100644 index 00000000000..2290396a108 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/deprecatedHiddenMultipleClasses.fir.kt @@ -0,0 +1,46 @@ +// MODULE: m1 +// FILE: a.kt + +package p1 + +@Deprecated("1", level = DeprecationLevel.HIDDEN) +class A(val v1: Unit) + +// MODULE: m2 +// FILE: b.kt + +package p2 + +@Deprecated("2", level = DeprecationLevel.HIDDEN) +class A(val v2: Unit) + +// MODULE: m3 +// FILE: c.kt + +package p3 + +@Deprecated("3", level = DeprecationLevel.HIDDEN) +class A(val v3: Unit) + +// MODULE: m4(m1, m2, m3) +// FILE: oneExplicitImportOtherStars.kt +import p1.* +import p2.A +import p3.* + +fun test(a: A) { + a.v1 + a.v2 + a.v3 +} + +// FILE: severalStarImports.kt +import p1.* +import p2.* +import p3.* + +fun test(a: A) { + a.v1 + a.v2 + a.v3 +} diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt new file mode 100644 index 00000000000..0af9e1e0168 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinImportPriority.fir.kt @@ -0,0 +1,38 @@ +// !API_VERSION: 1.0 +// MODULE: m1 +// FILE: a.kt + +package p1 + +@SinceKotlin("1.1") +class A { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt + +package p2 + +class A { + fun m2() {} +} + +// MODULE: m3(m1, m2) +// FILE: severalStarImports.kt +import p1.* +import p2.* + +fun test(a: A) { + a.m1() + a.m2() +} + +// FILE: explicitlyImportP1.kt +import p1.A +import p2.* + +fun test(a: A) { + a.m1() + a.m2() +} diff --git a/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt new file mode 100644 index 00000000000..5979ec665c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/hiddenClass/sinceKotlinMultipleClasses.fir.kt @@ -0,0 +1,47 @@ +// !API_VERSION: 1.0 +// MODULE: m1 +// FILE: a.kt + +package p1 + +@SinceKotlin("1.1") +class A(val v1: Unit) + +// MODULE: m2 +// FILE: b.kt + +package p2 + +@SinceKotlin("1.1") +class A(val v2: Unit) + +// MODULE: m3 +// FILE: c.kt + +package p3 + +@SinceKotlin("1.1") +class A(val v3: Unit) + +// MODULE: m4(m1, m2, m3) +// FILE: oneExplicitImportOtherStars.kt +import p1.* +import p2.A +import p3.* + +fun test(a: A) { + a.v1 + a.v2 + a.v3 +} + +// FILE: severalStarImports.kt +import p1.* +import p2.* +import p3.* + +fun test(a: A) { + a.v1 + a.v2 + a.v3 +} diff --git a/compiler/testData/diagnostics/tests/multimodule/internal.fir.kt b/compiler/testData/diagnostics/tests/multimodule/internal.fir.kt new file mode 100644 index 00000000000..d22b0c4034b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/internal.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// MODULE: m1 +// FILE: a.kt + +package p + +public class A { + internal val a = A() + internal var v = A() + internal fun a() = A() + internal inner class B +} + +internal val a = A() +internal var v = A() +internal fun a() = A() +internal class B + +// MODULE: m2(m1) +// FILE: b.kt + +import p.* + +fun test() { + val _a = a + val _v = v + a() + B() + + val inst = A() + val ia = inst.a + val iv = inst.v + inst.a() + inst.B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/kt14249.fir.kt b/compiler/testData/diagnostics/tests/multimodule/kt14249.fir.kt new file mode 100644 index 00000000000..cbcb03b507a --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/kt14249.fir.kt @@ -0,0 +1,20 @@ +// MODULE: m1 +// FILE: test/Foo.java + +package test; + +class Foo { + static Foo create() { return Foo(); } + void takeFoo(Foo f) {} +} + +// MODULE: m2(m1) +// FILE: test.kt + +package test + +fun test() { + Foo() + val a: Foo = Foo.create() + Foo().takeFoo(a) +} diff --git a/compiler/testData/diagnostics/tests/multimodule/packagePrivate.fir.kt b/compiler/testData/diagnostics/tests/multimodule/packagePrivate.fir.kt new file mode 100644 index 00000000000..2cc1dbbbe05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/packagePrivate.fir.kt @@ -0,0 +1,19 @@ +// MODULE: m1 +// FILE: a.kt + +package p + +private val a = 1 + +// FILE: b.kt + +package p + +val b = a // same package, same module + +// MODULE: m2(m1) +// FILE: c.kt + +package p + +val c = a // same package, another module diff --git a/compiler/testData/diagnostics/tests/multimodule/publishedApiInternal.fir.kt b/compiler/testData/diagnostics/tests/multimodule/publishedApiInternal.fir.kt new file mode 100644 index 00000000000..6828470cc55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/publishedApiInternal.fir.kt @@ -0,0 +1,56 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE +// MODULE: m1 +// FILE: a.kt + +package p + +public class A { + @PublishedApi + internal val a = A() + @PublishedApi + internal var v = A() + @PublishedApi + internal fun a() = A() + @PublishedApi + internal inner class B +} + +@PublishedApi +internal val a = A() +@PublishedApi +internal var v = A() +@PublishedApi +internal fun a() = A() +@PublishedApi +internal class B + +// MODULE: m2(m1) +// FILE: b.kt + +import p.* + +fun test() { + val _a = a + val _v = v + a() + B() + + val inst = A() + val ia = inst.a + val iv = inst.v + inst.a() + inst.B() +} + +inline fun testInline() { + val _a = a + val _v = v + a() + B() + + val inst = A() + val ia = inst.a + val iv = inst.v + inst.a() + inst.B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/redundantElseInWhen.fir.kt b/compiler/testData/diagnostics/tests/multimodule/redundantElseInWhen.fir.kt new file mode 100644 index 00000000000..16e0dd3ddea --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/redundantElseInWhen.fir.kt @@ -0,0 +1,45 @@ +// MODULE: m1 +// FILE: a.kt + +package test + +enum class E { + FIRST +} + +sealed class S + +class Derived : S() + +// MODULE: m2(m1) +// FILE: b.kt + +package other + +import test.* + +fun foo(e: E) = when (e) { + E.FIRST -> 42 + else -> -42 +} + +fun bar(s: S?) = when (s) { + is Derived -> "Derived" + null -> "" + else -> TODO("What?!?!") +} + +fun baz(b: Boolean?) = when (b) { + true -> 1 + false -> 0 + null -> -1 + // Still warning + else -> TODO() +} + +fun baz(b: Boolean) = when (b) { + true -> 1 + false -> 0 + // Still warning + else -> TODO() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/varargConflict.fir.kt b/compiler/testData/diagnostics/tests/multimodule/varargConflict.fir.kt new file mode 100644 index 00000000000..0631d24ad78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/varargConflict.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public fun foo(a: Int) {} +public fun foo(vararg values: Int) {} + +// MODULE: m2 +// FILE: b.kt + +package p + +public fun foo(a: Int) {} +public fun foo(vararg values: Int) {} + +// MODULE: m3(m1, m2) +// FILE: c.kt +package m + +import p.foo + +fun main() { + foo(12) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationArgumentEquality.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationArgumentEquality.fir.kt new file mode 100644 index 00000000000..550215ec4b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationArgumentEquality.fir.kt @@ -0,0 +1,89 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +import kotlin.reflect.KClass + +expect annotation class Primitives( + val z: Boolean = true, + val c: Char = 'c', + val b: Byte = 42.toByte(), + val s: Short = (-1).toShort(), + val i: Int = -42, + val f: Float = 2.72f, + val j: Long = 123456789123456789L, + val d: Double = 3.14159265358979 +) + +expect annotation class PrimitiveArrays( + val z: BooleanArray = [true], + val c: CharArray = ['c'], + val b: ByteArray = [42.toByte()], + val s: ShortArray = [(-1).toShort()], + val i: IntArray = [-42], + val f: FloatArray = [2.72f], + val j: LongArray = [123456789123456789L], + val d: DoubleArray = [3.14159265358979] +) + +enum class En { A, B } + +annotation class Anno(val value: String = "Anno") + +expect annotation class Classes( + val s: String = "OK", + val e: En = En.B, + // TODO: this does not work at the moment because AnnotationDescriptor subclasses do not implement equals correctly + // val a: Anno = Anno(), + val k: KClass<*> = List::class +) + +expect annotation class ClassArrays( + val s: Array = ["OK"], + val e: Array = [En.B], + // val a: Array = [Anno()], + val k: Array> = [List::class], + vararg val v: Int = [42] +) + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +import kotlin.reflect.KClass + +actual annotation class Primitives( + actual val z: Boolean = true, + actual val c: Char = 'c', + actual val b: Byte = 42.toByte(), + actual val s: Short = (-1).toShort(), + actual val i: Int = -42, + actual val f: Float = 2.72f, + actual val j: Long = 123456789123456789L, + actual val d: Double = 3.14159265358979 +) + +actual annotation class PrimitiveArrays( + actual val z: BooleanArray = [true], + actual val c: CharArray = ['c'], + actual val b: ByteArray = [42.toByte()], + actual val s: ShortArray = [(-1).toShort()], + actual val i: IntArray = [-42], + actual val f: FloatArray = [2.72f], + actual val j: LongArray = [123456789123456789L], + actual val d: DoubleArray = [3.14159265358979] +) + +actual annotation class Classes( + actual val s: String = "OK", + actual val e: En = En.B, + // actual val a: Anno = Anno(), + actual val k: KClass<*> = List::class +) + +actual annotation class ClassArrays( + actual val s: Array = ["OK"], + actual val e: Array = [En.B], + // actual val a: Array = [Anno()], + actual val k: Array> = [List::class], + actual vararg val v: Int = [42] +) diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotations.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotations.fir.kt new file mode 100644 index 00000000000..80ee3795709 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotations.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect annotation class A1(val x: Int, val y: String = "OK") + +expect annotation class A2(val x: Int = 42, val y: String = "OK") + +expect annotation class A3(val x: Int, val y: String) + +expect annotation class A4(val x: Int = 42, val y: String) + +expect annotation class A5(val x: Int = 42, val y: String) + +@A1(0) +@A2 +@A3(0, "") +@A4(0, "") +@A5(0, "") +fun test() {} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual annotation class A1(actual val x: Int, actual val y: String) + +actual annotation class A2(actual val x: Int, actual val y: String = "OK") + +actual annotation class A3(actual val x: Int = 42, actual val y: String = "OK") + +actual annotation class A4(actual val x: Int, actual val y: String = "OK") + +actual annotation class A5(actual val x: Int = 239, actual val y: String = "OK") diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias.fir.kt new file mode 100644 index 00000000000..0fdad4b88fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias.fir.kt @@ -0,0 +1,64 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect annotation class A1(val x: Int, val y: String = "OK") + +expect annotation class A2(val x: Int = 42, val y: String = "OK") + +expect annotation class A3(val x: Int, val y: String) + +expect annotation class A4(val x: Int = 42, val y: String) + +expect annotation class A5(val x: Int = 42, val y: String) + +@A1(0) +@A2 +@A3(0, "") +@A4(0, "") +@A5(0, "") +fun test() {} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias A1 = J1 +actual typealias A2 = J2 +actual typealias A3 = J3 +actual typealias A4 = J4 +actual typealias A5 = J5 + +// FILE: J1.java + +public @interface J1 { + int x(); + String y(); +} + +// FILE: J2.java + +public @interface J2 { + int x(); + String y() default "OK"; +} + +// FILE: J3.java + +public @interface J3 { + int x() default 42; + String y() default "OK"; +} + +// FILE: J4.java + +public @interface J4 { + int x(); + String y() default "OK"; +} + +// FILE: J5.java + +public @interface J5 { + int x() default 239; + String y() default "OK"; +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias2.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias2.fir.kt new file mode 100644 index 00000000000..71e75036b5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias2.fir.kt @@ -0,0 +1,79 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +// See also compiler/testData/codegen/boxAgainstJava/multiplatform/annotationsViaActualTypeAliasFromBinary.kt + +import kotlin.reflect.KClass + +expect annotation class Anno( + val b: Byte = 1.toByte(), + val c: Char = 'x', + val d: Double = 3.14, + val f: Float = -2.72f, + val i: Int = 42424242, + val i2: Int = 53535353, + val j: Long = 239239239239239L, + val j2: Long = 239239L, + val s: Short = 42.toShort(), + val z: Boolean = true, + val ba: ByteArray = [(-1).toByte()], + val ca: CharArray = ['y'], + val da: DoubleArray = [-3.14159], + val fa: FloatArray = [2.7218f], + val ia: IntArray = [424242], + val ja: LongArray = [239239239239L, 239239L], + val sa: ShortArray = [(-43).toShort()], + val za: BooleanArray = [false, true], + val str: String = "fizz", + val k: KClass<*> = Number::class, + val e: E = E.E1, + // TODO: val a: A = A("1"), + val stra: Array = ["bu", "zz"], + val ka: Array> = [Double::class, String::class, LongArray::class, Array>>::class, Unit::class], + val ea: Array = [E.E2, E.E3] + // TODO: val aa: Array = [A("2"), A("3")] +) + +enum class E { E1, E2, E3 } + +annotation class A(val value: String) + +@Anno +fun test() {} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias Anno = Jnno + +// FILE: Jnno.java + +public @interface Jnno { + byte b() default 1; + char c() default 'x'; + double d() default 3.14; + float f() default -2.72f; + int i() default 42424242; + int i2() default 21212121 + 32323232; + long j() default 239239239239239L; + long j2() default 239239; + short s() default 42; + boolean z() default true; + byte[] ba() default {-1}; + char[] ca() default {'y'}; + double[] da() default {-3.14159}; + float[] fa() default {2.7218f}; + int[] ia() default {424242}; + long[] ja() default {239239239239L, 239239}; + short[] sa() default {-43}; + boolean[] za() default {false, true}; + String str() default "fi" + "zz"; + Class k() default Number.class; + E e() default E.E1; + // TODO: A a() default @A("1"); + String[] stra() default {"bu", "zz"}; + Class[] ka() default {double.class, String.class, long[].class, Integer[][][].class, void.class}; + E[] ea() default {E.E2, E.E3}; + // TODO: A[] aa() default {@A("2"), @A("3")}; +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/constructor.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/constructor.fir.kt new file mode 100644 index 00000000000..d801d2363de --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/constructor.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Ok(x: Int, y: String = "") + +expect class FailX(x: Int, y: String = "") + +expect class FailY(x: Int, y: String = "") + +fun test() { + Ok(42) + Ok(42, "OK") +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class Ok actual constructor(x: Int, y: String) + +actual class FailX actual constructor(x: Int = 0, y: String) + +actual class FailY actual constructor(x: Int, y: String = "") diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedDeclaresDefaultArguments.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedDeclaresDefaultArguments.fir.kt new file mode 100644 index 00000000000..fbf064e3270 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedDeclaresDefaultArguments.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun ok(x: Int, y: String = "") + +expect fun failX(x: Int, y: String = "") + +expect fun failY(x: Int, y: String = "") + +expect open class Foo { + fun ok(x: Int, y: String = "") + + fun failX(x: Int, y: String = "") + + fun failY(x: Int, y: String = "") +} + +fun test(foo: Foo) { + ok(42) + ok(42, "OK") + foo.ok(42) + foo.ok(42, "OK") +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun ok(x: Int, y: String) {} + +actual fun failX(x: Int = 0, y: String) {} + +actual fun failY(x: Int, y: String = "") {} + +actual open class Foo { + actual fun ok(x: Int, y: String) {} + + actual fun failX(x: Int = 0, y: String) {} + + actual fun failY(x: Int, y: String = "") {} +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedInheritsDefaultArguments.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedInheritsDefaultArguments.fir.kt new file mode 100644 index 00000000000..1fb2506bad2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedInheritsDefaultArguments.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface Foo { + fun ok(x: Int, y: String = "") + + fun failX(x: Int, y: String = "") + + fun failY(x: Int, y: String = "") +} + +expect class Bar : Foo { + override fun ok(x: Int, y: String) + + override fun failX(x: Int, y: String) + + override fun failY(x: Int, y: String) +} + +fun test(foo: Foo, bar: Bar) { + foo.ok(42) + foo.ok(42, "OK") + bar.ok(42) + bar.ok(42, "OK") +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class Bar : Foo { + actual override fun ok(x: Int, y: String) {} + + actual override fun failX(x: Int = 0, y: String) {} + + actual override fun failY(x: Int, y: String = "") {} +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedVsNonExpectedWithDefaults.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedVsNonExpectedWithDefaults.fir.kt new file mode 100644 index 00000000000..b77b263b686 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/defaultArguments/expectedVsNonExpectedWithDefaults.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1-common +// FILE: common.kt + +expect fun ok(x: Int, y: String = "") + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun ok(x: Int, y: String) {} + +fun ok(x: Int, y: Long = 1L) {} + +fun test() { + ok(1) +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/deprecated/header.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/deprecated/header.fir.kt new file mode 100644 index 00000000000..04c968e8d9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/deprecated/header.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +header class My + +header fun foo(): Int + +header val x: String + +header object O + +header enum class E { + FIRST +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +impl class My + +impl fun foo() = 42 + +impl val x get() = "Hello" + +impl object O + +impl enum class E { + FIRST +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/additionalEntriesInImpl.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/additionalEntriesInImpl.fir.kt new file mode 100644 index 00000000000..0fdbc9c2816 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/additionalEntriesInImpl.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect enum class Foo { A, B } +expect enum class Bar { X, Y, Z } + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual enum class Foo { A, B, C, D, E } +actual enum class Bar { V, X, W, Y, Z } diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt new file mode 100644 index 00000000000..635e8e827d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect enum class En(x: Int) { + E1, + E2(42), + ; + + constructor(s: String) +} + +expect enum class En2 { + E1() +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/differentEntryOrder.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/differentEntryOrder.fir.kt new file mode 100644 index 00000000000..a0928c8d2ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/differentEntryOrder.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect enum class Foo { A, B } +expect enum class Bar { X, Y, Z } + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual enum class Foo { B, A } +actual enum class Bar { X, Z, Y } diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.fir.kt new file mode 100644 index 00000000000..0e3986250ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect enum class En { + E1, + E2 { + fun foo() = "" + }, + E3 { }; +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.fir.kt new file mode 100644 index 00000000000..5072b4f2cd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect enum class Foo { + ENTRY +} + +expect enum class _TimeUnit + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual typealias Foo = FooImpl + +actual typealias _TimeUnit = java.util.concurrent.TimeUnit + +// FILE: FooImpl.java +public enum FooImpl { + ENTRY("OK") { + @Override + public String getResult() { + return value; + } + }; + + protected final String value; + + public FooImpl(String value) { + this.value = value; + } + + public abstract String getResult(); +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.fir.kt new file mode 100644 index 00000000000..853f3029a2c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect enum class Foo { + ENTRY1, + ENTRY2, + ENTRY3; +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual enum class Foo(val x: String) { + ENTRY1("1"), + ENTRY2("2"), + ENTRY3("3"); +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/generic/functionTypeParameterBounds.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/generic/functionTypeParameterBounds.fir.kt new file mode 100644 index 00000000000..8023137fd55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/generic/functionTypeParameterBounds.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun > Array.sort(): Unit + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun > Array.sort(): Unit {} + +fun Array.sort(): Unit {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/generic/genericMemberBounds.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/generic/genericMemberBounds.fir.kt new file mode 100644 index 00000000000..e13adfe8d64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/generic/genericMemberBounds.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class A { + fun foo(): Unit + + fun > bar(): List +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias A = JavaA + +// FILE: JavaA.java +import java.util.List; + +public class JavaA { + public void foo() {} + + public > List bar() { + return null; + } +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/generic/membersInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/generic/membersInGenericClass.fir.kt new file mode 100644 index 00000000000..109e6652f72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/generic/membersInGenericClass.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect interface A { + val x: T + var y: List + fun f(p: Collection): Map> +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual interface A { + actual val x: T + actual var y: List + actual fun f(p: Collection): Map> +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/generic/typeParameterBoundsDifferentOrderActualMissing.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/generic/typeParameterBoundsDifferentOrderActualMissing.fir.kt new file mode 100644 index 00000000000..309c8d14dce --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/generic/typeParameterBoundsDifferentOrderActualMissing.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface A +interface B + +expect fun List.foo() where T : A, T : B + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +fun List.foo() where T : B, T : A {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.fir.kt new file mode 100644 index 00000000000..f632ea1d20c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect annotation class Foo1 +expect annotation class Foo2 +expect annotation class Foo3 +expect annotation class Foo4 +expect annotation class Foo5() +expect annotation class Foo6() +expect annotation class Foo7() + +@Foo1 +fun foo() {} + +@Foo5 +fun bar() {} + +// MODULE: m2-jvm(m1-common) + +// FILE: Bar1.java + +public @interface Bar1 { + String value() default ""; +} + +// FILE: Bar2.java + +public @interface Bar2 { + String value() default ""; + String path(); +} + +// FILE: jvm.kt + +actual typealias Foo1 = Bar1 + +actual typealias Foo4 = Bar2 + +actual annotation class Foo2(val p: String = "default") + +actual annotation class Foo3(val a: String = "a", val b: String = "b") + +actual annotation class Foo5 + +actual annotation class Foo6(val s: String = "value") + +actual typealias Foo7 = Bar2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDifferentConstructors.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDifferentConstructors.fir.kt new file mode 100644 index 00000000000..d9998d3d679 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDifferentConstructors.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo1 +expect class Foo2 +expect class Foo3 + +expect class Bar1() +expect class Bar2() +expect class Bar3() +expect class Bar4() +expect class Bar5() +expect class Bar6() +expect class Bar7(s: String) + +// MODULE: m2-jvm(m1-common) + +// FILE: JavaFoo.java + +public class JavaFoo { + public JavaFoo(int i) {} +} + +// FILE: JavaBar.java + +public class JavaBar { + public JavaBar(int i) {} +} + +// FILE: jvm.kt + +actual class Foo1(val s: String) +actual class Foo2(val p: String = "value", i: Int) +actual typealias Foo3 = JavaFoo + +actual class Bar1(val s: String) +actual class Bar2(val p: String = "value", i: Int) +actual typealias Bar3 = JavaBar +actual class Bar4(val s: String) { + constructor() : this("") +} + +actual class Bar5 { + actual constructor() + constructor(s: String) +} + +class Bar6 { + actual constructor() +} + +actual class Bar7 actual constructor(s: String) { + constructor() : this("") +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt new file mode 100644 index 00000000000..b6b5439476b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class A { + fun foo() +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +class A { + actual fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/baseExpectClassWithoutConstructor.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/baseExpectClassWithoutConstructor.fir.kt new file mode 100644 index 00000000000..f461354aa08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/baseExpectClassWithoutConstructor.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect open class A +expect class B : A +open class C : A + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +actual open class A +actual class B : A() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/classKinds.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/classKinds.fir.kt new file mode 100644 index 00000000000..d8f41113255 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/classKinds.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect interface Interface + +expect annotation class Anno(val prop: String) + +expect object Object + +expect class Class + +expect enum class En { ENTRY } + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual interface Interface + +actual annotation class Anno actual constructor(actual val prop: String) + +actual object Object + +actual class Class + +actual enum class En { ENTRY } diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/dontOverrideMethodsFromInterfaceInCommonCode.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/dontOverrideMethodsFromInterfaceInCommonCode.fir.kt new file mode 100644 index 00000000000..6aba00b82ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/dontOverrideMethodsFromInterfaceInCommonCode.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface Foo { + fun foo() +} + +expect class ImplicitFoo : Foo + +expect class ExplicitFoo : Foo { + override fun foo() +} + +expect class ImplicitFooCheck : Foo + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class ImplicitFoo : Foo { + override fun foo() {} +} + +actual class ExplicitFoo : Foo { + actual override fun foo() {} +} + +actual class ImplicitFooCheck : Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithExplicitAbstractMember.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithExplicitAbstractMember.fir.kt new file mode 100644 index 00000000000..901cb01a6d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithExplicitAbstractMember.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface Foo { + fun foo() +} + +expect class NonAbstractClass : Foo { + abstract fun bar() + + abstract val baz: Int + + abstract override fun foo() +} + +expect abstract class AbstractClass : Foo { + abstract fun bar() + + abstract val baz: Int + + abstract override fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt new file mode 100644 index 00000000000..cf76d6cbf37 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo +expect class Bar() +expect class Baz constructor() +expect class FooBar { + constructor() +} + +fun test() { + Foo() + Bar() + Baz() + FooBar() +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class Foo +actual class Bar +actual class Baz +actual class FooBar \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.fir.kt new file mode 100644 index 00000000000..615437435a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1-common +// FILE: common.kt + +expect fun foo1(x: Int) +expect fun foo2(x: Int) + +expect class NoArgConstructor() + +expect fun foo3(): Int +expect fun foo4(): Int + +// MODULE: m2-jvm(m1-common) + +// FILE: jvm.kt + +actual fun foo1(x: Int) {} + +fun foo1(x: Int, y: Int) {} +fun foo1(x: String) {} + +fun foo2(x: Int, y: Int) {} +fun foo2(x: String) {} + +actual fun foo3(): String = "" +fun foo4(x: Int): String = "" + +actual class NoArgConstructor { + actual constructor() + actual constructor(x: Int) + constructor(x: String) +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.fir.kt new file mode 100644 index 00000000000..e51224eba3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1-common +// FILE: common.kt + +expect class Foo1 +expect class Foo2 + +expect fun foo2(): Int + +expect val s: String + +expect open class Foo3 + +// MODULE: m2-jvm(m1-common) + +// FILE: jvm.kt + +interface Foo1 +actual interface Foo2 + +actual var s: String = "value" + +fun foo2(): Int = 0 + +actual class Foo3 + +class Foo3 diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectFinalActualOpen.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectFinalActualOpen.fir.kt new file mode 100644 index 00000000000..63088d416ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectFinalActualOpen.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + fun f() + val v: String +} + +expect class Bar { + fun g() +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual open class Foo(actual open val v: String) { + actual open fun f() {} +} + +actual typealias Bar = JavaBar + +// FILE: JavaBar.java + +public class JavaBar { + public void g() {} +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/explicitConstructorDelegation.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/explicitConstructorDelegation.fir.kt new file mode 100644 index 00000000000..c5b897ca5db --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/explicitConstructorDelegation.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect open class A { + constructor(s: String) + + constructor(n: Number) : this("A") +} + +expect class B : A { + constructor(i: Int) + + constructor() : super("B") +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithAbstractMember.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithAbstractMember.fir.kt new file mode 100644 index 00000000000..58af3847cb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithAbstractMember.fir.kt @@ -0,0 +1,62 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect abstract class BaseA() { + abstract fun foo() +} +expect open class BaseAImpl() : BaseA + +class DerivedA1 : BaseAImpl() +class DerivedA2 : BaseAImpl() { + override fun foo() = super.foo() +} + + + +expect interface BaseB { + fun foo() +} +expect open class BaseBImpl() : BaseB + +class DerivedB1 : BaseBImpl() +class DerivedB2 : BaseBImpl() { + override fun foo() = super.foo() +} + + + +expect interface BaseC { + fun foo() +} +expect abstract class BaseCImpl() : BaseC + +class DerivedC1 : BaseCImpl() +class DerivedC2 : BaseCImpl() { + override fun foo() = super.foo() +} + + + +expect interface BaseD { + fun foo() +} +abstract class BaseDImpl() : BaseD { + fun bar() = super.foo() +} + + + +expect interface BaseE { + fun foo() +} +sealed class BaseEImpl() : BaseE { + fun bar() = super.foo() +} + + + +expect interface BaseF { + fun foo() +} +expect class BaseFImpl() : BaseF diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithoutExplicitOverrideOfMethod.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithoutExplicitOverrideOfMethod.fir.kt new file mode 100644 index 00000000000..c2db2cca892 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extendExpectedClassWithoutExplicitOverrideOfMethod.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect abstract class Base { + abstract fun foo() +} + +expect class DerivedImplicit : Base + +expect class DerivedExplicit : Base { + override fun foo() +} + +expect class DerivedExplicitCheck : Base { + override fun foo() +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual abstract class Base { + actual abstract fun foo() +} + +actual class DerivedImplicit : Base() { + override fun foo() {} +} + +actual class DerivedExplicit : Base() { + actual override fun foo() {} +} + +actual class DerivedExplicitCheck : Base() { + override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/extraHeaderOnMembers.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extraHeaderOnMembers.fir.kt new file mode 100644 index 00000000000..fe29843bf5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/extraHeaderOnMembers.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class H { + expect fun foo() +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +actual class H { + actual fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.fir.kt new file mode 100644 index 00000000000..79af20b647b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + val bar: String +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +actual class Foo { + actual val bar = "bar" + fun bar() = bar +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.fir.kt new file mode 100644 index 00000000000..f732153f8c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -ACTUAL_WITHOUT_EXPECT +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class C1 +expect interface C2 +expect interface C3 +expect interface C4 +expect interface C5 +expect interface C6 +expect interface C7 +expect interface C8 +expect interface C9 +expect interface C10 + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias C1 = String +actual typealias C2 = List +actual typealias C3 = List +actual typealias C4 = MutableMap +actual typealias C5 = MutableMap +actual typealias C6 = MutableList +actual typealias C7 = MutableList +actual typealias C8 = MutableList<*> +actual typealias C9 = MutableList + +typealias Tmp = MutableList +actual typealias C10 = Tmp diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassMember.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassMember.fir.kt new file mode 100644 index 00000000000..89ac1118e5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassMember.fir.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect class Foo { + val foo: String + + fun bar(x: Int): Int +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual class Foo { + actual val foo: String = "JVM" + + actual fun bar(x: Int): Int = x + 1 +} + +// MODULE: m3-js(m1-common) +// FILE: js.kt +actual class Foo { + actual val foo: String = "JS" + + actual fun bar(x: Int): Int = x - 1 +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassWithFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassWithFunctionBody.fir.kt new file mode 100644 index 00000000000..338c52d9816 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/headerClassWithFunctionBody.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect class Foo( + val constructorProperty: String, + constructorParameter: String +) { + init { + "no" + } + + constructor(s: String) { + "no" + } + + constructor() : this("no") + + val prop: String = "no" + + var getSet: String + get() = "no" + set(value) {} + + fun functionWithBody(x: Int): Int { + return x + 1 + } +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/implDataClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/implDataClass.fir.kt new file mode 100644 index 00000000000..06bdbf3b645 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/implDataClass.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo(x: Int, y: String) { + val x: Int + val y: String +} + +expect class Bar(z: Double) + +expect class Baz(w: List) { + val w: List + + operator fun component1(): List + + // Disabled because default arguments are not allowed + // fun copy(w: List = ...): Baz + + override fun equals(other: Any?): Boolean + override fun hashCode(): Int + override fun toString(): String +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual data class Foo actual constructor(actual val x: Int, actual val y: String) + +actual data class Bar actual constructor(val z: Double) + +actual data class Baz actual constructor(actual val w: List) diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/implOpenClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/implOpenClass.fir.kt new file mode 100644 index 00000000000..f115edd5638 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/implOpenClass.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo + +expect fun getFoo(): Foo + +fun bar() {} // no "Foo is final" warning should be here + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual open class Foo + +class Bar : Foo() + +actual fun getFoo(): Foo = Bar() diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/inheritanceByDelegationInExpectClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/inheritanceByDelegationInExpectClass.fir.kt new file mode 100644 index 00000000000..cd03ae5bf0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/inheritanceByDelegationInExpectClass.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface A + +class B : A +expect class Foo(b: B) : A by b + +expect class Bar : A by B() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.fir.kt new file mode 100644 index 00000000000..cc6004b6ea3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + val justVal: String + var justVar: String + + val String.extensionVal: Unit + var T.genericExtensionVar: T + + val valWithGet: String + get + var varWithGetSet: String + get set + + val backingFieldVal: String = "no" + var backingFieldVar: String = "no" + + val customAccessorVal: String + get() = "no" + var customAccessorVar: String + get() = "no" + set(value) {} + + lateinit var lateinitVar: String + + val delegated: String by Delegate +} + +object Delegate { operator fun getValue(x: Any?, y: Any?): String = "" } diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.fir.kt new file mode 100644 index 00000000000..b81079ecae1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.fir.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo1 { + val x: String +} + +expect class Foo2 { + val x: String +} + +expect class Foo3 { + val x: String +} + +// MODULE: m2-jvm(m1-common) + +// FILE: jvm.kt + +open class Open { + open val x = "42" +} + +actual open class Foo1 : Open() { + override val x = super.x +} + +actual open class Foo2 : Open() + +open class WithFinal { + val x = "42" +} + +actual open class Foo3 : WithFinal() diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActual.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActual.fir.kt new file mode 100644 index 00000000000..649d8c1888f --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActual.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1-common +// FILE: common.kt + +expect open class Container { + fun publicFun() + + internal fun internalFun1() + internal fun internalFun2() + internal fun internalFun3() + + protected fun protectedFun1() + protected fun protectedFun2() + protected fun protectedFun3() + + open internal fun openInternalFun() + open fun openPublicFun() +} + +// MODULE: m2-jvm(m1-common) + +// FILE: jvm.kt + +actual open class Container { + actual fun publicFun() {} // OK: public -> public + + actual fun internalFun1() {} // OK: internal -> public + actual internal fun internalFun2() {} // OK: internal -> internal + + actual fun protectedFun1() {} // OK: protected -> public + actual protected fun protectedFun2() {} // OK: protected -> protected + + actual internal fun protectedFun3() {} // BAD: protected -> internal + actual protected fun internalFun3() {} // BAD: internal -> protected + + actual open fun openInternalFun() {} // BAD: internal+open -> public + actual internal fun openPublicFun() {} // BAD: open+public -> internal +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActualViaTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActualViaTypeAlias.fir.kt new file mode 100644 index 00000000000..5a44875cda6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/morePermissiveVisibilityOnActualViaTypeAlias.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1-common +// FILE: common.kt + +expect open class Container { + internal fun internalFun() +} + +// MODULE: m2-jvm(m1-common) + +// FILE: foo/Foo.java + +package foo; + +public class Foo { + public final void internalFun() {} // OK: internal -> public +} + +// FILE: jvm.kt + +actual typealias Container = foo.Foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClasses.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClasses.fir.kt new file mode 100644 index 00000000000..ba17319f3dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClasses.fir.kt @@ -0,0 +1,58 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class OuterClass { + class NestedClass { + class DeepNested { + class Another { + fun f(s: String) + val p: Int + } + } + } + + inner class InnerClass { + fun f(x: Int) + val p: String + } + + companion object +} + +expect class OuterClassWithNamedCompanion { + companion object Factory +} + +expect object OuterObject { + object NestedObject +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class OuterClass { + actual class NestedClass { + actual class DeepNested { + actual class Another { + actual fun f(s: String) {} + actual val p: Int = 42 + } + } + } + + actual inner class InnerClass { + actual fun f(x: Int) {} + actual val p: String = "" + } + + actual companion object +} + +actual class OuterClassWithNamedCompanion { + actual companion object Factory +} + +actual object OuterObject { + actual object NestedObject +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClassesWithErrors.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClassesWithErrors.fir.kt new file mode 100644 index 00000000000..8f47be93d20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/nestedClassesWithErrors.fir.kt @@ -0,0 +1,46 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class B { + class N { + fun body() {} + expect fun extraHeader() + } +} + +expect class C { + expect class N + expect enum class E + expect inner class I +} + +expect class D { + class N +} + +expect class E { + class N +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +actual class B { + actual class N { + actual fun body() {} + actual fun extraHeader() {} + } +} + +actual class C { + actual class N + actual enum class E + actual inner class I +} + +actual class D + +actual class E { + class N +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/noImplKeywordOnMember.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/noImplKeywordOnMember.fir.kt new file mode 100644 index 00000000000..b12c5d39467 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/noImplKeywordOnMember.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + fun bar(): String +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class Foo { + fun bar(): String = "bar" +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/privateMembers.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/privateMembers.fir.kt new file mode 100644 index 00000000000..fe2e20bb2ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/privateMembers.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class A { + private fun foo() + private val bar: String + private fun Int.memExt(): Any + + private class Nested +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt + +actual class A { + private fun foo() {} + private val bar: String = "" + actual private fun Int.memExt(): Any = 0 + + actual private class Nested +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/simpleHeaderClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/simpleHeaderClass.fir.kt new file mode 100644 index 00000000000..d4032bccead --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/simpleHeaderClass.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect class Foo + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual class Foo + +// MODULE: m3-js(m1-common) +// FILE: js.kt +actual class Foo diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/smartCastOnExpectClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/smartCastOnExpectClass.fir.kt new file mode 100644 index 00000000000..bb2649aa8ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/smartCastOnExpectClass.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { // also, it's important that Foo doesn't override equals + fun foo() +} + +fun check(x1: Foo, x: Any) { + if (x1 == x) { + x.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/superClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/superClass.fir.kt new file mode 100644 index 00000000000..25dafe6fef2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/superClass.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +interface I +open class C +interface J + +expect class Foo : I, C, J + +expect class Bar : C() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual class Foo : I, C(), J + +actual class Bar + +// MODULE: m3-js(m1-common) +// FILE: js.kt +actual class Foo : I, J, C() + +actual class Bar : C() diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerFunInNonHeaderClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerFunInNonHeaderClass.fir.kt new file mode 100644 index 00000000000..160a0998301 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/headerFunInNonHeaderClass.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +class Foo { + expect fun bar(): String +} + +// MODULE: m1-jvm(m1-common) +// FILE: jvm.kt diff --git a/compiler/testData/diagnostics/tests/multiplatform/implDelegatedMember.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/implDelegatedMember.fir.kt new file mode 100644 index 00000000000..9d3e9381025 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/implDelegatedMember.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect open class Foo { + open fun bar(): String +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +interface Bar { + fun bar(): String +} + +val bar: Bar + get() = null!! + +actual open class Foo : Bar by bar diff --git a/compiler/testData/diagnostics/tests/multiplatform/implDynamic.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/implDynamic.fir.kt new file mode 100644 index 00000000000..8f5f15bc218 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/implDynamic.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -UNSUPPORTED +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + constructor(p: Any) + + fun f1(s: String): Int + + fun f2(s: List?): MutableMap + + fun > f3(t: T): T? +} + +// MODULE: m2-js(m1-common) +// FILE: js.kt + +// TODO: do not suppress UNSUPPORTED once JS files in multi-platform tests are analyzed with JS analyzer facade + +actual class Foo { + actual constructor(p: dynamic) {} + + actual fun f1(s: dynamic): dynamic = null!! + + actual fun f2(s: dynamic): MutableMap = null!! + + actual fun > f3(t: T): dynamic = null!! +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/implFakeOverride.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/implFakeOverride.fir.kt new file mode 100644 index 00000000000..6b0167213e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/implFakeOverride.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + fun bar(): String +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +open class Bar { + fun bar() = "bar" +} + +actual class Foo : Bar() diff --git a/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt new file mode 100644 index 00000000000..3c6b058712a --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +MultiPlatformProjects + +header impl class First + +header expect class Second + +header actual class Third + +impl expect class Fourth + +impl actual class Fifth + +expect actual class Sixth \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/inlineClasses/expectActualInlineClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/inlineClasses/expectActualInlineClass.fir.kt new file mode 100644 index 00000000000..16e9f770049 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/inlineClasses/expectActualInlineClass.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +MultiPlatformProjects, +InlineClasses +// MODULE: m1-common +// FILE: common.kt + +expect inline class Foo1(val x: Int) { + fun bar(): String +} + +expect inline class Foo2(val x: Int) + +expect inline class Foo3 + +expect class NonInlineExpect + +expect inline class NonInlineActual(val x: Int) + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual inline class Foo1(val x: Int) { + actual fun bar(): String = "Hello" +} +actual inline class Foo2(val x: String) +actual inline class Foo3 + +actual inline class NonInlineExpect(val x: Int) + +actual class NonInlineActual actual constructor(actual val x: Int) diff --git a/compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.fir.kt new file mode 100644 index 00000000000..0c9ce6637e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + constructor(p: Any) + + fun f1(s: String): Int + + fun f2(s: List?): MutableMap + + fun > f3(t: T): T? +} + +// MODULE: m2-jvm(m1-common) +// FILE: FooImpl.java + +import java.util.*; + +public class FooImpl { + public FooImpl(Object p) {} + + public final int f1(String s) { return 0; } + + public final Map f2(List s) { return null; } + + public final > T f3(T t) { return null; } +} + +// FILE: jvm.kt + +actual typealias Foo = FooImpl diff --git a/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.fir.kt new file mode 100644 index 00000000000..e20079bebaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo { + fun foo(i: Int, d: Double, f: Float): Unit +} + +// MODULE: m2-jvm(m1-common) +// FILE: FooImpl.java + +public class FooImpl { + public final void foo(int d, double i, float f) {} +} + +// FILE: jvm.kt + +actual typealias Foo = FooImpl diff --git a/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt new file mode 100644 index 00000000000..a4fc5ba6c13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect typealias Foo = String + +class Outer expect constructor() { + expect class Nested + + expect init {} + + expect fun foo() + expect val bar: Int +} + +fun foo() { + expect fun localFun() + expect var x = 42 + expect class Bar +} + +// MODULE: m2-jvm +// FILE: jvm.kt + +class Outer actual constructor() { + actual class Nested + + actual init {} +} + +fun foo() { + actual fun localFun() {} + actual var x = 42 + actual class Bar +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt new file mode 100644 index 00000000000..acd1bb85ef5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect class Foo(zzz: Int) { + constructor(aaa: Boolean) + + fun f1(xxx: String): String +} + +expect fun f2(xxx: Int) + +fun testCommon() { + Foo(zzz = 0) + val f = Foo(aaa = true) + f.f1(xxx = "") + f2(xxx = 42) +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual class Foo actual constructor(val aaa: Boolean) { + actual constructor(zzz: Int) : this(zzz == 0) + + actual fun f1(xxx: String) = xxx +} + +actual fun f2(xxx: Int) {} + +fun testPlatform() { + Foo(zzz = 0) + val f = Foo(aaa = true) + f.f1(xxx = "") + f2(xxx = 42) +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.fir.kt new file mode 100644 index 00000000000..1b28447d41b --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +private expect fun foo() +private expect val bar: String +private expect fun Int.memExt(): Any + +private expect class Foo + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +private actual fun foo() {} +private actual val bar: String = "" +private actual fun Int.memExt(): Any = 0 + +private actual class Foo diff --git a/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAlias.fir.kt new file mode 100644 index 00000000000..8694b547fb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAlias.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect sealed class Presence { + object Online: Presence + object Offline: Presence +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias Presence = P +sealed class P { + object Online : P() + object Offline : P() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAliasTopLevel.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAliasTopLevel.fir.kt new file mode 100644 index 00000000000..f2f0aab5368 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/sealedTypeAliasTopLevel.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect sealed class Presence +expect object Online: Presence +expect object Offline: Presence + + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual typealias Presence = P +sealed class P +actual object Online : P() +actual object Offline : P() diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callHeaderFun.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callHeaderFun.fir.kt new file mode 100644 index 00000000000..722251b5fc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callHeaderFun.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo(x: Int): Int + +fun callFromCommonCode(x: Int) = foo(x) + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun foo(x: Int): Int { + return x + 1 +} + +fun callFromJVM(x: Int) = foo(x) + +// MODULE: m3-js(m1-common) +// FILE: js.kt + +actual fun foo(x: Int): Int { + return x - 1 +} + +fun callFromJS(x: Int) = foo(x) diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.fir.kt new file mode 100644 index 00000000000..0c3024de2fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +package test + +expect fun foo(): String + +fun g(f: () -> String): String = f() + +fun test() { + g(::foo) +} + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +package test + +@Deprecated("To check that ::foo is resolved to actual fun foo when compiling common+jvm") +actual fun foo(): String = "" diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.fir.kt new file mode 100644 index 00000000000..c7b164c9192 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo() +expect fun foo() + +expect fun foo(x: Int) diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingImplDeclarations.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingImplDeclarations.fir.kt new file mode 100644 index 00000000000..da6dad9b6c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingImplDeclarations.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun foo() {} +actual fun foo() {} + +// MODULE: m3-js(m1-common) +// FILE: js.kt + +actual fun foo() {} +actual fun foo() {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/functionModifiers.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/functionModifiers.fir.kt new file mode 100644 index 00000000000..4b5982611b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/functionModifiers.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// MODULE: m1-common +// FILE: common.kt + +expect fun external() +expect fun tailrec() +expect fun inline() +expect fun String.unaryMinus(): String +expect fun String.and(other: String): String + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual external fun external() +actual tailrec fun tailrec(): Unit = if (true) Unit else tailrec() +actual inline fun inline() {} +actual operator fun String.unaryMinus(): String = this +actual infix fun String.and(other: String): String = this + other diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerAndImplInDIfferentPackages.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerAndImplInDIfferentPackages.fir.kt new file mode 100644 index 00000000000..c091e129909 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerAndImplInDIfferentPackages.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +package common + +expect fun foo() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +package jvm + +actual fun foo() {} + +// MODULE: m3-js(m1-common) +// FILE: js.kt +package js + +actual fun foo() {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerDeclarationWithBody.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerDeclarationWithBody.fir.kt new file mode 100644 index 00000000000..dd4f3f56bde --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerDeclarationWithBody.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo() + +expect fun foo() {} + +expect fun bar() {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerWithoutImpl.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerWithoutImpl.fir.kt new file mode 100644 index 00000000000..28299c1d935 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/headerWithoutImpl.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo() diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implDeclarationWithoutBody.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implDeclarationWithoutBody.fir.kt new file mode 100644 index 00000000000..e0a91283d62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implDeclarationWithoutBody.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun foo() + +actual fun bar() diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implWithoutHeader.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implWithoutHeader.fir.kt new file mode 100644 index 00000000000..fb7e5052f0e --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/implWithoutHeader.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-jvm +// FILE: jvm.kt + +actual fun foo() { } diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/inlineFun.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/inlineFun.fir.kt new file mode 100644 index 00000000000..d398914f60c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/inlineFun.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +inline expect fun inlineFun() +expect fun nonInlineFun() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual fun inlineFun() { } +actual fun nonInlineFun() { } + +// MODULE: m3-js(m1-common) +// FILE: js.kt + +actual inline fun inlineFun() { } +actual inline fun nonInlineFun() { } diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/simpleHeaderFun.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/simpleHeaderFun.fir.kt new file mode 100644 index 00000000000..a6f7808abf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/simpleHeaderFun.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect fun foo() + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual fun foo() {} + +// MODULE: m3-js(m1-common) +// FILE: js.kt +actual fun foo() {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/valueParameterModifiers.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/valueParameterModifiers.fir.kt new file mode 100644 index 00000000000..b20033c7e33 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelFun/valueParameterModifiers.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +MultiPlatformProjects +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// MODULE: m1-common +// FILE: common.kt + +expect fun f1(s: () -> String) +expect inline fun f2(s: () -> String) +expect inline fun f3(noinline s: () -> String) + +expect fun f4(s: () -> String) +expect inline fun f5(s: () -> String) +expect inline fun f6(crossinline s: () -> String) + +expect fun f7(x: Any) +expect fun f8(vararg x: Any) + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +actual inline fun f1(noinline s: () -> String) {} +actual inline fun f2(noinline s: () -> String) {} +actual inline fun f3(s: () -> String) {} +actual inline fun f4(crossinline s: () -> String) {} +actual inline fun f5(crossinline s: () -> String) {} +actual inline fun f6(s: () -> String) {} +actual fun f7(vararg x: Any) {} +actual fun f8(x: Any) {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.fir.kt new file mode 100644 index 00000000000..d4ec1318474 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.fir.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +MultiPlatformProjects +LateinitTopLevelProperties +// MODULE: m1-common +// FILE: common.kt + +expect val justVal: String +expect var justVar: String + +expect val String.extensionVal: Unit +expect var T.genericExtensionVar: T + +expect val valWithGet: String + get +expect var varWithGetSet: String + get set + +expect var varWithPlatformGetSet: String + expect get + expect set + +expect val backingFieldVal: String = "no" +expect var backingFieldVar: String = "no" + +expect val customAccessorVal: String + get() = "no" +expect var customAccessorVar: String + get() = "no" + set(value) {} + +expect const val constVal: Int + +expect lateinit var lateinitVar: String + +expect val delegated: String by Delegate +object Delegate { operator fun getValue(x: Any?, y: Any?): String = "" } + +fun test(): String { + expect val localVariable: String + localVariable = "no" + return localVariable +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simpleHeaderVar.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simpleHeaderVar.fir.kt new file mode 100644 index 00000000000..5f0401c080f --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simpleHeaderVar.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt +expect var foo: String + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt +actual var foo: String = "JVM" + +// MODULE: m3-js(m1-common) +// FILE: js.kt +actual var foo: String = "JS" diff --git a/compiler/testData/diagnostics/tests/namedArguments/allowForJavaAnnotation.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/allowForJavaAnnotation.fir.kt new file mode 100644 index 00000000000..86e395e8dbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/allowForJavaAnnotation.fir.kt @@ -0,0 +1,12 @@ +// FILE: A.java + +public @interface A { + int x(); + + String y(); +} + +// FILE: 1.kt + +@A(x = 1, y = "2") +fun test() {} diff --git a/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments1.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments1.fir.kt new file mode 100644 index 00000000000..6620127a9ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments1.fir.kt @@ -0,0 +1,27 @@ +interface A { + fun foo(x : Int) +} + +interface B { + fun foo(y : Int) +} + +interface C : A, B +interface D : B, A + +fun foo(x : C, y : D){ + x.foo(x = 0) + x.foo(y = 0) + y.foo(x = 0) + y.foo(y = 0) +} + +abstract class C1 : A, B +abstract class D1 : A, B + +fun bar(x : C1, y : D1){ + x.foo(x = 0) + x.foo(y = 0) + y.foo(x = 0) + y.foo(y = 0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments2.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments2.fir.kt new file mode 100644 index 00000000000..aae1ca6de24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArguments2.fir.kt @@ -0,0 +1,24 @@ +interface A { + fun foo(a1: Int, a2: Double) + fun bar(a1: Int, a2: Double, a3: String) + fun baz(a1: Int, a2: Double, a3: String, a4: Int, a5: String) +} + +interface B { + fun foo(b1: Int, b2: Double) + fun bar(a1: Int, a2: Double, b3: String) + fun baz(a1: Int, b2: Double, a3: String, b4: Int, a5: String) +} + +interface C : A, B { // Warning here, this is correct +} + +fun test(c: C) { + c.foo(b1 = 1, b2 = 1.0) + c.foo(a1 = 1, b2 = 1.0) + c.foo(a1 = 1, a2 = 1.0) + c.foo(a1 = 1, a2 = 1.0) + c.bar(a1 = 1, a2 = 1.0, b3= "") + c.baz(a1 = 1, b2 = 1.0, a3 = "", b4 = 2, a5 = "") + c.baz(a1 = 1, a2 = 1.0, a3 = "", b4 = 2, a5 = "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics1.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics1.fir.kt new file mode 100644 index 00000000000..2ba29a9054f --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics1.fir.kt @@ -0,0 +1,15 @@ +interface A { + fun foo(a: T) +} + +interface B { + fun foo(b: Int) +} + +interface C : A, B { // Warning here, this is correct +} + +fun test(c: C) { + c.foo(a = 1) + c.foo(b = 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics2.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics2.fir.kt new file mode 100644 index 00000000000..a585e0831b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics2.fir.kt @@ -0,0 +1,15 @@ +interface A { + fun foo(a: E) +} + +interface B { + fun foo(b: T) +} + +interface C : A, B { // Warning here, this is correct +} + +fun test(c: C) { + c.foo(a = 1) + c.foo(b = 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics3.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics3.fir.kt new file mode 100644 index 00000000000..f75dd574cf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/ambiguousNamedArgumentsWithGenerics3.fir.kt @@ -0,0 +1,15 @@ +interface A { + fun foo(a: T) +} + +interface B { + fun foo(b: E) +} + +interface C : A, B { // Warning here, this is correct +} + +fun test(c: C) { + c.foo(a = 1) + c.foo(b = 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaConstructor.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaConstructor.fir.kt new file mode 100644 index 00000000000..609f9cb2316 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaConstructor.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java + +public class A { + public A(int x, String y) {} +} + +// FILE: 1.kt + +val test = A(x = 1, y = "2") diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.fir.kt new file mode 100644 index 00000000000..5cdaa97f87a --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForJavaMethods.fir.kt @@ -0,0 +1,27 @@ +// FILE: JavaSuperClass.java + +public class JavaSuperClass { + public void foo(int javaName) {} + + public void multipleParameters(int first, long second, String third) {} +} + +// FILE: 1.kt + +fun directInvocation() = JavaSuperClass().foo(javaName = 1) + +open class KotlinSubClass : JavaSuperClass() + +fun viaFakeOverride() = KotlinSubClass().foo(javaName = 2) + +class KotlinSubSubClass : KotlinSubClass() { + override fun foo(kotlinName: Int) {} +} + +fun viaRealOverride() = KotlinSubSubClass().foo(kotlinName = 3) + + +fun unresolvedParameter() = JavaSuperClass().foo(nonexistentName = 4) + + +fun multipleParameters() = JavaSuperClass().multipleParameters(first = 1, second = 2L, third = "3") diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt new file mode 100644 index 00000000000..be0da77be10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// FILE: test/J.java + +package test; + +public class J { + public J(String s, Runnable r, Boolean z) { + } +} + +// FILE: usage.kt + +package test + +fun test() { + J("", r = { }, z = false) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterFunction.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterFunction.fir.kt new file mode 100644 index 00000000000..df2330f04be --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterFunction.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// FILE: test/J.java + +package test; + +public class J { + public static void foo(String s, Runnable r, Boolean z) { + } +} + +// FILE: usage.kt + +package test + +fun test() { + J.foo("", r = { }, z = false) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/defaults.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/defaults.fir.kt new file mode 100644 index 00000000000..638026dae9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/defaults.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +NewInference +MixedNamedArgumentsInTheirOwnPosition +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun foo( + p1: Int = 1, + p2: String = "", + p3: Double = 3.0, + p4: Char = '4' +) {} + +fun main() { + foo(p1 = 1, "2", 3.0) + foo(1, p2 = "2", 3.0) + foo(1, "2", p3 = 3.0) + + foo(p1 = 1) + foo(1, p2 = "2") + + foo(p1 = 1, p2 = "2", 3.0) + + foo() + foo(1, p2 = "") + foo(p3 = 4.0, '4') + + foo(1, p3 = 2.0, "") + foo(1, p3 = 2.0, 3.0) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/disabledFeature.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/disabledFeature.fir.kt new file mode 100644 index 00000000000..63d48fa62a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/disabledFeature.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference -MixedNamedArgumentsInTheirOwnPosition +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun foo( + p1: Int, + p2: String, + p3: Double +) {} + +fun main() { + foo(p1 = 1, "2", 3.0) + foo(1, p2 = "2", 3.0) + foo(1, "2", p3 = 3.0) + + foo(p1 = 1, p2 = "2", 3.0) + + foo(1, p3 = 2.0, "") + foo(1, p3 = 2.0, 3.0) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/oldInference.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/oldInference.fir.kt new file mode 100644 index 00000000000..080d5086720 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/oldInference.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: -NewInference +MixedNamedArgumentsInTheirOwnPosition +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun foo( + p1: Int, + p2: String, + p3: Double +) {} + +fun main() { + foo(p1 = 1, "2", 3.0) + foo(1, p2 = "2", 3.0) + foo(1, "2", p3 = 3.0) + + foo(p1 = 1, p2 = "2", 3.0) + + foo(1, p3 = 2.0, "") + foo(1, p3 = 2.0, 3.0) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/simple.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/simple.fir.kt new file mode 100644 index 00000000000..eb0a087d90d --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/simple.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +MixedNamedArgumentsInTheirOwnPosition +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun foo( + p1: Int, + p2: String, + p3: Double +) {} + +fun main() { + foo(p1 = 1, "2", 3.0) + foo(1, p2 = "2", 3.0) + foo(1, "2", p3 = 3.0) + + foo(p1 = 1, p2 = "2", 3.0) + + foo(1, p3 = 2.0, "") + foo(1, p3 = 2.0, 3.0) +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/varargs.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/varargs.fir.kt new file mode 100644 index 00000000000..068fd00c589 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/mixedNamedPosition/varargs.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +NewInference +MixedNamedArgumentsInTheirOwnPosition +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun foo1( + vararg p1: Int, + p2: String, + p3: Double +) {} + +fun foo2( + p1: Int, + vararg p2: String, + p3: Double +) {} + +fun foo3( + p1: Int, + p2: String, + vararg p3: Double +) {} + +fun foo4( + p1: Int, + vararg p2: String, + p3: Double, + p4: Int +) {} + +fun main() { + foo1(1, 2, p2 = "3", 4.0) + foo1(p1 = *intArrayOf(1, 2), "3", p3 = 4.0) + + foo1(p2 = "3", 4.0) + + foo2(p1 = 1, "2", "3", p3 = 4.0) + foo2(1, p2 = *arrayOf("2", "3"), 4.0) + foo2(1, p3 = 3.0) + + foo3(p1 = 1, "2", 3.0, 4.0) + foo3(p1 = 1, "2", p3 = *doubleArrayOf(3.0, 4.0)) + + foo4(p1 = 1, "2", "3", p3 = 4.0, 5) + foo4(1, "2", "3", p3 = 4.0, 5) + foo4(1, p3 = 4.0, 5) + + foo1(1, 2, p3 = 3.0, "4") + foo1(1, 2, p3 = 3.0, p2 = "4") + foo1(*intArrayOf(1, 2), p3 = 3.0, p2 = "4") + + foo2(1, p3 = 2.0, "4") + foo2(1, p3 = 2.0, *arrayOf("3", "4")) + foo2(1, p3 = 2.0, p2 = *arrayOf("3", "4")) + + foo3(1, p3 = *doubleArrayOf(2.0, 3.0), "4") + foo3(1, p3 = *doubleArrayOf(2.0, 3.0), p2 = "4") +} diff --git a/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt new file mode 100644 index 00000000000..01c0d4c33e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt @@ -0,0 +1,27 @@ +fun foo(a : Int = 1, b : String = "abc") { +} + +fun bar(x : Int = 1, y : Int = 1, z : String) { +} + +fun test() { + foo() + foo(2) + foo("") + foo(b = "") + foo(1, "") + foo(a = 2) + foo(1, "", "") + + bar(z = "") + bar() + bar("") + bar(1, 1, "") + bar(1, 1, "") + bar(1, z = "") + bar(1, z = "", y = 2) + bar(z = "", 1) + bar(1, zz = "", + zz.foo + ) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverloads.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverloads.fir.kt new file mode 100644 index 00000000000..ce61b4cfa3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverloads.fir.kt @@ -0,0 +1,14 @@ +interface A { + fun foo(a1: Int, a2: Double) +} + +interface B { + fun foo(b1: Int, b2: String) +} + +interface C : A, B {} + +fun test(d: C) { + d.foo(a1 = 1, a2 = 1.0) + d.foo(b1 = 1, b2 = "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverrides.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverrides.fir.kt new file mode 100644 index 00000000000..8b8e9d729d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsInOverrides.fir.kt @@ -0,0 +1,22 @@ +interface A { + fun foo(a1: Int, a2: Double) +} + +interface B { + fun foo(b1: Int, b2: Double) +} + +interface C : A, B { // Warning here, this is correct, C.foo has no named parameters +} + +interface D : C { + override fun foo(d1: Int, d2: Double) +} + +fun test1(d: D) { + d.foo(d1 = 1, d2 = 1.0) +} + +fun test2(c: C) { + c.foo(b1 = 1, b2 = 1.0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt new file mode 100644 index 00000000000..c86e322fbab --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/AssertNotNull.fir.kt @@ -0,0 +1,39 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun main() { + val a : Int? = null + val b : Int? = null + checkSubtype(a!!) + a!! + 2 + a!!.plus(2) + a!!.plus(b!!) + 2.plus(b!!) + 2 + b!! + + val c = 1 + c!! + + val d : Any? = null + + if (d != null) { + d!! + } + + // smart cast isn't needed, but is reported due to KT-4294 + if (d is String) { + d!! + } + + if (d is String?) { + if (d != null) { + d!! + } + if (d is String) { + d!! + } + } + + val f : String = a!! + checkSubtype(a!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/InfixCallNullability.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/InfixCallNullability.fir.kt new file mode 100644 index 00000000000..feb0e66f806 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/InfixCallNullability.fir.kt @@ -0,0 +1,41 @@ +// !WITH_NEW_INFERENCE +class A() { + operator infix fun plus(i : Int) {} + operator fun unaryMinus() {} + operator infix fun contains(a : Any?) : Boolean = true +} + +operator infix fun A.div(i : Int) {} +operator infix fun A?.times(i : Int) {} + +fun test(x : Int?, a : A?) { + x.plus(1) + x?.plus(1) + x + 1 + -x + x.unaryMinus() + x?.unaryMinus() + + a.plus(1) + a?.plus(1) + a plus 1 + a + 1 + -a + a.unaryMinus() + a?.unaryMinus() + + a.div(1) + a / 1 + a div 1 + a?.div(1) + + a.times(1) + a * 1 + a times 1 + a?.times(1) + + 1 in a + a contains 1 + a.contains(1) + a?.contains(1) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.fir.kt new file mode 100644 index 00000000000..6b400c9e105 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.fir.kt @@ -0,0 +1,8 @@ +fun test() { + val out : Int? = null + val x : Nothing? = null + if (out != x) + out.plus(1) + if (out == x) return + out.plus(1) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/PreferExtensionsOnNullableReceiver.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/PreferExtensionsOnNullableReceiver.fir.kt new file mode 100644 index 00000000000..b841960b590 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/PreferExtensionsOnNullableReceiver.fir.kt @@ -0,0 +1,9 @@ +class Foo { + fun foo() {} +} + +fun Any?.foo() {} + +fun test(f : Foo?) { + f.foo() +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt new file mode 100644 index 00000000000..0444e2a1c20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +class Foo { + fun foo(a: Foo): Foo = a +} + +fun main() { + val x: Foo? = null + val y: Foo? = null + + x.foo(y) + x!!.foo(y) + x.foo(y!!) + x!!.foo(y!!) + + val a: Foo? = null + val b: Foo? = null + val c: Foo? = null + + a.foo(b.foo(c)) + a!!.foo(b.foo(c)) + a.foo(b!!.foo(c)) + a!!.foo(b!!.foo(c)) + a.foo(b.foo(c!!)) + a!!.foo(b.foo(c!!)) + a.foo(b!!.foo(c!!)) + a!!.foo(b!!.foo(c!!)) + + val z: Foo? = null + z!!.foo(z!!) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/ReceiverNullability.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/ReceiverNullability.fir.kt new file mode 100644 index 00000000000..803bcad34ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/ReceiverNullability.fir.kt @@ -0,0 +1,44 @@ +class A { + fun foo() {} +} + +fun A.bar() {} +fun A?.buzz() {} + +fun test(a : A?) { + a.foo() // error + a.bar() // error + a.buzz() + + a?.foo() + a?.bar() + a?.buzz() +} + +fun A.test2() { + foo() + bar() + buzz() + + this.foo() + this.bar() + this.buzz() + + this?.foo() // warning + this?.bar() // warning + this?.buzz() // warning +} + +fun A?.test3() { + foo() // error + bar() // error + buzz() + + this.foo() // error + this.bar() // error + this.buzz() + + this?.foo() + this?.bar() + this?.buzz() +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/SenselessNullInWhen.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/SenselessNullInWhen.fir.kt new file mode 100644 index 00000000000..665a439ed25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/SenselessNullInWhen.fir.kt @@ -0,0 +1,10 @@ +//KT-2457 Verify error when comparing not null value with null in when + +package kt2457 + +fun foo(i: Int) : Int = + when (i) { + 1 -> 1 + null -> 1 + else -> 1 + } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/dataFlowInfoAfterExclExcl.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/dataFlowInfoAfterExclExcl.fir.kt new file mode 100644 index 00000000000..c533df109b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/dataFlowInfoAfterExclExcl.fir.kt @@ -0,0 +1,8 @@ +fun foo(d: Any?) { + if (d is String?) { + d!! + doString(d) + } +} + +fun doString(s: String) = s \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/equalityUnderNotNullCheck.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/equalityUnderNotNullCheck.fir.kt new file mode 100644 index 00000000000..47dc3d1626c --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/equalityUnderNotNullCheck.fir.kt @@ -0,0 +1,5 @@ +fun test(a: Any?) { + if (a is String) { + a == "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideAmbiguity.fir.kt new file mode 100644 index 00000000000..c1cedf45194 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideAmbiguity.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +package d + +fun bar() { + val i: Int? = 42 + if (i != null) { + doSmth1 { + val x = i + 1 + } +} +} + +fun doSmth1(f: ()->Unit) {} +fun doSmth1(g: (Int)->Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideUnresolvedFunction.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideUnresolvedFunction.fir.kt new file mode 100644 index 00000000000..a98b1329340 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/funcLiteralArgsInsideUnresolvedFunction.fir.kt @@ -0,0 +1,10 @@ +package a + +fun foo() { + val i : Int? = 42 + if (i != null) { + doSmth { + val x = i + 1 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1270.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1270.fir.kt new file mode 100644 index 00000000000..da7a0604f37 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1270.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//KT-1270 Poor highlighting when trying to dereference a nullable reference + +package kt1270 + +fun foo() { + val sc = java.util.HashMap()[""] + val value = sc.value +} + +private class SomeClass() { + val value : Int = 5 +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1680.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1680.fir.kt new file mode 100644 index 00000000000..85967016431 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1680.fir.kt @@ -0,0 +1,14 @@ +//KT-1680 Warn if non-null variable is compared to null +package kt1680 + +fun foo() { + val x = 1 + if (x != null) {} // <-- need a warning here! + if (x == null) {} + if (null != x) {} + if (null == x) {} + + val y : Int? = 1 + if (y != null) {} + if (y == null) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt new file mode 100644 index 00000000000..1530d65eb5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt1778.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE +//KT-1778 Automatically cast error +package kt1778 + +fun main(args : Array) { + val x = checkSubtype(args[0]) + if(x is java.lang.CharSequence) { + if ("a" == x) x.length else x.length() // OK + if ("a" == x || "b" == x) x.length else x.length() // <– THEN ERROR + if ("a" == x && "a" == x) x.length else x.length() // <– ELSE ERROR + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2109.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2109.fir.kt new file mode 100644 index 00000000000..e8677780cce --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2109.fir.kt @@ -0,0 +1,20 @@ +//KT-2109 Nullability inference fails in extension function +package kt2109 + +class A { + fun foo() {} +} + +fun A?.bar() { + if (this == null) { + return + } + foo() +} + +fun A.baz() { + if (this == null) { + return + } + foo() +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2125.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2125.fir.kt new file mode 100644 index 00000000000..b50cddfcd3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2125.fir.kt @@ -0,0 +1,12 @@ +//KT-2125 Inconsistent error message on UNSAFE_CALL + +package e + +fun main() { + val compareTo = 1 + val s: String? = null + s.compareTo("") + + val bar = 2 + s.bar() +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.fir.kt new file mode 100644 index 00000000000..89a349c22ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.fir.kt @@ -0,0 +1,55 @@ +// !WITH_NEW_INFERENCE +//KT-2146 Nullability casts in when. +package kt2146 + +fun f1(s: Int?): Int { + return when (s) { + null -> 3 + else -> s + } +} + +fun f2(s: Int?): Int { + return when (s) { + !is Int -> s + else -> s + } +} + +fun f3(s: Int?): Int { + return when (s) { + is Int -> s + else -> s + } +} + +fun f4(s: Int?): Int { + return when { + s == 4 -> s + s == null -> s + else -> s + } +} + +fun f5(s: Int?): Int { + return when (s) { + s -> s + s!! -> s + s -> s + else -> 0 + } +} + +fun f6(s: Int?): Int { + return when { + s is Int -> s + else -> s + } +} + +fun f7(s: Int?): Int { + return when { + s !is Int -> s + else -> s + } +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt new file mode 100644 index 00000000000..b11da4a5726 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.fir.kt @@ -0,0 +1,39 @@ +// !WITH_NEW_INFERENCE +//KT-2164 !! does not propagate nullability information +package kt2164 + +fun foo(x: Int): Int = x + 1 + +fun main() { + val x: Int? = null + + foo(x) + + if (x != null) { + foo(x) + foo(x!!) + foo(x) + } + + foo(x) + + if (x != null) { + foo(x) + foo(x!!) + foo(x) + } else { + foo(x) + foo(x!!) + foo(x) + } + + foo(x) + foo(x!!) + foo(x) + + val y: Int? = null + y!! + y!! + foo(y) + foo(y!!) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt new file mode 100644 index 00000000000..67c08638cce --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2176.fir.kt @@ -0,0 +1,29 @@ +// !CHECK_TYPE + +//KT-2176 non-nullability is not inferred after !! or "as" +package kt2176 + +fun f1(a: String?) { + a!! + checkSubtype(a) +} + +fun f2(a: String) { + a!! + checkSubtype(a) +} + +fun f3(a: Any?) { + a as String + checkSubtype(a) +} + +fun f4(a: Any) { + a as String + checkSubtype(a) +} + +fun f5(a: String) { + a as Any? + checkSubtype(a) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2195.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2195.fir.kt new file mode 100644 index 00000000000..673e4ea7220 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2195.fir.kt @@ -0,0 +1,8 @@ +//KT-2195 error "Only safe calls are allowed ..." but it is function param (val) +package foo + +private fun sendCommand(errorCallback: (()->Unit)? = null) { + if (errorCallback != null) { + errorCallback() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt new file mode 100644 index 00000000000..5e549d859dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2212.fir.kt @@ -0,0 +1,8 @@ +//KT-2212 Incomplete nullability information +package kt2212 + +fun main() { + val x: Int? = 1 + if (x == null) return + System.out.println(x.plus(x!!)) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt new file mode 100644 index 00000000000..efc455e8dc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2216.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST +//KT-2216 Nullability of a value determined in function parameter computation doesn't pass to code following +package kt2216 + +fun bar(y: Int, z: Int) = y + z +fun baz(a: Int, b: Int, c: Int, d: Int) = a + b + c + d + +fun foo() { + val x: Int? = 0 + + bar(if (x != null) x else return, x) + x + 2 + bar(x, x!!) + + val y: Int? = 0 + val z: Int? = 0 + bar(if (y != null) y else z, y) + y + 2 + baz(y, y, if (y == null) return else y, y) + baz(y, z!!, z, y) +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2223.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2223.fir.kt new file mode 100644 index 00000000000..2817ee45012 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2223.fir.kt @@ -0,0 +1,8 @@ +//KT-2223 Comparing non-null value with null might produce helpful warning +package kt2223 + +fun foo() { + val x: Int? = null + if (x == null) return + if (x == null) return +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt new file mode 100644 index 00000000000..f79097f30b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2234.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE + +package a + +//KT-2234 'period!!' has type Int? + +class Pair(val a: A, val b: B) + +fun main() { + val d : Long = 1 + val period : Int? = null + if (period != null) Pair(d, checkSubtype(period!!)) else Pair(d, 1) + if (period != null) Pair(d, checkSubtype(period)) else Pair(d, 1) +} + +fun foo() { + val x : Int? = 3 + if (x != null) { + val u = checkSubtype(x!!) + val y = checkSubtype(x) + val z : Int = y + } +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt new file mode 100644 index 00000000000..aaf1a9743cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2336.fir.kt @@ -0,0 +1,11 @@ +fun main() { + val b: Boolean? = null + if (b != null) { + if (!b) {} // OK + if (b) {} // Error: Condition must be of type kotlin.Boolean, but is of type kotlin.Boolean? + if (b!!) {} // WARN: Unnecessary non-null assertion (!!) on a non-null receiver of type kotlin.Boolean? + foo(b) // OK + } +} + +fun foo(a: Boolean) = a diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.fir.kt new file mode 100644 index 00000000000..85372301de9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.fir.kt @@ -0,0 +1,33 @@ +package kt244 + + +// KT-244 Use dataflow info while resolving variable initializers + +fun f(s: String?) { + if (s != null) { + s.length //ok + var i = s.length //error: Only safe calls are allowed on a nullable receiver + System.out.println(s.length) //error + } +} + +// more tests +class A(a: String?) { + val b = if (a != null) a.length else 1 + init { + if (a != null) { + val c = a.length + } + } + + val i : Int + + init { + if (a is String) { + i = a.length + } + else { + i = 3 + } + } +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.fir.kt new file mode 100644 index 00000000000..25ea6b526a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// !LANGUAGE: +NewInference +// Issue: KT-30734 + +class Sample { + fun foo(): Boolean = true +} + +fun test(ls: Sample?) { + val filter: () -> Boolean = if (ls == null) { + { false } + } else { + { ls.foo() } // OK in OI, error in NI + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.fir.kt new file mode 100644 index 00000000000..301ae2f36b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.fir.kt @@ -0,0 +1,29 @@ +// FILE: this.kt + +// KT-362 Don't allow.smartcasts on vals that are not internal +package example + +fun test() { + val p = test.Public() + if (p.public is Int) p.public + 1 + if (p.protected is Int) p.protected + 1 + if (p.internal is Int) p.internal + 1 + val i = test.Internal() + if (i.public is Int) i.public + 1 + if (i.protected is Int) i.protected + 1 + if (i.internal is Int) i.internal + 1 +} + +// FILE: other.kt +package test + +public class Public() { + public val public : Int? = 1; + protected val protected : Int? = 1; + val internal : Int? = 1 +} +internal class Internal() { + public val public : Int? = 1; + protected val protected : Int? = 1; + val internal : Int? = 1 +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noSenselessNullOnNullableType.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noSenselessNullOnNullableType.fir.kt new file mode 100644 index 00000000000..b0624fd098e --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noSenselessNullOnNullableType.fir.kt @@ -0,0 +1,21 @@ +// FILE: A.java + +class A { + enum Empty {} + + static Empty foo() { return null; } +} + +// FILE: 1.kt + +fun bar() = when (A.foo()) { + null -> "null" + else -> "else" +} + +fun baz(t: T) = when (t) { + is Int -> "int" + is Long -> "long" + null -> "null" + else -> "else" +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noUnnecessaryNotNullAssertionOnErrorType.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noUnnecessaryNotNullAssertionOnErrorType.fir.kt new file mode 100644 index 00000000000..ff08f2d31c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/noUnnecessaryNotNullAssertionOnErrorType.fir.kt @@ -0,0 +1,7 @@ +package a + +fun foo() { + bar()!! +} + +fun bar() = aa \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.fir.kt new file mode 100644 index 00000000000..cc63bf707ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.fir.kt @@ -0,0 +1,20 @@ +// FILE: JClass.java + +import org.jetbrains.annotations.NotNull; + +public class JClass { + @NotNull + public static T getNotNullT() { + return null; + } +} + +// FILE: test.kt +fun test() { + var value: T? = null + if (value == null) { + value = JClass.getNotNullT() + } + + value.hashCode() // unsafe call error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/nullableReceiverWithOverloadedMethod.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/nullableReceiverWithOverloadedMethod.fir.kt new file mode 100644 index 00000000000..722a7a5af42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/nullableReceiverWithOverloadedMethod.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun f(x: Boolean): Int = 0 + + fun f(y: String): Int = 0 +} + +class B { + private var a: A? = null + + fun takeInt(i: Int) {} + + fun f() { + a = A() + a.f(true) + takeInt(a.f("")) + a.f() + } + + fun g() { + takeInt(if (3 > 2) { + a = A() + a.f(true) + } else { + 6 + }) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/senslessComparisonWithNullOnTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/senslessComparisonWithNullOnTypeParameters.fir.kt new file mode 100644 index 00000000000..2f1d0404768 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/senslessComparisonWithNullOnTypeParameters.fir.kt @@ -0,0 +1,16 @@ +// The type checker used to think that T is not null no matter what the upper bound + +fun nullableUpperBound(t: T, ind: INDIRECT) { + if (t == null) {} // was a warning + if (t != null) {} // was a warning + if (ind == null) {} // was a warning + if (ind != null) {} // was a warning +} + +fun notNullUpperBound(t: T, ind: INDIRECT) { + if (t == null) {} // still a warning + if (t != null) {} // still a warning + if (ind == null) {} // still a warning + if (ind != null) {} // still a warning +} + diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastReceiverWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastReceiverWithGenerics.fir.kt new file mode 100644 index 00000000000..d2df085942c --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastReceiverWithGenerics.fir.kt @@ -0,0 +1,7 @@ +fun test(a: Any?) { + if (a != null) { + a.foo(11) + } +} + +fun Any.foo(t: T) = t \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastsAndBooleanExpressions.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastsAndBooleanExpressions.fir.kt new file mode 100644 index 00000000000..ad109901e41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/smartCastsAndBooleanExpressions.fir.kt @@ -0,0 +1,8 @@ +fun foo(b: Boolean?, c: Boolean) { + if (b != null && b) {} + if (b == null || b) {} + if (b != null) { + if (b && c) {} + if (b || c) {} + } +} diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt new file mode 100644 index 00000000000..a99f24208ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unnecessaryNotNullAssertion.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST + +fun takeNotNull(s: String) {} +fun notNull(): T = TODO() +fun nullable(): T? = null +fun dependOn(x: T) = x + +fun test() { + takeNotNull(notNull()!!) + takeNotNull(nullable()!!) + + var x: String? = null + takeNotNull(dependOn(x)!!) + takeNotNull(dependOn(dependOn(x))!!) + takeNotNull(dependOn(dependOn(x)!!)) + takeNotNull(dependOn(dependOn(x!!))) + + if (x != null) { + takeNotNull(dependOn(x)!!) + takeNotNull(dependOn(dependOn(x))!!) + takeNotNull(dependOn(dependOn(x)!!)) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWhenOpenGetterWithOverloading.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWhenOpenGetterWithOverloading.fir.kt new file mode 100644 index 00000000000..92eb68bb5a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWhenOpenGetterWithOverloading.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Ctx +class CtxImpl : Ctx { + fun doJob(a: Int) {} + fun doJob(s: String) {} +} + +open class Test(open val ctx: Ctx) { + fun test() { + when (ctx) { + is CtxImpl -> ctx.doJob(2) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWithOverloadedExtensions.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWithOverloadedExtensions.fir.kt new file mode 100644 index 00000000000..f3b15e045ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/unstableSmartcastWithOverloadedExtensions.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +class B + +fun A.foo(a: A) {} +fun A.foo(b: B) {} +var a: A? = null + +fun smartCastInterference(b: B) { + if (a != null) { + a.foo(b) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.fir.kt new file mode 100644 index 00000000000..1ae495cde52 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.fir.kt @@ -0,0 +1,13 @@ +fun nonMisleadingNullable( + nn: NN?, + nnn: NNN? +) {} + +fun misleadingNullableSimple( + t: T?, + t2: T?, + n: N?, + ind: INDIRECT? +) {} + +fun interactionWithRedundant(t: T??) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.fir.kt new file mode 100644 index 00000000000..87606001595 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.fir.kt @@ -0,0 +1,11 @@ +class My { + fun other() {} +} + +fun another() {} + +fun foo(x: My?) { + // Both elvis parts should be alive + // See also KT-7936, KT-8347 + x?.other() ?: another() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt new file mode 100644 index 00000000000..c687da5c046 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +fun test(t: T): T { + if (t != null) { + return t!! + } + return t!! +} + +fun T.testThis(): String { + if (this != null) { + return this!!.toString() + } + return this!!.toString() +} + diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentForIn.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentForIn.fir.kt new file mode 100644 index 00000000000..8adfaa1fcd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentForIn.fir.kt @@ -0,0 +1,3 @@ +fun test(x: Int?) { + x in 1..2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterPlatform.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterPlatform.fir.kt new file mode 100644 index 00000000000..2ef99b24447 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterPlatform.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + void foo(String x) {} + void foo(@NotNull Double x) {} + void foo(@Nullable Byte x) {} +} + +// FILE: test.kt + +fun test(j: J, nullStr: String?, nullByte: Byte?, nullDouble: Double?) { + j.foo(nullStr) + j.foo(nullDouble) + j.foo(nullByte) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterSimple.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterSimple.fir.kt new file mode 100644 index 00000000000..af6e1aea464 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentToNonNullParameterSimple.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: String) {} +fun foo(x: Int) {} +fun foo(x: Int, y: String) {} + +fun bar(nullX: Int?, nullY: String?, notNullY: String) { + foo(nullX) + foo(nullX, notNullY) + foo(nullX, nullY) + foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.fir.kt new file mode 100644 index 00000000000..509d372da7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.fir.kt @@ -0,0 +1,9 @@ +class Generic + +fun redundantNullable( + i: Int??, + three: Int???, + gOut: Generic??, + gIn: Generic +) { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.fir.kt new file mode 100644 index 00000000000..6924c396747 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.fir.kt @@ -0,0 +1,9 @@ +interface A +interface X: A?? { + +} + +fun interaction(t: T) { + if (t == null) {} + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/safeAccessOnUnit.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/safeAccessOnUnit.fir.kt new file mode 100644 index 00000000000..e9904a7da75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/safeAccessOnUnit.fir.kt @@ -0,0 +1,7 @@ +data class My(val x: Unit) + +fun foo(my: My?): Int? { + val x = my?.x + // ?. is required here + return x?.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.fir.kt new file mode 100644 index 00000000000..4cedf9fc624 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/safeCallOnTypeWithNullableUpperBound.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +fun test(t: T): String? { + if (t != null) { + return t?.toString() + } + return t?.toString() +} + +fun T.testThis(): String? { + if (this != null) { + return this?.toString() + } + return this?.toString() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/safeCallWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/safeCallWithInvoke.fir.kt new file mode 100644 index 00000000000..feb936e7966 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/safeCallWithInvoke.fir.kt @@ -0,0 +1,12 @@ +class A { + val b = B() +} +class B +operator fun B.invoke(i: Int) = i + +fun foo(i: Int) = i + +fun test(a: A?) { + a?.b(1) //should be no warning + foo(a?.b(1)) //no warning, only error +} diff --git a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt new file mode 100644 index 00000000000..6a169949d59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST + +fun test1(t: Any?): Any { + return t as T ?: "" +} + +fun test2(t: Any?): Any { + return t as T ?: "" +} + +fun test3(t: Any?): Any { + if (t != null) { + return t ?: "" + } + + return 1 +} + +fun takeNotNull(s: String) {} +fun notNull(): T = TODO() +fun nullable(): T? = null +fun dependOn(x: T) = x + +fun test() { + takeNotNull(notNull() ?: "") + takeNotNull(nullable() ?: "") + + val x: String? = null + takeNotNull(dependOn(x) ?: "") + takeNotNull(dependOn(dependOn(x)) ?: "") + takeNotNull(dependOn(dependOn(x as String)) ?: "") + + if (x != null) { + takeNotNull(dependOn(x) ?: "") + takeNotNull(dependOn(dependOn(x)) ?: "") + takeNotNull(dependOn(dependOn(x) as? String) ?: "") + } + + takeNotNull(bar()!!) +} + +inline fun reifiedNull(): T? = null + +fun testFrom13648() { + takeNotNull(reifiedNull() ?: "") +} + +fun bar() = unresolved \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/numbers/characterIsNotANumber.fir.kt b/compiler/testData/diagnostics/tests/numbers/characterIsNotANumber.fir.kt new file mode 100644 index 00000000000..6e89529d5b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/characterIsNotANumber.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +fun foo(n: Number) = n + +fun test() { + foo('a') + + val c = 'c' + foo(c) + + val d: Char? = 'd' + foo(d!!) +} diff --git a/compiler/testData/diagnostics/tests/numbers/doublesInSimpleConstraints.fir.kt b/compiler/testData/diagnostics/tests/numbers/doublesInSimpleConstraints.fir.kt new file mode 100644 index 00000000000..31ef50e4c41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/doublesInSimpleConstraints.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package a + +fun id(t: T): T = t + +fun either(t1: T, t2: T): T = t1 + +fun test() { + val a: Float = id(2.0.toFloat()) + + val b = id(2.0) + checkSubtype(b) + + val c = either(1, 2.3) + checkSubtype(c) + + val d = either(11, 2.3) + checkSubtype(d) + + val e: Float = id(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt new file mode 100644 index 00000000000..48e649a2cb5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +package a + +fun foo(i: Int) = i + +fun bar(l: Long) = l + +fun main() { + val i = 111111111111111777777777777777 + + //todo add diagnostic text messages + //report only 'The value is out of range' + //not 'An integer literal does not conform to the expected type Int/Long' + val l: Long = 1111111111111117777777777777777 + foo(11111111111111177777777777777) + bar(11111111111111177777777777777) +} diff --git a/compiler/testData/diagnostics/tests/numbers/numberAsUnionAndIntersection.fir.kt b/compiler/testData/diagnostics/tests/numbers/numberAsUnionAndIntersection.fir.kt new file mode 100644 index 00000000000..4d9df23ad57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/numberAsUnionAndIntersection.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test(numbers: List) { + + // Short <: R, ILT <: R => CST(Short, ILT) = Short + // => we should pick Short in such situation as it more specific + shortExpected { getShort() ?: 1 } + + // Short <: R, ILT <: R, R <: Comparable => + // Short <: Comparable, ILT <: Comparable => + // Comparable <: Comparable, Comparable <: Comparable => + // R <: Short, R <: ILT => + // R := Short, R := ILT + // => we should pick Short as it more specific + shortComparable { getShort() ?: 1 } +} + +fun shortExpected(f: () -> R) {} +fun > shortComparable(f: () -> R) {} + +fun getShort(): Short? = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.fir.kt b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.fir.kt new file mode 100644 index 00000000000..4058881faf7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.fir.kt @@ -0,0 +1,78 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +package a + +fun id(t: T): T = t + +fun either(t1: T, t2: T): T = t1 + +fun other(s: String) {} + +fun otherGeneric(l: List) {} + +fun test() { + val a: Byte = id(1) + + val b: Byte = id(300) + + val c: Int = id(9223372036854775807) + + val d = id(22) + checkSubtype(d) + + val e = id(9223372036854775807) + e checkType { _() } + + val f: Byte = either(1, 2) + + val g: Byte = either(1, 300) + + other(11) + + otherGeneric(1) + + val r = either(1, "") + r checkType { _() } + + use(a, b, c, d, e, f, g, r) +} + +fun use(vararg a: Any?) = a + +interface Inv + +fun exactBound(t: T, l: Inv): T = throw Exception("$t $l") + +fun testExactBound(invS: Inv, invI: Inv, invB: Inv) { + exactBound(1, invS) + exactBound(1, invI) + + val b = exactBound(1, invB) + b checkType { _() } +} + +interface Cov + +fun lowerBound(t: T, l : Cov): T = throw Exception("$t $l") + +fun testLowerBound(cov: Cov, covN: Cov) { + val r = lowerBound(1, cov) + r checkType { _() } + + val n = lowerBound(1, covN) + n checkType { _() } +} + +interface Contr + +fun upperBound(t: T, l: Contr): T = throw Exception("$t $l") + +fun testUpperBound(contrS: Contr, contrB: Contr, contrN: Contr) { + upperBound(1, contrS) + + val n = upperBound(1, contrN) + n checkType { _() } + + val b = upperBound(1, contrB) + b checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/objects/Objects.fir.kt b/compiler/testData/diagnostics/tests/objects/Objects.fir.kt new file mode 100644 index 00000000000..c417e1904c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/Objects.fir.kt @@ -0,0 +1,29 @@ +package toplevelObjectDeclarations + + open class Foo(y : Int) { + open fun foo() : Int = 1 + } + + class T : Foo {} + + object A : Foo { + val x : Int = 2 + + fun test() : Int { + return x + foo() + } + } + + object B : A {} + + val x = A.foo() + + val y = object : Foo(x) { + init { + x + 12 + } + + override fun foo() : Int = 1 + } + + val z = y.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/ObjectsInheritance.fir.kt b/compiler/testData/diagnostics/tests/objects/ObjectsInheritance.fir.kt new file mode 100644 index 00000000000..06a40bef38f --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/ObjectsInheritance.fir.kt @@ -0,0 +1,5 @@ +package toplevelObjectDeclarations + +object CObj {} + +object DOjb : CObj {} diff --git a/compiler/testData/diagnostics/tests/objects/ObjectsLocal.fir.kt b/compiler/testData/diagnostics/tests/objects/ObjectsLocal.fir.kt new file mode 100644 index 00000000000..38cd5054c67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/ObjectsLocal.fir.kt @@ -0,0 +1,25 @@ +// NI_EXPECTED_FILE + +package localObjects + +object A { + val x : Int = 0 +} + +open class Foo { + fun foo() : Int = 1 +} + +fun test() { + A.x + val b = object : Foo() { + } + b.foo() + + object B { + fun foo() {} + } + B.foo() +} + +val bb = B.foo() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/ObjectsNested.fir.kt b/compiler/testData/diagnostics/tests/objects/ObjectsNested.fir.kt new file mode 100644 index 00000000000..faf7d4a6cd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/ObjectsNested.fir.kt @@ -0,0 +1,29 @@ +package nestedObejcts + +object A { + val b = B + val d = A.B.A + + object B { + val a = A + val e = B.A + + object A { + val a = A + val b = B + val x = nestedObejcts.A.B.A + val y = this@A + } + } + +} +object B { + val b = B + val c = A.B +} + +val a = A +val b = B +val c = A.B +val d = A.B.A +val e = B.A.B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/OpenInObject.fir.kt b/compiler/testData/diagnostics/tests/objects/OpenInObject.fir.kt new file mode 100644 index 00000000000..ca357cdd3c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/OpenInObject.fir.kt @@ -0,0 +1,9 @@ +object Obj { + fun foo() {} + + open fun bar() {} + + var x: Int = 0 + + open var y: Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/objects/invokeOnInnerObject.fir.kt b/compiler/testData/diagnostics/tests/objects/invokeOnInnerObject.fir.kt new file mode 100644 index 00000000000..6720e33f495 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/invokeOnInnerObject.fir.kt @@ -0,0 +1,12 @@ +//no nested class access via instance reference error +fun test() { + A.Companion.f("") +} + +class A() { + companion object { + object f { + operator fun invoke(i: Int) = i + } + } +} diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt new file mode 100644 index 00000000000..52c9decb651 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +open class Base { + companion object { + annotation class Foo + } +} + +class Derived : Base() { + + @Foo + fun foo() = 42 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferenceComplexCasesWithImportsOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferenceComplexCasesWithImportsOld.fir.kt new file mode 100644 index 00000000000..54d29f1c5d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferenceComplexCasesWithImportsOld.fir.kt @@ -0,0 +1,74 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +import A.Base.Companion.FromABaseCompanion +import B.Base.Companion.FromBBaseCompanion +import C.Base.Companion.FromCBaseCompanion +import D.Base.Companion.FromDBaseCompanion + +// ===== Case 1: LHS is a class +// +object A { + open class Base { + companion object { + class FromABaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = FromABaseCompanion::foo + } +} + +// ===== Case 2: LHS is a class with companion object, function comes from class + +object B { + open class Base { + companion object { + class FromBBaseCompanion { + fun foo() = 42 + + companion object {} + } + } + } + + class Derived : Base() { + val a = FromBBaseCompanion::foo + } +} + +// ==== Case 3: LHS is a class with companion object, function comes from companion + +object C { + open class Base { + companion object { + class FromCBaseCompanion { + companion object { + fun foo() = 42 + } + } + } + } + + class Derived : Base() { + val a = FromCBaseCompanion::foo + } +} + +// ==== Case 4: LHS is an object + +object D { + open class Base { + companion object { + object FromDBaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = FromDBaseCompanion::foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesComplexCasesWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesComplexCasesWithQualificationOld.fir.kt new file mode 100644 index 00000000000..9f5fb426f29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesComplexCasesWithQualificationOld.fir.kt @@ -0,0 +1,69 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// ===== Case 1: LHS is a class +// +object A { + open class Base { + companion object { + class FromBaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = A.Base.Companion.FromBaseCompanion::foo + } +} + +// ===== Case 2: LHS is a class with companion object, function comes from class + +object B { + open class Base { + companion object { + class FromBaseCompanion { + fun foo() = 42 + + companion object {} + } + } + } + + class Derived : Base() { + val a = B.Base.Companion.FromBaseCompanion::foo + } +} + +// ==== Case 3: LHS is a class with companion object, function comes from companion + +object C { + open class Base { + companion object { + class FromBaseCompanion { + companion object { + fun foo() = 42 + } + } + } + } + + class Derived : Base() { + val a = C.Base.Companion.FromBaseCompanion::foo + } +} + +// ==== Case 4: LHS is an object + +object D { + open class Base { + companion object { + object FromBaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = D.Base.Companion.FromBaseCompanion::foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesNew.fir.kt new file mode 100644 index 00000000000..bdf54158467 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesNew.fir.kt @@ -0,0 +1,142 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// class is to prevent accidental short-name import +class O { + open class Alpha { + open fun foo() = 42 + + class FromAlpha { + fun foo() = 42 + } + + companion object { + class FromCompanionAlpha { + fun foo() = 42 + } + } + } + + open class Beta : Alpha() { + override fun foo() = 42 + + class FromBeta { + fun foo() = 42 + } + + companion object { + class FromCompanionBeta { + fun foo() = 42 + } + } + } + + + open class A { + open fun foo() = 42 + + class FromA { + fun foo() = 42 + } + + companion object : Beta() { + class FromCompanionA { + fun foo() = 42 + } + } + } + +////////////////////////// + + open class FarAway { + open fun foo() = 42 + + class FromFarAway { + fun foo() = 42 + } + + } + + open class Gamma { + open fun foo() = 42 + + class FromGamma { + fun foo() = 42 + } + + companion object : FarAway() { + class FromCompanionGamma { + fun foo() = 42 + } + } + } + + open class B : A() { + override fun foo() = 42 + + class FromB { + fun foo() = 42 + } + + companion object : Gamma() { + override fun foo() = 42 + + class FromCompanionB { + fun foo() = 42 + } + } + } +} + +/////////////////////////////// + + +open class Delta { + open fun foo() = 42 + class FromDelta { + fun foo() = 42 + } +} + +class C : O.B() { + override fun foo() = 42 + + companion object : Delta() { + class FromCompanionC { + fun foo() = 42 + } + } + + // VISIBLE: Classifiers from direct superclasses + val c = FromA::foo + val d = FromB::foo + + // VISIBLE: Classifiers from our own companion + val n = FromCompanionC::foo + + // INVISIBLE: direct superclasses themselves. + val a = A::foo + val b = A::foo + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = FromCompanionA::foo + val f = FromCompanionB::foo + + // INVISIBLE: "cousin" supertypes themselves + val g = Alpha::foo + val h = Beta::foo + val i = Gamma::foo + + // DEPRECATED: classifiers from "cousin" superclasses + val k = FromAlpha::foo + val l = FromBeta::foo + val m = FromGamma::foo + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = FromCompanionAlpha::foo + val p = FromCompanionBeta::foo + val q = FromCompanionGamma::foo + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = FromDelta::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOld.fir.kt new file mode 100644 index 00000000000..4ada62f2fa3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOld.fir.kt @@ -0,0 +1,142 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// class is to prevent accidental short-name import +class O { + open class Alpha { + open fun foo() = 42 + + class FromAlpha { + fun foo() = 42 + } + + companion object { + class FromCompanionAlpha { + fun foo() = 42 + } + } + } + + open class Beta : Alpha() { + override fun foo() = 42 + + class FromBeta { + fun foo() = 42 + } + + companion object { + class FromCompanionBeta { + fun foo() = 42 + } + } + } + + + open class A { + open fun foo() = 42 + + class FromA { + fun foo() = 42 + } + + companion object : Beta() { + class FromCompanionA { + fun foo() = 42 + } + } + } + +////////////////////////// + + open class FarAway { + open fun foo() = 42 + + class FromFarAway { + fun foo() = 42 + } + + } + + open class Gamma { + open fun foo() = 42 + + class FromGamma { + fun foo() = 42 + } + + companion object : FarAway() { + class FromCompanionGamma { + fun foo() = 42 + } + } + } + + open class B : A() { + override fun foo() = 42 + + class FromB { + fun foo() = 42 + } + + companion object : Gamma() { + override fun foo() = 42 + + class FromCompanionB { + fun foo() = 42 + } + } + } +} + +/////////////////////////////// + + +open class Delta { + open fun foo() = 42 + class FromDelta { + fun foo() = 42 + } +} + +class C : O.B() { + override fun foo() = 42 + + companion object : Delta() { + class FromCompanionC { + fun foo() = 42 + } + } + + // VISIBLE: Classifiers from direct superclasses + val c = FromA::foo + val d = FromB::foo + + // VISIBLE: Classifiers from our own companion + val n = FromCompanionC::foo + + // INVISIBLE: direct superclasses themselves. + val a = A::foo + val b = A::foo + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = FromCompanionA::foo + val f = FromCompanionB::foo + + // INVISIBLE: "cousin" supertypes themselves + val g = Alpha::foo + val h = Beta::foo + val i = Gamma::foo + + // DEPRECATED: classifiers from "cousin" superclasses + val k = FromAlpha::foo + val l = FromBeta::foo + val m = FromGamma::foo + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = FromCompanionAlpha::foo + val p = FromCompanionBeta::foo + val q = FromCompanionGamma::foo + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = FromDelta::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOldComplexCases.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOldComplexCases.fir.kt new file mode 100644 index 00000000000..5902f6f0990 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesOldComplexCases.fir.kt @@ -0,0 +1,69 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// ===== Case 1: LHS is a class +// +object A { + open class Base { + companion object { + class FromBaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = FromBaseCompanion::foo + } +} + +// ===== Case 2: LHS is a class with companion object, function comes from class + +object B { + open class Base { + companion object { + class FromBaseCompanion { + fun foo() = 42 + + companion object {} + } + } + } + + class Derived : Base() { + val a = FromBaseCompanion::foo + } +} + +// ==== Case 3: LHS is a class with companion object, function comes from companion + +object C { + open class Base { + companion object { + class FromBaseCompanion { + companion object { + fun foo() = 42 + } + } + } + } + + class Derived : Base() { + val a = FromBaseCompanion::foo + } +} + +// ==== Case 4: LHS is an object + +object D { + open class Base { + companion object { + object FromBaseCompanion { + fun foo() = 42 + } + } + } + + class Derived : Base() { + val a = FromBaseCompanion::foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationNew.fir.kt new file mode 100644 index 00000000000..4a72ff41864 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationNew.fir.kt @@ -0,0 +1,142 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// class is to prevent accidental short-name import +class O { + open class Alpha { + open fun foo() = 42 + + class FromAlpha { + fun foo() = 42 + } + + companion object { + class FromCompanionAlpha { + fun foo() = 42 + } + } + } + + open class Beta : Alpha() { + override fun foo() = 42 + + class FromBeta { + fun foo() = 42 + } + + companion object { + class FromCompanionBeta { + fun foo() = 42 + } + } + } + + + open class A { + open fun foo() = 42 + + class FromA { + fun foo() = 42 + } + + companion object : Beta() { + class FromCompanionA { + fun foo() = 42 + } + } + } + +////////////////////////// + + open class FarAway { + open fun foo() = 42 + + class FromFarAway { + fun foo() = 42 + } + + } + + open class Gamma { + open fun foo() = 42 + + class FromGamma { + fun foo() = 42 + } + + companion object : FarAway() { + class FromCompanionGamma { + fun foo() = 42 + } + } + } + + open class B : A() { + override fun foo() = 42 + + class FromB { + fun foo() = 42 + } + + companion object : Gamma() { + override fun foo() = 42 + + class FromCompanionB { + fun foo() = 42 + } + } + } +} + +/////////////////////////////// + + +open class Delta { + open fun foo() = 42 + class FromDelta { + fun foo() = 42 + } +} + +class C : O.B() { + override fun foo() = 42 + + companion object : Delta() { + class FromCompanionC { + fun foo() = 42 + } + } + + // VISIBLE: Classifiers from direct superclasses + val c = O.A.FromA::foo + val d = O.B.FromB::foo + + // VISIBLE: Classifiers from our own companion + val n = C.Companion.FromCompanionC::foo + + // INVISIBLE: direct superclasses themselves. + val a = O.A::foo + val b = O.A::foo + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = O.A.Companion.FromCompanionA::foo + val f = O.B.Companion.FromCompanionB::foo + + // INVISIBLE: "cousin" supertypes themselves + val g = O.Alpha::foo + val h = O.Beta::foo + val i = O.Gamma::foo + + // DEPRECATED: classifiers from "cousin" superclasses + val k = O.Alpha.FromAlpha::foo + val l = O.Beta.FromBeta::foo + val m = O.Gamma.FromGamma::foo + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = O.Alpha.Companion.FromCompanionAlpha::foo + val p = O.Beta.Companion.FromCompanionBeta::foo + val q = O.Gamma.Companion.FromCompanionGamma::foo + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = Delta.FromDelta::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationOld.fir.kt new file mode 100644 index 00000000000..365ce45f7b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/callableReferencesWithQualificationOld.fir.kt @@ -0,0 +1,142 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// class is to prevent accidental short-name import +class O { + open class Alpha { + open fun foo() = 42 + + class FromAlpha { + fun foo() = 42 + } + + companion object { + class FromCompanionAlpha { + fun foo() = 42 + } + } + } + + open class Beta : Alpha() { + override fun foo() = 42 + + class FromBeta { + fun foo() = 42 + } + + companion object { + class FromCompanionBeta { + fun foo() = 42 + } + } + } + + + open class A { + open fun foo() = 42 + + class FromA { + fun foo() = 42 + } + + companion object : Beta() { + class FromCompanionA { + fun foo() = 42 + } + } + } + +////////////////////////// + + open class FarAway { + open fun foo() = 42 + + class FromFarAway { + fun foo() = 42 + } + + } + + open class Gamma { + open fun foo() = 42 + + class FromGamma { + fun foo() = 42 + } + + companion object : FarAway() { + class FromCompanionGamma { + fun foo() = 42 + } + } + } + + open class B : A() { + override fun foo() = 42 + + class FromB { + fun foo() = 42 + } + + companion object : Gamma() { + override fun foo() = 42 + + class FromCompanionB { + fun foo() = 42 + } + } + } +} + +/////////////////////////////// + + +open class Delta { + open fun foo() = 42 + class FromDelta { + fun foo() = 42 + } +} + +class C : O.B() { + override fun foo() = 42 + + companion object : Delta() { + class FromCompanionC { + fun foo() = 42 + } + } + + // VISIBLE: Classifiers from direct superclasses + val c = O.A.FromA::foo + val d = O.B.FromB::foo + + // VISIBLE: Classifiers from our own companion + val n = FromCompanionC::foo + + // INVISIBLE: direct superclasses themselves. + val a = O.A::foo + val b = O.A::foo + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = O.A.Companion.FromCompanionA::foo + val f = O.B.Companion.FromCompanionB::foo + + // INVISIBLE: "cousin" supertypes themselves + val g = O.Alpha::foo + val h = O.Beta::foo + val i = O.Gamma::foo + + // DEPRECATED: classifiers from "cousin" superclasses + val k = O.Alpha.FromAlpha::foo + val l = O.Beta.FromBeta::foo + val m = O.Gamma.FromGamma::foo + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = O.Alpha.Companion.FromCompanionAlpha::foo + val p = O.Beta.Companion.FromCompanionBeta::foo + val q = O.Gamma.Companion.FromCompanionGamma::foo + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = Delta.FromDelta::foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectNew.fir.kt new file mode 100644 index 00000000000..80326a4b109 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectNew.fir.kt @@ -0,0 +1,99 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c: FromA? = null + val d: FromB? = null + + // VISIBLE: Classifiers from our own companion + val n: FromCompanionC? = null + + // INVISIBLE: direct superclasses themselves. + val a: A? = null + val b: B? = null + + // DEPRECATED: Classifiers from companions of direct superclasses + val e: FromCompanionA? = null + val f: FromCompanionB? = null + + // INVISIBLE: "cousin" supertypes themselves + val g: Alpha? = null + val h: Beta? = null + val i: Gamma? = null + + // DEPRECATED: classifiers from "cousin" superclasses + val k: FromAlpha? = null + val l: FromBeta? = null + val m: FromGamma? = null + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o: FromCompanionAlpha? = null + val p: FromCompanionBeta? = null + val q: FromCompanionGamma? = null + + // DEPRECATED: Classifiers from supertypes of our own companion + val r: FromDelta? = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectOld.fir.kt new file mode 100644 index 00000000000..f2d2fb0820e --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectOld.fir.kt @@ -0,0 +1,98 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c: FromA? = null + val d: FromB? = null + + // VISIBLE: Classifiers from our own companion + val n: FromCompanionC? = null + + // INVISIBLE: direct superclasses themselves. + val a: A? = null + val b: B? = null + + // DEPRECATED: Classifiers from companions of direct superclasses + val e: FromCompanionA? = null + val f: FromCompanionB? = null + + // INVISIBLE: "cousin" supertypes themselves + val g: Alpha? = null + val h: Beta? = null + val i: Gamma? = null + + // DEPRECATED: classifiers from "cousin" superclasses + val k: FromAlpha? = null + val l: FromBeta? = null + val m: FromGamma? = null + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o: FromCompanionAlpha? = null + val p: FromCompanionBeta? = null + val q: FromCompanionGamma? = null + + // DEPRECATED: Classifiers from supertypes of our own companion + val r: FromDelta? = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationNew.fir.kt new file mode 100644 index 00000000000..cee85fc989c --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationNew.fir.kt @@ -0,0 +1,99 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c: O.A.FromA? = null + val d: O.B.FromB? = null + + // VISIBLE: Classifiers from our own companion + val n: C.Companion.FromCompanionC? = null + + // INVISIBLE: direct superclasses themselves. + val a: O.A? = null + val b: O.B? = null + + // DEPRECATED: Classifiers from companions of direct superclasses + val e: O.A.Companion.FromCompanionA? = null + val f: O.B.Companion.FromCompanionB? = null + + // INVISIBLE: "cousin" supertypes themselves + val g: O.Alpha? = null + val h: O.Beta? = null + val i: O.Gamma? = null + + // DEPRECATED: classifiers from "cousin" superclasses + val k: O.Alpha.FromAlpha? = null + val l: O.Beta.FromBeta? = null + val m: O.Gamma.FromGamma? = null + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o: O.Alpha.Companion.FromCompanionAlpha? = null + val p: O.Beta.Companion.FromCompanionBeta? = null + val q: O.Gamma.Companion.FromCompanionGamma? = null + + // DEPRECATED: Classifiers from supertypes of our own companion + val r: Delta.FromDelta? = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationOld.fir.kt new file mode 100644 index 00000000000..6a65b624428 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/classifierFromCompanionObjectWithQualificationOld.fir.kt @@ -0,0 +1,98 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c: O.A.FromA? = null + val d: O.B.FromB? = null + + // VISIBLE: Classifiers from our own companion + val n: C.Companion.FromCompanionC? = null + + // INVISIBLE: direct superclasses themselves. + val a: O.A? = null + val b: O.B? = null + + // DEPRECATED: Classifiers from companions of direct superclasses + val e: O.A.Companion.FromCompanionA? = null + val f: O.B.Companion.FromCompanionB? = null + + // INVISIBLE: "cousin" supertypes themselves + val g: O.Alpha? = null + val h: O.Beta? = null + val i: O.Gamma? = null + + // DEPRECATED: classifiers from "cousin" superclasses + val k: O.Alpha.FromAlpha? = null + val l: O.Beta.FromBeta? = null + val m: O.Gamma.FromGamma? = null + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o: O.Alpha.Companion.FromCompanionAlpha? = null + val p: O.Beta.Companion.FromCompanionBeta? = null + val q: O.Gamma.Companion.FromCompanionGamma? = null + + // DEPRECATED: Classifiers from supertypes of our own companion + val r: Delta.FromDelta? = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/classifierIsVisibleByTwoPaths.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/classifierIsVisibleByTwoPaths.fir.kt new file mode 100644 index 00000000000..bdc9c72d601 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/classifierIsVisibleByTwoPaths.fir.kt @@ -0,0 +1,17 @@ +open class A { + class FromA { + fun foo() = 42 + } +} + +class B : A() { + companion object : A() { } + + // we're seeing FromA here by two paths: one is deprecated (via companion object), and another one is not, + // so we shouldn't see deprecation warning + val a: FromA? = null + + val b = FromA::foo + + val c = FromA() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt new file mode 100644 index 00000000000..118f24674a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a open class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + open class FromAlpha + + companion object { + open class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + open class FromBeta + + companion object { + open class FromCompanionBeta + } + } + + + open class A { + open class FromA + + companion object : Beta() { + open class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + open class FromFarAway + + } + + open class Gamma { + open class FromGamma + companion object : FarAway() { + open class FromCompanionGamma + } + } + + open class B : A() { + open class FromB + + companion object : Gamma() { + open class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + open class FromDelta +} + +open class C : O.B() { + companion object : Delta() { + open class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + open class c : FromA() + open class d : FromB() + + // VISIBLE: Classifiers from our own companion + open class n : FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + open class a : A() + open class b : B() + + // DEPRECATED: Classifiers from companions of direct superclasses + open class e : FromCompanionA() + open class f : FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + open class g : Alpha() + open class h : Beta() + open class i : Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + open class k : FromAlpha() + open class l : FromBeta() + open class m : FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + open class o : FromCompanionAlpha() + open class p : FromCompanionBeta() + open class q : FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + open class r : FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt new file mode 100644 index 00000000000..99dfc2d318b --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a open class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + open class FromAlpha + + companion object { + open class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + open class FromBeta + + companion object { + open class FromCompanionBeta + } + } + + + open class A { + open class FromA + + companion object : Beta() { + open class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + open class FromFarAway + + } + + open class Gamma { + open class FromGamma + companion object : FarAway() { + open class FromCompanionGamma + } + } + + open class B : A() { + open class FromB + + companion object : Gamma() { + open class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + open class FromDelta +} + +open class C : O.B() { + companion object : Delta() { + open class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + open class c : FromA() + open class d : FromB() + + // VISIBLE: Classifiers from our own companion + open class n : FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + open class a : A() + open class b : B() + + // DEPRECATED: Classifiers from companions of direct superclasses + open class e : FromCompanionA() + open class f : FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + open class g : Alpha() + open class h : Beta() + open class i : Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + open class k : FromAlpha() + open class l : FromBeta() + open class m : FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + open class o : FromCompanionAlpha() + open class p : FromCompanionBeta() + open class q : FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + open class r : FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationNew.fir.kt new file mode 100644 index 00000000000..f1abf117b2d --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationNew.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a open class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + open class FromAlpha + + companion object { + open class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + open class FromBeta + + companion object { + open class FromCompanionBeta + } + } + + + open class A { + open class FromA + + companion object : Beta() { + open class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + open class FromFarAway + + } + + open class Gamma { + open class FromGamma + companion object : FarAway() { + open class FromCompanionGamma + } + } + + open class B : A() { + open class FromB + + companion object : Gamma() { + open class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + open class FromDelta +} + +open class C : O.B() { + companion object : Delta() { + open class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + open class c : O.A.FromA() + open class d : O.B.FromB() + + // VISIBLE: Classifiers from our own companion + open class n : C.Companion.FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + open class a : O.A() + open class b : O.B() + + // DEPRECATED: Classifiers from companions of direct superclasses + open class e : O.A.Companion.FromCompanionA() + open class f : O.B.Companion.FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + open class g : O.Alpha() + open class h : O.Beta() + open class i : O.Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + open class k : O.Alpha.FromAlpha() + open class l : O.Beta.FromBeta() + open class m : O.Gamma.FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + open class o : O.Alpha.Companion.FromCompanionAlpha() + open class p : O.Beta.Companion.FromCompanionBeta() + open class q : O.Gamma.Companion.FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + open class r : Delta.FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationOld.fir.kt new file mode 100644 index 00000000000..ea97e72b0c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedWithQualificationOld.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a open class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + open class FromAlpha + + companion object { + open class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + open class FromBeta + + companion object { + open class FromCompanionBeta + } + } + + + open class A { + open class FromA + + companion object : Beta() { + open class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + open class FromFarAway + + } + + open class Gamma { + open class FromGamma + companion object : FarAway() { + open class FromCompanionGamma + } + } + + open class B : A() { + open class FromB + + companion object : Gamma() { + open class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + open class FromDelta +} + +open class C : O.B() { + companion object : Delta() { + open class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + open class c : O.A.FromA() + open class d : O.B.FromB() + + // VISIBLE: Classifiers from our own companion + open class n : C.Companion.FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + open class a : O.A() + open class b : O.B() + + // DEPRECATED: Classifiers from companions of direct superclasses + open class e : O.A.Companion.FromCompanionA() + open class f : O.B.Companion.FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + open class g : O.Alpha() + open class h : O.Beta() + open class i : O.Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + open class k : O.Alpha.FromAlpha() + open class l : O.Beta.FromBeta() + open class m : O.Gamma.FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + open class o : O.Alpha.Companion.FromCompanionAlpha() + open class p : O.Beta.Companion.FromCompanionBeta() + open class q : O.Gamma.Companion.FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + open class r : Delta.FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt new file mode 100644 index 00000000000..03695a19fb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: test/Java.java +package test; + +public class Java { + public static void method() { } + public static int property = 42; + public static class Classifier { } + public static void syntheticSam(Runnable r) { } + + public static int getStaticSyntheticProperty() { return 42; } + public static int setStaticSyntheticProperty(int x) { return 42; } + + public int getInstanceSyntheticProperty() { return 42; } + public int setInstanceSyntheticProperty(int x) { return 42; } +} + +// FILE: Kotlin.kt +package test + +open class Base { + companion object : Java() { + + } +} + +class Derived : Base() { + fun test(javaStaticInTypePosition: Classifier) { + method() + property + Classifier() + syntheticSam { } + + // Instance members shouldn't be affected, but we check them, just in case + val y = instanceSyntheticProperty + instanceSyntheticProperty = 43 + + // Note that statics actually aren't converted into synthetic property in Kotlin + val x = syntheticProperty + syntheticProperty = 42 + } + + class JavaStaticInSupertypeList : Classifier() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt new file mode 100644 index 00000000000..fcb485158b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: test/Java.java +package test; + +public class Java { + public static void method() { } + public static int property = 42; + public static class Classifier { } + public static void syntheticSam(Runnable r) { } + + public static int getStaticSyntheticProperty() { return 42; } + public static int setStaticSyntheticProperty(int x) { return 42; } + + public int getInstanceSyntheticProperty() { return 42; } + public int setInstanceSyntheticProperty(int x) { return 42; } +} + +// FILE: Kotlin.kt +package test + +open class Base { + companion object : Java() { + + } +} + +class Derived : Base() { + fun test(javaStaticInTypePosition: Classifier) { + method() + property + Classifier() + syntheticSam { } + + // Instance members shouldn't be affected, but we check them, just in case + val y = instanceSyntheticProperty + instanceSyntheticProperty = 43 + + // Note that statics actually aren't converted into synthetic property in Kotlin + val x = syntheticProperty + syntheticProperty = 42 + } + + class JavaStaticInSupertypeList : Classifier() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationNew.fir.kt new file mode 100644 index 00000000000..7ffea50e305 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationNew.fir.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: test/Java.java +package test; + +public class Java { + public static void method() { } + public static int property = 42; + public static class Classifier { } + public static void syntheticSam(Runnable r) { } + + public static int getStaticSyntheticProperty() { return 42; } + public static int setStaticSyntheticProperty(int x) { return 42; } + + public int getInstanceSyntheticProperty() { return 42; } + public int setInstanceSyntheticProperty(int x) { return 42; } +} + +// FILE: Kotlin.kt +package test + +import test.Java.method +import test.Java.Classifier +import test.Java.property +import test.Java.syntheticSam + +open class Base { + companion object : Java() { + + } +} + +class Derived : Base() { + fun test(javaStaticInTypePosition: Classifier) { + method() + property + Classifier() + syntheticSam { } + + // Instance members shouldn't be affected, but we check them, just in case + val y = instanceSyntheticProperty + instanceSyntheticProperty = 43 + + // Note that statics actually aren't converted into synthetic property in Kotlin + val x = syntheticProperty + syntheticProperty = 42 + } + + class JavaStaticInSupertypeList : Classifier() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationOld.fir.kt new file mode 100644 index 00000000000..5ecec00f0a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaWithQualificationOld.fir.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: test/Java.java +package test; + +public class Java { + public static void method() { } + public static int property = 42; + public static class Classifier { } + public static void syntheticSam(Runnable r) { } + + public static int getStaticSyntheticProperty() { return 42; } + public static int setStaticSyntheticProperty(int x) { return 42; } + + public int getInstanceSyntheticProperty() { return 42; } + public int setInstanceSyntheticProperty(int x) { return 42; } +} + +// FILE: Kotlin.kt +package test + +import test.Java.method +import test.Java.Classifier +import test.Java.property +import test.Java.syntheticSam + +open class Base { + companion object : Java() { + + } +} + +class Derived : Base() { + fun test(javaStaticInTypePosition: Classifier) { + method() + property + Classifier() + syntheticSam { } + + // Instance members shouldn't be affected, but we check them, just in case + val y = instanceSyntheticProperty + instanceSyntheticProperty = 43 + + // Note that statics actually aren't converted into synthetic property in Kotlin + val x = syntheticProperty + syntheticProperty = 42 + } + + class JavaStaticInSupertypeList : Classifier() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorNew.fir.kt new file mode 100644 index 00000000000..b9552eb18a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorNew.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c = FromA() + val d = FromB() + + // VISIBLE: Classifiers from our own companion + val n = FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + val a = A() + val b = B() + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = FromCompanionA() + val f = FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + val g = Alpha() + val h = Beta() + val i = Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + val k = FromAlpha() + val l = FromBeta() + val m = FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = FromCompanionAlpha() + val p = FromCompanionBeta() + val q = FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorOld.fir.kt new file mode 100644 index 00000000000..a3ad9f862f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorOld.fir.kt @@ -0,0 +1,99 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c = FromA() + val d = FromB() + + // VISIBLE: Classifiers from our own companion + val n = FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + val a = A() + val b = B() + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = FromCompanionA() + val f = FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + val g = Alpha() + val h = Beta() + val i = Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + val k = FromAlpha() + val l = FromBeta() + val m = FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = FromCompanionAlpha() + val p = FromCompanionBeta() + val q = FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationNew.fir.kt new file mode 100644 index 00000000000..2a1da9d91d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationNew.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c = O.A.FromA() + val d = O.B.FromB() + + // VISIBLE: Classifiers from our own companion + val n = C.Companion.FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + val a = O.A() + val b = O.B() + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = O.A.Companion.FromCompanionA() + val f = O.B.Companion.FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + val g = O.Alpha() + val h = O.Beta() + val i = O.Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + val k = O.Alpha.FromAlpha() + val l = O.Beta.FromBeta() + val m = O.Gamma.FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = O.Alpha.Companion.FromCompanionAlpha() + val p = O.Beta.Companion.FromCompanionBeta() + val q = O.Gamma.Companion.FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = Delta.FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationOld.fir.kt new file mode 100644 index 00000000000..ab80273e1c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt21515/useDeprecatedConstructorWithQualificationOld.fir.kt @@ -0,0 +1,100 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// See KT-21515 for a class diagram and details + +// Object is to prevent accidental short-name import +object O { + open class Alpha { + class FromAlpha + + companion object { + class FromCompanionAlpha + } + } + + open class Beta : Alpha() { + class FromBeta + + companion object { + class FromCompanionBeta + } + } + + + open class A { + class FromA + + companion object : Beta() { + class FromCompanionA + } + } + +////////////////////////// + + open class FarAway { + class FromFarAway + + } + + open class Gamma { + class FromGamma + companion object : FarAway() { + class FromCompanionGamma + } + } + + open class B : A() { + class FromB + + companion object : Gamma() { + class FromCompanionB + } + } +} + +/////////////////////////////// + + +open class Delta { + class FromDelta +} + +class C : O.B() { + companion object : Delta() { + class FromCompanionC + } + + // VISIBLE: Classifiers from direct superclasses + val c = O.A.FromA() + val d = O.B.FromB() + + // VISIBLE: Classifiers from our own companion + val n = C.Companion.FromCompanionC() + + // INVISIBLE: direct superclasses themselves. + val a = O.A() + val b = O.B() + + // DEPRECATED: Classifiers from companions of direct superclasses + val e = O.A.Companion.FromCompanionA() + val f = O.B.Companion.FromCompanionB() + + // INVISIBLE: "cousin" supertypes themselves + val g = O.Alpha() + val h = O.Beta() + val i = O.Gamma() + + // DEPRECATED: classifiers from "cousin" superclasses + val k = O.Alpha.FromAlpha() + val l = O.Beta.FromBeta() + val m = O.Gamma.FromGamma() + + // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses + val o = O.Alpha.Companion.FromCompanionAlpha() + val p = O.Beta.Companion.FromCompanionBeta() + val q = O.Gamma.Companion.FromCompanionGamma() + + // DEPRECATED: Classifiers from supertypes of our own companion + val r = Delta.FromDelta() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt2240.fir.kt b/compiler/testData/diagnostics/tests/objects/kt2240.fir.kt new file mode 100644 index 00000000000..dc03783e2fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt2240.fir.kt @@ -0,0 +1,13 @@ +package a + +//KT-2240 Wrong overload resolution ambiguity when object literal is involved + +class A {} + +fun A.foo(f : T) {} + +val o = object { + fun foo(f: T) { + A().foo(f) // Ambiguity here! + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt5527.fir.kt b/compiler/testData/diagnostics/tests/objects/kt5527.fir.kt new file mode 100644 index 00000000000..24c1fc278ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/kt5527.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +object Boo {} +class A { + object Boo {} +} + +fun foo() { + val i1: Int = Boo + val i2: Int = A.Boo + useInt(Boo) + useInt(A.Boo) +} +fun bar() { + val i1: Int = Unit + useInt(Unit) +} + +fun useInt(i: Int) = i diff --git a/compiler/testData/diagnostics/tests/objects/localObjectInsideObject.fir.kt b/compiler/testData/diagnostics/tests/objects/localObjectInsideObject.fir.kt new file mode 100644 index 00000000000..6a593b39d65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/localObjectInsideObject.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun foo() { + val a = object { + val b = object { + val c = 42 + } + } + + checkSubtype(a.b.c) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/localObjects.fir.kt b/compiler/testData/diagnostics/tests/objects/localObjects.fir.kt new file mode 100644 index 00000000000..0ec89e28f78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/localObjects.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + object a {} + val b = object { + object c {} + } + b.c + class A { + object d {} + } + val f = { + object e {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/nestedClassInAnonymousObject.fir.kt b/compiler/testData/diagnostics/tests/objects/nestedClassInAnonymousObject.fir.kt new file mode 100644 index 00000000000..1a182ce94d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/nestedClassInAnonymousObject.fir.kt @@ -0,0 +1,11 @@ +class X { + val foo = object { + class Foo + } + + fun test() { + object { + class Foo + } + } +} diff --git a/compiler/testData/diagnostics/tests/objects/objectInsideFun.fir.kt b/compiler/testData/diagnostics/tests/objects/objectInsideFun.fir.kt new file mode 100644 index 00000000000..481c7c017ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/objectInsideFun.fir.kt @@ -0,0 +1,11 @@ +interface A { + val foo: Int + val bar: String + get() = "" +} + +fun test(foo: Int, bar: Int) { + object : A { + override val foo: Int = foo + bar + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/objectLiteralExpressionTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/objects/objectLiteralExpressionTypeMismatch.fir.kt new file mode 100644 index 00000000000..1c9378ffee8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/objectLiteralExpressionTypeMismatch.fir.kt @@ -0,0 +1,9 @@ +interface A + +interface B + +fun test1(): B = object : A { +} + +fun test2(): B = object { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/upperBoundViolated.fir.kt b/compiler/testData/diagnostics/tests/objects/upperBoundViolated.fir.kt new file mode 100644 index 00000000000..86ba09f738d --- /dev/null +++ b/compiler/testData/diagnostics/tests/objects/upperBoundViolated.fir.kt @@ -0,0 +1,9 @@ +interface Trait + +object O1 : Trait + +object O2 : Trait + +class C { + companion object : Trait +} diff --git a/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModAssignOperatorConventions.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModAssignOperatorConventions.fir.kt new file mode 100644 index 00000000000..8dbd3ff4ab0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModAssignOperatorConventions.fir.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class OldAndNew { + operator fun modAssign(x: Int) {} + operator fun remAssign(x: Int) {} +} + +class OnlyOld { + operator fun modAssign(x: Int) {} +} + +class OnlyNew { + operator fun remAssign(x: Int) {} +} + +class Sample + +operator fun Sample.modAssign(x: Int) {} +operator fun Sample.remAssign(x: Int) {} + +class ModAndRemAssign { + operator fun mod(x: Int): ModAndRemAssign = ModAndRemAssign() + operator fun remAssign(x: Int) {} +} + +fun test() { + val oldAndNew = OldAndNew() + oldAndNew %= 1 + + val onlyOld = OnlyOld() + onlyOld %= 1 + + val onlyNew = OnlyNew() + onlyNew %= 1 + + val sample = Sample() + sample %= 1 + + var modAndRemAssign = ModAndRemAssign() + modAndRemAssign %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModOperatorConventions.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModOperatorConventions.fir.kt new file mode 100644 index 00000000000..2b1cd615b4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/DeprecatedModOperatorConventions.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class OldAndNew { + operator fun mod(x: Int) {} + operator fun rem(x: Int) {} +} + +class OnlyOld { + operator fun mod(x: Int) {} +} + +class OnlyNew { + operator fun rem(x: Int) {} +} + +class Sample + +operator fun Sample.mod(x: Int) {} +operator fun Sample.rem(x: Int) {} + +class IntAndUnit { + operator fun mod(x: Int) = 0 + operator fun rem(x: Int): Int = 0 +} + +fun test() { + OldAndNew() % 1 + OnlyOld() % 1 + OnlyNew() % 1 + Sample() % 1 + + takeInt(IntAndUnit() % 1) +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/deprecatedModConvention.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/deprecatedModConvention.fir.kt new file mode 100644 index 00000000000..990401d58be --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/deprecatedModConvention.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object ModAndRem { + operator fun mod(x: Int) {} + operator fun rem(x: Int) {} +} + +object OldMod { + operator fun mod(x: Int) {} +} + +object ModAndRemExtension +operator fun ModAndRemExtension.mod(x: Int) {} +operator fun ModAndRemExtension.rem(x: Int) {} + +object ModExtension +operator fun ModExtension.mod(x: Int) {} + +object ModMemberAndRemExtension { + operator fun mod(x: Int) {} +} + +operator fun ModMemberAndRemExtension.rem(x: Int) {} + +fun foo() { + ModAndRem % 1 + OldMod % 1 + + ModAndRemExtension % 1 + + ModExtension % 1 + + ModMemberAndRemExtension % 1 + + OldMod.mod(1) + ModExtension.mod(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/doNotResolveToInapplicableRem.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/doNotResolveToInapplicableRem.fir.kt new file mode 100644 index 00000000000..3c5b319096e --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/doNotResolveToInapplicableRem.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object OldMod { + operator fun mod(x: Int) {} +} + +object RemExtension +operator fun RemExtension.rem(x: Int) {} + +fun foo() { + OldMod % 123 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/errorOnExplicitModCall.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/errorOnExplicitModCall.fir.kt new file mode 100644 index 00000000000..7a4fd584c21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/errorOnExplicitModCall.fir.kt @@ -0,0 +1,3 @@ +fun test() { + 1.mod(3) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/forbiddenModOperatorConvention.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/forbiddenModOperatorConvention.fir.kt new file mode 100644 index 00000000000..1b7ad2ad8af --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/forbiddenModOperatorConvention.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object ModAndRem { + operator fun mod(x: Int) {} + operator fun rem(x: Int) {} + + operator fun modAssign(x: Int) {} + operator fun remAssign(x: Int) {} +} + +object JustMod { + operator fun mod(x: Int) {} + operator fun modAssign(x: Int) {} +} + +fun foo() { + ModAndRem % 1 + ModAndRem.mod(1) + ModAndRem.rem(1) + + JustMod % 1 + JustMod.mod(1) + + val r = ModAndRem + r %= 1 + r.remAssign(1) + + val m = JustMod + m %= 1 + m.modAssign(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/modWithRemAssign.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/modWithRemAssign.fir.kt new file mode 100644 index 00000000000..1f88d50ea19 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/modWithRemAssign.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER + +class ModAndRemAssign { + operator fun mod(x: Int) = ModAndRemAssign() + operator fun mod(x: String) = ModAndRemAssign() + operator fun modAssign(x: String) {} + operator fun remAssign(x: Int) {} +} + +operator fun ModAndRemAssign.mod(x: String) = ModAndRemAssign() +operator fun ModAndRemAssign.modAssign(x: String) {} + +fun test() { + val modAndRemAssign = ModAndRemAssign() + modAndRemAssign %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/noDeprecatedModConventionWithoutFeature.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/noDeprecatedModConventionWithoutFeature.fir.kt new file mode 100644 index 00000000000..b3e37e080ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/noDeprecatedModConventionWithoutFeature.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: -OperatorRem +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object ModAndRem { + operator fun mod(x: Int) {} + operator fun rem(x: Int) {} +} + +object OldMod { + operator fun mod(x: Int) {} +} + +object ModAndRemExtension +operator fun ModAndRemExtension.mod(x: Int) {} +operator fun ModAndRemExtension.rem(x: Int) {} + +object ModExtension +operator fun ModExtension.mod(x: Int) {} + +object ModMemberAndRemExtension { + operator fun mod(x: Int) {} +} + +operator fun ModMemberAndRemExtension.rem(x: Int) {} + +fun foo() { + ModAndRem % 1 + OldMod % 1 + + ModAndRemExtension % 1 + + ModExtension % 1 + + ModMemberAndRemExtension % 1 + + OldMod.mod(1) + ModExtension.mod(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/noOperatorRemFeature.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/noOperatorRemFeature.fir.kt new file mode 100644 index 00000000000..8b8327f0836 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/noOperatorRemFeature.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: -OperatorRem +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -EXTENSION_SHADOWED_BY_MEMBER + +class Foo { + operator fun rem(x: Int): Foo = Foo() +} + +class Bar { + operator fun remAssign(x: Int) {} +} + +class Baz { + companion object { + operator fun rem(x: Int) {} + operator fun Int.rem(x: Int) {} + } +} + +operator fun Baz.rem(x: Int) {} + +fun local() { + operator fun Int.rem(x: Int) {} + operator fun String.remAssign(x: Int) {} +} + +fun noOverflow() { + (-1).mod(5) +} + +fun builtIns(b: Byte, s: Short) { + var a = 1 % 2 + a %= 3 + 1.mod(2) + b % s + 1.0 % 2.0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_after.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_after.fir.kt new file mode 100644 index 00000000000..4051aa674a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_after.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +ProhibitOperatorMod +// !WITH_NEW_INFERENCE +// !API_VERSION: 1.0 +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -EXTENSION_SHADOWED_BY_MEMBER + +class Foo { + operator fun rem(x: Int): Foo = Foo() +} + +class Bar { + operator fun remAssign(x: Int) {} +} + +class Baz { + companion object { + operator fun rem(x: Int) {} + operator fun Int.rem(x: Int) {} + } +} + +operator fun Baz.rem(x: Int) {} + +fun local() { + operator fun Int.rem(x: Int) {} + operator fun String.remAssign(x: Int) {} +} + +class WithMod { + operator fun mod(other: WithMod) = this + + fun test() { + val a = this % this + var b = this.mod(this) + b %= this + } +} + +fun noOverflow() { + (-1).mod(5) +} + +fun builtIns(b: Byte, s: Short) { + var a = 1 % 2 + a %= 3 + 1.mod(2) + b % s + 1.0 % 2.0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_before.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_before.fir.kt new file mode 100644 index 00000000000..ff50595bd9d --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/noWarningForModFromBuiltinsWhenApi1_0_before.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !WITH_NEW_INFERENCE +// !API_VERSION: 1.0 +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -EXTENSION_SHADOWED_BY_MEMBER + +class Foo { + operator fun rem(x: Int): Foo = Foo() +} + +class Bar { + operator fun remAssign(x: Int) {} +} + +class Baz { + companion object { + operator fun rem(x: Int) {} + operator fun Int.rem(x: Int) {} + } +} + +operator fun Baz.rem(x: Int) {} + +fun local() { + operator fun Int.rem(x: Int) {} + operator fun String.remAssign(x: Int) {} +} + +class WithMod { + operator fun mod(other: WithMod) = this + + fun test() { + val a = this % this + var b = this.mod(this) + b %= this + } +} + +fun noOverflow() { + (-1).mod(5) +} + +fun builtIns(b: Byte, s: Short) { + var a = 1 % 2 + a %= 3 + 1.mod(2) + b % s + 1.0 % 2.0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt new file mode 100644 index 00000000000..9ba8553cda5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun fooInt(p: Int) = p +fun fooLong(p: Long) = p +fun fooByte(p: Byte) = p +fun fooShort(p: Short) = p + +fun test() { + fooInt(1 % 1) + fooByte(1 % 1) + fooLong(1 % 1) + fooShort(1 % 1) +} + +public operator fun Int.rem(other: Int): Int = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/operatorRem.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/operatorRem.fir.kt new file mode 100644 index 00000000000..7cd65cc45ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/operatorRem.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE + +class Foo { + operator fun rem(x: Int): Foo = Foo() +} + +class Bar { + operator fun remAssign(x: Int) {} +} + +fun baz() { + val f = Foo() % 1 + val b = Bar() + b %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/preferRemAsExtentionOverMod.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/preferRemAsExtentionOverMod.fir.kt new file mode 100644 index 00000000000..3695372a668 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/preferRemAsExtentionOverMod.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { +} +operator fun Foo.mod(x: Int): Foo = Foo() +operator fun Foo.rem(x: Int): Int = 0 + +fun foo() { + takeInt(Foo() % 1) +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/preferRemAsMemberOverMod.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/preferRemAsMemberOverMod.fir.kt new file mode 100644 index 00000000000..eec75b34f0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/preferRemAsMemberOverMod.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + operator fun mod(x: Int): Foo = Foo() + operator fun rem(x: Int): Int = 0 +} + +fun foo() { + takeInt(Foo() % 1) +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/preferRemFromCompanionObjectOverRem.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/preferRemFromCompanionObjectOverRem.fir.kt new file mode 100644 index 00000000000..acf62c6d659 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/preferRemFromCompanionObjectOverRem.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + companion object { + operator fun A.rem(x: Int) = 0 + } + + fun test() { + operator fun A.mod(x: Int) = "" + + takeInt(A() % 123) + } +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/preferRemOverModInLocalFunctions.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/preferRemOverModInLocalFunctions.fir.kt new file mode 100644 index 00000000000..d7059144f35 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/preferRemOverModInLocalFunctions.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object B + +class A { + operator fun B.rem(x: Int) = 0 +} + +fun test1() { + operator fun B.mod(x: Int) = "" + + with(A()) { + takeInt(B % 10) + } +} + +class C { + operator fun B.mod(x: Int) = "" +} + +fun test2() { + operator fun B.rem(x: Int) = 0 + + with(C()) { + takeInt(B % 10) + } +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/preferRemWithImplicitReceivers.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/preferRemWithImplicitReceivers.fir.kt new file mode 100644 index 00000000000..7778fdb28d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/preferRemWithImplicitReceivers.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + operator fun Int.mod(s: String) = 4 +} + +class B { + operator fun Int.rem(s: String) = "" +} + +fun test() { + with(B()) { + with(A()) { + takeString(1 % "") + } + } +} + +fun takeString(s: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/prefereRemAsExtensionOverMemberMod.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/prefereRemAsExtensionOverMemberMod.fir.kt new file mode 100644 index 00000000000..0b7bcaef8fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/prefereRemAsExtensionOverMemberMod.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Foo { + operator fun mod(x: Int): Foo = Foo() +} + +operator fun Foo.rem(x: Int): Int = 0 + + +fun foo() { + takeInt(Foo() % 1) +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt new file mode 100644 index 00000000000..4f0bc9ff038 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object RemAndRemAssign { + operator fun rem(x: Int) = RemAndRemAssign +} + +operator fun RemAndRemAssign.remAssign(x: Int) {} + +fun test() { + var c = RemAndRemAssign + c %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/remWithModAndModAssign.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/remWithModAndModAssign.fir.kt new file mode 100644 index 00000000000..530b5050668 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/remWithModAndModAssign.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER + +class ModAndRemAssign { + operator fun mod(x: Int) = ModAndRemAssign() + operator fun mod(x: String) = ModAndRemAssign() + operator fun modAssign(x: String) {} + operator fun rem(x: Int) = ModAndRemAssign() +} + +operator fun ModAndRemAssign.mod(x: String) = ModAndRemAssign() +operator fun ModAndRemAssign.modAssign(x: String) {} + +fun test() { + var modAndRemAssign = ModAndRemAssign() + modAndRemAssign %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/remWithModAssign.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/remWithModAssign.fir.kt new file mode 100644 index 00000000000..2ceabb24a13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/remWithModAssign.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object RemAndModAssign { + operator fun modAssign(x: String) {} + operator fun rem(x: Int) = RemAndModAssign +} + +fun test2() { + var c = RemAndModAssign + c %= 123 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/resolveModIfRemIsHidden.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/resolveModIfRemIsHidden.fir.kt new file mode 100644 index 00000000000..60c26d0d1d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/resolveModIfRemIsHidden.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitOperatorMod +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object A { + @Deprecated("Use mod instead", ReplaceWith("mod"), DeprecationLevel.HIDDEN) + operator fun rem(x: Int) = 0 + + operator fun mod(x: Int) = "" +} + +fun test() { + takeString(A % 123) +} + +fun takeString(s: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/resolveToModWhenNoOperatorRemFeature.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/resolveToModWhenNoOperatorRemFeature.fir.kt new file mode 100644 index 00000000000..1877165b621 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/resolveToModWhenNoOperatorRemFeature.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: -OperatorRem +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object ModAndRem { + operator fun mod(x: Int) = 0 + operator fun rem(x: Int) = "" +} + +object ModAssignAndRemAssign { + operator fun modAssign(x: String) {} + operator fun remAssign(x: Int) {} +} + +object RemAndModAssign { + operator fun modAssign(x: Int) {} + operator fun rem(x: Int) = RemAndModAssign +} + +object OnlyRem { + operator fun rem(x: Int) {} + operator fun remAssign(x: Int) {} +} + +fun test() { + takeInt(ModAndRem % 1) + + val c = ModAssignAndRemAssign + c %= "" + + var c1 = RemAndModAssign + c1 %= 1 + + OnlyRem % 1 + + val c2 = OnlyRem + c2 %= 1 +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_1.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_1.fir.kt new file mode 100644 index 00000000000..30758e5c931 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_1.fir.kt @@ -0,0 +1,5 @@ +// !API_VERSION: 1.1 + +fun test() { + 1.mod(3) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_2.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_2.fir.kt new file mode 100644 index 00000000000..7f076d9c8d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorRem/warningOnExplicitModCall1_2.fir.kt @@ -0,0 +1,5 @@ +// !API_VERSION: 1.2 + +fun test() { + 1.mod(3) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt new file mode 100644 index 00000000000..2fcd95faf7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt @@ -0,0 +1,17 @@ +//KT-1820 Write test for ASSIGN_OPERATOR_AMBIGUITY +package kt1820 + +class MyInt(val i: Int) { + operator fun plus(m: MyInt) : MyInt = MyInt(m.i + i) +} + +operator fun Any.plusAssign(a: Any) {} + +fun test(m: MyInt) { + m += m + + var i = 1 + i += 34 +} + + diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/AssignmentOperations.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignmentOperations.fir.kt new file mode 100644 index 00000000000..6f1790ed0d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignmentOperations.fir.kt @@ -0,0 +1,40 @@ +class A { + operator fun plusAssign(x: Int) {} + operator fun minusAssign(x: Int) {} + operator fun timesAssign(x: Int) {} + operator fun divAssign(x: Int) {} + operator fun remAssign(x: Int) {} +} + +fun testVal() { + val a = A() + a += 1 + a -= 1 + a *= 1 + a /= 1 + a %= 1 +} + +fun testExpr() { + A() += 1 + A() -= 1 + A() *= 1 + A() /= 1 + A() %= 1 +} + +class B { + operator fun plus(x: Int): B = B() + operator fun minus(x: Int): B = B() + operator fun times(x: Int): B = B() + operator fun div(x: Int): B = B() + operator fun rem(x: Int): B = B() +} + +fun testWrong() { + B() += 1 + B() -= 1 + B() *= 1 + B() /= 1 + B() %= 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/InconsistentGetSet.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/InconsistentGetSet.fir.kt new file mode 100644 index 00000000000..acb1654a31f --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/InconsistentGetSet.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Legal { + operator fun get(i: Int) = 0 + operator fun set(i: Int, newValue: Int) {} + operator fun set(i: Int, newValue: String) {} +} + +fun testLegal() { + ++Legal[0] + Legal[0]++ + Legal[0] += 1 +} + +object MismatchingTypes { + operator fun get(i: Int) = 0 + operator fun set(i: Int, newValue: String) {} +} + +fun testMismatchingTypes() { + ++MismatchingTypes[0] + MismatchingTypes[0]++ + MismatchingTypes[0] += 1 +} + +object MismatchingArities1 { + operator fun get(i: Int) = 0 + operator fun set(i: Int, j: Int, newValue: Int) {} +} + +object MismatchingArities2 { + operator fun get(i: Int, j: Int) = 0 + operator fun set(i: Int, newValue: Int) {} +} + +fun testMismatchingArities() { + ++MismatchingArities1[0] + MismatchingArities1[0]++ + MismatchingArities1[0] += 1 + + ++MismatchingArities2[0] + MismatchingArities2[0]++ + MismatchingArities2[0] += 1 +} + diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/IteratorAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/IteratorAmbiguity.fir.kt new file mode 100644 index 00000000000..f709915a9d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/IteratorAmbiguity.fir.kt @@ -0,0 +1,27 @@ +//KT-1821 Write test for ITERATOR_AMBIGUITY diagnostic + +interface MyCollectionInterface { +} + +interface MyAnotherCollectionInterface { +} + +class MyCollection : MyCollectionInterface, MyAnotherCollectionInterface { +} + +fun MyCollectionInterface.iterator() = MyIterator() + +fun MyAnotherCollectionInterface.iterator() = MyIterator() + +class MyIterator { + fun next() : MyElement = MyElement() + fun hasNext() = true +} + +class MyElement + +fun test1(collection: MyCollection) { + collection.iterator() + for (element in collection) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt new file mode 100644 index 00000000000..67a60bb81f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt @@ -0,0 +1,48 @@ +fun intBinEq() { + var x = 0 + x += 'a' + x += 1.toByte() + x += 1.toShort() + x += 1L + x += 1f + x += 1.0 + x *= 'a' + x *= 1.toByte() + x *= 1.toShort() + x *= 1L + x *= 1f + x *= 1.0 +} + +fun shortBinEq() { + var x = 0.toShort() + x += 'a' + x += 1.toByte() + x += 1.toShort() + x += 1L + x += 1f + x += 1.0 + + x *= 'a' + x *= 1.toByte() + x *= 1.toShort() + x *= 1L + x *= 1f + x *= 1.0 +} + +class A { + operator fun plus(x : A) : A { return x } +} + +class B { + operator fun plus(x : A) : A { return x } +} + +fun overloading() { + var x = A() + var y = A() + x += y + var z = B() + z += x +} diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.fir.kt new file mode 100644 index 00000000000..a400f76638a --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + operator fun compareTo(c: C): Int? = null +} + +fun test(c: C) { + c < c + c <= c + c >= c + c > c +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt1028.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt1028.fir.kt new file mode 100644 index 00000000000..b4e43ca6326 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt1028.fir.kt @@ -0,0 +1,35 @@ +//KT-1028 Wrong type checking for plusAssign +package kt1028 + +import java.util.* + +class event() +{ + val callbacks = ArrayList< Function1 >() // Should be ArrayList<()->Unit>, bug posted + + operator fun plusAssign(f : (T) -> Unit) = callbacks.add(f) + operator fun minusAssign(f : (T) -> Unit) = callbacks.remove(f) + fun call(value : T) { for(c in callbacks) c(value) } +} + +class MouseMovedEventArgs() +{ + public val X : Int = 0 +} + +class Control() +{ + public val MouseMoved : event = event() + + fun MoveMouse() = MouseMoved.call(MouseMovedEventArgs()) +} + +class Test() +{ + fun test() + { + val control = Control() + control.MouseMoved += { it.X } // here + control.MouseMoved.plusAssign( { it.X } ) // ok + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.fir.kt new file mode 100644 index 00000000000..9542129f87d --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE + +class A { + operator fun get(x: Int): Int = x + fun set(x: Int, y: Int) {} // no `operator` modifier +} + +fun main() { + val a = A() + a[1]++ + a[1] += 3 + a[1] = a[1] + 3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt13330.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt13330.fir.kt new file mode 100644 index 00000000000..f811d50b9f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt13330.fir.kt @@ -0,0 +1,4 @@ +// !WITH_NEW_INFERENCE +//KT-13330 AssertionError: Illegal resolved call to variable with invoke + +fun foo(exec: (String.() -> Unit)?) = "".exec() // is test data tag here \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt13349.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt13349.fir.kt new file mode 100644 index 00000000000..b3c73e430df --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt13349.fir.kt @@ -0,0 +1,7 @@ +object Foo { + operator fun invoke() {} +} + +fun main() { + Foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt3450.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt3450.fir.kt new file mode 100644 index 00000000000..3f5d1e27f07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt3450.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +public class A { + public operator fun get(vararg attrs : Pair) : A = this +} +operator fun String.unaryPlus() : A = A() +operator fun A.div(s : String) : A = A() + +fun test() { + (+"node2" / "node3" / "zzz") ["attr" to "value", "a2" to "v2"] +} + +//--------- +class B { + public operator fun get(s : String, q : String) : B = this + public operator fun get(s : Pair) : B = this + public operator fun invoke(q : B.() -> Unit) : B = this +} +val x = B()["a", "v"]["a" to "b"] {} ["q" to "p"] // does not parses around {} + +//from library +data class Pair (val first: A, val second: B) +infix fun A.to(that: B) = Pair(this, that) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnArray.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnArray.fir.kt new file mode 100644 index 00000000000..532bba2f335 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnArray.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + operator fun get(i: Int): C = this +} + +operator fun C.plus(a: Any): C = this +operator fun C.plusAssign(a: Any) {} + +class C1 { + operator fun get(i: Int): C = C() + operator fun set(i: Int, v: C) {} +} + +fun test() { + val c = C() + c[0] += "" + var c1 = C1() + c1[0] += "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt new file mode 100644 index 00000000000..4063b709120 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C + +operator fun C.plus(a: Any): C = this +operator fun C.plusAssign(a: Any) {} + +fun test() { + val c = C() + c += "" + var c1 = C() + c1 += "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt new file mode 100644 index 00000000000..fc1bb6297da --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class C { + val c: C = C() +} + +operator fun C.plus(a: Any): C = this +operator fun C.plusAssign(a: Any) {} + +class C1 { + var c: C = C() +} + +fun test() { + val c = C() + c.c += "" + var c1 = C1() + c1.c += "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOlverloadsGenericFunctions.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOlverloadsGenericFunctions.fir.kt new file mode 100644 index 00000000000..e54843f0cc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOlverloadsGenericFunctions.fir.kt @@ -0,0 +1,34 @@ +fun test1(x: List) = x +fun test1(x: List) = x + +fun List.test1a() {} +fun List.test1a() {} + +fun test2(x: List) = x +fun test2(x: List) = x + +fun List.test2a() {} +fun List.test2a() {} + +fun test3(x: List) = x +fun test3(x: List) = x + +fun List.test3a() {} +fun List.test3a() {} + +fun test4(x: Map) = x +fun test4(x: Map) = x + +fun Map.test4a() {} +fun Map.test4a() {} + +class Inv + +fun test5(x: Inv) = x +fun test5(x: Inv) = x + +fun test6(x: Array) = x +fun test6(x: Array) = x + +fun test7(x: Inv) = x +fun Inv.test7() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInClass.fir.kt new file mode 100644 index 00000000000..e2f8356240f --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInClass.fir.kt @@ -0,0 +1,6 @@ +class A { + fun a(a: Int): Int = 0 + + fun a(a: Int) { + } +} diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInPackage.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInPackage.fir.kt new file mode 100644 index 00000000000..9eb073bf03a --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsFunsDifferentReturnInPackage.fir.kt @@ -0,0 +1,7 @@ +package qwertyuiop + +fun c(s: String) { +} + +fun c(s: String) { +} diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalExtFunsInPackage.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalExtFunsInPackage.fir.kt new file mode 100644 index 00000000000..559f0c9ab01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalExtFunsInPackage.fir.kt @@ -0,0 +1,5 @@ +package extensionFunctions + +fun Int.qwe(a: Float) = 1 + +fun Int.qwe(a: Float) = 2 diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsInClass.fir.kt new file mode 100644 index 00000000000..93a3bbb7069 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsInClass.fir.kt @@ -0,0 +1,7 @@ +class A() { + fun b() { + } + + fun b() { + } +} diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsTPInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsTPInClass.fir.kt new file mode 100644 index 00000000000..48213d13dd6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalFunsTPInClass.fir.kt @@ -0,0 +1,4 @@ +class Aaa() { + fun f() = 1 + fun

f() = 1 +} diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalValsInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalValsInClass.fir.kt new file mode 100644 index 00000000000..56352d941f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsIdenticalValsInClass.fir.kt @@ -0,0 +1,4 @@ +class Aaa() { + val a = 1 + val a = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsValsDifferentTypeInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsValsDifferentTypeInClass.fir.kt new file mode 100644 index 00000000000..da5d63eba02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConflictingOverloadsValsDifferentTypeInClass.fir.kt @@ -0,0 +1,4 @@ +class Aaa() { + val a = 1 + val a = "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/ConstructorVsFunOverload.fir.kt b/compiler/testData/diagnostics/tests/overload/ConstructorVsFunOverload.fir.kt new file mode 100644 index 00000000000..24e7c934b48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ConstructorVsFunOverload.fir.kt @@ -0,0 +1,29 @@ +// constructor vs. fun overload + +package constructorVsFun + +class a() { } + +fun a() = 1 + +class Tram { + fun f() { } + + class f() { } +} + +class Yvayva { + companion object { + fun fghj() { } + + class fghj() { } + } +} + +class Rtyu { + fun ololo() { } + + companion object { + class ololo() { } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/EmptyArgumentListInLambda.fir.kt b/compiler/testData/diagnostics/tests/overload/EmptyArgumentListInLambda.fir.kt new file mode 100644 index 00000000000..c7967cb0894 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/EmptyArgumentListInLambda.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(g: () -> Int) {} +fun foo(f: (Int) -> Int) {} + +fun test() { + foo { -> 42 } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/ExtFunDifferentReceiver.fir.kt b/compiler/testData/diagnostics/tests/overload/ExtFunDifferentReceiver.fir.kt new file mode 100644 index 00000000000..066ad1f50a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/ExtFunDifferentReceiver.fir.kt @@ -0,0 +1,3 @@ +fun Int.rty() = 3 + +fun String.rty() = 4 diff --git a/compiler/testData/diagnostics/tests/overload/FunNoConflictInDifferentPackages.fir.kt b/compiler/testData/diagnostics/tests/overload/FunNoConflictInDifferentPackages.fir.kt new file mode 100644 index 00000000000..7ef2f1c5738 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/FunNoConflictInDifferentPackages.fir.kt @@ -0,0 +1,13 @@ +// FILE: pkg1.kt +// check no error in overload in different packages + +package pkg1 +fun e() = 1 + +// FILE: pkg2.kt +package pkg2 +fun e() = 1 + +// FILE: pkg3pkg1.kt +package pkg3.pkg1 +fun e() = 1 diff --git a/compiler/testData/diagnostics/tests/overload/LocalFunctions.fir.kt b/compiler/testData/diagnostics/tests/overload/LocalFunctions.fir.kt new file mode 100644 index 00000000000..1e9a89bbffd --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/LocalFunctions.fir.kt @@ -0,0 +1,213 @@ +fun test() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + + fun local() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + } +} + +class Test { + init { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + } + + fun test() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + } + + val property: Any get() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + + return 0 + } +} + +val property: Any get() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + + return 0 +} + +object Object { + fun test() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + } + + val property: Any get() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + + return 0 + } +} + +val obj = object { + fun test() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + } + + val property: Any get() { + fun test1() {} + fun test1() {} + + fun Any.test2() {} + fun test2(x: Any) = x + + fun Any.test3() {} + fun Any.test3() {} + + fun test4(): Int = 0 + fun test4(): String = "" + + class Test5(val x: Int) { + constructor(): this(0) + } + fun Test5() {} + fun Test5(x: Int) = x + + return 0 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/OverloadFunRegularAndExt.fir.kt b/compiler/testData/diagnostics/tests/overload/OverloadFunRegularAndExt.fir.kt new file mode 100644 index 00000000000..34c84965174 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/OverloadFunRegularAndExt.fir.kt @@ -0,0 +1,7 @@ +// check no error when regular function and extension function have same name + +package extensionAndRegular + +fun who() = 1 + +fun Int.who() = 1 diff --git a/compiler/testData/diagnostics/tests/overload/OverloadVarAndFunInClass.fir.kt b/compiler/testData/diagnostics/tests/overload/OverloadVarAndFunInClass.fir.kt new file mode 100644 index 00000000000..201a1193c06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/OverloadVarAndFunInClass.fir.kt @@ -0,0 +1,4 @@ +class Aaaa() { + val bb = 1 + fun bb() = 1 +} diff --git a/compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.fir.kt b/compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.fir.kt new file mode 100644 index 00000000000..0fbe04eebe7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/SyntheticAndNotSynthetic.fir.kt @@ -0,0 +1,7 @@ +fun Runnable(f: () -> Unit): Runnable = object : Runnable { + public override fun run() { + f() + } +} + +val x = Runnable { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/TypeParameterMultipleBounds.fir.kt b/compiler/testData/diagnostics/tests/overload/TypeParameterMultipleBounds.fir.kt new file mode 100644 index 00000000000..55e95f4bc38 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/TypeParameterMultipleBounds.fir.kt @@ -0,0 +1,15 @@ +import java.io.Serializable + +interface Test1 { + fun foo(t: T) where T : Cloneable, T : Serializable + fun foo(t: T) where T : Serializable, T : Cloneable +} + + +interface I1 +interface I2 : I1 + +interface Test2 { + fun foo(t: T) where T : I1, T : I2 + fun foo(t: T) where T : I2, T : I1 +} diff --git a/compiler/testData/diagnostics/tests/overload/UnsubstitutedJavaGenetics.fir.kt b/compiler/testData/diagnostics/tests/overload/UnsubstitutedJavaGenetics.fir.kt new file mode 100644 index 00000000000..9615bb55a6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/UnsubstitutedJavaGenetics.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// FILE: Base.java +public interface Base { + String foo(T a); + int foo(T a, Object... args); +} + +// FILE: Derived.java +public interface Derived extends Base { +} + +// FILE: test.kt +fun testDerived(base: Base, derived: Derived) { + val test1: String = base.foo("") + val test2: String = derived.foo("") +} diff --git a/compiler/testData/diagnostics/tests/overload/defaultParameters.fir.kt b/compiler/testData/diagnostics/tests/overload/defaultParameters.fir.kt new file mode 100644 index 00000000000..1a28b795288 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/defaultParameters.fir.kt @@ -0,0 +1,59 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun simple() = 1 +fun simple(a: Int = 3) = "" + +fun twoDefault(a: Int = 2) = 1 +fun twoDefault(a: Any = 2, b: String = "") = "" + +fun withGeneric(a: T) = 1 +fun withGeneric(a: T, b: Int = 4) = "" + +fun discriminateGeneric(a: T) = 1 +fun discriminateGeneric(a: Int, b: String = "") = "" + +fun withDefaultGeneric(t: T, d: T? = null) = 1 +fun withDefaultGeneric(t: T, d: T? = null, a: Int = 1) = "" + +fun withDefaults(a: Any = 2) = 1 +fun withDefaults(a: Int = 2, b: String = "") = "" + +fun withGenericDefaults(t: T, d: T? = null) = 1 +fun withGenericDefaults(t: T, d: T? = null, a: Int = 1) = "" + +fun wrong(a: Int = 1) {} +fun wrong(a: String = "", b: Int = 1) {} + +fun test() { + val a = simple() + a checkType { _() } + + val b = simple(1) + b checkType { _() } + + val c = twoDefault() + c checkType { _() } + + val d = twoDefault(1) + d checkType { _() } + + val e = twoDefault(1, "") + e checkType { _() } + + val f = withGeneric(3) + f checkType { _() } + + val g = discriminateGeneric(1) + g checkType { _() } + + val h = withDefaultGeneric("") + h checkType { _() } + + withDefaults(1) + + withGenericDefaults("") + + wrong(null!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt10939.fir.kt b/compiler/testData/diagnostics/tests/overload/kt10939.fir.kt new file mode 100644 index 00000000000..1aca3d7749a --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt10939.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +object X1 +object X2 + +interface Base { + fun foo(a: T1): X1 + fun foo(a: T2, vararg args: Any): X2 +} + +interface Derived : Base + +fun testDerived(base: Base, derived: Derived) { + val test1: X1 = base.foo("") + val test2: X1 = derived.foo("") +} + +interface GenericBase { + fun foo(x: T, a: T1): X1 +} + +interface SpecializedDerived : GenericBase { + fun foo(x: String, a: T2, vararg args: Any): X2 +} + +fun testSpecializedDerived(derived: SpecializedDerived) { + val test1: X1 = derived.foo("", "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt1998.fir.kt b/compiler/testData/diagnostics/tests/overload/kt1998.fir.kt new file mode 100644 index 00000000000..56e521a67e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt1998.fir.kt @@ -0,0 +1,14 @@ +// KT-1998 Strange "Overload resolution ambiguity" + +object A { + val c : String = "test" + + fun f(b: B): String { + return b.c // Test no "Overload resolution ambiguity" is reported here + } +} + +class B + +val B.c : String + get() = "test" diff --git a/compiler/testData/diagnostics/tests/overload/kt2493.fir.kt b/compiler/testData/diagnostics/tests/overload/kt2493.fir.kt new file mode 100644 index 00000000000..ccde55d8321 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt2493.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +interface A +interface B + +fun R.f() { +} + +fun R.f() { +} + +class AImpl: A +class BImpl: B + +class C: A, B + +fun main() { + AImpl().f() + BImpl().f() + C().f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt7068.fir.kt b/compiler/testData/diagnostics/tests/overload/kt7068.fir.kt new file mode 100644 index 00000000000..cc337d40b11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt7068.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun withLambda(block : Int.(String) -> Unit) { +} + +fun withLambda(o : Int, block : Int.(String) -> Unit) { +} + +fun test() { + withLambda { + it.length + } + + withLambda { r -> // no error should be here + r.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt7068_2.fir.kt b/compiler/testData/diagnostics/tests/overload/kt7068_2.fir.kt new file mode 100644 index 00000000000..d038ee2264f --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt7068_2.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun withLambda(block : Int.(String) -> Unit) { +} + +fun withLambda(block : Int.(String, String) -> Unit) { +} + +fun test() { + withLambda { r -> + r.length + } + + withLambda { x, y -> + x.length + y.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt7440.fir.kt b/compiler/testData/diagnostics/tests/overload/kt7440.fir.kt new file mode 100644 index 00000000000..afc5a210323 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt7440.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER +// KT-7440 Cannot complete type inference if two extension functions for interface hierarchy + +package inferenceagain + +interface Base +interface Derived : Base + +fun , T : Any> Base.maxBy(f: (T) -> R): T? = null +fun , T : Any> Derived.maxBy(f: (T) -> R): T? = null + +fun derivedOf(vararg members: T): Derived = null!! + +fun x(l: Derived) { + derivedOf(1, 2, 3).maxBy { it } // works + derivedOf(1, 2, 3).maxBy { it } // should work +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/onlyPrivateOverloadsDiagnostic.fir.kt b/compiler/testData/diagnostics/tests/overload/onlyPrivateOverloadsDiagnostic.fir.kt new file mode 100644 index 00000000000..13028da997e --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/onlyPrivateOverloadsDiagnostic.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + private fun foo(i: Int) {} + private fun foo(s: String) {} +} + +fun test(a: A) { + a.foo(3) + a.foo() +} + diff --git a/compiler/testData/diagnostics/tests/override/AbstractFunImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractFunImplemented.fir.kt new file mode 100644 index 00000000000..ef6b6fa41b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractFunImplemented.fir.kt @@ -0,0 +1,7 @@ +abstract class A { + abstract fun foo(): Int +} + +class B() : A() { + override fun foo() = 1 +} diff --git a/compiler/testData/diagnostics/tests/override/AbstractFunNotImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractFunNotImplemented.fir.kt new file mode 100644 index 00000000000..1059e1aae84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractFunNotImplemented.fir.kt @@ -0,0 +1,6 @@ +abstract class A { + abstract fun foo(): Int +} + +class B() : A() { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/AbstractValImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractValImplemented.fir.kt new file mode 100644 index 00000000000..a9669a69142 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractValImplemented.fir.kt @@ -0,0 +1,7 @@ +abstract class A { + abstract val i: Int +} + +class B() : A() { + override val i = 1 +} diff --git a/compiler/testData/diagnostics/tests/override/AbstractValNotImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractValNotImplemented.fir.kt new file mode 100644 index 00000000000..813af28f460 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractValNotImplemented.fir.kt @@ -0,0 +1,6 @@ +abstract class A { + abstract val i: Int +} + +class B() : A() { +} diff --git a/compiler/testData/diagnostics/tests/override/AbstractVarImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractVarImplemented.fir.kt new file mode 100644 index 00000000000..b0c3055b5fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractVarImplemented.fir.kt @@ -0,0 +1,7 @@ +abstract class A { + abstract var i: Int +} + +class B() : A() { + override var i = 1 +} diff --git a/compiler/testData/diagnostics/tests/override/AbstractVarNotImplemented.fir.kt b/compiler/testData/diagnostics/tests/override/AbstractVarNotImplemented.fir.kt new file mode 100644 index 00000000000..27305d3b2fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AbstractVarNotImplemented.fir.kt @@ -0,0 +1,6 @@ +abstract class A { + abstract var i: Int +} + +class B() : A() { +} diff --git a/compiler/testData/diagnostics/tests/override/AllPrivateFromSuperTypes.fir.kt b/compiler/testData/diagnostics/tests/override/AllPrivateFromSuperTypes.fir.kt new file mode 100644 index 00000000000..4a6d96de823 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/AllPrivateFromSuperTypes.fir.kt @@ -0,0 +1,14 @@ +package test + +interface A { + private val a: String + get() = "AAAA!" +} + +open class C { + private val a: String = "" +} + +class Subject : C(), A { + val c = a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.fir.kt b/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.fir.kt new file mode 100644 index 00000000000..c9f056a1d6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER +package override.generics + +abstract class MyAbstractClass { + abstract val pr : T +} + +abstract class MyLegalAbstractClass2(t : T) : MyAbstractClass() { + val pr : T = t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ConflictingFunctionSignatureFromSuperclass.fir.kt b/compiler/testData/diagnostics/tests/override/ConflictingFunctionSignatureFromSuperclass.fir.kt new file mode 100644 index 00000000000..a4e1448448d --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ConflictingFunctionSignatureFromSuperclass.fir.kt @@ -0,0 +1,7 @@ +open class Aaa() { + fun foo() = 1 +} + +open class Bbb() : Aaa() { + fun foo() = 2 +} diff --git a/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.fir.kt b/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.fir.kt new file mode 100644 index 00000000000..9b2d5ffd2a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER +open class Aaa() { + val bar = 1 +} + +open class Bbb() : Aaa() { + val bar = "aa" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/DefaultParameterValueInOverride.fir.kt b/compiler/testData/diagnostics/tests/override/DefaultParameterValueInOverride.fir.kt new file mode 100644 index 00000000000..ddae0ca41b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DefaultParameterValueInOverride.fir.kt @@ -0,0 +1,13 @@ +open class A { + open fun foo(a : Int) {} +} + +class C : A() { + override fun foo(a : Int = 1) { + } +} + +class D : A() { + override fun foo(a : Int = 1) { + } +} diff --git a/compiler/testData/diagnostics/tests/override/DefaultParameterValues-NoErrorsWhenInheritingFromOneTypeTwice.fir.kt b/compiler/testData/diagnostics/tests/override/DefaultParameterValues-NoErrorsWhenInheritingFromOneTypeTwice.fir.kt new file mode 100644 index 00000000000..a27d78224ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DefaultParameterValues-NoErrorsWhenInheritingFromOneTypeTwice.fir.kt @@ -0,0 +1,15 @@ +interface Y { + fun foo(a : Int = 1) +} + +interface YSub : Y { + +} + +class Z2 : Y, YSub { + override fun foo(a : Int) {} +} + +object Z2O : Y, YSub { + override fun foo(a : Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/Delegation.fir.kt b/compiler/testData/diagnostics/tests/override/Delegation.fir.kt new file mode 100644 index 00000000000..f4820e64c54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/Delegation.fir.kt @@ -0,0 +1,49 @@ +package test + +interface X { + fun foo(): String? { + return null + } +} + +interface Y { + fun foo(): String { + return "foo" + } +} + +interface Incompatible { + fun foo(): Int { + return 3 + } +} + +class Test1(val x: X) : X by x, Y { + override fun foo(): String? { + return null + } +} + +class Test2(val x: X) : X by x, Y { + override fun foo(): String { + return "foo" + } +} + +class Test3(val y: Y) : X, Y by y { + override fun foo(): String? { + return null + } +} + +class Test4(val y: Y) : X, Y by y { + override fun foo(): String { + return "foo" + } +} + +class Test5(val y: Y, val x: X) : X by x, Y by y, Incompatible { + override fun foo(): Int { + return 3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/DelegationFun.fir.kt b/compiler/testData/diagnostics/tests/override/DelegationFun.fir.kt new file mode 100644 index 00000000000..b7ff2c55ef7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DelegationFun.fir.kt @@ -0,0 +1,7 @@ +package delegation + +interface Aaa { + fun foo() +} + +class Bbb(aaa: Aaa) : Aaa by aaa diff --git a/compiler/testData/diagnostics/tests/override/DelegationVal.fir.kt b/compiler/testData/diagnostics/tests/override/DelegationVal.fir.kt new file mode 100644 index 00000000000..7f7a506b5b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DelegationVal.fir.kt @@ -0,0 +1,7 @@ +package delegation + +interface Aaa { + val i: Int +} + +class Bbb(aaa: Aaa) : Aaa by aaa diff --git a/compiler/testData/diagnostics/tests/override/DelegationVar.fir.kt b/compiler/testData/diagnostics/tests/override/DelegationVar.fir.kt new file mode 100644 index 00000000000..4c9a70763c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DelegationVar.fir.kt @@ -0,0 +1,7 @@ +package delegation + +interface Aaa { + var i: Int +} + +class Bbb(aaa: Aaa) : Aaa by aaa diff --git a/compiler/testData/diagnostics/tests/override/DuplicateMethod.fir.kt b/compiler/testData/diagnostics/tests/override/DuplicateMethod.fir.kt new file mode 100644 index 00000000000..3a5b3e7b8e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DuplicateMethod.fir.kt @@ -0,0 +1,8 @@ +interface Some { + fun test() +} + +class SomeImpl : Some { + override fun test() {} + override fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.fir.kt b/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.fir.kt new file mode 100644 index 00000000000..fc35e955bac --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.fir.kt @@ -0,0 +1,15 @@ +interface Foo +interface Bar + +interface A { + fun foo() + where T : Foo, T : Bar + = Unit +} + +class B : A { + override fun foo() + where T : Foo, T : Bar + = Unit + +} diff --git a/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.fir.kt b/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.fir.kt new file mode 100644 index 00000000000..9a56a456d57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.fir.kt @@ -0,0 +1,9 @@ +package extendFunctionClass + +class A : Function1 { + +} + +class B : Function1 { + override fun invoke(p1 : Int) = p1 +} diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.fir.kt b/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.fir.kt new file mode 100644 index 00000000000..7c8c385152a --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.fir.kt @@ -0,0 +1,9 @@ +open class Ccc() { + fun foo() = 1 +} + +interface Ttt { + fun foo(): Int +} + +class Zzz() : Ccc(), Ttt diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideDifferentDeclarationSignatures.fir.kt b/compiler/testData/diagnostics/tests/override/FakeOverrideDifferentDeclarationSignatures.fir.kt new file mode 100644 index 00000000000..35f3a9059b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideDifferentDeclarationSignatures.fir.kt @@ -0,0 +1,11 @@ +interface A { + fun f(): String = "string" +} + +open class B { + open fun f(): CharSequence = "charSequence" +} + +class C : B(), A + +val obj: A = object : B(), A {} diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideModality1.fir.kt b/compiler/testData/diagnostics/tests/override/FakeOverrideModality1.fir.kt new file mode 100644 index 00000000000..370dee14575 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideModality1.fir.kt @@ -0,0 +1,14 @@ +interface A { + fun foo() {} +} + +interface B : A { + abstract override fun foo() +} + +interface C { + abstract fun foo() +} + +// Fake override Z#foo should be abstract +class Z : B, C diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideModality2.fir.kt b/compiler/testData/diagnostics/tests/override/FakeOverrideModality2.fir.kt new file mode 100644 index 00000000000..3b5f283db50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideModality2.fir.kt @@ -0,0 +1,18 @@ +interface A { + fun foo() {} +} + +interface B : A { + abstract override fun foo() +} + +interface C : A { + abstract override fun foo() +} + +interface D : A { + override fun foo() = super.foo() +} + +// Fake override Z#foo should be open +class Z : B, C, D diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideModality3.fir.kt b/compiler/testData/diagnostics/tests/override/FakeOverrideModality3.fir.kt new file mode 100644 index 00000000000..022cd3bd460 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideModality3.fir.kt @@ -0,0 +1,16 @@ +interface A { + fun foo() {} +} + +interface B : A { + abstract override fun foo() +} + +interface C : A { + abstract override fun foo() +} + +interface D : A + +// Fake override Z#foo should be abstract +class Z : B, C, D diff --git a/compiler/testData/diagnostics/tests/override/Generics.fir.kt b/compiler/testData/diagnostics/tests/override/Generics.fir.kt new file mode 100644 index 00000000000..3f0d4bc44e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/Generics.fir.kt @@ -0,0 +1,60 @@ +package override.generics + +interface MyTrait { + fun foo(t: T) : T +} + +abstract class MyAbstractClass { + abstract fun bar(t: T) : T + abstract val pr : T +} + +interface MyProps { + val p : T +} + +open class MyGenericClass(t : T) : MyTrait, MyAbstractClass(), MyProps { + override fun foo(t: T) = t + override fun bar(t: T) = t + override val p : T = t + override val pr : T = t +} + +class MyChildClass() : MyGenericClass(1) {} +class MyChildClass1(t : T) : MyGenericClass(t) {} +class MyChildClass2(t : T) : MyGenericClass(t) { + fun foo(t: T) = t + val pr : T = t + override fun bar(t: T) = t + override val p : T = t +} + +open class MyClass() : MyTrait, MyAbstractClass() { + override fun foo(t: Int) = t + override fun bar(t: String) = t + override val pr : String = "1" +} + +abstract class MyAbstractClass1 : MyTrait, MyAbstractClass() { + override fun foo(t: Int) = t + override fun bar(t: String) = t +} + +class MyIllegalGenericClass1 : MyTrait, MyAbstractClass() {} +class MyIllegalGenericClass2(r : R) : MyTrait, MyAbstractClass() { + override fun foo(r: R) = r + override val pr : R = r +} +class MyIllegalClass1 : MyTrait, MyAbstractClass() {} +abstract class MyLegalAbstractClass1 : MyTrait, MyAbstractClass() {} + +class MyIllegalClass2(t : T) : MyTrait, MyAbstractClass() { + fun foo(t: T) = t + fun bar(t: T) = t + val pr : T = t +} +abstract class MyLegalAbstractClass2(t : T) : MyTrait, MyAbstractClass() { + fun foo(t: T) = t + fun bar(t: T) = t + val pr : T = t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/InvisiblePotentialOverride.fir.kt b/compiler/testData/diagnostics/tests/override/InvisiblePotentialOverride.fir.kt new file mode 100644 index 00000000000..94867e7289b --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/InvisiblePotentialOverride.fir.kt @@ -0,0 +1,7 @@ +open class A { + private fun foo() : Int = 1 +} + +class B : A() { + fun foo() : String = "" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MissingDelegate.fir.kt b/compiler/testData/diagnostics/tests/override/MissingDelegate.fir.kt new file mode 100644 index 00000000000..21889dbfe5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/MissingDelegate.fir.kt @@ -0,0 +1,3 @@ +class C : Base1 by Base2(1) { + fun test() { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.fir.kt new file mode 100644 index 00000000000..4de8d35e241 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.fir.kt @@ -0,0 +1,15 @@ +interface X { + fun foo(a : Int = 1) +} + +interface Y { + fun foo(a : Int = 1) +} + +class Z : X, Y { + override fun foo(a : Int) {} +} + +object ZO : X, Y { + override fun foo(a : Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.fir.kt b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.fir.kt new file mode 100644 index 00000000000..e00f26b093a --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.fir.kt @@ -0,0 +1,15 @@ +interface X { + fun foo(a : Int = 1) +} + +interface Y { + fun foo(a : Int = 1) +} + +class Z : X, Y { + fun foo(a : Int) {} +} + +object ZO : X, Y { + fun foo(a : Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultsAndNamesInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/override/MultipleDefaultsAndNamesInSupertypes.fir.kt new file mode 100644 index 00000000000..5a99fa791e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultsAndNamesInSupertypes.fir.kt @@ -0,0 +1,14 @@ +interface A { + fun foo(x: Int = 42): Int +} + +open class B { + fun foo(x: Int = 239) = x +} + +interface C { + fun foo(y: Int): Int +} + +// TODO DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES reported twice +class Z : A, B(), C \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultsInSupertypesNoExplicitOverride.fir.kt b/compiler/testData/diagnostics/tests/override/MultipleDefaultsInSupertypesNoExplicitOverride.fir.kt new file mode 100644 index 00000000000..bb84bf8ce14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultsInSupertypesNoExplicitOverride.fir.kt @@ -0,0 +1,10 @@ +interface X { + fun foo(a : Int = 1) +} + +interface Y { + fun foo(a : Int = 1) +} + +class Z1 : X, Y {} // BUG +object Z1O : X, Y {} // BUG \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt b/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt new file mode 100644 index 00000000000..7d9430c7527 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt @@ -0,0 +1,50 @@ +package override.normal + +interface MyTrait { + fun foo() + val pr : Unit +} + +abstract class MyAbstractClass { + abstract fun bar() + abstract val prr : Unit + +} + +open class MyClass() : MyTrait, MyAbstractClass() { + override fun foo() {} + override fun bar() {} + + override val pr : Unit = Unit + override val prr : Unit = Unit +} + +class MyChildClass() : MyClass() {} + +class MyIllegalClass : MyTrait, MyAbstractClass() {} + +class MyIllegalClass2() : MyTrait, MyAbstractClass() { + override fun foo() {} + override val pr : Unit = Unit + override val prr : Unit = Unit +} + +class MyIllegalClass3() : MyTrait, MyAbstractClass() { + override fun bar() {} + override val pr : Unit = Unit + override val prr : Unit = Unit +} + +class MyIllegalClass4() : MyTrait, MyAbstractClass() { + fun foo() {} + val pr : Unit + override fun other() {} + override val otherPr : Int = 1 +} + +class MyChildClass1() : MyClass() { + fun foo() {} + val pr : Unit = Unit + override fun bar() {} + override val prr : Unit = Unit +} diff --git a/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.fir.kt b/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.fir.kt new file mode 100644 index 00000000000..2dd58530d21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.fir.kt @@ -0,0 +1,13 @@ +interface D { + fun foo() +} + +interface E { + fun foo() {} +} + +object Impl : D, E { + override fun foo() {} +} + +val obj: D = object : D by Impl, E by Impl {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/OverrideWithErrors.fir.kt b/compiler/testData/diagnostics/tests/override/OverrideWithErrors.fir.kt new file mode 100644 index 00000000000..e492c6cfbeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/OverrideWithErrors.fir.kt @@ -0,0 +1,9 @@ +package test + +open class A { + open fun foo(a: E) {} +} + +class B : A() { + override fun foo(a: E) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/OverridingFinalMember.fir.kt b/compiler/testData/diagnostics/tests/override/OverridingFinalMember.fir.kt new file mode 100644 index 00000000000..95f20afd171 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/OverridingFinalMember.fir.kt @@ -0,0 +1,7 @@ +open class A { + final fun foo() {} +} + +class B : A() { + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/override/ParameterDefaultValues-DefaultValueFromOnlyOneSupertype.fir.kt b/compiler/testData/diagnostics/tests/override/ParameterDefaultValues-DefaultValueFromOnlyOneSupertype.fir.kt new file mode 100644 index 00000000000..158db681970 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ParameterDefaultValues-DefaultValueFromOnlyOneSupertype.fir.kt @@ -0,0 +1,11 @@ +interface X { + fun foo(a : Int = 1) +} + +interface Y { + fun foo(a : Int) +} + +class Z : X, Y { + override fun foo(a : Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ParentInheritsManyImplementations.fir.kt b/compiler/testData/diagnostics/tests/override/ParentInheritsManyImplementations.fir.kt new file mode 100644 index 00000000000..1a64254694c --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ParentInheritsManyImplementations.fir.kt @@ -0,0 +1,17 @@ +package d + +interface A { + fun foo() = 1 +} + +interface B { + fun foo() = 2 +} + +open class C : A, B {} + +interface E { + fun foo(): Int +} + +class D : C() {} diff --git a/compiler/testData/diagnostics/tests/override/PropertyInConstructor.fir.kt b/compiler/testData/diagnostics/tests/override/PropertyInConstructor.fir.kt new file mode 100644 index 00000000000..409fbb14b2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/PropertyInConstructor.fir.kt @@ -0,0 +1,11 @@ +open class Base { + protected open val prot: Int = 1 + internal open val int: Int = 1 + public open val pub: Int = 1 +} + +class Child( + override val prot: Int, + override val int: Int, + override val pub: Int +) : Base() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ProtectedAndPrivateFromSupertypes.fir.kt b/compiler/testData/diagnostics/tests/override/ProtectedAndPrivateFromSupertypes.fir.kt new file mode 100644 index 00000000000..13616922adb --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ProtectedAndPrivateFromSupertypes.fir.kt @@ -0,0 +1,17 @@ +package test + +interface A { + val a: String +} + +interface B { + val a: String +} + +open class C { + private val a: String = "" +} + +class Subject : C(), A, B { + val c = a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/SuspiciousCase1.fir.kt b/compiler/testData/diagnostics/tests/override/SuspiciousCase1.fir.kt new file mode 100644 index 00000000000..e80e4732343 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/SuspiciousCase1.fir.kt @@ -0,0 +1,12 @@ +// NamedFunctionDescriptor.substitute substitutes "overrides" +// this test checks it does it properly + +interface Foo

{ + fun quux(p: P, q: Int = 17) : Int = 18 +} + +interface Bar : Foo + +abstract class Baz() : Bar + +fun zz(b: Baz) = b.quux("a") diff --git a/compiler/testData/diagnostics/tests/override/ToAbstractMembersFromSuper-kt1996.fir.kt b/compiler/testData/diagnostics/tests/override/ToAbstractMembersFromSuper-kt1996.fir.kt new file mode 100644 index 00000000000..fcdda569a7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ToAbstractMembersFromSuper-kt1996.fir.kt @@ -0,0 +1,11 @@ +// http://youtrack.jetbrains.com/issue/KT-1996 + +interface Foo { + fun foo(): Unit +} + +interface Bar { + fun foo(): Unit +} + +class Baz : Foo, Bar \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/covariantOverrides.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/covariantOverrides.fir.kt new file mode 100644 index 00000000000..c0ac2b03bc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/covariantOverrides.fir.kt @@ -0,0 +1,37 @@ +interface IBase { + fun copy(): IBase +} + +interface ILeft : IBase { + override fun copy(): ILeft +} + +open class CLeft : ILeft { + override fun copy(): ILeft = CLeft() +} + +interface IRight : IBase { + override fun copy(): IRight +} + +interface IDerived : ILeft, IRight { + override fun copy(): IDerived +} + +// Error: ILeft::copy and IRight::copy have unrelated return types +class CDerivedInvalid1 : ILeft, IRight + +// Error: CLeft::copy and IRight::copy have unrelated return types +class CDerivedInvalid2 : CLeft(), IRight + +// OK: CDerived1::copy overrides both ILeft::copy and IRight::copy +class CDerived1 : ILeft, IRight { + override fun copy(): CDerived1 = CDerived1() +} + +// Although ILeft::copy and IRight::copy return types are unrelated, IDerived::copy return type is the most specific of three. +abstract class CDerived2 : ILeft, IRight, IDerived + +class CDerived2a : ILeft, IRight, IDerived { + override fun copy(): IDerived = CDerived2a() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnType.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnType.fir.kt new file mode 100644 index 00000000000..1c27c283354 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnType.fir.kt @@ -0,0 +1,27 @@ +// FILE: J.java +public interface J { + String foo(); // String! +} + +// FILE: K.kt +interface K1 { + fun foo(): String +} + +interface K2 { + fun foo(): String? +} + +interface KDerived1a : K1, J + +interface KDerived1b : J, K1 + +interface KDerived2a : K2, J + +interface KDerived2b : J, K2 + +interface KDerived12a : K1, K2, J + +interface KDerived12b : K1, J, K2 + +interface KDerived12c : J, K1, K2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.fir.kt new file mode 100644 index 00000000000..0c0e63b2220 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.fir.kt @@ -0,0 +1,61 @@ +// FILE: InOut.kt +interface In + +// FILE: J1.java +public interface J1 { + In foo(); +} + +// FILE: J2.java +import org.jetbrains.annotations.*; + +public interface J2 { + @NotNull In foo(); +} + +// FILE: J3.java +import org.jetbrains.annotations.*; + +public interface J3 { + @Nullable In foo(); +} + +// FILE: K.kt +interface K1 { + fun foo(): In +} + +interface K2 { + fun foo(): In +} + +// FIXME TestJ1K1 should have foo(): In, since In <: In. +interface TestJ1K1 : J1, K1 +interface TestK1J1 : K1, J1 + +interface TestJ1K2 : J1, K2 +interface TestK2J1 : K2, J1 + +interface TestJ2K1 : J2, K1 +interface TestK1J2 : K1, J2 + +interface TestJ2K2 : J2, K2 +interface TestK2J2 : K2, J2 + +interface TestJ3K1 : J3, K1 +interface TestK1J3 : K1, J3 + +interface TestJ3K2 : J3, K2 +interface TestK2J3 : K2, J3 + +interface TestJ1K1K2 : J1, K1, K2 +interface TestK1J1K2 : K1, J1, K2 +interface TestK1K2J1 : K1, K2, J1 + +interface TestJ2K1K2 : J2, K1, K2 +interface TestK1J2K2 : K1, J2, K2 +interface TestK1K2J2 : K1, K2, J2 + +interface TestJ3K1K2 : J3, K1, K2 +interface TestK1J3K2 : K1, J3, K2 +interface TestK1K2J3 : K1, K2, J3 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.fir.kt new file mode 100644 index 00000000000..5c7598aafaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.fir.kt @@ -0,0 +1,43 @@ +// FILE: J.java +public interface J { + java.util.List foo(); +} + +// FILE: K.kt +interface ILNS { + fun foo(): List +} + +interface IMLS { + fun foo(): MutableList +} + +interface IMLNS { + fun foo(): MutableList +} + +interface ILS { + fun foo(): List +} + +interface Test1 : ILNS, J +interface Test2 : J, ILNS + +interface Test3 : IMLS, J +interface Test4 : J, IMLS + +interface Test5 : ILNS, IMLS, J +interface Test6 : ILNS, J, IMLS +interface Test7 : J, ILNS, IMLS + +// Return types of ILS::foo and IMLNS::foo are incompatible themselves. +// However, return type of J::foo is (Mutable)List!, +// which is subtype of both List and MutalbeList. +// Thus, inheriting from J, IMLNS, and ILS is Ok, +// but inheriting from IMLNS and ILS is not. + +interface Test8 : J, IMLNS, ILS +interface Test9 : IMLNS, J, ILS +interface Test10 : IMLNS, ILS, J + +interface Test11 : IMLNS, ILS \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/genericWithUpperBound.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/genericWithUpperBound.fir.kt new file mode 100644 index 00000000000..453cbb87571 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/genericWithUpperBound.fir.kt @@ -0,0 +1,56 @@ +// FILE: JFooWithUpperBound.java +public interface JFooWithUpperBound { + T foo(); +} + +// FILE: JFooWithUpperBoundDerived.java +public interface JFooWithUpperBoundDerived extends JFooWithUpperBound { +} + +// FILE: JCFooWithUpperBound.java +public class JCFooWithUpperBound { + public T foo() { + return null; + } +} + +// FILE: JCFooWithUpperBoundDerived.java +public class JCFooWithUpperBoundDerived extends JCFooWithUpperBound { +} + +// FILE: K.kt +interface IBase + +interface IDerived : IBase + +interface IFooWithUpperBound { + fun foo(): T +} + +interface IFooT { + fun foo(): T +} + +interface IFoo { + fun foo(): IBase +} + +interface IFooDerived : IFoo { + override fun foo(): IDerived +} + +interface IFooWithUpperBoundDerived : IFooWithUpperBound + +interface Test1 : IFooWithUpperBound, IFoo + +interface Test2 : IFooT, IFoo + +interface Test3 : IFooWithUpperBoundDerived, IFooDerived + +interface Test4 : JFooWithUpperBound, IFoo + +interface Test5 : JFooWithUpperBoundDerived, IFooDerived + +class Test6 : JCFooWithUpperBound(), IFoo + +class Test7 : JCFooWithUpperBoundDerived(), IFooDerived \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355.fir.kt new file mode 100644 index 00000000000..7d3db4e4f22 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355.fir.kt @@ -0,0 +1,13 @@ +interface IFooAny { + val foo: Any +} + +interface IFooStr : IFooAny { + override val foo: String +} + +abstract class BaseAny(override val foo: Any): IFooAny + +abstract class BaseStr : BaseAny(42), IFooStr + +class C : BaseStr() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355viaJava.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355viaJava.fir.kt new file mode 100644 index 00000000000..0ad54762042 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt13355viaJava.fir.kt @@ -0,0 +1,47 @@ +// FILE: K.kt +abstract class ATest1 : TestNN.JNullVsNotNull() + +abstract class ATest2 : TestNN.JUnknownImpl(), TestNN.JNotNull + +abstract class ATest3 : TestNN.JUnknownVsNotNull() + +class CTest1 : TestNN.JNullVsNotNull() + +class CTest2 : TestNN.JUnknownImpl(), TestNN.JNotNull + +class CTest3 : TestNN.JUnknownVsNotNull() + +// FILE: TestNN.java +import org.jetbrains.annotations.*; + +public class TestNN { + public interface JNull { + @Nullable Object foo(); + } + + public interface JNotNull { + @NotNull Object foo(); + } + + public static class JNullVsNotNull implements JNull, JNotNull { + public Object foo() { + return this; + } + } + + public static class JNullBase { + @Nullable public Object foo() { + return null; + } + } + + public static class JUnknownImpl extends JNullBase { + public Object foo() { + return this; + } + } + + public static class JUnknownVsNotNull extends JUnknownImpl implements JNotNull { + } +} + diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt9550.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt9550.fir.kt new file mode 100644 index 00000000000..054e69b9189 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/kt9550.fir.kt @@ -0,0 +1,13 @@ +interface A { + fun foo() + fun bar() +} + +interface B { + fun foo() + fun bar() +} + +interface C1 : A, B { + override fun bar() +} diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/returnTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/returnTypeMismatch.fir.kt new file mode 100644 index 00000000000..93f1a1414fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/returnTypeMismatch.fir.kt @@ -0,0 +1,29 @@ +open class A { + open fun foo(): Boolean = true +} + +interface IA { + fun foo(): String +} + +interface IAA { + fun foo(): Int +} + +interface IGA { + fun foo(): T +} + +class B1: A(), IA + +class B2: A(), IA, IAA + +abstract class B3: IA, IAA + +class BS1: A(), IGA + +class BS2: A(), IGA + +class BS3: A(), IGA + +class BG1: A(), IGA diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/unrelatedInherited.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/unrelatedInherited.fir.kt new file mode 100644 index 00000000000..c8b6efc9e1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/unrelatedInherited.fir.kt @@ -0,0 +1,33 @@ +interface IA { + fun method(): String + val propVal: String + var propVar: String +} + +interface IB1 : IA +interface IB2 : IA + +interface IGA { + fun method(): T + val propVal: T + var propVar: T +} + +interface IGB1Str : IGA +interface IGB2Str : IGA +interface IGB3Int : IGA + +interface IGB4T : IGA +interface IGB5T : IGA + +interface IC : IB1, IB2 + +interface IGC1 : IGB1Str, IGB2Str + +interface IGC2 : IGB1Str, IGB3Int + +interface IGC3 : IGB4T, IGB5T + +interface IGC4 : IGB4T, IGB5T + +interface IGC5 : IGB4T, IGB5T \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/valTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/valTypeMismatch.fir.kt new file mode 100644 index 00000000000..a46c47515ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/valTypeMismatch.fir.kt @@ -0,0 +1,29 @@ +open class A { + open val foo: Boolean = true +} + +interface IA { + val foo: String +} + +interface IAA { + val foo: Int +} + +interface IGA { + val foo: T +} + +class B1: A(), IA + +class B2: A(), IA, IAA + +abstract class B3: IA, IAA + +class BS1: A(), IGA + +class BS2: A(), IGA + +class BS3: A(), IGA + +class BG1: A(), IGA diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/varTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/varTypeMismatch.fir.kt new file mode 100644 index 00000000000..81f5a80065e --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/varTypeMismatch.fir.kt @@ -0,0 +1,29 @@ +open class A { + open var foo: Boolean = true +} + +interface IA { + var foo: String +} + +interface IAA { + var foo: Int +} + +interface IGA { + var foo: T +} + +class B1: A(), IA + +class B2: A(), IA, IAA + +abstract class B3: IA, IAA + +class BS1: A(), IGA + +class BS2: A(), IGA + +class BS3: A(), IGA + +class BG1: A(), IGA diff --git a/compiler/testData/diagnostics/tests/override/fakeEquals.fir.kt b/compiler/testData/diagnostics/tests/override/fakeEquals.fir.kt new file mode 100644 index 00000000000..81e96a21e8b --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/fakeEquals.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_REFERENCE + +class Foo + +fun test(a: Foo, b: Foo) { + // Note that signature matches the 'equals' + fun equals(x: Any?): Boolean = false + equals(b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt12358.fir.kt b/compiler/testData/diagnostics/tests/override/kt12358.fir.kt new file mode 100644 index 00000000000..74b73cf0ba5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt12358.fir.kt @@ -0,0 +1,9 @@ +abstract class A { + abstract override fun toString(): String +} + +interface B + +abstract class C : A(), B + +class Test : C() diff --git a/compiler/testData/diagnostics/tests/override/kt12467.fir.kt b/compiler/testData/diagnostics/tests/override/kt12467.fir.kt new file mode 100644 index 00000000000..a6028721b18 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt12467.fir.kt @@ -0,0 +1,14 @@ +interface A { + fun test() { + } +} + +interface B : A { + override fun test() +} + +interface C : A + +interface D : C, B + +class K : D diff --git a/compiler/testData/diagnostics/tests/override/kt12482.fir.kt b/compiler/testData/diagnostics/tests/override/kt12482.fir.kt new file mode 100644 index 00000000000..db5999b06e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt12482.fir.kt @@ -0,0 +1,11 @@ +interface A { + fun test(): String = "A" +} + +interface B : A { + override fun test(): Unit = "B" +} + +open class C : A + +class D : C(), B diff --git a/compiler/testData/diagnostics/tests/override/kt1862.fir.kt b/compiler/testData/diagnostics/tests/override/kt1862.fir.kt new file mode 100644 index 00000000000..0cc1c2ab5f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt1862.fir.kt @@ -0,0 +1,11 @@ +open class Aaa() { + open fun foo() = 1 +} + +open class Bbb() : Aaa() { + override fun foo() = 2 +} + +interface Ccc : Aaa + +class Ddd() : Bbb(), Ccc \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt2052.fir.kt b/compiler/testData/diagnostics/tests/override/kt2052.fir.kt new file mode 100644 index 00000000000..6b263071aa5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt2052.fir.kt @@ -0,0 +1,10 @@ +interface Runnable { + fun run() +} + +class C { + fun f() { + class MyRunnable(): Runnable { + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt2491.fir.kt b/compiler/testData/diagnostics/tests/override/kt2491.fir.kt new file mode 100644 index 00000000000..988ed79e63e --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt2491.fir.kt @@ -0,0 +1,11 @@ +interface T { + public fun foo() +} + +open class C { + protected fun foo() {} +} + +class D : C(), T + +val obj: C = object : C(), T {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt4763.fir.kt b/compiler/testData/diagnostics/tests/override/kt4763.fir.kt new file mode 100644 index 00000000000..0f18e051678 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt4763.fir.kt @@ -0,0 +1,11 @@ +interface A { + fun f(): String +} + +open class B { + open fun f(): CharSequence = "charSequence" +} + +class C : B(), A + +val d: A = object : B(), A {} diff --git a/compiler/testData/diagnostics/tests/override/kt4763property.fir.kt b/compiler/testData/diagnostics/tests/override/kt4763property.fir.kt new file mode 100644 index 00000000000..e14e07a22f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt4763property.fir.kt @@ -0,0 +1,11 @@ +interface P { + var f: Number +} + +open class Q { + val x: Int = 42 +} + +class R : P, Q() + +val s: Q = object : Q(), P {} diff --git a/compiler/testData/diagnostics/tests/override/kt4785.fir.kt b/compiler/testData/diagnostics/tests/override/kt4785.fir.kt new file mode 100644 index 00000000000..7db8c26e68b --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt4785.fir.kt @@ -0,0 +1,11 @@ +interface T { + fun foo() +} + +open class C { + protected fun foo() {} +} + +class E : C(), T + +val z: T = object : C(), T {} diff --git a/compiler/testData/diagnostics/tests/override/kt6014.fir.kt b/compiler/testData/diagnostics/tests/override/kt6014.fir.kt new file mode 100644 index 00000000000..a8ecad03d8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt6014.fir.kt @@ -0,0 +1,17 @@ +interface IBase { + override fun toString(): String +} + +interface IDerived : IBase + +object BaseImpl : IBase { + override fun toString(): String = "A" +} + +object DerivedImpl : IDerived { + override fun toString(): String = "A" +} + +class Test1 : IBase by BaseImpl + +class Test2 : IDerived by DerivedImpl diff --git a/compiler/testData/diagnostics/tests/override/kt880.fir.kt b/compiler/testData/diagnostics/tests/override/kt880.fir.kt new file mode 100644 index 00000000000..814e808b9fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt880.fir.kt @@ -0,0 +1,16 @@ +// KT-880 Overload resolution ambiguity + +public interface I { + open fun test() : Unit +} + +abstract public class A() { + open public fun test() : Unit { + } +} + +public open class T() : A(), I { + open fun main() : Unit { + test() // Test no "Overload resolution ambiguity" is here + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/kt8990.fir.kt b/compiler/testData/diagnostics/tests/override/kt8990.fir.kt new file mode 100644 index 00000000000..ca218fc52c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/kt8990.fir.kt @@ -0,0 +1,11 @@ +open class A { + private fun foo() {} + + inner class B : A() { + private fun foo() {} + } +} + +class C : A() { + private fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/overrideMemberFromFinalClass.fir.kt b/compiler/testData/diagnostics/tests/override/overrideMemberFromFinalClass.fir.kt new file mode 100644 index 00000000000..c0430ca06a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/overrideMemberFromFinalClass.fir.kt @@ -0,0 +1,28 @@ +class Foo { + open fun openFoo() {} + fun finalFoo() {} +} + +class Bar : Foo() { + override fun openFoo() {} + override fun finalFoo() {} +} + + +open class A1 { + open fun foo() {} +} + +class B1 : A1() +class C1 : B1() { + override fun foo() {} +} + +abstract class A2 { + abstract fun foo() +} + +class B2 : A2() +class C2 : B2() { + override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/changeOnOverrideDiagnostic.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/changeOnOverrideDiagnostic.fir.kt new file mode 100644 index 00000000000..8a0a91be12d --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/changeOnOverrideDiagnostic.fir.kt @@ -0,0 +1,13 @@ +interface A { + fun b(a : Int) +} + +interface B : A {} + +class C1 : A { + override fun b(b : Int) {} +} + +class C2 : B { + override fun b(b : Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/differentNamesInSupertypesDiagnostic.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/differentNamesInSupertypesDiagnostic.fir.kt new file mode 100644 index 00000000000..cfb3941a6ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/differentNamesInSupertypesDiagnostic.fir.kt @@ -0,0 +1,15 @@ +interface C { + fun foo(a : Int) +} + +interface D { + fun foo(b : Int) +} + +interface E : C, D + +interface F : C, D { + override fun foo(a : Int) { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/invokeInFunctionClass.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/invokeInFunctionClass.fir.kt new file mode 100644 index 00000000000..5fa63c79496 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/invokeInFunctionClass.fir.kt @@ -0,0 +1,27 @@ +class Function1Impl : (String) -> Unit { + override fun invoke(myParamName: String) {} +} + +fun test1(f: Function1Impl) { + f("") + f(p0 = "") + f(myParamName = "") + f.invoke("") + f.invoke(p0 = "") + f.invoke(myParamName = "") +} + +fun test2(f: (String) -> Unit) { + f("") + f(p0 = "") + f(myParamName = "") + f.invoke("") + f.invoke(p0 = "") + f.invoke(myParamName = "") +} + +fun test3(f: String.(String) -> Unit) { + "".f("") + "".f(p0 = "") + "".f(zzz = "") +} diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/jjkHierarchy.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/jjkHierarchy.fir.kt new file mode 100644 index 00000000000..dacf0a11ff9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/jjkHierarchy.fir.kt @@ -0,0 +1,16 @@ +// FILE: Super.java + +interface Super { + void foo(long superName); +} + +// FILE: Sub.java + +interface Sub extends Super { +} + +// FILE: SubSub.kt + +class SubSub : Sub { + override fun foo(subName: Long) {} +} diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kjkHierarchy.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/kjkHierarchy.fir.kt new file mode 100644 index 00000000000..75f7d2c4112 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kjkHierarchy.fir.kt @@ -0,0 +1,16 @@ +// FILE: Super.kt + +interface Super { + fun foo(superName: Int) +} + +// FILE: Sub.java + +interface Sub extends Super { +} + +// FILE: SubSub.kt + +class SubSub : Sub { + override fun foo(subName: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kjkWithSeveralSupers.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/kjkWithSeveralSupers.fir.kt new file mode 100644 index 00000000000..32527db7597 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kjkWithSeveralSupers.fir.kt @@ -0,0 +1,51 @@ +// FILE: KSuper.kt + +interface KSuper { + fun foo(ksuperName: Int) +} + +// FILE: JSuper1.java + +interface JSuper1 { + void foo(int jsuper1Name); +} + +// FILE: JSuper2.java + +interface JSuper2 { + void foo(int jsuper2Name); +} + + +// FILE: Sub1.java +interface Sub1 extends KSuper, JSuper1, JSuper2 { + @Override + void foo(int sub1Name); +} + +// FILE: Sub2.java +interface Sub2 extends JSuper1, KSuper, JSuper2 { + @Override + void foo(int sub2Name); +} + +// FILE: Sub3.java +interface Sub3 extends JSuper1, JSuper2, KSuper { + @Override + void foo(int sub3Name); +} + + +// FILE: SubSub.kt + +class SubSub1 : Sub1 { + override fun foo(ksuperName: Int) {} +} + +class SubSub2 : Sub2 { + override fun foo(ksuperName: Int) {} +} + +class SubSub3 : Sub3 { + override fun foo(ksuperName: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsBothJavaAndKotlin.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsBothJavaAndKotlin.fir.kt new file mode 100644 index 00000000000..7845a3c17bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsBothJavaAndKotlin.fir.kt @@ -0,0 +1,13 @@ +// FILE: JavaInterface.java + +interface JavaInterface { + void foo(int javaName); +} + +// FILE: kotlin.kt + +interface KotlinTrait { + public fun foo(someOtherName: Int) {} +} + +class BothTraitsSubclass : JavaInterface, KotlinTrait \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.fir.kt b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.fir.kt new file mode 100644 index 00000000000..1e7d997c393 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/parameterNames/kotlinInheritsJava.fir.kt @@ -0,0 +1,18 @@ +// FILE: JavaInterface.java + +public interface JavaInterface { + void foo(int javaName); +} + +// FILE: kotlin.kt + +class SimpleSubclass : JavaInterface { + override fun foo(kotlinName: Int) {} +} + + +interface SubtraitWithFakeOverride : JavaInterface + +class Subclass : SubtraitWithFakeOverride { + override fun foo(otherKotlinName: Int) {} +} diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/classAndTwoInterfaceBounds.fir.kt b/compiler/testData/diagnostics/tests/override/typeParameters/classAndTwoInterfaceBounds.fir.kt new file mode 100644 index 00000000000..61f5cf91a8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/typeParameters/classAndTwoInterfaceBounds.fir.kt @@ -0,0 +1,31 @@ +interface I1 +interface I2 +open class C + +interface A { + fun foo(t: T) where T : I1, T : C, T : I2 +} + +interface B1 : A { + override fun foo(t: T) where T : C, T : I1, T : I2 +} + +interface B2 : A { + override fun foo(t: T) where T : I1, T : C, T : I2 +} + +interface B3 : A { + override fun foo(t: T) where T : I1, T : I2, T : C +} + +interface B4 : A { + override fun foo(t: T) where T : C, T : I2, T : I1 +} + +interface B5 : A { + override fun foo(t: T) where T : I2, T : C, T : I1 +} + +interface B6 : A { + override fun foo(t: T) where T : I2, T : I1, T : C +} diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt b/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt new file mode 100644 index 00000000000..efe77a95f12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt @@ -0,0 +1,7 @@ +interface A { + fun foo() where T : Any, T : Cloneable? +} + +interface B : A { + override fun foo() where T : Any?, T : Cloneable +} diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/kt9850.fir.kt b/compiler/testData/diagnostics/tests/override/typeParameters/kt9850.fir.kt new file mode 100644 index 00000000000..413c36eebd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/typeParameters/kt9850.fir.kt @@ -0,0 +1,8 @@ +abstract class Base { + abstract fun foo(list: List) where T : Number, T : Comparable +} + +class Derived : Base() { + override fun foo(list: List) where T : Number, T : Comparable { + } +} diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/simpleVisitorTwoAccepts.fir.kt b/compiler/testData/diagnostics/tests/override/typeParameters/simpleVisitorTwoAccepts.fir.kt new file mode 100644 index 00000000000..37d3705f995 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/typeParameters/simpleVisitorTwoAccepts.fir.kt @@ -0,0 +1,10 @@ +interface A + +interface B { + fun accept(visitor: String) + fun accept(visitor: A): R +} + +interface C : B { + override fun accept(visitor: A): R +} diff --git a/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnNullableParenthesizedTypes.fir.kt b/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnNullableParenthesizedTypes.fir.kt new file mode 100644 index 00000000000..a33e3c04054 --- /dev/null +++ b/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnNullableParenthesizedTypes.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface AnnotationsOnNullableParenthesizedTypes { + fun B<(@A C)?>.receiverArgument() {} + + fun parameter(a: (@A C)?) {} + + fun parameterArgument(a: B<(@A C)?>) {} + + fun returnValue(): (@A C)? + + fun returnTypeParameterValue(): (@A T)? + + fun returnArgument(): B<(@A C)?> + + val lambdaType: (@A() (() -> C))? + + val lambdaParameter: ((@A C)?) -> C + + val lambdaReturnValue: () -> (@A C)? + + val lambdaReceiver: (@A C)?.() -> C +} + +@Target(AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER) +annotation class A + +interface B +interface C \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnParenthesizedTypes.fir.kt b/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnParenthesizedTypes.fir.kt new file mode 100644 index 00000000000..ab5e5e046e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/parenthesizedTypes/annotationsOnParenthesizedTypes.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface AnnotationsOnParenthesizedTypes { + fun B<(@A C)>.receiverArgument() {} + + fun parameter(a: (@A C)) {} + + fun parameterArgument(a: B<(@A C)>) {} + + fun returnValue(): (@A C) + + fun returnTypeParameterValue(): (@A T) + + fun returnArgument(): B<(@A C)> + + val lambdaType: (@A() (() -> C)) + + val lambdaParameter: ((@A C)) -> C + + val lambdaReturnValue: () -> (@A C) + + val lambdaReceiver: (@A C).() -> C + + val lambdaParameterNP: (@A C) -> C +} + +@Target(AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER) +annotation class A + +interface B +interface C \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/parenthesizedTypes/splitModifierList.fir.kt b/compiler/testData/diagnostics/tests/parenthesizedTypes/splitModifierList.fir.kt new file mode 100644 index 00000000000..0e41b321904 --- /dev/null +++ b/compiler/testData/diagnostics/tests/parenthesizedTypes/splitModifierList.fir.kt @@ -0,0 +1,16 @@ +@Target(AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER) +annotation class A + +@Target(AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER) +annotation class B + +typealias Test0 = @A @B Int +typealias Test1 = @A() (@A Int) +typealias Test2 = @A() (@B Int) +typealias Test3 = @A() (@A Int) -> Int +typealias Test4 = @A() (@B Int)? +typealias Test5 = @A() ( (@B Int)? ) +typealias Test6 = (@A @B Int) +typealias Test7 = (@A @B Int)? +typealias Test8 = (@A() (@B Int)? ) +typealias Test9 = (@A() (@B Int) )? \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/collectionOrNull.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/collectionOrNull.fir.kt new file mode 100644 index 00000000000..73340ce072f --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/collectionOrNull.fir.kt @@ -0,0 +1,19 @@ +// FILE: p/Utils.java + +package p; + +public class Utils { + public static java.util.Collection c() { return null; } +} + +// FILE: k.kt + +import p.* + +fun T.foo() {} + +fun test(b: Boolean) { + val c = if (b) Utils.c() else null + + c?.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/inferenceWithBound.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/inferenceWithBound.fir.kt new file mode 100644 index 00000000000..4a4d125e162 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/inferenceWithBound.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: p/Super.java + +package p; + +public interface Super { + +} + +// FILE: p/Sub.java + +package p; + +public interface Sub extends Super {} + +// FILE: p/Other.java + +package p; + +import java.util.*; + +public class Other { + + public static Sub sub; + + public static Collection subs; + public static Collection supers; +} + +// FILE: k.kt + +import p.* + +fun test() { + val col = if (1 < 2) Other.subs else Other.supers + col.foo() +} + +fun Collection.foo(): T = null!! +fun listOf(t: T): List = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.fir.kt new file mode 100644 index 00000000000..eab1285e638 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !CHECK_TYPE + +import java.util.ArrayList + +fun foo(handlers: Array?>) { + val v = handlers[0] ?: ArrayList() + handlers[0] = v + val js: MutableList = v + // TODO: fix with dominance +// v checkType { it : _>} +// v checkType { it : _>} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.fir.kt new file mode 100644 index 00000000000..5c1639e3079 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !CHECK_TYPE +// FILE: p/J.java + +package p; + +public class J { + public static J j() { return null; } +} + +// FILE: k.kt + +import p.* + +fun foo(j: J) { + val v = if (true) j else J.j() + val js: J = v + // TODO: fix with dominance +// v checkType { it : _>} +// v checkType { it : _>} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.fir.kt new file mode 100644 index 00000000000..fd370e7547e --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/recursiveGeneric.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE + +// FILE: p/Rec.java + +package p; + +public interface Rec { + +} + +// FILE: p/A.java + +package p; + +public interface A extends Rec { + +} + +// FILE: p/B.java + +package p; + +public interface B extends Rec { + +} + +// FILE: k.kt + +import p.* + +fun test(a: A, b: B, c: Boolean) { + var ab = if (c) a else b + ab = a + ab = b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/stringOrNull.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/stringOrNull.fir.kt new file mode 100644 index 00000000000..79e2df864bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/stringOrNull.fir.kt @@ -0,0 +1,19 @@ +// FILE: p/Utils.java + +package p; + +public class Utils { + public static String str() { return null; } +} + +// FILE: k.kt + +import p.* + +fun T.foo() {} + +fun test(b: Boolean) { + val str = if (b) Utils.str() else null + + str?.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/typeOfElvis.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/typeOfElvis.fir.kt new file mode 100644 index 00000000000..907f324a43b --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/typeOfElvis.fir.kt @@ -0,0 +1,20 @@ +// FILE: p/J.java + +package p; + +public class J { + public static J j() { return null; } +} + +// FILE: k.kt + +import p.* + +fun foo(): J? = null + +fun main() { + val v = foo() ?: J.j() + if (v != null) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.fir.kt new file mode 100644 index 00000000000..83c5ac36b0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// JAVAC_SKIP +// NI_EXPECTED_FILE +// FILE: p/J.java + +package p; + +public class J { + public static J j() { return null; } +} + +// FILE: k.kt + +import p.* + +interface Out + +fun f(a: Out, b: Out, c: Out): T = null!! +fun out(t: T): Out> = null!! + +fun test(a: Out, b: Out>) { + val v = f(a, b, out(J.j())) + v checkType { _>() } + v checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/delegateByComplexInheritance.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/delegateByComplexInheritance.fir.kt new file mode 100644 index 00000000000..ffc1f27d5dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/delegateByComplexInheritance.fir.kt @@ -0,0 +1,15 @@ +// FILE: A.java + +import java.util.*; + +public interface A { + void foo(); +} + +// FILE: B.java + +public interface B extends A {} + +// FILE: k.kt + +class C(x: A) : A by x, B {} diff --git a/compiler/testData/diagnostics/tests/platformTypes/dereference.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/dereference.fir.kt new file mode 100644 index 00000000000..78a8bfaae72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/dereference.fir.kt @@ -0,0 +1,30 @@ +// !CHECK_TYPE + +// FILE: p/J.java + +package p; + +public class J { + public J j() {return null;} + + public T foo() {return null;} + public T foo1() {return null;} +} + +// FILE: k.kt + +import p.* + +fun test(j: J) { + checkSubtype(j.j()) + j.j().j() + j.j()!!.j() + + val ann = j.foo() + ann!!.length + ann.length + + val a = j.foo() + a!!.j() + a.j() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/elvis.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/elvis.fir.kt new file mode 100644 index 00000000000..ce6b32105a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/elvis.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +// FILE: p/J.java + +package p; + +public class J { + public String s() { return null; } +} + +// FILE: k.kt +import p.* + +fun test(j: J) { + j.s()?.length ?: "" +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.fir.kt new file mode 100644 index 00000000000..cf6f0e4f55c --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !EXPLICIT_FLEXIBLE_TYPES +// !CHECK_TYPE + +fun foo(f: ft) { + f.checkType { _() } + f.checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.fir.kt new file mode 100644 index 00000000000..571418a21e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !EXPLICIT_FLEXIBLE_TYPES +// !CHECK_TYPE +package ppp + +fun foo(f: ft) { + f.checkType { _() } + f.checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/listSuperType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/listSuperType.fir.kt new file mode 100644 index 00000000000..d14ca7e5698 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/listSuperType.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} +} +// FILE: main.kt + +abstract class B : MutableList + +fun main(a: A, b: B) { + a.foo(b) + a.foo(b as List) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/rawTypes.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/rawTypes.fir.kt new file mode 100644 index 00000000000..6be7f3dcf05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/rawTypes.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} +} +// FILE: main.kt + +fun main(a: A, ml: MutableList, l: List) { + a.foo(ml) + a.foo(l) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt new file mode 100644 index 00000000000..7ee4ad14d0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt @@ -0,0 +1,67 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} + void foo(Iterable x) {} + void foo(Iterator x) {} + void foo(Set x) {} + void foo(Map x) {} + void foo(Map.Entry x) {} + + void foo(List> x) {} +} + +// FILE: main.kt + +fun main( + a: A, + ml: MutableList, l: List, + ms: MutableSet, s: Set, + mm: MutableMap, m: Map, + mme: MutableMap.MutableEntry, me: Map.Entry, + mll: MutableList>, ll: List> +) { + // Lists + a.foo(ml) + a.foo(l) + a.foo(ml as MutableList) + a.foo(l as List) + + // Iterables + val mit: MutableIterable = ml + val it: Iterable = ml + a.foo(mit) + a.foo(it) + + // Iterators + a.foo(ml.iterator()) + a.foo(l.iterator()) + + // Sets + a.foo(ms) + a.foo(s) + a.foo(ms as MutableSet) + a.foo(s as Set) + + // Maps + a.foo(mm) + a.foo(m) + a.foo(mm as MutableMap) + a.foo(m as Map) + + // Map entries + a.foo(mme) + a.foo(me) + a.foo(mme as MutableMap.MutableEntry) + a.foo(me as Map.Entry) + + // Lists of lists + a.foo(mll) + a.foo(ll) + a.foo(mll as MutableList>) + a.foo(ll as List>) + +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.fir.kt new file mode 100644 index 00000000000..e5b210a4c71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/smartCast.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} +} +// FILE: main.kt + +fun main(a: A, ml: Any) { + if (ml is MutableList) { + a.foo(ml) + a.foo(ml as List) + } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/strangeVariance.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/strangeVariance.fir.kt new file mode 100644 index 00000000000..f4610b66e4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/strangeVariance.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} + void bar(List x) {} +} +// FILE: main.kt + +fun main(a: A, ml: MutableList, l: List) { + a.foo(ml) + a.foo(l) + + a.bar(ml) + a.bar(l) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/userDefinedOut.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/userDefinedOut.fir.kt new file mode 100644 index 00000000000..f06e8d918d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/userDefinedOut.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(Out x) {} + void bar(Out x) {} +} +// FILE: main.kt + +public class Out() + +fun main(a: A, o: Out) { + a.foo(o) + a.bar(o) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/valueFromJava.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/valueFromJava.fir.kt new file mode 100644 index 00000000000..a83e2c15f3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/valueFromJava.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} + List bar() {} +} +// FILE: main.kt + +fun main(a: A) { + a.foo(a.bar()) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/wildcards.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/wildcards.fir.kt new file mode 100644 index 00000000000..844dc40d09a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/wildcards.fir.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + void foo(List x) {} + void foo(Iterable x) {} + void foo(Iterator x) {} + void foo(Set x) {} + void foo(Map x) {} + void foo(Map.Entry x) {} +} + +// FILE: main.kt + +fun main( + a: A, + ml: MutableList, l: List, + ms: MutableSet, s: Set, + mm: MutableMap, m: Map, + mme: MutableMap.MutableEntry, me: Map.Entry +) { + // Lists + a.foo(ml) + a.foo(l) + + // Iterables + val mit: MutableIterable = ml + val it: Iterable = ml + a.foo(mit) + a.foo(it) + + // Iterators + a.foo(ml.iterator()) + a.foo(l.iterator()) + + // Sets + a.foo(ms) + a.foo(s) + + // Maps + a.foo(mm) + a.foo(m) + + // Map entries + a.foo(mme) + a.foo(me) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/getParentOfType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/getParentOfType.fir.kt new file mode 100644 index 00000000000..298c74ab12a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/getParentOfType.fir.kt @@ -0,0 +1,36 @@ +// FILE: p/PsiElement.java + +package p; + +public interface PsiElement {} + +// FILE: p/JetExpression.java + +package p; + +public interface JetExpression extends PsiElement {} + +// FILE: p/Util.java + +package p; + +public class Util { + + public static T getParentOfType(@Nullable PsiElement element, @NotNull Class aClass) { + return null; + } + + public static void on(JetExpression e) {} +} + +// FILE: k.kt + +import p.* + +fun test(e: JetExpression) { + Util.on( + Util.getParentOfType(e, javaClass()) ?: e + ) +} + +fun javaClass(): Class = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/inference.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/inference.fir.kt new file mode 100644 index 00000000000..ea06d3c395c --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/inference.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +// FILE: foo/Base.java + +package foo; + +public interface Base {} + +// FILE: foo/HS.java + +package foo; + +public class HS extends Base {} + +// FILE: k.kt + +import foo.*; + +fun > convert(src: HS, dest: C): C = throw Exception("$src $dest") + +fun test(l: HS) { + //todo should be inferred + val r = convert(l, HS()) + r checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/intVsIntegerAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/intVsIntegerAmbiguity.fir.kt new file mode 100644 index 00000000000..0e13d7b542d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/intVsIntegerAmbiguity.fir.kt @@ -0,0 +1,37 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: p/J.java + +package p; + +public class J { + public interface A {} + public static A foo(int s); + + public interface B {} + public static B foo(Integer s); + + public static Integer getInteger(); +} + +// FILE: k.kt + +import p.* +import p.J.* + +class C + +fun foo(i: Int?) : C = null!! + +fun test(i: Int, ni: Int?) { + checkSubtype(foo(2)) + checkSubtype(J.foo(2)) + checkSubtype(J.foo(i)) + checkSubtype(J.foo(ni)) + checkSubtype(foo(ni)) + checkSubtype(J.foo(ni)) + + foo(J.getInteger()) + J.foo(J.getInteger()) +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/intersection/map.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/intersection/map.fir.kt new file mode 100644 index 00000000000..5edcc2d090d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/intersection/map.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE +// !EXPLICIT_FLEXIBLE_TYPES + +fun foo( + p1: ft, Map?>, + p2: Map +) = p1 == p2 + +fun foo( + p1: ft, + p2: String +) = p1 == p2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/javaEmptyList.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/javaEmptyList.fir.kt new file mode 100644 index 00000000000..a31eb896c2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/javaEmptyList.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +// FILE: Collections.java +import java.util.List; + +public class Collections { + public static final List emptyList() { + return null; + } +} + +// FILE: 1.kt + +fun bar(): List = null!! + +fun test() { + val f = if (true) { + Collections.emptyList() + } + else { + bar() + } + + checkSubtype>(f) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.fir.kt new file mode 100644 index 00000000000..3aaf4cce6e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/entrySet.fir.kt @@ -0,0 +1,24 @@ +// FILE: p/MultiMap.java + +package p; + +import java.util.*; + +public class MultiMap { + public Set> entrySet() { + return null; + } +} + +// FILE: k.kt + +import p.* + +fun test() { + val map = MultiMap() + val set = map.entrySet() + set.iterator() + + val set1 = map.entrySet()!! + set1.iterator() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/genericsAndArrays.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/genericsAndArrays.fir.kt new file mode 100644 index 00000000000..143f5c4cd89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/genericsAndArrays.fir.kt @@ -0,0 +1,24 @@ +// FILE: p/J.java + +package p; + +public class J { + public void foo(Ref r) {} +} + +// FILE: p/Ref.java + +package p; + +public class Ref { + public static Ref create() { return null; } +} + +// FILE: k.kt + +import p.* + +fun main(j: J) { + val r = Ref.create>() + j.foo(r) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt new file mode 100644 index 00000000000..cfcf3e01468 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/int.fir.kt @@ -0,0 +1,16 @@ +// FILE: p/J.java + +package p; + +public class J { + public void _int(int s) {} +} + +// FILE: k.kt + +import p.* + +fun test() { + J()._int(1) + J()._int(null) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/intArray.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/intArray.fir.kt new file mode 100644 index 00000000000..d79113f9023 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/intArray.fir.kt @@ -0,0 +1,16 @@ +// FILE: p/J.java + +package p; + +public class J { + public void intArr(int[] s) {} +} + +// FILE: k.kt + +import p.* + +fun test(ia: IntArray) { + J().intArr(ia) + J().intArr(null) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaCollectionToKotlin.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaCollectionToKotlin.fir.kt new file mode 100644 index 00000000000..fa1baddc8f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaCollectionToKotlin.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.* + +fun takeJ(map: Map) {} + +fun test() { + takeJ(HashMap()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToJava.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToJava.fir.kt new file mode 100644 index 00000000000..cbd9d0da968 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToJava.fir.kt @@ -0,0 +1,20 @@ +// FILE: p/J.java + +package p; + +import java.util.ArrayList; + +public class J { + public ArrayList list() { return null; } + public void takeList(ArrayList list) { } +} + +// FILE: k.kt + +import p.* + +fun test(j: J) { + j.takeList(j.list()) + val l = j.list() + j.takeList(l) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToKotlin.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToKotlin.fir.kt new file mode 100644 index 00000000000..e454e5b2dca --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/javaToKotlin.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: p/J.java + +package p; + +public class J { + public J j() { return this; } +} + +// FILE: k.kt + +import p.* + +fun takeJ(j: J) {} + +fun test() { + takeJ(J().j()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/kotlinCollectionToJava.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/kotlinCollectionToJava.fir.kt new file mode 100644 index 00000000000..d08d6cf52fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/kotlinCollectionToJava.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.* + +fun test(map: Map) { + HashMap(map) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/kt27565.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/kt27565.fir.kt new file mode 100644 index 00000000000..8edd7891956 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/kt27565.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-27565 + +// FILE: Runnable.java + +public interface Runnable { + void run(); +} + +// FILE: k.kt + +fun fail() { + foo({ }, { }) + foo(::bar, { }) +} + +fun foo(f: Runnable, selector: () -> Unit) {} +fun foo(func1: () -> Unit, func2: () -> Unit) {} + +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/list.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/list.fir.kt new file mode 100644 index 00000000000..a1f4cf524f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/list.fir.kt @@ -0,0 +1,18 @@ +// FILE: p/J.java + +package p; + +public class J { + public void list(java.util.List s) {} +} + +// FILE: k.kt + +import p.* + +fun test(ls: List, mls: MutableList, lsn: List, mlsn: MutableList?) { + J().list(ls) + J().list(mls) + J().list(lsn) + J().list(mlsn) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBounds.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBounds.fir.kt new file mode 100644 index 00000000000..daa89b278a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBounds.fir.kt @@ -0,0 +1,21 @@ +import java.util.HashMap + +interface ModuleDescriptorImpl +interface ModuleInfo +interface ResolverForModule +interface ResolverForProject + +class ResolverForProjectImpl( + descriptorByModule: Map, + delegateResolver: ResolverForProject +) : ResolverForProject + +fun foo(delegateResolver: ResolverForProject): ResolverForProject { + val descriptorByModule = HashMap() + return ResolverForProjectImpl(descriptorByModule, delegateResolver) +} + +// M = M2 +// HashMap :< Map => M = M2! +// R = A +// RFP :< RFP \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBoundsNullable.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBoundsNullable.fir.kt new file mode 100644 index 00000000000..73eb3d69552 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/multipleExactBoundsNullable.fir.kt @@ -0,0 +1,39 @@ +// JAVAC_EXPECTED_FILE +// FILE: MyMap.java + +import java.util.AbstractMap; +import java.util.Set; + +class MyMap extends AbstractMap { + @Override + public Set> entrySet() { + return null; + } +} + +// FILE: main.kt + +interface ResolverForProject { + val exposeM: M1 get() = null!! +} + +class ResolverForProjectImpl( + descriptorByModule: Map, + delegateResolver: ResolverForProject +) : ResolverForProject + +interface WithFoo { + fun foo() +} + +fun foo(delegateResolver: ResolverForProject): ResolverForProject { + val descriptorByModule = MyMap() + val result = ResolverForProjectImpl(descriptorByModule, delegateResolver) + result.exposeM.foo() // M is not M2? + result.exposeM?.foo() // no warning, M is not M2, hense M is M2! + + return ResolverForProjectImpl(descriptorByModule, delegateResolver) // another bound check +} + +// MyMap :< Map => M = M2! +// RFP :< RFP => M = M2? \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/objectArray.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/objectArray.fir.kt new file mode 100644 index 00000000000..64ac5f084cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/objectArray.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// FILE: p/J.java + +package p; + +public class J { + public void arr(Object[] s) {} +} + +// FILE: k.kt + +import p.* + +fun test( + aa: Array, + sa: Array, + san: Array +) { + J().arr(null) + J().arr(aa) + J().arr(sa) + J().arr(san) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/overloadingForSubclass.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/overloadingForSubclass.fir.kt new file mode 100644 index 00000000000..d15ca76f0a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/overloadingForSubclass.fir.kt @@ -0,0 +1,30 @@ +// FILE: p/Super.java +package p; + +public interface Super {} + +// FILE: p/Sub.java +package p; + +public interface Sub extends Super {} + +// FILE: p/Util.java + +package p; + +public abstract class Util { + public abstract void foo(String s, Super sup); + public void foo(String s, Sub sub) {} +} + +// FILE: k.kt + +import p.* + +class C: Util() { + override fun foo(s: String, sub: Super) {} +} + +fun foo(sub: Sub) { + C().foo("", sub) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.fir.kt new file mode 100644 index 00000000000..ed1b08ed76a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/sam.fir.kt @@ -0,0 +1,26 @@ +// FILE: p/SAM.java + +package p; + +public interface SAM { + R foo(); +} + +// FILE: p/Util.java + +package p; + +public class Util { + + public static void sam(SAM sam) {} +} + +// FILE: k.kt + +import p.* + +fun test() { + Util.sam { + null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.fir.kt new file mode 100644 index 00000000000..395fbdddb07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +interface Foo + +fun test() { + var nullable: Foo? = null + val foo: Collection = java.util.Collections.singleton(nullable) + val foo1: Collection = java.util.Collections.singleton(nullable!!) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/string.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/string.fir.kt new file mode 100644 index 00000000000..1b0f1370754 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/string.fir.kt @@ -0,0 +1,16 @@ +// FILE: p/J.java + +package p; + +public class J { + public void str(J s) {} +} + +// FILE: k.kt + +import p.* + +fun test() { + J().str(J()) + J().str(null) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodCall/visitor.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodCall/visitor.fir.kt new file mode 100644 index 00000000000..ee932531ddb --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodCall/visitor.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// FILE: p/Visitor.java + +package p; + +public interface Visitor { + +} + +// FILE: p/Element.java + +package p; + +import org.jetbrains.annotations.NotNull; + +public class Element { + public R accept(@NotNull Visitor visitor, D data) {return null;} +} + +// FILE: k.kt + +import p.* + +fun test(v: Visitor, e: Element) { + e.accept(v, null) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/methodTypeParameterDefaultBound.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/methodTypeParameterDefaultBound.fir.kt new file mode 100644 index 00000000000..2d3b7398878 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/methodTypeParameterDefaultBound.fir.kt @@ -0,0 +1,25 @@ +// FILE: Derived.java +import kotlin.jvm.functions.Function0; +import org.jetbrains.annotations.NotNull; + +public class Derived implements Base { + @Override + public void foo() {} +} + +// FILE: main.kt +interface Base { + fun foo() +} + +class KotlinDerived1 : Derived() { + override fun foo() {} +} + +class KotlinDerived2 : Derived() { + override fun foo() {} +} + +fun main() { + Derived().foo() +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.fir.kt new file mode 100644 index 00000000000..de64ac8a435 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java + +// It's supposed that there is no JSR-305 annotation in classpath +public interface A { + public boolean foo(@javax.annotation.Nullable T y) {} +} + +// FILE: B.java + +public class B { + public static void bar(A y) {} +} + +// FILE: main.kt +fun test() { + B.bar() { it.hashCode() > 0 } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromAnnotation.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromAnnotation.fir.kt new file mode 100644 index 00000000000..59a9fc1f575 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromAnnotation.fir.kt @@ -0,0 +1,28 @@ +// FILE: A.java + +import org.jetbrains.annotations.NotNull; +public interface A { + void foo(@NotNull T x); +} + +// FILE: B.java +public class B { + public void foo(E x) {} +} + +// FILE: C.java +public class C extends B implements A { + public static C create() { return null; } + public void foo(F x) {} +} + +// FILE: main.kt + +fun test() { + C.create().foo(null) + C.create().foo("") + + C().foo(null) + C().foo(null) + C().foo("") +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromKotlin.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromKotlin.fir.kt new file mode 100644 index 00000000000..c86b1711a17 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/enhancementFromKotlin.fir.kt @@ -0,0 +1,28 @@ +// FILE: A.kt + +import org.jetbrains.annotations.NotNull; +public interface A { + fun foo(x: T) +} + +// FILE: B.java +public class B { + public void foo(E x) {} +} + +// FILE: C.java +public class C extends B implements A { + public static C create() { return null; } + public void foo(F x) {} +} + +// FILE: main.kt + +fun test() { + C.create().foo(null) + C.create().foo("") + + C().foo(null) + C().foo(null) + C().foo("") +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/methodTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/methodTypeParameter.fir.kt new file mode 100644 index 00000000000..689e6e31ab5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/methodTypeParameter.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// FILE: A.java + +import org.jetbrains.annotations.NotNull; + +public class A { + public static void bar(@NotNull T x, T y) { } + public static String platformString() { return null; } +} + +// FILE: k.kt + +fun test() { + A.bar(null, "") + + A.bar(null, "") + A.bar(null, "") + A.bar(null, A.platformString()) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceReturnType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceReturnType.fir.kt new file mode 100644 index 00000000000..9e558217c08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceReturnType.fir.kt @@ -0,0 +1,23 @@ +// FILE: A.java + +import java.util.*; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class A { + public static A create() { + return null; + } + + @NotNull + public T bar() { + } +} + +// FILE: k.kt + +fun test() { + A.create().bar()?.length + A().bar()?.length +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt new file mode 100644 index 00000000000..833b6ecaab4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/noInheritanceValueParameter.fir.kt @@ -0,0 +1,26 @@ +// FILE: A.java + +import java.util.*; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class A { + public static A create() { + return null; + } + + public void bar(@NotNull T x) { + } +} + +// FILE: k.kt + +fun test() { + A.create().bar(null) + A.create().bar("") + + A().bar(null) + A().bar(null) + A().bar("") +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/onTypeProjection.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/onTypeProjection.fir.kt new file mode 100644 index 00000000000..e0269c09835 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/onTypeProjection.fir.kt @@ -0,0 +1,19 @@ +// FILE: A.java + +import java.util.*; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class A { + @NotNull + public T bar() { + } +} + +// FILE: k.kt + +fun test(a: A) { + a.bar()?.length + a.bar()?.length +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt new file mode 100644 index 00000000000..7027ad2ac42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt @@ -0,0 +1,41 @@ +// FILE: A.java + +import java.util.*; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class A { + public void bar(@NotNull T x) { + } +} + +// FILE: B1.java +public class B1 extends A { + // real override + public void bar(String x) { + } +} + +// FILE: B2.java +public class B2 extends A { + // fake override bar +} + +// FILE: k.kt + +class C1 : A() { + override fun bar(x: String) {} +} + +class C2 : A() { + override fun bar(x: String?) {} +} + +fun test() { + B1().bar(null) + B2().bar(null) + + C1().bar(null) +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/arithmetic.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/arithmetic.fir.kt new file mode 100644 index 00000000000..9bced64c4a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/arithmetic.fir.kt @@ -0,0 +1,55 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static Integer staticNN; + @Nullable + public static Integer staticN; + public static Integer staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + var platformNN = J.staticNN + // @Nullable platform type + var platformN = J.staticN + // platform type with no annotation + var platformJ = J.staticJ + + +platformNN + +platformN + +platformJ + + ++platformNN + ++platformN + ++platformJ + + platformNN++ + platformN++ + platformJ++ + + 1 + platformNN + 1 + platformN + 1 + platformJ + + platformNN + 1 + platformN + 1 + platformJ + 1 + + 1 plus platformNN + 1 plus platformN + 1 plus platformJ + + platformNN plus 1 + platformN plus 1 + platformJ plus 1 + + platformNN += 1 + platformN += 1 + platformJ += 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/array.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/array.fir.kt new file mode 100644 index 00000000000..6947757570d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/array.fir.kt @@ -0,0 +1,31 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static Integer[] staticNN; + @Nullable + public static Integer[] staticN; + public static Integer[] staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + platformNN[0] + platformN[0] + platformJ[0] + + platformNN[0] = 1 + platformN[0] = 1 + platformJ[0] = 1 +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/assignToVar.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/assignToVar.fir.kt new file mode 100644 index 00000000000..0bd4993ff8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/assignToVar.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +var v: J = J() +var n: J? = J() + +fun test() { + v = J.staticNN + v = J.staticN + v = J.staticJ + + n = J.staticNN + n = J.staticN + n = J.staticJ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/conditions.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/conditions.fir.kt new file mode 100644 index 00000000000..b81312ebbed --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/conditions.fir.kt @@ -0,0 +1,48 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static Boolean staticNN; + @Nullable + public static Boolean staticN; + public static Boolean staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + if (platformNN) {} + if (platformN) {} + if (platformJ) {} + + while (platformNN) {} + while (platformN) {} + while (platformJ) {} + + do {} while (platformNN) + do {} while (platformN) + do {} while (platformJ) + + platformNN && false + platformN && false + platformJ && false + + platformNN || false + platformN || false + platformJ || false + + !platformNN + !platformN + !platformJ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt new file mode 100644 index 00000000000..83f6b64ec77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt @@ -0,0 +1,32 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; +} + +// FILE: k.kt + +fun test() { + val n = J.staticN + foo(n) + J.staticNN = n + if (n != null) { + foo(n) + J.staticNN = n + } + + val x: J? = null + J.staticNN = x + if (x != null) { + J.staticNN = x + } +} + +fun foo(j: J) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/defaultParameters.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/defaultParameters.fir.kt new file mode 100644 index 00000000000..1ef043f66e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/defaultParameters.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + fun foo(p: J = platformNN, p1: J = platformN, p2: J = platformJ) {} + + fun foo1(p: J? = platformNN, p1: J? = platformN, p2: J? = platformJ) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt new file mode 100644 index 00000000000..fae7807c753 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt @@ -0,0 +1,23 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + + public interface DP { + String getValue(Object a, Object b); + String setValue(Object a, Object b, Object c); + } + + @NotNull + public static DP staticNN; + @Nullable + public static DP staticN; + public static DP staticJ; +} + +// FILE: k.kt + +var A by J.staticNN +var B by J.staticN +var C by J.staticJ \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegation.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegation.fir.kt new file mode 100644 index 00000000000..2a16ec3d803 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegation.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; +import java.util.*; + +public class J { + @NotNull + public static List staticNN; + @Nullable + public static List staticN; + public static List staticJ; +} + +// FILE: k.kt + +class A : List by J.staticNN +class B : List by J.staticN +class C : List by J.staticJ \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceExtension.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceExtension.fir.kt new file mode 100644 index 00000000000..413bcb99789 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceExtension.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + platformNN.foo() + platformN.foo() + platformJ.foo() + + with(platformNN) { + foo() + } + with(platformN) { + foo() + } + with(platformJ) { + foo() + } + + platformNN.bar() + platformN.bar() + platformJ.bar() +} + +fun J.foo() {} +fun J?.bar() {} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceMember.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceMember.fir.kt new file mode 100644 index 00000000000..16310cc8fb5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/derefenceMember.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; + + public void foo() {} +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + platformNN.foo() + platformN.foo() + platformJ.foo() + + with(platformNN) { + foo() + } + with(platformN) { + foo() + } + with(platformJ) { + foo() + } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.fir.kt new file mode 100644 index 00000000000..85fd8105cea --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.fir.kt @@ -0,0 +1,67 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -SENSELESS_COMPARISON, -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; + + public static T getAny() { + return null; + } + + @NotNull + public static T getNNAny() { + return (T) null; + } + + @Nullable + public static T getNAny() { + return null; + } +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + val v0 = platformNN ?: J() + platformNN ?: J() + platformN ?: J() + platformJ ?: J() + + if (platformNN != null) { + platformNN ?: J() + } + + if (platformN != null) { + platformN ?: J() + } + + if (platformJ != null) { + platformJ ?: J() + } + + takeNotNull(J.staticNN ?: J()) + takeNotNull(J.staticN ?: J()) + takeNotNull(J.staticJ ?: J()) + takeNotNull(J.getAny() ?: J()) + takeNotNull(J.getNNAny() ?: J()) + takeNotNull(J.getNAny() ?: J()) + + val x = unresolved ?: null + val y = unresolved.foo ?: return +} + +fun takeNotNull(s: J) {} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/expectedType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/expectedType.fir.kt new file mode 100644 index 00000000000..4cb1e8e3926 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/expectedType.fir.kt @@ -0,0 +1,32 @@ +// !CHECK_TYPE + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + checkSubtype(platformNN) + checkSubtype(platformN) + checkSubtype(platformJ) + + checkSubtype(platformNN) + checkSubtype(platformN) + checkSubtype(platformJ) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/for.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/for.fir.kt new file mode 100644 index 00000000000..85fe29d1472 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/for.fir.kt @@ -0,0 +1,28 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; +import java.util.*; + +public class J { + @NotNull + public static List staticNN; + @Nullable + public static List staticN; + public static List staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + for (x in platformNN) {} + for (x in platformN) {} + for (x in platformJ) {} +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/functionArguments.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/functionArguments.fir.kt new file mode 100644 index 00000000000..981585397c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/functionArguments.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + foo(J.staticNN) + foo(J.staticN) + foo(J.staticJ) + + bar(J.staticNN) + bar(J.staticN) + bar(J.staticJ) +} + +fun foo(j: J) {} +fun bar(j: J?) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/inferenceInConditionals.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/inferenceInConditionals.fir.kt new file mode 100644 index 00000000000..fe37a7510fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/inferenceInConditionals.fir.kt @@ -0,0 +1,27 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; +import java.util.*; + +public class J { + @NotNull + public String nn() { return ""; } + + @Nullable + public List n() { return null; } +} + +// FILE: k.kt + +fun safeCall(c: J?) { + c?.nn()?.length +} + +fun ifelse(c: J): Any? { + return if (true) c.nn() else null +} + +fun elvis(c: J): Any? { + return null ?: c.nn() +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/invoke.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/invoke.fir.kt new file mode 100644 index 00000000000..cd541506a09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/invoke.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + public interface Invoke { + void invoke(); + } + + @NotNull + public static Invoke staticNN; + @Nullable + public static Invoke staticN; + public static Invoke staticJ; +} + +// FILE: k.kt + +fun test() { + J.staticNN() + J.staticN() + J.staticJ() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.fir.kt new file mode 100644 index 00000000000..356e46c7d01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// KT-6829 False warning on map to @Nullable + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + + @Nullable + public String method() { return ""; } +} + +// FILE: k.kt + +fun foo(collection: Collection) { + val mapped = collection.map { it.method() } + mapped[0].length +} + +public fun Iterable.map(transform: (T) -> R): List { + null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/multiDeclaration.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/multiDeclaration.fir.kt new file mode 100644 index 00000000000..c997080cc1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/multiDeclaration.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + public interface Multi { + String component1(); + String component2(); + } + + @NotNull + public static Multi staticNN; + @Nullable + public static Multi staticN; + public static Multi staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + val (a1, b1) = platformNN + val (a2, b2) = platformN + val (a3, b3) = platformJ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/noWarningOnDoubleElvis.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/noWarningOnDoubleElvis.fir.kt new file mode 100644 index 00000000000..e9891546877 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/noWarningOnDoubleElvis.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test() { + take(nullable() ?: nullable() ?: "foo") +} + +fun nullable(): T? = TODO() +fun take(x: Any) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAfterSafeCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAfterSafeCall.fir.kt new file mode 100644 index 00000000000..420dc45a990 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAfterSafeCall.fir.kt @@ -0,0 +1,16 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + public @NotNull String nn() { return ""; } +} + +// FILE: k.kt + +fun test(j: J?) { + val s = j?.nn() + if (s != null) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt new file mode 100644 index 00000000000..c388c511f33 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertion.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -SENSELESS_COMPARISON -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + if (platformNN != null) { + platformNN!! + } + + if (platformN != null) { + platformN!! + } + + if (platformJ != null) { + platformJ!! + } + + platformNN!! + platformN!! + platformJ!! +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt new file mode 100644 index 00000000000..51129def4ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullAssertionInCall.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + + foo(platformNN!!) + val bar = Bar() + bar(platformNN!!) +} + +fun foo(a: Any) {} + +class Bar { + operator fun invoke(a: Any) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt new file mode 100644 index 00000000000..5e68aea15f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/notNullTypeMarkedWithNullableAnnotation.fir.kt @@ -0,0 +1,22 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; +import java.util.*; + +public class J { + @Nullable + public List n() { return null; } +} + +// FILE: k.kt + +fun list(j: J): Any { + val a = j.n()!! + + a?.get(0) + if (a == null) {} + a!! + + a.get(0) + return a +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt new file mode 100644 index 00000000000..280455894df --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt @@ -0,0 +1,90 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; + + public static void staticSet(@NotNull J nn, @Nullable J n, J j) {} + + public J(@NotNull J nn, @Nullable J n, J j) {} + public J() {} + + @NotNull + public J nn; + @Nullable + public J n; + public J j; + + public void set(@NotNull J nn, @Nullable J n, J j) {} +} + +// FILE: k.kt + +fun test(n: J?, nn: J) { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + J.staticNN = n + J.staticNN = platformN + J.staticNN = nn + J.staticNN = platformNN + J.staticNN = platformJ + + J.staticN = n + J.staticN = platformN + J.staticN = nn + J.staticN = platformNN + J.staticN = platformJ + + J.staticJ = n + J.staticJ = platformN + J.staticJ = nn + J.staticJ = platformNN + J.staticJ = platformJ + + J.staticSet(nn, nn, nn) + J.staticSet(platformNN, platformNN, platformNN) + J.staticSet(n, n, n) + J.staticSet(platformN, platformN, platformN) + J.staticSet(platformJ, platformJ, platformJ) + + J().nn = n + J().nn = platformN + J().nn = nn + J().nn = platformNN + J().nn = platformJ + + J().n = n + J().n = platformN + J().n = nn + J().n = platformNN + J().n = platformJ + + J().j = n + J().j = platformN + J().j = nn + J().j = platformNN + J().j = platformJ + + J().set(nn, nn, nn) + J().set(platformNN, platformNN, platformNN) + J().set(n, n, n) + J().set(platformN, platformN, platformN) + J().set(platformJ, platformJ, platformJ) + + J(nn, nn, nn) + J(platformNN, platformNN, platformNN) + J(n, n, n) + J(platformN, platformN, platformN) + J(platformJ, platformJ, platformJ) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/primitiveArray.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/primitiveArray.fir.kt new file mode 100644 index 00000000000..9821a82d704 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/primitiveArray.fir.kt @@ -0,0 +1,31 @@ +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static int[] staticNN; + @Nullable + public static int[] staticN; + public static int[] staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + platformNN[0] + platformN[0] + platformJ[0] + + platformNN[0] = 1 + platformN[0] = 1 + platformJ[0] = 1 +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/safeCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/safeCall.fir.kt new file mode 100644 index 00000000000..6704268cb6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/safeCall.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -SENSELESS_COMPARISON + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; + + public void foo() {} +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + platformNN?.foo() + platformN?.foo() + platformJ?.foo() + + if (platformNN != null) { + platformNN?.foo() + } + + if (platformN != null) { + platformN?.foo() + } + + if (platformJ != null) { + platformJ?.foo() + } +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.fir.kt new file mode 100644 index 00000000000..fff0b3bf8a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonEquals.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + val a: Any? = null + + if (platformNN != null) {} + if (null != platformNN) {} + if (platformNN == null) {} + if (null == platformNN) {} + + if (a != null && platformNN != a) {} + + if (platformN != null) {} + if (platformN == null) {} + if (a == null && platformN == a) {} + + if (platformJ != null) {} + if (platformJ == null) {} + if (a == null && platformJ == a) {} +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.fir.kt new file mode 100644 index 00000000000..971328e16a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/senselessComparisonIdentityEquals.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; + @Nullable + public static J staticN; + public static J staticJ; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + // @Nullable platform type + val platformN = J.staticN + // platform type with no annotation + val platformJ = J.staticJ + + val a: Any? = null + + if (platformNN !== null) {} + if (null !== platformNN) {} + if (platformNN === null) {} + if (null === platformNN) {} + + if (platformN !== null) {} + if (platformN === null) {} + if (a === null && platformN === a) {} + + if (platformJ !== null) {} + if (platformJ === null) {} + if (a === null && platformJ === a) {} +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/throw.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/throw.fir.kt new file mode 100644 index 00000000000..2755f518ced --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/throw.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static Exception staticNN; + @Nullable + public static Exception staticN; + public static Exception staticJ; +} + +// FILE: k.kt + +fun test() { + throw J.staticNN +} + +fun test1() { + throw J.staticN +} + +fun test2() { + throw J.staticJ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisInCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisInCall.fir.kt new file mode 100644 index 00000000000..d7d368057b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisInCall.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @NotNull + public static J staticNN; +} + +// FILE: k.kt + +fun test() { + // @NotNull platform type + val platformNN = J.staticNN + + foo(platformNN ?: "") + + val bar = Bar() + bar(platformNN ?: "") +} + +fun foo(a: Any) {} + +class Bar { + operator fun invoke(a: Any) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.fir.kt new file mode 100644 index 00000000000..d3fa74464b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public class J { + @Nullable + public static J staticN; +} + +// FILE: JJ.java + +public class JJ { + public static JJ staticNN; +} + +// FILE: JJJ.java + +import org.jetbrains.annotations.*; + +public class JJJ { + @NotNull + public static JJJ staticNNN; +} + +// FILE: k.kt + +fun test() { + val a = J.staticN ?: null + foo(a) + val b = JJ.staticNN ?: null + foo(b) + val c = JJJ.staticNNN ?: null + foo(c) +} + +fun foo(a: Any?) { +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullableTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullableTypeArgument.fir.kt new file mode 100644 index 00000000000..a1b02c34276 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullableTypeArgument.fir.kt @@ -0,0 +1,9 @@ +import java.util.ArrayList + +fun foo() { + val list = ArrayList() + + for (s in list) { + s.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/override.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/override.fir.kt new file mode 100644 index 00000000000..bf7c372a64f --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/override.fir.kt @@ -0,0 +1,26 @@ +// FILE: p/I.java + +package p; + +import p.J.Param; + +public interface I { + String s(); +} + +// FILE: p/J.java + +package p; + +public class J implements I { + public String s() { return null; } +} + +// FILE: k.kt +import p.* + +fun test() { + val s = J().s() + s.get(0) + s!!.get(0) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt new file mode 100644 index 00000000000..6dab60f9d3d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt @@ -0,0 +1,41 @@ +// FILE: A.java +import java.util.*; +public interface A { + E foo(T x, List y); +} + +// FILE: B.java +import java.util.*; +public interface B extends A { + @Override + public String foo(Object x, List y); +} + +// FILE: C.java +import java.util.*; +public abstract class C { + E bar(F x, List> y); +} + +// FILE: D.java +import java.util.*; +public class D extends C { + @Override + public String bar(CharSequence x, List y) { + return null; + } +} + +// FILE: main.kt + +class E : D(), B { + override fun foo(x: Any, y: List): String = "" + override fun bar(x: CharSequence?, y: List<*>?): String = "" +} + +class E2 : B { + override fun foo(x: Any, y: List): String = "" +} + + +class F : D() diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt new file mode 100644 index 00000000000..ce1dd6cabcd --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt @@ -0,0 +1,41 @@ +// (failed) attempt to reproduce exception in +// http://stackoverflow.com/questions/42571812/unsupportedoperationexception-while-building-a-kotlin-project-in-idea + +// FILE: Fun.java +public interface Fun { + public void invoke(T x); +} + +// FILE: A.java +public interface A { + public void foo(T x, Fun y); +} + +// FILE: B.java +public interface B extends A { + @Override + public void foo(Object x, Fun y); +} + +// FILE: C.java +public abstract class C { + public abstract void bar(Fun y); + + public static void aStaticMethod(T x, Fun y) {} + + public static abstract class D extends C { + @Override + public void bar(Fun y) {} + + public static void aStaticMethod(Object x, Fun y) {} + } +} + +// FILE: main.kt +class E1 : C.D(), B { + override fun foo(x: Any, y: Fun) {} +} + +class E2 : B { + override fun foo(x: Any, y: Fun) {} +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt new file mode 100644 index 00000000000..f29a54568c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt @@ -0,0 +1,44 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + T[] charSequences; + Map[] maps; + List[][] arraysOfLists; + E[][] arraysOfAny; + + List[] erasedLists; +} + +// FILE: Test.java + +class Test { + static class RawADerived extends A {} + static A rawAField = null; +} + +// FILE: main.kt + +fun arrayOf(): Array = null!! + +fun main() { + val raw = Test.rawAField + + raw.charSequences = arrayOf() + raw.charSequences = arrayOf() + + raw.maps = arrayOf>() + raw.maps = arrayOf>() + raw.maps = arrayOf>() + + raw.arraysOfLists = arrayOf>>() + raw.arraysOfLists = arrayOf>() + raw.arraysOfLists = arrayOf>>() + + raw.arraysOfAny = arrayOf>>() + + raw.erasedLists = arrayOf>() +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/errorType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/errorType.fir.kt new file mode 100644 index 00000000000..594034d0c9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/errorType.fir.kt @@ -0,0 +1,12 @@ +// FILE: A.java +import java.util.*; + +public class A { + public void foo(Err x, List y); +} + +// FILE: B.java + +public class B extends A { + +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/genericInnerClass.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/genericInnerClass.fir.kt new file mode 100644 index 00000000000..8c109ee9e4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/genericInnerClass.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A { + + void foo(T x) {} + + public class Inner { + Inner(E x0, T x, List y) {} + + void foo(E x0, T x, List y) {} + A> bar() {} + } +} + +// FILE: Test.java + +class Test { + static A rawAField = null; +} + +// FILE: main.kt + +val strList: List = null!! + +fun main() { + val rawA = Test.rawAField + var rawInner = rawA.Inner("", "", strList) + rawInner.foo("", "", strList) + rawInner.bar().foo("") +} + diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interClassesRecursion.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interClassesRecursion.fir.kt new file mode 100644 index 00000000000..a0351f21e5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interClassesRecursion.fir.kt @@ -0,0 +1,4 @@ +// FILE: JavaScriptParser.java +public class JavaScriptParser {} +// FILE: JSPsiTypeParser.java +public class JSPsiTypeParser {} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonGenericRawMember.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonGenericRawMember.fir.kt new file mode 100644 index 00000000000..824d6553cd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonGenericRawMember.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A { + B b; +} + +// FILE: B.java + +import java.util.*; + +class B { + void bar(List x); +} + +// FILE: Test.java + +class Test { + static class RawADerived extends A {} + static A rawAField = null; +} + + +// FILE: main.kt + +val strList: List = null!! + +fun main() { + val rawB = Test.rawAField.b; + // Raw(A).b is not erased because it have no type parameters + var rawInner = rawB.bar(!", "List<String>")!>strList) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt new file mode 100644 index 00000000000..eab6503afe8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A, E extends T, F extends List> { + T first; + E second; + F listOfDoubles; +} + +// FILE: Test.java + +class Test { + static class DerivedRawA extends A {} + static A rawAField = null; +} + +// FILE: main.kt +val strList: List = null!! + +fun main() { + val rawA = Test.rawAField + rawA.first = Test.rawAField.second + Test.rawAField.second = rawA.first.second + + rawA.listOfDoubles = strList + rawA.listOfDoubles = "" // first should be List +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawEnhancment.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawEnhancment.fir.kt new file mode 100644 index 00000000000..302f3976a29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawEnhancment.fir.kt @@ -0,0 +1,17 @@ +// FILE: B.java +import java.util.List; + +public class B implements X { + @Override + List foo(List l) { + return super.foo(l); + } +} + +// FILE: 1.kt + +interface X { + fun foo(l: MutableList): List? +} + +internal class C : B() diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertype.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertype.fir.kt new file mode 100644 index 00000000000..9cb68995aa6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertype.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A { + List x; + + void foo(T x, List y) {} + + A> bar() {} +} + +// FILE: Test.java + +class Test { + static class RawADerived extends A { + + } +} + +// FILE: main.kt + +val strList: List = null!! +val strMap: Map = null!! + +fun main() { + val rawADerived = Test.RawADerived() + rawADerived.x = strList + rawADerived.foo("", strList) + + + val rawA = rawADerived.bar() + rawA.x = strList + rawA.foo("", strList) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt new file mode 100644 index 00000000000..a2140ed2e02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A { + A> foo(T x, Map> y, HashMap z) {} + + void bar(List[][] d) {} +} + +// FILE: RawADerived.java + +public class RawADerived extends A { +} + +// FILE: main.kt +import java.util.*; + +class B1 : RawADerived() { + override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! + + override fun bar(d: Array>>) {} +} + +class B2 : RawADerived() { + override fun foo(x: CharSequence?, y: MutableMap, z: HashMap): A = null!! + + override fun bar(d: Array>>) {} +} + +class B3 : RawADerived() { + // Type of second parameter (y) is not equal to overridden + // RawADerived.foo.y --- (MutableMap..Map) is not a subtype of Map + override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! +} + +class B4 : RawADerived() { + // Type of first parameter is not equal to overridden + override fun bar(d: Array>>>) {} +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt new file mode 100644 index 00000000000..d6a67267f13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.List; + +public class A { + List getChildrenStubs() { return null; } + void consume(T x) {} + + T produce() { return null; } +} + +// FILE: B.java + +public class B { + public E foo() { return null;} + E field; +} + +// FILE: Test.java + +public class Test { + static B rawB = null; +} + +// FILE: main.kt + +fun foo(x: B<*>) { + // TODO: x.foo() now is flexible type instead of raw, because of captured type approximation + val q: MutableList = x.foo().getChildrenStubs() + + // Raw(B).field erased to A..A? + Test.rawB.field = A() + val anyA: A = Test.rawB.field + + Test.rawB.field.consume("") + val y: Any = Test.rawB.field.produce() +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawWithInProjection.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawWithInProjection.fir.kt new file mode 100644 index 00000000000..db44de8b200 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawWithInProjection.fir.kt @@ -0,0 +1,11 @@ +// FILE: Test.java + +class Test { + static void foo(Comparable x) {} +} + +// FILE: main.kt + +fun main() { + Test.foo(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/recursiveBound.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/recursiveBound.fir.kt new file mode 100644 index 00000000000..2c6e7839c86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/recursiveBound.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.List; + +public interface A {} +// FILE: main.kt + +class D : A + +fun main(x: A<*>) { + if (x is D) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/samRaw.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/samRaw.fir.kt new file mode 100644 index 00000000000..761b2b25bbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/samRaw.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.List; + +public interface A { + boolean value(T t); +} + +// FILE: B.java + +class B { + void foo(Runnable runnable, A x); + + static A bar() {} +} + +// FILE: main.kt + +fun main() { + fun println() {} + // All parameters in SAM adapter of `foo` have functional types + B().foo({ println() }, B.bar()) + // So you should use SAM constructors when you want to use mix lambdas and Java objects + B().foo(Runnable { println() }, B.bar()) + B().foo({ println() }, { it: Any? -> it == null } ) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/saveRawCapabilitiesAfterSubtitution.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/saveRawCapabilitiesAfterSubtitution.fir.kt new file mode 100644 index 00000000000..aac713a9e7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/saveRawCapabilitiesAfterSubtitution.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A { + public class Inner { + List foo() {} + } +} + +// FILE: Test.java + +class Test { + static A rawAField = null; +} + +// FILE: main.kt + +val result = Test.rawAField.Inner().foo() diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/simple.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/simple.fir.kt new file mode 100644 index 00000000000..c095717a028 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/simple.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +class A { + List x; + Map y; + + A> z; + + void foo(T x, List y, List> z) {} + + A> bar() {} +} + +// FILE: Test.java + +class Test { + static A rawAField = null; +} + +// FILE: main.kt + +val strList: List = null!! +val strMap: Map = null!! + +fun main() { + val rawA = Test.rawAField + rawA.x = strList + rawA.y = strMap + rawA.foo("", strList, strList) + + val barResult = rawA.bar() + + barResult.x = strList + barResult.y = strMap + barResult.foo("", strList, null) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.fir.kt new file mode 100644 index 00000000000..4a89c3ce777 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/starProjectionToRaw.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.*; + +public class A {} + +// FILE: B.java + +import java.util.*; + +public class B {} + +// FILE: Test.java + +class Test { + static void foo(B x) {} +} + +// FILE: main.kt + + +fun main(x: B<*>) { + Test.foo(x) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt new file mode 100644 index 00000000000..f4ebcf67d44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/typeEnhancement.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java + +import org.jetbrains.annotations.*; +import java.util.*; + +class A { + @NotNull + List foo(@NotNull T x, @Nullable List y) {} +} + +// FILE: Test.java + +class Test { + static class DerivedRawA extends A {} + + static A rawField = null; +} + +// FILE: main.kt + +val doubleList: List = null!! + +fun main() { + Test.rawField.foo("", doubleList) + Test.rawField.foo(null, doubleList) + Test.DerivedRawA().foo(null, doubleList) +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/safeCall.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/safeCall.fir.kt new file mode 100644 index 00000000000..9c38f26a63d --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/safeCall.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE +// FILE: p/J.java + +package p; + +public class J { + public String s() { return null; } +} + +// FILE: k.kt +import p.* + +fun test(j: J) { + j.s()?.length.checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt new file mode 100644 index 00000000000..d3e7f0f3441 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER + +// FILE: A.java +import java.util.Comparator; + +public class A { + public A(Comparator comparator) {} +} + +// FILE: main.kt + +fun foo() { + val result: A = A { x, y -> 1 } +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/samConstructor.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/samConstructor.fir.kt new file mode 100644 index 00000000000..51507e0d511 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/samConstructor.fir.kt @@ -0,0 +1,17 @@ +// FILE: p/J.java + +package p; + +public class J { + public static void c(java.util.Comparator c) {} + +} + +// FILE: k.kt + +import java.util.* +import p.* + +fun test() { + J.c(Comparator { a, b -> b - a }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/supertypeArgumentsExplicit.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/supertypeArgumentsExplicit.fir.kt new file mode 100644 index 00000000000..eb566663584 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/supertypeArgumentsExplicit.fir.kt @@ -0,0 +1,13 @@ +// !EXPLICIT_FLEXIBLE_TYPES + +interface A +interface B: A> + +interface C: A, B +interface D: B, A +interface E: A, B +interface F: A, B + +interface G: A, B +interface H: A, B +interface I: B, A \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/supertypeTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/supertypeTypeArguments.fir.kt new file mode 100644 index 00000000000..899414d61cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/supertypeTypeArguments.fir.kt @@ -0,0 +1,3 @@ +// JAVAC_EXPECTED_FILE +interface ExtMap : Map +class HashMapEx : java.util.HashMap(), ExtMap \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.fir.kt new file mode 100644 index 00000000000..fe29fe38d9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.fir.kt @@ -0,0 +1,63 @@ +// FILE: A.kt +open class A { + open fun String.foo(y: String?): Int = 1 + open fun String?.bar(y: String): Int = 1 +} + +class E : B1() { + fun baz() { + val x: String? = "" + + x.foo(x) + x.foo("") + x.bar(x) + x.bar("") + } + + override fun String.foo(y: String?): Int = 1 + override fun String?.bar(y: String): Int = 1 +} + +// FILE: B.java +import org.jetbrains.annotations.*; + +// Just inherit enhanced types +class B extends A { + @Override + int foo(String x, String y); + @Override + int bar(String x, String y); +} + +// FILE: B1.java +import org.jetbrains.annotations.*; + +// Just inherit enhanced types (annotations without conflicts) +public class B1 extends A { + @Override + public int foo(@NotNull String x, String y); + @Override + public int bar(@Nullable String x, String y); +} + +// FILE: C.java +import org.jetbrains.annotations.*; + +// Conflicting annotations. Everything is flexible +class C extends A { + @Override + int foo(@Nullable String x, @NotNull String y); + @Override + int bar(@NotNull String x, @Nullable String y); +} + +// FILE: D.java +import org.jetbrains.annotations.*; + +// Just inherit enhanced types (annotations without conflicts) +class D extends B { + @Override + int foo(@Nullable String x, @Nullable String y); + @Override + int bar(@NotNull String x, @NotNull String y); +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt new file mode 100644 index 00000000000..96c0111f5e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt @@ -0,0 +1,43 @@ +// FILE: A.java + +import org.jetbrains.annotations.*; + +public interface A { + void foo(@NotNull T x, @Nullable T y); +} + +// FILE: B1.java + +// contains fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) +public interface B1 extends A {} + +// FILE: B2.java +import org.jetbrains.annotations.*; + +public interface B2 extends A { + // Ok, consistent override + // override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) + void foo(@NotNull String x, @Nullable String y); +} + +// FILE: B3.java +import org.jetbrains.annotations.*; + +public interface B3 extends A { + // inconsistent override, both parameters are platform + // override /*1*/ fun foo(/*0*/ org.jetbrains.annotations.Nullable() x: kotlin.String!, /*1*/ org.jetbrains.annotations.NotNull() y: kotlin.String!): kotlin.Unit + void foo(@Nullable String x, @NotNull String y); +} + +// FILE: main.kt + +// fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit +interface C1 : A + +// fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String?, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit +interface C2 : A + +interface C3 : B1 { + // inconsistent override + override fun foo(x: String?, y: String?); +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.fir.kt new file mode 100644 index 00000000000..d7cb1f069f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentParameterNullability.fir.kt @@ -0,0 +1,33 @@ +// FILE: A.java +import org.jetbrains.annotations.*; + +public interface A { + void foo(@Nullable String x); +} + +// FILE: B.java +import org.jetbrains.annotations.*; + +public interface B { + void foo(@NotNull String x); +} + +// FILE: C.kt + +class C1 : A, B { + override fun foo(x: String) {} +} + +class C2 : A, B { + override fun foo(x: String?) {} +} + +interface I : A, B + +class C3 : I { + override fun foo(x: String) {} +} + +class C4 : I { + override fun foo(x: String?) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.fir.kt new file mode 100644 index 00000000000..ab727c004be --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/supertypeDifferentReturnNullability.fir.kt @@ -0,0 +1,35 @@ +// FILE: A.java +import org.jetbrains.annotations.*; + +public interface A { + @Nullable + String foo(); +} + +// FILE: B.java +import org.jetbrains.annotations.*; + +public interface B { + @NotNull + String foo(); +} + +// FILE: C.kt + +class C1 : A, B { + override fun foo(): String? = "" +} + +class C2 : A, B { + override fun foo(): String = "" +} + +interface I : A, B + +class C3 : I { + override fun foo(): String? = "" +} + +class C4 : I { + override fun foo(): String = "" +} diff --git a/compiler/testData/diagnostics/tests/privateInFile/kt12429.fir.kt b/compiler/testData/diagnostics/tests/privateInFile/kt12429.fir.kt new file mode 100644 index 00000000000..9cc707d89e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/privateInFile/kt12429.fir.kt @@ -0,0 +1,4 @@ +private const val a = "" + +@Deprecated("$a") +fun test() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/privateInFile/topLevelAnnotationCall.fir.kt b/compiler/testData/diagnostics/tests/privateInFile/topLevelAnnotationCall.fir.kt new file mode 100644 index 00000000000..f3e97cd8266 --- /dev/null +++ b/compiler/testData/diagnostics/tests/privateInFile/topLevelAnnotationCall.fir.kt @@ -0,0 +1,27 @@ +// FILE: 1.kt +package pp + +private annotation class A(val s: String) +private const val foo = "O" + +@A(foo) +fun f1() {} + +@A(foo) +val p1 = "" + +@A(foo) +class C1 + + +// FILE: 2.kt +package pp + +@A(foo) +fun f2() {} + +@A(foo) +val p2 = "" + +@A(foo) +class C2 diff --git a/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt b/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt new file mode 100644 index 00000000000..fdb9710d13b --- /dev/null +++ b/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt @@ -0,0 +1,54 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +//FILE:file1.kt +package a + +private open class A { + fun bar() {} +} + +private var x: Int = 10 + +var xx: Int = 20 + private set(value: Int) {} + +private fun foo() {} + +private fun bar() { + val y = x + x = 20 + xx = 30 +} + +fun makeA() = A() + +private object PO {} + +//FILE:file2.kt +package a + +fun test() { + val y = makeA() + y.bar() + foo() + + val u : A = A() + + val z = x + x = 30 + + val po = PO + + val v = xx + xx = 40 +} + +class B : A() {} + +class Q { + class W { + fun foo() { + val y = makeA() //assure that 'makeA' is visible + } + } +} diff --git a/compiler/testData/diagnostics/tests/properDefaultInitializationInTailrec.fir.kt b/compiler/testData/diagnostics/tests/properDefaultInitializationInTailrec.fir.kt new file mode 100644 index 00000000000..62acd1f9aba --- /dev/null +++ b/compiler/testData/diagnostics/tests/properDefaultInitializationInTailrec.fir.kt @@ -0,0 +1,39 @@ +//!LANGUAGE: +ProperComputationOrderOfTailrecDefaultParameters +import kotlin.reflect.KClass + +fun withEffects(): String = "OK" + +const val Z = "123" + +enum class EnumA { + A +} + +tailrec fun foo(i: Int = 1, c: Char = '2', s: String = "1234", b: Boolean = true, d: Double = 1.0, l: Long = 1L, y: String = withEffects()) { + foo(i, c, s, b, d, l, y) +} + + +tailrec fun foo2(x: Int = 1, y: String = withEffects(), z: String = Z) { + foo2(x, y, z) +} + +tailrec fun foo3(y: String = withEffects()) { + foo3(y) +} + +tailrec fun foo4(x: String = withEffects(), y: String = withEffects()) { + foo4(x, y) +} + +tailrec fun foo5(x: String = withEffects(), y: String = withEffects(), z: String = withEffects()) { + foo5(x, y, z) +} + +tailrec fun foo6(x: String = withEffects(), y: EnumA = EnumA.A) { + foo6(x, y) +} + +tailrec fun foo7(x: String = withEffects(), y: KClass = EnumA.A::class) { + foo7(x, y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.fir.kt b/compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.fir.kt new file mode 100644 index 00000000000..5dc414355bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.fir.kt @@ -0,0 +1,25 @@ +val String.test1: Int +var String.test2: Int + +var String.test3: Int; public set + +class C { + val String.test1: Int + var String.test2: Int + var String.test3: Int; public set +} + +interface I { + val String.test1: Int + var String.test2: Int + var String.test3: Int; public set +} + +abstract class A { + val String.test1: Int + var String.test2: Int + var String.test3: Int; public set + + abstract val String.testA1: Int + abstract var String.testA2: Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/blockBodyGetter.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/blockBodyGetter.fir.kt new file mode 100644 index 00000000000..45062a5af6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/blockBodyGetter.fir.kt @@ -0,0 +1,3 @@ +val x get() { + return 1 +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/cantBeInferred.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/cantBeInferred.fir.kt new file mode 100644 index 00000000000..8091a2cabdf --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/cantBeInferred.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +val x get() = foo() +val y get() = bar() + +fun foo(): E = null!! +fun bar(): List = null!! diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/explicitGetterType.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/explicitGetterType.fir.kt new file mode 100644 index 00000000000..2e8bcf7bad6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/explicitGetterType.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +val x get(): String = foo() +val y get(): List = bar() +val z get(): List { + return bar() +} + +val u get(): String = field + +fun foo(): E = null!! +fun bar(): List = null!! + + +fun baz() { + x checkType { _() } + y checkType { _>() } + z checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/members.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/members.fir.kt new file mode 100644 index 00000000000..59e36b0d91f --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/members.fir.kt @@ -0,0 +1,24 @@ +// !CHECK_TYPE +class A { + val x get() = 1 + val y get() = id(1) + val y2 get() = id(id(2)) + val z get() = l("") + val z2 get() = l(id(l(""))) + + val T.u get() = id(this) +} +fun id(x: E) = x +fun l(x: E): List = null!! + +fun foo(a: A) { + a.x checkType { _() } + a.y checkType { _() } + a.y2 checkType { _() } + a.z checkType { _>() } + a.z2 checkType { _>>() } + + with(a) { + 1.u checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.fir.kt new file mode 100644 index 00000000000..0ac6589f0c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/nullAsNothing.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +val x get() = null +val y get() = null!! + +fun foo() { + x checkType { _() } + y checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/objectExpression.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/objectExpression.fir.kt new file mode 100644 index 00000000000..9be9503435e --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/objectExpression.fir.kt @@ -0,0 +1,36 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +object Outer { + private var x + get() = object : CharSequence { + override val length: Int + get() = 0 + + override fun get(index: Int): Char { + checkSubtype(x) + return ' ' + } + + override fun subSequence(startIndex: Int, endIndex: Int) = "" + + fun bar() { + } + } + set(q) { + checkSubtype(x) + y = q + x = q + } + + private var y = x + + fun foo() { + x = y + + checkSubtype(x) + checkSubtype(y) + + x.bar() + y.bar() + } +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/overrides.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/overrides.fir.kt new file mode 100644 index 00000000000..c329821e32d --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/overrides.fir.kt @@ -0,0 +1,41 @@ +// !CHECK_TYPE +interface A { + val x: Int + + val z: Comparable<*> +} + +open class B { + open var y = "" + + open val z: CharSequence = "" +} + +class C : B(), A { + override val x + get() = 1 + + override var y + get() = super.y + set(value) { + value checkType { _() } + } + + override var z + get() = "" + set(value) { + value checkType { _() } + } +} + +fun foo(c: C) { + c.x checkType { _() } + c.y checkType { _() } + c.z checkType { _() } + + c.y = "" + c.y = 1 + + c.z = "" + c.z = 1 +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/primaryConstructorParameter.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/primaryConstructorParameter.fir.kt new file mode 100644 index 00000000000..9eb73a466d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/primaryConstructorParameter.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Delegate { + operator fun getValue(x: Any?, y: Any?): String = "" +} + +fun delegateFactory(p: Any) = Delegate + +class C(p: Any, val v: Any) { + + val test1 get() = p + + val test2 get() = v + + // NB here we can use both 'T' (property type parameter) and 'p' (primary constructor parameter) + val List.test3 by delegateFactory(p) + + val test4 get() { return p } + + var test5 + get() { return p } + set(nv) { p.let {} } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.fir.kt new file mode 100644 index 00000000000..7550d94921b --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// NI_EXPECTED_FILE + +val x get() = x + +class A { + val y get() = y + + val a get() = b + val b get() = a + + val z1 get() = id(z1) + val z2 get() = l(z2) + + val u get() = field +} + +fun id(x: E) = x +fun l(x: E): List = null!! diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/topLevel.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/topLevel.fir.kt new file mode 100644 index 00000000000..fee3f677993 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/topLevel.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE +val x get() = 1 +val y get() = id(1) +val y2 get() = id(id(2)) +val z get() = l("") +val z2 get() = l(id(l(""))) + +val T.u get() = id(this) + +fun id(x: E) = x +fun l(x: E): List = null!! + +fun foo() { + x checkType { _() } + y checkType { _() } + y2 checkType { _() } + z checkType { _>() } + z2 checkType { _>>() } + + 1.u checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/unsupportedInferenceFromGetters.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/unsupportedInferenceFromGetters.fir.kt new file mode 100644 index 00000000000..ba0c9f422bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/unsupportedInferenceFromGetters.fir.kt @@ -0,0 +1,71 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: -ShortSyntaxForPropertyGetters +// NI_EXPECTED_FILE + +// blockBodyGetter.kt +val x get() { + return 1 +} + +// cantBeInferred.kt +val x1 get() = foo() +val y1 get() = bar() + +fun foo(): E = null!! +fun bar(): List = null!! + +// explicitGetterType.kt +val x2 get(): String = foo() +val y2 get(): List = bar() +val z2 get(): List { + return bar() +} + +val u get(): String = field + +// members.kt +class A { + val x get() = 1 + val y get() = id(1) + val y2 get() = id(id(2)) + val z get() = l("") + val z2 get() = l(id(l(""))) + + val T.u get() = id(this) +} +fun id(x: E) = x +fun l(x: E): List = null!! + +// vars +var x3 + get() = 1 + set(q) { + } + +// recursive +val x4 get() = x4 + +// null as nothing +val x5 get() = null +val y5 get() = null!! + +// objectExpression.kt +object Outer { + private var x + get() = object : CharSequence { + override val length: Int + get() = 0 + + override fun get(index: Int): Char { + return ' ' + } + + override fun subSequence(startIndex: Int, endIndex: Int) = "" + + fun bar() { + } + } + set(q) { + x = q + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/vars.fir.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/vars.fir.kt new file mode 100644 index 00000000000..d8e9261d7f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/vars.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE +var x + get() = 1 + set(q) { + q checkType { _() } + } + +var noSetter + get() = 1 + + +fun foo() { + x checkType { _() } + noSetter checkType { _() } + + x = 1 + x = "" + + noSetter = 2 + noSetter = "" +} diff --git a/compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.fir.kt b/compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.fir.kt new file mode 100644 index 00000000000..f13d54e7923 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +LateinitTopLevelProperties + +object Delegate { + operator fun getValue(instance: Any?, property: Any) : String = "" + operator fun setValue(instance: Any?, property: Any, value: String) {} +} + +lateinit var testOk: String + +lateinit val testErr0: Any +lateinit var testErr1: Int +lateinit var testErr2: Any? +lateinit var testErr3: String = "" +lateinit var testErr4 by Delegate diff --git a/compiler/testData/diagnostics/tests/publishedApi.fir.kt b/compiler/testData/diagnostics/tests/publishedApi.fir.kt new file mode 100644 index 00000000000..a1d00b75dcc --- /dev/null +++ b/compiler/testData/diagnostics/tests/publishedApi.fir.kt @@ -0,0 +1,71 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@kotlin.PublishedApi +class A + +@kotlin.PublishedApi +internal class B + +@kotlin.PublishedApi +private class C + + +@kotlin.PublishedApi +fun a() {} + +@kotlin.PublishedApi +internal fun b() {} + +@kotlin.PublishedApi +internal fun c() {} + + +@kotlin.PublishedApi +var ap = 1 + +@kotlin.PublishedApi +internal var bp = 1 + +@kotlin.PublishedApi +internal var c = 1 + + + +class E { + @kotlin.PublishedApi + fun a() {} + + @kotlin.PublishedApi + internal fun b() {} + + @kotlin.PublishedApi + private fun c() {} + + @kotlin.PublishedApi + protected fun d() {} + + + @kotlin.PublishedApi + val ap = 1 + + @kotlin.PublishedApi + internal val bp = 1 + + @kotlin.PublishedApi + protected val c = 1 + + @kotlin.PublishedApi + private val d = 1 +} + + +class D @kotlin.PublishedApi constructor() { + + @kotlin.PublishedApi + constructor(a: String) : this() + + @kotlin.PublishedApi + private constructor(a: String, b: String): this() + + @kotlin.PublishedApi + internal constructor(a: String, b: String, c: String): this() +} diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/GenericClassVsPackage.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/GenericClassVsPackage.fir.kt new file mode 100644 index 00000000000..8b40039c0d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/GenericClassVsPackage.fir.kt @@ -0,0 +1,76 @@ +// MODULE: m1 +// FILE: a.kt +package a.b + +class c { + fun ab_c() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class b { + class c { + fun a_bc() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.b.c + +fun test(ab_c: c) { + ab_c.ab_c() + + val ab_c2: a.b.c = a.b.c() + ab_c2.ab_c() + + val ab_c3 = a.b.c() + ab_c3.ab_c() +} + +// NB according to the maximum package prefix rule, 'a.b.c' denotes 'c' in package 'a.b' (thus ab_c, not a_bc) +fun test2(ab_c: a.b.c) { + ab_c.a_bc() + ab_c.ab_c() +} + + + +//---------------------------TOP LEVEL---------- +// MODULE: top_m1 +// FILE: top_a.kt +package a + +class b { + fun a_b() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class a { + class b { + fun _ab() {} + } + fun _a() {} +} + +// MODULE: top_m3(top_m1, top_m2) +// FILE: top_c.kt +import a.b + +fun test(a_b: b) { + a_b.a_b() + + val _ab: a.b = a.b() + _ab._ab() + + val _ab2 = a.b() + _ab2._ab() +} + +fun test2(_ab: a.b) { + _ab._ab() + _ab.a_b() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/JavaQualifier.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/JavaQualifier.fir.kt new file mode 100644 index 00000000000..b0f497158d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/JavaQualifier.fir.kt @@ -0,0 +1,9 @@ +// FILE: Owner.java + +public class Owner { + public static final String name = "Owner"; +} + +// FILE: Use.kt + +val x = Owner.name diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass.fir.kt new file mode 100644 index 00000000000..53c311808ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass.fir.kt @@ -0,0 +1,88 @@ +// MODULE: m1 +// FILE: a.kt +package a.b + +class c { + fun ab_c() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt + +fun test(a_b: a.b) { + a_b.a_b() + + val ab_c: a.b.c = a.b.c() + ab_c.ab_c() + ab_c.a_bc() + + val ab_c2 = a.b.c() + ab_c2.ab_c() + ab_c2.a_bc() +} + +fun test2(ab_c: a.b.c) { + ab_c.ab_c() +} + +//---- Changed dependence order +// MODULE: _m1 +// FILE: _a.kt +package a.b + +fun ab_fun() {} + +class c { + fun ab_c() {} + + class d { + fun ab_cd() {} + } +} + +// MODULE: _m2 +// FILE: _b.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: _m3(_m1, _m2) +// FILE: _c.kt + +fun test(a_b: a.b) { + a_b.a_b() + + val ab_c: a.b.c = a.b.c() + ab_c.ab_c() + ab_c.a_bc() + + val ab_c2 = a.b.c() + ab_c2.ab_c() + ab_c2.a_bc() +} + +fun test2(ab_c: a.b.c) { + ab_c.ab_c() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass2.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass2.fir.kt new file mode 100644 index 00000000000..6cccc7a53f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsClass2.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt +package a + +class a { + companion object {} +} + +class b { + fun a_b() {} +} + +// MODULE: m2(m1) +// FILE: b.kt +package test + +class a + +val x = a.b() + +// MODULE: m3(m1) +// FILE: c.kt +package test + +import a.a + +fun foo(i: a) { + a + a() + a.a + a.a() +} diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsRootClass.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsRootClass.fir.kt new file mode 100644 index 00000000000..e81b8ef51d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/PackageVsRootClass.fir.kt @@ -0,0 +1,44 @@ +// MODULE: m1 +// FILE: a.kt +package a + +class b { + fun a_b() {} +} + +// MODULE: m2 +// FILE: b.kt +class a { + class b { + fun _ab() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c1.kt +package some + +fun test(a_b: a.b) { + a_b.a_b() + + val a_b2 = a.b() + a_b2.a_b() +} + +// FILE: c2.kt +package a + +fun test(a_b: a.b) { + a_b.a_b() + + val a_b2 = a.b() + a_b2.a_b() +} + +// FILE: c3.kt +fun test(_ab: a.b) { + _ab._ab() + + val _ab2 = a.b() + _ab2._ab() // todo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.fir.kt new file mode 100644 index 00000000000..852b5d5c946 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/TypeWithError.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -UNREACHABLE_CODE +// !WITH_NEW_INFERENCE + +class A { + class B { + class C + } +} + +fun test(a: A.): A. { + val aa: A. = null!! +} + +fun test1(a: A.B.): A.B. { + val aa: A.B. = null!! +} + +fun test2(a: A.e.C): A.e.C { + val aa: A.e.C = null!! +} + +fun test3(a: a.A.C): a.A.C { + val aa: a.A.C = null!! +} + +fun test4(a: A.B.ee): A.B.ee { + val aa: A.B.ee = null!! +} + +fun test5(a: A.ee): A.ee { + val aa: A.ee = null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/calleeExpressionAsCallExpression.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/calleeExpressionAsCallExpression.fir.kt new file mode 100644 index 00000000000..5f2399d1564 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/calleeExpressionAsCallExpression.fir.kt @@ -0,0 +1,2 @@ +// !WITH_NEW_INFERENCE +val unwrapped = some<sdf()()::unwrap \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/nullCalleeExpression.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/nullCalleeExpression.fir.kt new file mode 100644 index 00000000000..81fced65a49 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/nullCalleeExpression.fir.kt @@ -0,0 +1,4 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +val unwrapped = some.<cabc$Wrapper::unwrap \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/qualifiedExpression/visibleClassVsQualifiedClass.fir.kt b/compiler/testData/diagnostics/tests/qualifiedExpression/visibleClassVsQualifiedClass.fir.kt new file mode 100644 index 00000000000..9e9cebd91d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/qualifiedExpression/visibleClassVsQualifiedClass.fir.kt @@ -0,0 +1,58 @@ +// MODULE: m1 +// FILE: a.kt +package a + +class b { + fun a_b() {} +} + +// MODULE: m2 +// FILE: b.kt +package some + +class a { + class b { + fun some_ab() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c1.kt +package other + +class a {} + +fun test(a_: a.b) { + a_.a_b() + + val a_2 = a.b() + a_2.a_b() + a_2.some_ab() + a_2.a_() +} + +// FILE: c2.kt +package other2 + +class a { + class b { + fun other2_ab() {} + } +} + +fun test(_ab: a.b) { + _ab.other2_ab() + + val _ab2 = a.b() + _ab2.other2_ab() +} + +// FILE: c3.kt +package some + +fun test(_ab: a.b) { + _ab.some_ab() + + val _ab2 = a.b() + _ab2.some_ab() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/afterfor.fir.kt b/compiler/testData/diagnostics/tests/reassignment/afterfor.fir.kt new file mode 100644 index 00000000000..17d208686ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/afterfor.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(k: Int): Int { + val i: Int + for (j in 1..k) { + i = j + } + i = 6 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/dowhile.fir.kt b/compiler/testData/diagnostics/tests/reassignment/dowhile.fir.kt new file mode 100644 index 00000000000..8d76e571678 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/dowhile.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(): Int { + val i: Int + var j = 0 + do { + i = ++j + } while (j < 5) + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/else.fir.kt b/compiler/testData/diagnostics/tests/reassignment/else.fir.kt new file mode 100644 index 00000000000..3b3d5f2f6d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/else.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(f: Boolean): Int { + val i: Int + if (f) {} + else { + i = 2 + } + i = 3 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/foronly.fir.kt b/compiler/testData/diagnostics/tests/reassignment/foronly.fir.kt new file mode 100644 index 00000000000..bc5907df2c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/foronly.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(k: Int): Int { + val i: Int + for (j in 1..k) { + i = j + } + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/if.fir.kt b/compiler/testData/diagnostics/tests/reassignment/if.fir.kt new file mode 100644 index 00000000000..3b69ff4fb28 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/if.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(f: Boolean): Int { + val i: Int + if (f) { + i = 1 + } + i = 3 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/ifelse.fir.kt b/compiler/testData/diagnostics/tests/reassignment/ifelse.fir.kt new file mode 100644 index 00000000000..4a7acfd06f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/ifelse.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(f: Boolean): Int { + val i: Int + if (f) { + i = 1 + } + else { + i = 2 + } + i = 3 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/noifelse.fir.kt b/compiler/testData/diagnostics/tests/reassignment/noifelse.fir.kt new file mode 100644 index 00000000000..b096df5bcdb --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/noifelse.fir.kt @@ -0,0 +1,6 @@ +fun foo(f: Boolean): Int { + val i: Int + if (f) {} + i = 3 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/when.fir.kt b/compiler/testData/diagnostics/tests/reassignment/when.fir.kt new file mode 100644 index 00000000000..bdc46e59d62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/when.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(f: Boolean): Int { + val i: Int + when (f) { + true -> i = 1 + } + i = 3 + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/reassignment/whiletrue.fir.kt b/compiler/testData/diagnostics/tests/reassignment/whiletrue.fir.kt new file mode 100644 index 00000000000..a17eabfa441 --- /dev/null +++ b/compiler/testData/diagnostics/tests/reassignment/whiletrue.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VALUE + +fun foo(): Int { + val i: Int + var j = 0 + while (true) { + i = ++j + if (j > 5) break + } + return i +} diff --git a/compiler/testData/diagnostics/tests/recovery/absentLeftHandSide.fir.kt b/compiler/testData/diagnostics/tests/recovery/absentLeftHandSide.fir.kt new file mode 100644 index 00000000000..2a108a6ca91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/recovery/absentLeftHandSide.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +fun import() { + import a.* +} + +fun composite() { + val s = 13+~/12 +} + +fun html() { + <html></html> +} + +fun html1() { + <html></html>html +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/recovery/emptyTypeArgs.fir.kt b/compiler/testData/diagnostics/tests/recovery/emptyTypeArgs.fir.kt new file mode 100644 index 00000000000..4152b60aa97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/recovery/emptyTypeArgs.fir.kt @@ -0,0 +1,3 @@ +fun main(args: Array) { + args is Array<> +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/recovery/namelessInJava.fir.kt b/compiler/testData/diagnostics/tests/recovery/namelessInJava.fir.kt new file mode 100644 index 00000000000..78d2e8f4415 --- /dev/null +++ b/compiler/testData/diagnostics/tests/recovery/namelessInJava.fir.kt @@ -0,0 +1,18 @@ +// JAVAC_SKIP +// FILE: p/Nameless.java + +package p; + +public class Nameless { + void () {} + int ; +} + +// FILE: k.kt + +import p.* + +class K : Nameless() { + fun () {} + val : Int = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/recovery/namelessMembers.fir.kt b/compiler/testData/diagnostics/tests/recovery/namelessMembers.fir.kt new file mode 100644 index 00000000000..6bd0aa7f1fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/recovery/namelessMembers.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -REDECLARATION -DUPLICATE_CLASS_NAMES + +class C { + fun () { + + } + + val : Int = 1 + + class {} + + enum class {} +} + +class C1<in> {} + +class C2(val) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.fir.kt b/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.fir.kt new file mode 100644 index 00000000000..4c13a3703b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -REDECLARATION + +package + +fun () { + +} + +val : Int = 1 + + +class { + +} + +interface { + +} + +object { + +} + +enum class {} + +annotation class {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.fir.kt new file mode 100644 index 00000000000..c6b6cfd77f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.fir.kt @@ -0,0 +1,11 @@ +// FILE: f1.kt +package test + +class A +class F1 + +// FILE: f2.kt +package test + +class A +class F2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/ConflictingExtensionProperties.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/ConflictingExtensionProperties.fir.kt new file mode 100644 index 00000000000..4a0c17cc96f --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/ConflictingExtensionProperties.fir.kt @@ -0,0 +1,4 @@ +package foo + +val Int.foo: Int get() = 2 +val Int.foo: Int get() = 3 diff --git a/compiler/testData/diagnostics/tests/redeclarations/DuplicateParameterNamesInFunctionType.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/DuplicateParameterNamesInFunctionType.fir.kt new file mode 100644 index 00000000000..5d6770c5b77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/DuplicateParameterNamesInFunctionType.fir.kt @@ -0,0 +1,7 @@ +fun test0(f: (String, String) -> Unit) { + f("", "") +} + +fun test1(f: (a: Int, a: Int) -> Unit) { + f(1, 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/EnumName.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/EnumName.fir.kt new file mode 100644 index 00000000000..9aa96f3064e --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/EnumName.fir.kt @@ -0,0 +1,3 @@ +enum class A { + name +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.fir.kt new file mode 100644 index 00000000000..0e47fe33efd --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.fir.kt @@ -0,0 +1,10 @@ +// FILE: test1.kt +class A +class B(val x: Int) { + constructor(x: Int, y: Int): this(x + y) +} + +// FILE: test2.kt +fun A() {} +fun B(x: Int) = x +fun B(x: Int, y: Int) = x + y \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.fir.kt new file mode 100644 index 00000000000..878e410c051 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.fir.kt @@ -0,0 +1,7 @@ +// FILE: f.kt +package a +class b {} +// FILE: f.kt +package a.b +// FILE: f.kt +package a.b \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForClassesInDefaultObject.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForClassesInDefaultObject.fir.kt new file mode 100644 index 00000000000..4ccc2f901a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForClassesInDefaultObject.fir.kt @@ -0,0 +1,12 @@ +package kt2247 + +class B { + companion object { + class Y { + } + } + + class Y { + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForEnumEntriesAndDefaultObjectMembers.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForEnumEntriesAndDefaultObjectMembers.fir.kt new file mode 100644 index 00000000000..cc2979f1768 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/NoRedeclarationForEnumEntriesAndDefaultObjectMembers.fir.kt @@ -0,0 +1,11 @@ +enum class E { + FIRST, + + SECOND; + + companion object { + class FIRST + + val SECOND = this + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/PropertyAndFunInClass.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/PropertyAndFunInClass.fir.kt new file mode 100644 index 00000000000..651d4ac0235 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/PropertyAndFunInClass.fir.kt @@ -0,0 +1,9 @@ +class A() { + val a: Int = 1 + fun a(): Int = 2 +} + +class B() { + fun b(): Int = 2 + val b: Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/PropertyAndInnerClass.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/PropertyAndInnerClass.fir.kt new file mode 100644 index 00000000000..897272f303d --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/PropertyAndInnerClass.fir.kt @@ -0,0 +1,13 @@ +public class A() { + public val FOO: String = "test" + + public class FOO() { } +} + +public class B() { + companion object { + public val FOO: String = "test" + + public class FOO() { } + } +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInDefaultObject.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInDefaultObject.fir.kt new file mode 100644 index 00000000000..dbacb0355db --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInDefaultObject.fir.kt @@ -0,0 +1,6 @@ +class A { + companion object B { + class G + val G = 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInMultiFile.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInMultiFile.fir.kt new file mode 100644 index 00000000000..2e34762bb74 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationInMultiFile.fir.kt @@ -0,0 +1,9 @@ +// FILE: a.kt +val a : Int = 1 +fun f() { +} + +// FILE: b.kt +val a : Int = 1 +fun f() { +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInFile.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInFile.fir.kt new file mode 100644 index 00000000000..c6a009b2b61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInFile.fir.kt @@ -0,0 +1,4 @@ +// KT-9733 No error shown for 2 "main" functions in the same file + +fun main(args: Array) {} +fun main(args: Array) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInMultiFile.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInMultiFile.fir.kt new file mode 100644 index 00000000000..b98f96fdc4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationMainInMultiFile.fir.kt @@ -0,0 +1,5 @@ +// FILE: a.kt +fun main() {} + +// FILE: b.kt +fun main() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain.fir.kt new file mode 100644 index 00000000000..41583bce9c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain.fir.kt @@ -0,0 +1,5 @@ +// FILE: a.kt +fun main() {} + +// FILE: b.kt +fun main() {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMainInvalid.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMainInvalid.fir.kt new file mode 100644 index 00000000000..be65bf3c15c --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMainInvalid.fir.kt @@ -0,0 +1,7 @@ +// FILE: a.kt +fun main() {} + +suspend fun main(args: Array) {} + +// FILE: b.kt +fun main() {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain_before.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain_before.fir.kt new file mode 100644 index 00000000000..28f0c97317c --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationParameterlessMain_before.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -ExtendedMainConvention + +// FILE: a.kt +fun main() {} + +// FILE: b.kt +fun main() {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile.fir.kt new file mode 100644 index 00000000000..edb92ec06bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile.fir.kt @@ -0,0 +1,5 @@ +// FILE: a.kt +suspend fun main() {} + +// FILE: b.kt +suspend fun main() {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile_before.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile_before.fir.kt new file mode 100644 index 00000000000..53601588209 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationSuspendMainInMultiFile_before.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -ExtendedMainConvention + +// FILE: a.kt +suspend fun main(args: Array) {} + +// FILE: b.kt +suspend fun main(args: Array) {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.fir.kt new file mode 100644 index 00000000000..f73cefbdb20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.fir.kt @@ -0,0 +1,15 @@ +// FILE: f.kt +package redeclarations + object A { + val x : Int = 0 + + val A = 1 + } + + class A {} + + val A = 1 + +// FILE: f.kt + package redeclarations.A + class A {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclarationsInObjects.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationsInObjects.fir.kt new file mode 100644 index 00000000000..69d28fec063 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclarationsInObjects.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES +// KT-3525 +object B { + class C + class C + + val a : Int = 1 + val a : Int = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.fir.kt new file mode 100644 index 00000000000..ed1cc72fc2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.fir.kt @@ -0,0 +1,6 @@ +fun Pair() {} + +class P {} + +val T.foo : Int + get() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.fir.kt new file mode 100644 index 00000000000..048c5bf2a5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.fir.kt @@ -0,0 +1,49 @@ +// FILE: a.kt +package a + +interface A +interface B : A + +private fun validFun() {} +private val validVal = 1 + +private fun invalidFun0() {} +private val invalidProp0 = 1 + +// NB invalidFun0 and invalidProp0 are conflicting overloads, since the following is an ambiguity: +fun useInvalidFun0() = invalidFun0() +fun useInvalidProp0() = invalidProp0 + +private fun invalidFun1() {} +private fun invalidFun1() {} + +private fun invalidFun2() {} +public fun invalidFun2() {} + +public fun invalidFun3() {} + +private fun invalidFun4() {} +public fun invalidFun4() {} + +public fun validFun2(a: A) = a +public fun validFun2(b: B) = b + +// FILE: b.kt +package a + +private fun validFun() {} +private val validVal = 1 + +private fun invalidFun0() {} + +private val invalidProp0 = 1 + +internal fun invalidFun3() {} +internal fun invalidFun4() {} + +// FILE: c.kt +package a + +public fun invalidFun0() {} + +public val invalidProp0 = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.fir.kt new file mode 100644 index 00000000000..ee0f5f28a01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/SingletonAndFunctionSameName.fir.kt @@ -0,0 +1,21 @@ +fun Foo() = 42 + +object Foo { + fun Bar() = 239 + + object Bar +} + + + +fun En() = 239 + +enum class En { + ENTRY, + + SUBCLASS { }; + + fun ENTRY() = 42 + + fun SUBCLASS() = ENTRY() +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.fir.kt new file mode 100644 index 00000000000..d34d5646823 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.fir.kt @@ -0,0 +1,13 @@ +val Test1 = null +class Test1 + +val Test2 = null +interface Test2 + +val Test3 = null +object Test3 + +val Test4 = null +class Test4 +interface Test4 +object Test4 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.fir.kt new file mode 100644 index 00000000000..7ef178e52bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +class C(val x: Int) + +typealias CC = C + +fun CC(x: Int) = x + +class Outer { + class C(val x: Int) + + typealias CC = C + + fun CC(x: Int) = x +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.fir.kt new file mode 100644 index 00000000000..6865692e7d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// FILE: file1.kt +class SomeClass + +typealias SomeClass = Any +typealias SomeClass = Any +typealias SomeClass = Any + +class Outer { + class Nested + + typealias Nested = Any + typealias Nested = Any + typealias Nested = Any +} + +// FILE: file2.kt +typealias SomeClass = Any \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.fir.kt new file mode 100644 index 00000000000..a52cf540780 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// FILE: file1.kt +typealias Test = String + +val Test = 42 + +class Outer { + typealias Test = String + + val Test = 42 +} + +typealias Test2 = String + +// FILE: file2.kt +val Test2 = 42 diff --git a/compiler/testData/diagnostics/tests/redeclarations/interfaceTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/interfaceTypeParameters.fir.kt new file mode 100644 index 00000000000..774f0c684ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/interfaceTypeParameters.fir.kt @@ -0,0 +1,6 @@ +interface Test1 +interface Test2 + +class Outer { + interface TestNested +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/kt2418.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/kt2418.fir.kt new file mode 100644 index 00000000000..8089c93e100 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/kt2418.fir.kt @@ -0,0 +1,27 @@ +//KT-2418 Front-end allows enum constants with same name + +package kt2418 + +enum class A { + FOO, + FOO +} + +enum class B { + FOO; + + fun FOO() {} +} + +enum class C { + FOO; + + val FOO = 1 +} + +enum class D { + FOO; + + class FOO {} +} + diff --git a/compiler/testData/diagnostics/tests/redeclarations/kt2438.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/kt2438.fir.kt new file mode 100644 index 00000000000..e559d20a8b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/kt2438.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES +//KT-2438 Prohibit inner classes with the same name + +package kt2438 + +class B { + class C + class C +} + + + +class A { + class B + + companion object { + class B + class B + } + + class B +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/kt470.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/kt470.fir.kt new file mode 100644 index 00000000000..167ac8dbfd7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/kt470.fir.kt @@ -0,0 +1,37 @@ +val a : Int = 1 +val a : Int = 1 +val a : Int = 1 + +val b : Int = 1 +val b : Int = 1 +val b : Int = 1 +val b : Int = 1 + +fun foo() {} // and here too +fun foo() {} // and here +fun foo() {} // and here +fun foo() {} // and here + +fun bar() {} // and here +fun bar() {} // and here +fun bar() {} // and here + +class A { + val a : Int = 1 + val a : Int = 1 + val a : Int = 1 + + val b : Int = 1 + val b : Int = 1 + val b : Int = 1 + val b : Int = 1 + + fun foo() {} // and here too + fun foo() {} // and here + fun foo() {} // and here + fun foo() {} // and here + + fun bar() {} // and here + fun bar() {} // and here + fun bar() {} // and here +} diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByInnerClassConstructor.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByInnerClassConstructor.fir.kt new file mode 100644 index 00000000000..946a4f9e593 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByInnerClassConstructor.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Outer { + inner class Test1 + inner class Test2(val x: Int) + inner class Test3(val x: Any) + inner class Test4(val x: T) + inner class Test5(val x: Int) { + constructor() : this(0) + private constructor(z: String) : this(z.length) + } + + class TestNested + + internal class TestInternal + protected class TestProtected + private class TestPrivate +} + +fun Outer.Test1() {} +fun Outer.Test2(x: Int) {} +fun Outer.Test3(x: String) {} +fun Outer.Test3(x: T) {} +fun Outer.Test4(x: T) {} +fun Outer.Test5() {} +fun Outer.Test5(z: String) {} + +fun Outer.TestNested() {} +fun Outer.TestInternal() {} +fun Outer.TestProtected() {} +fun Outer.TestPrivate() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberFun.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberFun.fir.kt new file mode 100644 index 00000000000..6780abb07f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberFun.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Test1 { + fun test1() {} +} +fun Test1.test1() {} + +interface Test2 { + fun test2(x: String) {} +} +fun Test2.test2(x: Any) {} + +interface Test3 { + fun test3(x: Any) {} +} +fun Test3.test3(x: String) {} +fun Test3.test3(x: T) {} + +interface Test4 { + fun test4(x: T) {} +} +fun Test4.test4(x: String) {} + +interface Test5 { + fun test5(x: T) {} +} +fun Test5.test5(x: T) {} + +interface Test6 { + fun > test6(x: T) {} +} +fun > Test6.test6(x: T) {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberPropertyWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberPropertyWithInvoke.fir.kt new file mode 100644 index 00000000000..aad3ff63313 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberPropertyWithInvoke.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface WithInvoke { + operator fun invoke() + operator fun invoke(s: String) + operator fun invoke(x: T, y: Int) + fun invoke(i: Int) +} + +interface Test1 { + val test1: WithInvoke +} + +fun Test1.test1() {} +fun Test1.test1(s: String) {} +fun Test1.test1(i: Int) {} +fun Test1.test1(x: Any, y: Int) {} +fun Test1.test1(x: T, y: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedBySynthesizedMemberFun.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedBySynthesizedMemberFun.fir.kt new file mode 100644 index 00000000000..0c85c304347 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedBySynthesizedMemberFun.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +data class DataClass(val x: Int) + +fun DataClass.component1() = 42 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunVsMemberExtensionFun.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunVsMemberExtensionFun.fir.kt new file mode 100644 index 00000000000..8298c498e70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunVsMemberExtensionFun.fir.kt @@ -0,0 +1,5 @@ +class C { + fun Int.foo() {} +} + +fun C.foo() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnErrorType.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnErrorType.fir.kt new file mode 100644 index 00000000000..10292f79764 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnErrorType.fir.kt @@ -0,0 +1,7 @@ +interface G { + fun foo() + val bar: Int +} + +fun G.foo() {} +val G.bar: Int get() = 42 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnNullableReceiver.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnNullableReceiver.fir.kt new file mode 100644 index 00000000000..796aee5f4e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionOnNullableReceiver.fir.kt @@ -0,0 +1,7 @@ +interface Test { + fun foo() + val bar: Int +} + +fun Test?.foo() {} +val Test?.bar: Int get() = 42 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionPropertyShadowedByMemberProperty.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionPropertyShadowedByMemberProperty.fir.kt new file mode 100644 index 00000000000..08b03b7803b --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionPropertyShadowedByMemberProperty.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Test1 { + val test1: Int +} +val Test1.test1: Int get() = 42 + +interface Test2 { + var test2: Int +} +val Test2.test2: Int get() = 42 + +interface Test3 { + val test3: Int +} +var Test3.test3: Int get() = 42; set(v) {} + +interface Test4 { + val test4: Int +} +var Test4.test4: Int get() = 42; set(v) {} + diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionShadowedByDelegatedMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionShadowedByDelegatedMember.fir.kt new file mode 100644 index 00000000000..eb9374ad41e --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionShadowedByDelegatedMember.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface IBase { + fun foo() + val bar: Int +} + +object Impl : IBase { + override fun foo() {} + override val bar: Int get() = 42 +} + +object Test : IBase by Impl + +fun Test.foo() {} +val Test.bar: Int get() = 42 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionVsNonPublicMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionVsNonPublicMember.fir.kt new file mode 100644 index 00000000000..ba1d38269dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionVsNonPublicMember.fir.kt @@ -0,0 +1,47 @@ +class WithPublicInvoke { + public operator fun invoke() {} +} + +class WithInternalInvoke { + internal operator fun invoke() {} +} + +class WithProtectedInvoke { + protected operator fun invoke() {} +} + +class WithPrivateInvoke { + private operator fun invoke() {} +} + +class Test { + public fun publicFoo() {} + internal fun internalFoo() {} + protected fun protectedFoo() {} + private fun privateFoo() {} + + public val publicVal = 42 + internal val internalVal = 42 + protected val protectedVal = 42 + private val privateVal = 42 + + public val withPublicInvoke = WithPublicInvoke() + public val withInternalInvoke = WithInternalInvoke() + public val withProtectedInvoke = WithProtectedInvoke() + public val withPrivateInvoke = WithPrivateInvoke() +} + +private fun Test.publicFoo() {} +fun Test.internalFoo() {} +fun Test.protectedFoo() {} +fun Test.privateFoo() {} + +val Test.publicVal: Int get() = 42 +val Test.internalVal: Int get() = 42 +val Test.protectedVal: Int get() = 42 +val Test.privateVal: Int get() = 42 + +fun Test.withPublicInvoke() {} +fun Test.wihtInternalInvoke() {} +fun Test.withProtectedInvoke() {} +fun Test.withPrivateInvoke() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/infixExtensionVsNonInfixMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/infixExtensionVsNonInfixMember.fir.kt new file mode 100644 index 00000000000..40ec24b1d1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/infixExtensionVsNonInfixMember.fir.kt @@ -0,0 +1,7 @@ +interface IFoo { + fun foo(i: Int): Int + infix fun bar(i: Int): Int +} + +infix fun IFoo.foo(i: Int) = i +infix fun IFoo.bar(i: Int) = i \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/localExtensionShadowedByMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/localExtensionShadowedByMember.fir.kt new file mode 100644 index 00000000000..30a1f33716a --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/localExtensionShadowedByMember.fir.kt @@ -0,0 +1,7 @@ +interface IFoo { + fun foo() +} + +fun outer() { + fun IFoo.foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/memberExtensionShadowedByMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/memberExtensionShadowedByMember.fir.kt new file mode 100644 index 00000000000..f21accfe873 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/memberExtensionShadowedByMember.fir.kt @@ -0,0 +1,9 @@ +interface IFooBar { + fun foo() + val bar: Int +} + +class Host { + fun IFooBar.foo() {} + val IFooBar.bar: Int get() = 42 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/operatorExtensionVsNonOperatorMember.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/operatorExtensionVsNonOperatorMember.fir.kt new file mode 100644 index 00000000000..a373cd38dcc --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/operatorExtensionVsNonOperatorMember.fir.kt @@ -0,0 +1,7 @@ +interface Test { + fun invoke() + operator fun invoke(i: Int): Int +} + +operator fun Test.invoke() {} +operator fun Test.invoke(i: Int) = i \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/typeParameterWithTwoBounds.fir.kt b/compiler/testData/diagnostics/tests/redeclarations/typeParameterWithTwoBounds.fir.kt new file mode 100644 index 00000000000..ad354abd6b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/typeParameterWithTwoBounds.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Foo +interface Bar + +fun foo(x: T): T where T: Foo, T: Bar {null!!} +fun foo(x: Foo): Foo {null!!} +fun foo(x: Bar): Bar {null!!} diff --git a/compiler/testData/diagnostics/tests/reflection/noReflectionInClassPath.fir.kt b/compiler/testData/diagnostics/tests/reflection/noReflectionInClassPath.fir.kt new file mode 100644 index 00000000000..0eb9f3505de --- /dev/null +++ b/compiler/testData/diagnostics/tests/reflection/noReflectionInClassPath.fir.kt @@ -0,0 +1,62 @@ +import kotlin.reflect.* + +class Foo(val prop: Any) { + fun func() {} +} + +fun n01() = Foo::prop +fun n02() = Foo::func +fun n03() = Foo::class +fun n04(p: KProperty0) = p.get() +fun n05(p: KMutableProperty0) = p.set("") +fun n07(p: KFunction) = p.name +fun n08(p: KProperty1) = p.get("") +fun n09(p: KProperty2) = p.get("", "") +fun n10() = (Foo::func).invoke(Foo("")) +fun n11() = (Foo::func)(Foo("")) + +fun y01() = Foo::prop.getter +fun y02() = Foo::class.members +fun y03() = Foo::class.simpleName +fun y04() = Foo::class.properties + +fun kclass(k: KClass<*>, kt: KClass) { + k.simpleName + k.qualifiedName + k.members + k.constructors + k.nestedClasses + k.objectInstance + k.typeParameters + k.supertypes + k.visibility + k.isFinal + k.isOpen + k.isAbstract + k.isSealed + k.isData + k.isInner + k.isCompanion + + k.annotations + k.isInstance(42) + + k == kt + k.hashCode() + k.toString() +} + +fun ktype(t: KType, t2: KType) { + t.classifier + t.arguments + t.isMarkedNullable + t.annotations + + t == t2 + t.hashCode() + t.toString() + + KTypeProjection.Companion.covariant(t) + KTypeProjection.STAR + KTypeProjection(KVariance.IN, t) +} diff --git a/compiler/testData/diagnostics/tests/regressions/AmbiguityOnLazyTypeComputation.fir.kt b/compiler/testData/diagnostics/tests/regressions/AmbiguityOnLazyTypeComputation.fir.kt new file mode 100644 index 00000000000..68cd9854c50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/AmbiguityOnLazyTypeComputation.fir.kt @@ -0,0 +1,12 @@ +// One of the two passes is making a scope and turning vals into functions +// See KT-76 + +package x + +val b : Foo = Foo() +val a1 = b.compareTo(2) + +class Foo() { + fun compareTo(other : Byte) : Int = 0 + fun compareTo(other : Char) : Int = 0 +} diff --git a/compiler/testData/diagnostics/tests/regressions/AssignmentsUnderOperators.fir.kt b/compiler/testData/diagnostics/tests/regressions/AssignmentsUnderOperators.fir.kt new file mode 100644 index 00000000000..b942565037b --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/AssignmentsUnderOperators.fir.kt @@ -0,0 +1,6 @@ +fun test() { + var a : Any? = null + if (a is Any) else a = null; + while (a is Any) a = null + while (true) a = null +} diff --git a/compiler/testData/diagnostics/tests/regressions/CoercionToUnit.fir.kt b/compiler/testData/diagnostics/tests/regressions/CoercionToUnit.fir.kt new file mode 100644 index 00000000000..575b3387c25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/CoercionToUnit.fir.kt @@ -0,0 +1,9 @@ +fun foo(u : Unit) : Int = 1 + +fun test() : Int { + foo(1) + val a : () -> Unit = { + foo(1) + } + return 1 +} diff --git a/compiler/testData/diagnostics/tests/regressions/DoubleDefine.fir.kt b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.fir.kt new file mode 100644 index 00000000000..8e63f0f3c10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.fir.kt @@ -0,0 +1,65 @@ +import java.util.* + +import java.io.* + +fun takeFirst(expr: StringBuilder): Char { + val c = expr.get(0) + expr.deleteCharAt(0) + return c +} + +fun evaluateArg(expr: CharSequence, numbers: ArrayList): Int { + if (expr.length == 0) throw Exception("Syntax error: Character expected"); + val c = takeFirst(expr) + if (c >= '0' && c <= '9') { + val n = c - '0' + if (!numbers.contains(n)) throw Exception("You used incorrect number: " + n) + numbers.remove(n) + return n + } + throw Exception("Syntax error: Unrecognized character " + c) +} + +fun evaluateAdd(expr: StringBuilder, numbers: ArrayList): Int { + val lhs = evaluateArg(expr, numbers) + if (expr.length > 0) { + + } + return lhs +} + +fun evaluate(expr: StringBuilder, numbers: ArrayList): Int { + val lhs = evaluateAdd(expr, numbers) + if (expr.length > 0) { + val c = expr.get(0) + expr.deleteCharAt(0) + } + return lhs +} + +fun main() { + System.out.println("24 game") + val numbers = ArrayList(4) + val rnd = Random(); + val prompt = StringBuilder() + for(i in 0..3) { + val n = rnd.nextInt(9) + 1 + numbers.add(n) + if (i > 0) prompt.append(" "); + prompt.append(n) + } + System.out.println("Your numbers: " + prompt) + System.out.println("Enter your expression:") + val reader = BufferedReader(InputStreamReader(System.`in`)) + val expr = StringBuilder(reader.readLine()!!) + try { + val result = evaluate(expr, numbers) + if (result != 24) + System.out.println("Sorry, that's " + result) + else + System.out.println("You won!"); + } + catch(e: Throwable) { + System.out.println(e.message) + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.fir.kt b/compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.fir.kt new file mode 100644 index 00000000000..a773dd1bbf1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.fir.kt @@ -0,0 +1,5 @@ +fun foo(a : Any) {} + +fun test() { + foo(object {}); +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet11.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet11.fir.kt new file mode 100644 index 00000000000..10db1b15a24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet11.fir.kt @@ -0,0 +1,4 @@ +// JET-11 Redeclaration & Forward reference for classes cause an exception +open class NoC +class NoC1 : NoC() +open class NoC diff --git a/compiler/testData/diagnostics/tests/regressions/Jet121.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet121.fir.kt new file mode 100644 index 00000000000..c3eddacc387 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet121.fir.kt @@ -0,0 +1,14 @@ +package jet121 + +fun box() : String { +val answer = apply("OK") { + get(0) + length +} + +return if (answer == 2) "OK" else "FAIL" +} + +fun apply(arg:String, f : String.() -> Int) : Int { + return arg.f() +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet124.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet124.fir.kt new file mode 100644 index 00000000000..6fa400a1acc --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet124.fir.kt @@ -0,0 +1,8 @@ +fun foo1() : (Int) -> Int = { x: Int -> x } + +fun foo() { + val h : (Int) -> Int = foo1(); + h(1) + val m : (Int) -> Int = {a : Int -> 1}//foo1() + m(1) +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet169.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet169.fir.kt new file mode 100644 index 00000000000..35f484e4332 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet169.fir.kt @@ -0,0 +1,8 @@ +fun set(key : String, value : String) { + val a : String? = "" + when (a) { + "" -> a.get(0) + is String, is Any -> a.compareTo("") + else -> a.toString() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/Jet17.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet17.fir.kt new file mode 100644 index 00000000000..d9fb94fa6c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet17.fir.kt @@ -0,0 +1,6 @@ +// JET-17 Do not infer property types by the initializer before the containing scope is ready + +class WithC() { + val a = 1 + val b = a +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet183-1.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet183-1.fir.kt new file mode 100644 index 00000000000..8103acc9fd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet183-1.fir.kt @@ -0,0 +1,21 @@ +enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + }, + + TALKING { + override fun signal() = ProtocolState.WAITING + }; + + abstract fun signal() : ProtocolState +} + + +fun box(): String { + var x: ProtocolState = ProtocolState.WAITING + x = x.signal() + if (x != ProtocolState.TALKING) return "fail 1" + x = x.signal() + if (x != ProtocolState.WAITING) return "fail 2" + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet183.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet183.fir.kt new file mode 100644 index 00000000000..65c0a2efb39 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet183.fir.kt @@ -0,0 +1,15 @@ +enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + }, + + TALKING { + override fun signal() = ProtocolState.WAITING + }; + + abstract fun signal() : ProtocolState +} + +fun box() { + val x: ProtocolState = ProtocolState.WAITING +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet53.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet53.fir.kt new file mode 100644 index 00000000000..0703aa50dd6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet53.fir.kt @@ -0,0 +1,5 @@ +// !CHECK_TYPE + +import java.util.Collections + +val ab = checkSubtype?>(Collections.emptyList()) diff --git a/compiler/testData/diagnostics/tests/regressions/Jet67.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet67.fir.kt new file mode 100644 index 00000000000..94549ab8df9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet67.fir.kt @@ -0,0 +1,4 @@ +abstract class XXX { + abstract val a : Int get + +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet68.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet68.fir.kt new file mode 100644 index 00000000000..40348b96052 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet68.fir.kt @@ -0,0 +1,11 @@ +class Foo() + +fun test() { + val f : Foo? = null + if (f == null) { + + } + if (f != null) { + + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/Jet69.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet69.fir.kt new file mode 100644 index 00000000000..8c9d412b28c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet69.fir.kt @@ -0,0 +1,10 @@ +class Command() {} + +fun parse(cmd: String): Command? { return null } + +fun Any.equals(other : Any?) : Boolean = this === other + +fun main() { + val command = parse("") + if (command == null) 1 // error on this line, but must be OK +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/Jet72.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet72.fir.kt new file mode 100644 index 00000000000..accd324d8b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet72.fir.kt @@ -0,0 +1,18 @@ +// JET-72 Type inference doesn't work when iterating over ArrayList + +import java.util.ArrayList + +abstract class Item(val room: Object) { + abstract val name : String +} + +val items: ArrayList = ArrayList() + +fun test(room : Object) { + for(item: Item? in items) { + if (item?.room === room) { + // item?.room is not null + System.out.println("You see " + item?.name) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/Jet81.fir.kt b/compiler/testData/diagnostics/tests/regressions/Jet81.fir.kt new file mode 100644 index 00000000000..c1e59e0a376 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/Jet81.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// JET-81 Assertion fails when processing self-referring anonymous objects + +class Test { + private val y = object { + val a = y; + } + + val z = y.a; + +} + +object A { + val x = A +} + +class Test2 { + private val a = object { + init { + b + 1 + } + val x = b + val y = 1 + } + + val b = a.x + val c = a.y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.fir.kt b/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.fir.kt new file mode 100644 index 00000000000..a7e6c9f79df --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/OrphanStarProjection.fir.kt @@ -0,0 +1,3 @@ +class B {} + +val b : B<*> = 1 diff --git a/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt b/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt new file mode 100644 index 00000000000..d26f8e694c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +class Point() { +} + +class G() {} + +fun f(expression : T) : G = G() + + +fun foo() : G { + val p = Point() + return f(p) +} + +class Out() {} + +fun fout(expression : T) : Out = Out() + +fun fooout() : Out { + val p = Point(); + return fout(p); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/OverrideResolution.fir.kt b/compiler/testData/diagnostics/tests/regressions/OverrideResolution.fir.kt new file mode 100644 index 00000000000..26a262dc8c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/OverrideResolution.fir.kt @@ -0,0 +1,16 @@ +fun box(c : C) { + val a : C = c + a.foo() +} + +open class A { + open fun foo() {} +} + +open class B : A() { + override fun foo() {} +} + +open class C : B() { + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.fir.kt b/compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.fir.kt new file mode 100644 index 00000000000..4133e61a048 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.fir.kt @@ -0,0 +1,9 @@ +fun Any.equals(other : Any?) : Boolean = true + +fun main() { + + val command : Any = 1 + + command?.equals(null) + command.equals(null) +} diff --git a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt new file mode 100644 index 00000000000..ba05c3f1ffe --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +fun main() { + val a : Int? = null; + var v = 1 + val b : String = v; + val f : String = a!!; + val g : String = v++; + val g1 : String = ++v; + val h : String = v--; + val h1 : String = --v; + val i : String = !true; + val j : String = foo@ true; + val k : String = foo@ bar@ true; + val l : String = -1; + val m : String = +1; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/TypeParameterAsASupertype.fir.kt b/compiler/testData/diagnostics/tests/regressions/TypeParameterAsASupertype.fir.kt new file mode 100644 index 00000000000..6c0c8795e61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/TypeParameterAsASupertype.fir.kt @@ -0,0 +1 @@ +class A : T {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt b/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt new file mode 100644 index 00000000000..49cf7add2a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt @@ -0,0 +1,13 @@ +interface Iterator { + fun next() : T + val hasNext : Boolean + + fun map(transform: (element: T) -> R) : Iterator = + object : Iterator { + override fun next() : R = transform(this@map.next()) + + override val hasNext : Boolean + // There's no 'this' associated with the map() function, only this of the Iterator class + get() = this@map.hasNext + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/WrongTraceInCallResolver.fir.kt b/compiler/testData/diagnostics/tests/regressions/WrongTraceInCallResolver.fir.kt new file mode 100644 index 00000000000..bca7a4babd4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/WrongTraceInCallResolver.fir.kt @@ -0,0 +1,9 @@ +open class Foo {} +open class Bar {} + +fun foo(x : Int) {} +fun foo(x : Long) {} + +fun f(): Unit { + foo(1) +} diff --git a/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt new file mode 100644 index 00000000000..66b4444b6da --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test(a: Int, b: Boolean) { + bar(a.foo(b)) +} + +fun T.foo(l: (T) -> R): R = TODO() + +fun bar(a: S) {} diff --git a/compiler/testData/diagnostics/tests/regressions/delegationWithReceiver.fir.kt b/compiler/testData/diagnostics/tests/regressions/delegationWithReceiver.fir.kt new file mode 100644 index 00000000000..efc97fc4e05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/delegationWithReceiver.fir.kt @@ -0,0 +1,10 @@ +import kotlin.reflect.KProperty + +class MyMetadata(val default: R) { + operator fun getValue(thisRef: T, desc: KProperty<*>): R = TODO() + operator fun setValue(thisRef: T, desc: KProperty<*>, value: R) {} +} + +interface Something +class MyReceiver +var MyReceiver.something: Something? by MyMetadata(default = null) diff --git a/compiler/testData/diagnostics/tests/regressions/ea40964.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea40964.fir.kt new file mode 100644 index 00000000000..0410edc71ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea40964.fir.kt @@ -0,0 +1,8 @@ +package checkFiles + +import java.util.HashMap + +fun main() { + val hashMap = HashMap() + hashMap[] +} diff --git a/compiler/testData/diagnostics/tests/regressions/ea43298.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea43298.fir.kt new file mode 100644 index 00000000000..7a68643cae8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea43298.fir.kt @@ -0,0 +1,3 @@ +import A.; + +class A diff --git a/compiler/testData/diagnostics/tests/regressions/ea53340.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea53340.fir.kt new file mode 100644 index 00000000000..7205d13137b --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea53340.fir.kt @@ -0,0 +1,7 @@ +class A : Function0 { + override fun invoke(): Int = 1 +} + +fun main() { + A()() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/ea65509.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea65509.fir.kt new file mode 100644 index 00000000000..b636cc4d0db --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea65509.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -FUNCTION_DECLARATION_WITH_NO_NAME +class ClassB() { + private inner class ClassC: super.@ClassA() { + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/ea66984.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea66984.fir.kt new file mode 100644 index 00000000000..c26e7fc62bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea66984.fir.kt @@ -0,0 +1,2 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER +class Tree(T element, Tree left, Tree right) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/ea69735.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea69735.fir.kt new file mode 100644 index 00000000000..c7fd82de1cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea69735.fir.kt @@ -0,0 +1,5 @@ +enum class MyEnum { + // Here we have a problem + // while checking on a deprecated super constructor + FIRST: +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/ea72837.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea72837.fir.kt new file mode 100644 index 00000000000..62428aab796 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea72837.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun g(x: T) = 1 +fun h(x: () -> Unit) = 1 + +fun foo() { + f(::) + g(::) + h(::) +} diff --git a/compiler/testData/diagnostics/tests/regressions/ea76264.fir.kt b/compiler/testData/diagnostics/tests/regressions/ea76264.fir.kt new file mode 100644 index 00000000000..aab934787db --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea76264.fir.kt @@ -0,0 +1,4 @@ +// StackOverflow +val p = ::p + +fun foo() = ::foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/intchar.fir.kt b/compiler/testData/diagnostics/tests/regressions/intchar.fir.kt new file mode 100644 index 00000000000..edfb8c134cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/intchar.fir.kt @@ -0,0 +1 @@ +val x: Char = '1'.plus(1) diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBound.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBound.fir.kt new file mode 100644 index 00000000000..1b4dd0f6705 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBound.fir.kt @@ -0,0 +1,3 @@ +// !DIAGNOSTICS: -MUST_BE_INITIALIZED -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER +fun foo() {} +val prop \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClass.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClass.fir.kt new file mode 100644 index 00000000000..c826cffed8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClass.fir.kt @@ -0,0 +1 @@ +class MyClass \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClassNotNull.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClassNotNull.fir.kt new file mode 100644 index 00000000000..eef2a5ca164 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundInClassNotNull.fir.kt @@ -0,0 +1 @@ +class MyClass \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundLocal.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundLocal.fir.kt new file mode 100644 index 00000000000..e3a2e94fcd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundLocal.fir.kt @@ -0,0 +1,5 @@ +// !WITH_NEW_INFERENCE +fun bar() { + fun foo() {} + foo() +} diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundMember.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundMember.fir.kt new file mode 100644 index 00000000000..7d7a00b32d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundMember.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -MUST_BE_INITIALIZED_OR_BE_ABSTRACT -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER +class My { + fun foo() {} + val prop: T +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundNotNull.fir.kt b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundNotNull.fir.kt new file mode 100644 index 00000000000..7d0c85088b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/itselfAsUpperBoundNotNull.fir.kt @@ -0,0 +1,3 @@ +// !DIAGNOSTICS: -MUST_BE_INITIALIZED -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER +fun foo() {} +val prop: T \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt10243.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10243.fir.kt new file mode 100644 index 00000000000..eb1e3b5304f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt10243.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +val f: Boolean = true +private fun doUpdateRegularTasks() { + try { + while (f) { + val xmlText = getText() + if (xmlText == null) {} + else { + xmlText.value = 0 // !!! + } + } + + } + finally { + fun execute() {} + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt10243a.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10243a.fir.kt new file mode 100644 index 00000000000..e710a2b9cf8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt10243a.fir.kt @@ -0,0 +1,11 @@ +var x: Int +fun foo(f: Boolean) { + try { + if (f) { + x = 0 + } + } + finally { + fun bar() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt new file mode 100644 index 00000000000..0b14f8f5049 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +var count = 0 + +operator fun Int.get(s: Int): Int { + count++ + return this + s +} + +operator fun Int.set(s: Int, x: String = "", z: Int) { +} + +fun main() { + 1[2] = 1 + 1.set(2, z = 1) + 1[2] += 1 + + 1.set(2, 1) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt10824.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10824.fir.kt new file mode 100644 index 00000000000..f83396251b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt10824.fir.kt @@ -0,0 +1,52 @@ +// See KT-10824: Smart cast depending on control flow does not work inside `if` +class A +fun foo(a: A?, aOther: A?): A { + return if (a == null) { + A() + } + else { + var newA = aOther + if (newA == null) { + newA = A() + } + newA + } +} +fun bar(a: A?, aOther: A?): A { + return if (a == null) { + A() + } + else { + if (aOther == null) { + return A() + } + + aOther + } +} +fun foo1(a: A?, aOther: A?): A { + val result = if (a == null) { + A() + } + else { + var newA = aOther + if (newA == null) { + newA = A() + } + newA + } + return result +} +fun bar1(a: A?, aOther: A?): A { + val result = if (a == null) { + A() + } + else { + if (aOther == null) { + return A() + } + + aOther + } + return result +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt new file mode 100644 index 00000000000..c34a25f506f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// See EA-76890 / KT-10843: NPE during analysis +fun lambda(x : Int?) = x?.let l { + y -> + if (y > 0) return@l x + y +}!! diff --git a/compiler/testData/diagnostics/tests/regressions/kt127.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt127.fir.kt new file mode 100644 index 00000000000..6e026f7ecf0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt127.fir.kt @@ -0,0 +1,18 @@ +// KT-127 Support extension functions in when expressions + +class Foo() {} + +fun Any?.equals1(other : Any?) : Boolean = true + +fun main() { + + val command : Foo? = null + + // Commented for KT-621 + // when (command) { + // .equals(null) => 1; // must be resolved + // ?.equals(null) => 1 // same here + // } + command.equals1(null) + command?.equals(null) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt128.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt128.fir.kt new file mode 100644 index 00000000000..0225952f080 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt128.fir.kt @@ -0,0 +1,12 @@ +// KT-128 Support passing only the last closure if all the other parameters have default values + +fun div(c : String = "", f : () -> Unit) {} +fun f() { + div { // Nothing passed, but could have been... + // ... + } + + div (c = "foo") { // More things could have been passed + // ... + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt13685.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt13685.fir.kt new file mode 100644 index 00000000000..9d924b02776 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt13685.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNREACHABLE_CODE + +fun foo() { + val text: List = null!! + text.map Any?::toString +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt13954.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt13954.fir.kt new file mode 100644 index 00000000000..d5a0c803542 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt13954.fir.kt @@ -0,0 +1,26 @@ +// FILE: foo/A.kt + +package foo + +class A(val c: C) + +// FILE: foo/B.kt + +package foo + +class B { + interface D { + fun foo(): E + } + + class E +} + +// FILE: foo/C.java + +package foo; + +import static foo.B.D.*; + +@SuppressWarnings("RedundantTypeArguments") +public class C {} diff --git a/compiler/testData/diagnostics/tests/regressions/kt14740.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt14740.fir.kt new file mode 100644 index 00000000000..411e8dcbe5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt14740.fir.kt @@ -0,0 +1,20 @@ +// FILE: Foo.java +public abstract class Foo { + + public interface Transformer {} + public interface LifecycleTransformer extends Transformer {} + + public class Observable { + public Observable compose(Transformer transformer) { + return null; + } + } + + + public final LifecycleTransformer bindToLifecycle() { + return null; + } +} + +// FILE: 1.kt +fun Foo.Observable.bindTo(a: Foo): Foo.Observable = compose(a.bindToLifecycle()) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt1489_1728.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt1489_1728.fir.kt new file mode 100644 index 00000000000..8ce7619d2f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt1489_1728.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +package kt606_dependents + +//KT-1489 Code analyzer fails with assertion +interface AutoCloseable{ + fun close() +} + +class C { + class Resource : AutoCloseable { + override fun close() { + throw UnsupportedOperationException() + } + } + + fun foo(x : X, body : (X) -> Unit) { + } + + fun p() : Resource? = null + + fun bar() { + foo(p()) { + + } + } +} + +//KT-1728 Can't invoke extension property as a function + +val Int.ext : () -> Int get() = { 5 } +val x = 1.ext() diff --git a/compiler/testData/diagnostics/tests/regressions/kt1550.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt1550.fir.kt new file mode 100644 index 00000000000..f9bf9dcf7b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt1550.fir.kt @@ -0,0 +1,12 @@ +package foo + +import java.util.* + +fun main() +{ + val c = ArrayList() + c.add(3) + System.out.println(++(c[0])) + System.out.println((c[1])--) + System.out.println(-(c[2])) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt16086.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt16086.fir.kt new file mode 100644 index 00000000000..54173a9811c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt16086.fir.kt @@ -0,0 +1,21 @@ +// JAVAC_EXPECTED_FILE +// FILE: com/winterbe/domain/IEntity.java +package com.winterbe.domain; +import com.winterbe.observer.ObserverSupport; + +public interface IEntity { + ObserverSupport getObserverSupport(); +} + +// FILE: 1.kt +package com.winterbe.observer +import com.winterbe.domain.IEntity + +abstract class Observer : List + + +// FILE: 2.kt +package com.winterbe.observer +import com.winterbe.domain.IEntity + +class ObserverSupport(private val observers: List) diff --git a/compiler/testData/diagnostics/tests/regressions/kt16086_2.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt16086_2.fir.kt new file mode 100644 index 00000000000..abd3f382969 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt16086_2.fir.kt @@ -0,0 +1,13 @@ +// FILE: 1.kt +package a +import b.ObserverSupport + +interface IEntity + +fun IEntity(f: ObserverSupport) {} + +// FILE: 2.kt +package b +import a.IEntity + +class ObserverSupport \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.fir.kt new file mode 100644 index 00000000000..9571fa7e0e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.fir.kt @@ -0,0 +1,12 @@ +// FULL_JDK +// SKIP_TXT + +package test + +import javax.swing.JFrame + +class KFrame() : JFrame() { + init { + val x = this.rootPaneCheckingEnabled // make sure field is visible + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt1647.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt1647.fir.kt new file mode 100644 index 00000000000..dc0b3e26c38 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt1647.fir.kt @@ -0,0 +1,11 @@ +// KT-1647 Pattern matching doesn't work with generics + +open class Abs +class Bar : Abs() + +fun patternMatchingAndGenerics(arg : F) : String { + if(arg is Bar){ + return "Bar"; + } + return "else"; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt1736.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt1736.fir.kt new file mode 100644 index 00000000000..d81fdfcd2b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt1736.fir.kt @@ -0,0 +1,10 @@ +//KT-1736 AssertionError in CallResolver + +package kt1736 + +object Obj { + fun method() { + } +} + +val x = Obj.method{ -> } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt174.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt174.fir.kt new file mode 100644 index 00000000000..6c8c0e638c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt174.fir.kt @@ -0,0 +1,7 @@ +// KT-174 Nullability info for extension function receivers +interface Tree {} + +fun Any?.TreeValue() : Tree { + if (this is Tree) return this + throw Exception() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt201.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt201.fir.kt new file mode 100644 index 00000000000..99e9475c106 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt201.fir.kt @@ -0,0 +1,8 @@ +// KT-201 Allow to call extension with nullable receiver with a '.' + +fun T?.npe() : T = if (this == null) throw NullPointerException() else this + +fun foo() { + val i : Int? = 1 + i.npe() // error! +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt235.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt235.fir.kt new file mode 100644 index 00000000000..f404c6c8a8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt235.fir.kt @@ -0,0 +1,49 @@ +//KT-235 Illegal assignment return type + +package kt235 + +fun main() { + val array = MyArray() + val f: () -> String = { + array[2] = 23 //error: Type mismatch: inferred type is Int (!!!) but String was expected + } + val g: () -> String = { + var x = 1 + x += 2 //no error, but it should be here + } + val h: () -> String = { + var x = 1 + x = 2 //the same + } + val array1 = MyArray1() + val i: () -> String = { + array1[2] = 23 + } + + val fi: () -> String = { + array[2] = 23 + } + val gi: () -> String = { + var x = 1 + x += 21 + } + + var m: MyNumber = MyNumber() + val a: () -> MyNumber = { + m++ + } +} + +class MyArray() { + operator fun get(i: Int): Int = 1 + operator fun set(i: Int, value: Int): Int = 1 +} + +class MyArray1() { + operator fun get(i: Int): Int = 1 + operator fun set(i: Int, value: Int) {} +} + +class MyNumber() { + operator fun inc(): MyNumber = MyNumber() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt2376.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt2376.fir.kt new file mode 100644 index 00000000000..61acbc6a036 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt2376.fir.kt @@ -0,0 +1,10 @@ +// FILE: main.kt +//KT-2376 java.lang.Number should be visible in Kotlin as kotlin.Number +fun main() { + Test().number(5.toInt()) +} + +// FILE: Test.java +public class Test { + void number(Number n){} +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt new file mode 100644 index 00000000000..f454a2de1b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// SKIP_TXT + +class Bar { + val a: Array? = null +} + +fun foo(bar: Bar) = bar.a?.asIterable() ?: emptyArray() + +fun Array.asIterable(): Iterable = TODO() + +fun testFrontend() { + val bar = Bar() + foo(bar) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt new file mode 100644 index 00000000000..603b5de0d3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt @@ -0,0 +1,34 @@ +// !WITH_NEW_INFERENCE +class A() { + var x: Int = 0 + get() = "s" + set(value: String) { + field = value + } + val y: Int + get(): String = "s" + val z: Int + get() { + return "s" + } + + var a: Any = 1 + set(v: String) { + field = v + } + val b: Int + get(): Any = "s" + val c: Int + get() { + return 1 + } + val d = 1 + get() { + return field + } + val e = 1 + get(): String { + return field + } + +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt258.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt258.fir.kt new file mode 100644 index 00000000000..7ea51cec00d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt258.fir.kt @@ -0,0 +1,10 @@ +// KT-258 Support equality constraints in type inference + +import java.util.* + +fun test() { + val attributes : HashMap = HashMap() + attributes["href"] = "1" // inference fails, but it shouldn't +} + +operator fun MutableMap.set(key : K, value : V) {}//= this.put(key, value) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt26-1.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt26-1.fir.kt new file mode 100644 index 00000000000..3403459f44f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt26-1.fir.kt @@ -0,0 +1,9 @@ +// FILE: this.kt + +// KT-26 Import namespaces defined in this file +package foo + +import bar.* // Must not be an error + +// FILE: other.kt +package bar diff --git a/compiler/testData/diagnostics/tests/regressions/kt26.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt26.fir.kt new file mode 100644 index 00000000000..c1557c3de55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt26.fir.kt @@ -0,0 +1,12 @@ +// FILE: a.kt +// KT-26 Import namespaces defined in this file + +import html.* // Must not be an error + +// FILE: b.kt + +package html + +abstract class Factory { +fun create() : T? = null +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt26303.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt26303.fir.kt new file mode 100644 index 00000000000..99e58c6e68a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt26303.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt + +package foo + +operator fun Int.invoke() = null +fun Int.foo() = null + +// FILE: b.kt + +package bar + +import foo.foo as invoke +import foo.invoke + +fun main(args: Array) { + 42() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt2768.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt2768.fir.kt new file mode 100644 index 00000000000..0670f633eb2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt2768.fir.kt @@ -0,0 +1,20 @@ +fun assertEquals(a: T, b: T) { + if (a != b) throw AssertionError("$a != $b") +} + +fun main() { + val bytePos = 128.toByte() // Byte.MAX_VALUE + 1 + assertEquals(-128, bytePos.toInt()) // correct, wrapped to Byte.MIN_VALUE + + val byteNeg: Byte = -bytePos // should not compile, byteNeg should be Int + assertEquals(128, byteNeg.toInt()) // passes, should not be possible + + val shortPos = 32768.toShort() // Short.MAX_VALUE + 1 + assertEquals(-32768, shortPos.toInt()) // correct, wrapped to Short.MIN_VALUE + + val shortNeg: Short = -shortPos // should not compile, shortNeg should be Int + assertEquals(32768, shortNeg.toInt()) // passes, should not be possible + + (-128).toByte() + -128.toByte() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt28001.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt28001.fir.kt new file mode 100644 index 00000000000..0f51ff2f666 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt28001.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +private object Case1 { + interface Validator + + class CharSequenceValidator: Validator + + class PredicateValidator(val predicate: (T) -> Boolean): Validator + + class CompositeValidator(vararg val validators: Validator) + + fun process(input: String) = true + + fun main() { + val validators1 = CompositeValidator(CharSequenceValidator(), PredicateValidator(::process)) + val validators2 = CompositeValidator(CharSequenceValidator(), PredicateValidator(::process)) + val validators3 = CompositeValidator(CharSequenceValidator(), PredicateValidator { it: String -> process(it) }) + } +} + +private object Case2 { + interface Expr + data class Add(val left: Expr, val right: Expr): Expr + data class Subtract(val left: Expr, val right: Expr): Expr + + fun f() { + val operators1 = listOf(::Add, ::Subtract) + val operators2 = listOf<(Expr, Expr) -> Expr>(::Add, ::Subtract) + } + + fun listOf(vararg elements: T): List = TODO() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt282.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt282.fir.kt new file mode 100644 index 00000000000..566da395178 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt282.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// KT-282 Nullability in extension functions and in binary calls + +class Set { + operator fun contains(x : Int) : Boolean = true +} + +operator fun Set?.plus(x : Int) : Int = 1 + +operator fun Int?.contains(x : Int) : Boolean = false + +fun f(): Unit { + var set : Set? = null + val i : Int? = null + i + 1 + set + 1 + 1 in set + 1 in 2 +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt287.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt287.fir.kt new file mode 100644 index 00000000000..72ea707f966 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt287.fir.kt @@ -0,0 +1,12 @@ +// KT-287 Infer constructor type arguments + +import java.util.* + +fun attributes() : Map = HashMap() // Should be inferred; +val attributes : Map = HashMap() // Should be inferred; + +fun foo(m : Map) {} + +fun test() { + foo(HashMap()) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt2956.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt2956.fir.kt new file mode 100644 index 00000000000..491dea82e02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt2956.fir.kt @@ -0,0 +1 @@ +val a: String = Nothing \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt302.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt302.fir.kt new file mode 100644 index 00000000000..b13c4b483a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt302.fir.kt @@ -0,0 +1,13 @@ +// KT-302 Report an error when inheriting many implementations of the same member + +package kt302 + +interface A { + open fun foo() {} +} + +interface B { + open fun foo() {} +} + +class C : A, B {} //should be error here \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt306.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt306.fir.kt new file mode 100644 index 00000000000..73c9a1dac4d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt306.fir.kt @@ -0,0 +1,23 @@ +// KT-306 Ambiguity when different this's have same-looking functions + +fun test() { + (fun Foo.() { + bar() + (fun Barr.() { + this.bar() + bar() + }) + }) + (fun Barr.() { + this.bar() + bar() + }) +} + +class Foo { + fun bar() {} +} + +class Barr { + fun bar() {} +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt307.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt307.fir.kt new file mode 100644 index 00000000000..67c56729183 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt307.fir.kt @@ -0,0 +1,11 @@ +// KT-307 Unresolved reference + +open class AL { + fun get(i : Int) : Any? = i +} + +interface ALE : AL { + fun getOrNull(index: Int, value: T) : T { + return get(index) as? T ?: value + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt312.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt312.fir.kt new file mode 100644 index 00000000000..be907b58530 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt312.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// KT-312 Nullability problem when a nullable version of a generic type is returned + +fun Array.safeGet(index : Int) : T? { + return if (index < size) this[index] else null +} + +val args : Array = Array(1, {""}) +val name : String = args.safeGet(0) // No error, must be type mismatch +val name1 : String? = args.safeGet(0) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt313.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt313.fir.kt new file mode 100644 index 00000000000..d22f0dc4f2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt313.fir.kt @@ -0,0 +1,11 @@ +// KT-313 Bug in substitutions in a function returning its type parameter T + +fun Iterable.join(separator : String?) : String { + return separator.npe() +} + +fun T?.npe() : T { + if (this == null) + throw NullPointerException() + return this; +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt316.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt316.fir.kt new file mode 100644 index 00000000000..4816e9763f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt316.fir.kt @@ -0,0 +1,10 @@ +// KT-316 Members of traits must be open by default + +interface B { + fun bar() {} + fun foo() {} +} + +open class A() : B{ + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt new file mode 100644 index 00000000000..d7ac5e67b92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface MemoizedFunctionToNotNull + +fun createMemoizedFunction(compute: (K) -> V): MemoizedFunctionToNotNull = TODO() + +interface A + +interface TypeConstructor + +class Refiner { + val memoizedFunctionLambda = createMemoizedFunction { it.foo() } // error type infered, no diagnostic, BAD, backend fails + val memoizedFunctionReference = createMemoizedFunction(TypeConstructor::foo) // EXTENSION_IN_CLASS_REFERENCE_IS_NOT_ALLOWED, fine + val memoizedFunctionTypes = createMemoizedFunction { it.foo() } // works fine + + private fun TypeConstructor.foo(): Boolean = true +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt32205.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt32205.fir.kt new file mode 100644 index 00000000000..b8b6498cc7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt32205.fir.kt @@ -0,0 +1,12 @@ +// FILE: A.java + +public class A { + public static void foo(A... values) {} +} + +// FILE: test.kt + +fun test(vararg values: A) { + A.foo(*values) + A.foo(values) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt328.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt328.fir.kt new file mode 100644 index 00000000000..64d3028683f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt328.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +//KT-328 Local function in function literals cause exceptions + +fun bar1() = { + bar1() +} + +fun bar2() = { + fun foo2() = bar2() +} + +//properties +//in a class +class A() { + val x = { x } +} + +//in a package +val x = { x } + +//KT-787 AssertionError on code 'val x = x' +val z = z + +//KT-329 Assertion failure on local function +fun block(f : () -> Unit) = f() + +fun bar3() = block{ foo3() // <-- missing closing curly bracket +fun foo3() = block{ bar3() } + diff --git a/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt new file mode 100644 index 00000000000..adbdda52fea --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun parse(json: String): T? = TODO() + +class MyType + +fun parseMyData(json: String): MyType = + try { + parse(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter + ?: throw IllegalArgumentException("Can't parse") + } catch (e: Exception) { + throw IllegalArgumentException("Can't parse") + } + +fun main() { + parseMyData("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt334.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt334.fir.kt new file mode 100644 index 00000000000..3daf03e8233 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt334.fir.kt @@ -0,0 +1,8 @@ +// !CHECK_TYPE + +import java.lang.Comparable as Comparable + +fun f(c: Comparable<*>) { + checkSubtype>(c) + checkSubtype>(c) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt335.336.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt335.336.fir.kt new file mode 100644 index 00000000000..cf1e1ca7fe7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt335.336.fir.kt @@ -0,0 +1,13 @@ +// KT-336 Can't infer type parameter for ArrayList in a generic function (Exception in type inference) +// KT-335 Type inference fails on Collections.sort + +import java.util.* + +fun > MutableList.sort() { + Collections.sort(this) // Error here +} + +fun List.plus(other : List) : List { + val result = ArrayList(this) + return result +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt337.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt337.fir.kt new file mode 100644 index 00000000000..7cac265e866 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt337.fir.kt @@ -0,0 +1,14 @@ +//KT-337 Can't break a line before a dot + +class A() { + fun foo() {} +} + +fun test() { + val a = A() + + a + + .foo() // Should be a valid expression + +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt352.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt352.fir.kt new file mode 100644 index 00000000000..ba34d4d076c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt352.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +//KT-352 Function variable declaration type isn't checked inside a function body + +package kt352 + +val f : (Any) -> Unit = { -> } //type mismatch + +fun foo() { + val f : (Any) -> Unit = { -> } //!!! no error +} + +class A() { + val f : (Any) -> Unit = { -> } //type mismatch +} + +//more tests +val g : () -> Unit = { 42 } +val gFunction : () -> Unit = fun(): Int = 1 + +val h : () -> Unit = { doSmth() } + +fun doSmth(): Int = 42 +fun doSmth(a: String) {} + +val testIt : (Any) -> Unit = { + if (it is String) { + doSmth(it) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt353.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt353.fir.kt new file mode 100644 index 00000000000..86054faac9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt353.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +// KT-353 Generic type argument inference sometimes doesn't work + +interface A { + fun gen() : T +} + +fun foo(a: A) { + val g : () -> Unit = { + a.gen() //it works: Unit is derived + } + + val u: Unit = a.gen() // Unit should be inferred + + if (true) { + a.gen() // Shouldn't work: no info for inference + } + + val b : () -> Unit = { + if (true) { + a.gen() // unit can be inferred + } + else { + Unit + } + } + + val f : () -> Int = { + a.gen() //type mismatch, but Int can be derived + } + + a.gen() // Shouldn't work: no info for inference +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt3535.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt3535.fir.kt new file mode 100644 index 00000000000..4b027cb07d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt3535.fir.kt @@ -0,0 +1,9 @@ +// KT-3535 Functional value-parametr in nested class is inaccessible + +class Foo { + class Bar(val p: (Any) -> Any) { + fun f() { + p(1) + } + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt3647.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt3647.fir.kt new file mode 100644 index 00000000000..75416a55034 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt3647.fir.kt @@ -0,0 +1,9 @@ +// KT-3647 Unexpected compilation error: "Expression is inaccessible from a nested class" + +class Test(val value: Int) { + companion object { + fun create(init: () -> Int): Test { + return Test(init()) + } + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt3731.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt3731.fir.kt new file mode 100644 index 00000000000..c68937faed5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt3731.fir.kt @@ -0,0 +1,17 @@ +// KT-3731 Resolve & inner class + +class A { + fun foo() {} + fun bar(f: A.() -> Unit = {}) = f() +} + +class B { + class D { + init { + A().bar { + this.foo() + foo() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt3810.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt3810.fir.kt new file mode 100644 index 00000000000..a9b163040e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt3810.fir.kt @@ -0,0 +1,5 @@ +interface A { + var foo: String +} + +class B(override val foo: String) : A diff --git a/compiler/testData/diagnostics/tests/regressions/kt385.109.441.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt385.109.441.fir.kt new file mode 100644 index 00000000000..625e715e707 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt385.109.441.fir.kt @@ -0,0 +1,33 @@ +// KT-385 type inference does not work properly` +// KT-109 Good code is red: type arguments are not inferred +// KT-441 Exception in type inference when multiple overloads accepting an integer literal are accessible + +import java.util.* + +infix fun Iterator.foreach(operation: (element: T) -> Unit) : Unit { while(hasNext()) operation(next()) } + +infix fun Iterator.foreach(operation: (index: Int, element: T) -> Unit) : Unit { + var k = 0 + while(hasNext()) + operation(k++, next()) +} + +fun Iterable.foreach(operation: (element: T) -> Unit) : Unit = iterator() foreach operation + +fun Iterable.foreach(operation: (index: Int, element: T) -> Unit) : Unit = iterator() foreach operation + +fun box() : String { + return generic_invoker( { "OK"} ) +} + +fun generic_invoker(gen : () -> T) : T { + return gen() +} + +fun println(message : Int) { System.out.println(message) } +fun println(message : Long) { System.out.println(message) } + +fun main() { + + println(run { 1 }) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt394.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt394.fir.kt new file mode 100644 index 00000000000..53a666fc641 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt394.fir.kt @@ -0,0 +1,11 @@ +// KT-394 Make companion object members visible inside the owning class + +class X() { +// class Y {} + + companion object{ + class Y() {} + } + + val y : Y = Y() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt398.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt398.fir.kt new file mode 100644 index 00000000000..4302b861f9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt398.fir.kt @@ -0,0 +1,11 @@ +// KT-398 Internal error when property initializes with function + +class X() { + val check = { a : Any -> a is T } +} + +fun box() : String { + if(X().check(10)) return "fail" + if(!X().check("lala")) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt399.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt399.fir.kt new file mode 100644 index 00000000000..0fc1d91fffc --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt399.fir.kt @@ -0,0 +1,11 @@ +// KT-399 Type argument inference not implemented for CALL_EXPRESSION + +fun getSameTypeChecker(obj: T) : Function1 { + return { a : Any -> a is T } +} + +fun box() : String { + if(getSameTypeChecker("lala")(10)) return "fail" + if(!getSameTypeChecker("mama")("lala")) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt402.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt402.fir.kt new file mode 100644 index 00000000000..9594f32f227 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt402.fir.kt @@ -0,0 +1,8 @@ +package kt402 + +fun getTypeChecker() : (Any)->Boolean { + { a : Any -> a is T } // reports unsupported +} +fun f() : (Any) -> Boolean { + return { a : Any -> a is String } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt41.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt41.fir.kt new file mode 100644 index 00000000000..086d22787c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt41.fir.kt @@ -0,0 +1,11 @@ +// KT-41 Make functions with errors in returning statement return ERROR type and not Nothing + +package kt41 + +fun aaa() = + 6 foo 1 + +fun bbb() { + aaa() + 1 // Stupid error: unreachable code +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt411.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt411.fir.kt new file mode 100644 index 00000000000..e5b9998793d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt411.fir.kt @@ -0,0 +1,69 @@ +//kt-411 Wrong type expected when returning from a function literal + +package kt411 + +fun f() { + invoker( + l@{ + return@l 11 // expects Function, but should expect Int + } + ) +} +fun invoker(gen : () -> Int) : Int = 0 + +//more tests +fun t1() { + val v = l@{ + return@l 111 + } +} + +fun t2() : String { + val g : ()-> Int = l@{ + if (true) { + return@l 1 + } + return "s" + } + return "s" +} + +fun t3() : String { + invoker( + l@{ + if (true) { + return@t3 "1" + } + else { + return 2 + } + return@l 0 + } + ) + invoker( + l@{ + return@l 1 + } + ) + invoker( + { + return "0" + } + ) + return "2" +} + +fun t4() : Int { + val h : ()-> String = l@{ + return@l "a" + } + val g : ()-> String = l@{ + return@l "a" + } + + fun inner(): String { + return "2" + } + + return 12 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt439.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt439.fir.kt new file mode 100644 index 00000000000..d55d6a501f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt439.fir.kt @@ -0,0 +1,5 @@ +// KT-439 Support labeled function literals in call arguments + +fun main1(args : Array) { + run l@{ 1 } // should not be an error +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt442.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt442.fir.kt new file mode 100644 index 00000000000..806772e9518 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt442.fir.kt @@ -0,0 +1,31 @@ +// KT-442 Type inference fails on with() + +fun funny(f : () -> T) : T = f() + +fun testFunny() { + val a : Int = funny {1} +} + +fun funny2(f : (t : T) -> T) : T {} + +fun testFunny2() { + val a : Int = funny2 {it} +} + +fun box() : String { + return generic_invoker { it } +} + +fun generic_invoker(gen : (String) -> T) : T { + return gen("") +} + +infix fun T.with(f : T.() -> Unit) { + f() +} + +fun main() { + val a = 1 with { + plus(1) + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt443.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt443.fir.kt new file mode 100644 index 00000000000..c2a6e972395 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt443.fir.kt @@ -0,0 +1,14 @@ +// KT-443 Write allowed to super.val + +open class M() { + open val b: Int = 5 +} + +class N() : M() { + val a : Int + get() { + super.b = super.b + 1 + return super.b + 1 + } + override val b: Int = a + 1 +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt455.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt455.fir.kt new file mode 100644 index 00000000000..fb57b0d1f06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt455.fir.kt @@ -0,0 +1,10 @@ +//KT-455 Do not repeat errors in definite assignment checks + +package kt455 + +fun foo() { + val a: Int + doSmth(a) //error + doSmth(a) //no repeat error +} +fun doSmth(i: Int) {} diff --git a/compiler/testData/diagnostics/tests/regressions/kt456.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt456.fir.kt new file mode 100644 index 00000000000..a26799fc949 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt456.fir.kt @@ -0,0 +1,30 @@ +//KT-456 No check for obligatory return in getters + +package kt456 + +class A() { + val i: Int + get() : Int { //no error + } +} + +//more tests +class B() { + val i: Int + get() { //no error + } +} + +class C() { + val i : Int + get() : Int { + try { + doSmth() + } + finally { + doSmth() + } + } +} + +fun doSmth() {} diff --git a/compiler/testData/diagnostics/tests/regressions/kt459.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt459.fir.kt new file mode 100644 index 00000000000..02c5f40b7d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt459.fir.kt @@ -0,0 +1,8 @@ +// KT-459 Type argument inference fails when class names are fully qualified + +fun test() { + val attributes : java.util.HashMap = java.util.HashMap() // failure! + attributes["href"] = "1" // inference fails, but it shouldn't +} + +operator fun Map.set(key : K, value : V) {}//= this.put(key, value) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt469.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt469.fir.kt new file mode 100644 index 00000000000..716cda78433 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt469.fir.kt @@ -0,0 +1,28 @@ + +package kt469 + +//KT-512 plusAssign() : Unit does not work properly +import java.util.* + +fun bar(list : MutableList) { + for (i in 1..10) { + list += i // error + } + System.out.println(list) +} + +operator fun MutableList.plusAssign(t : T) { + add(t) +} + +//KT-469 Allow val-reassignment when appropriate functions are defined +fun foo() { + val m = MyNumber(2) + m -= MyNumber(3) //should not be error here +} + +class MyNumber(var i: Int) { + operator fun minusAssign(m : MyNumber) { + i -= m.i + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt4693.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt4693.fir.kt new file mode 100644 index 00000000000..a0b38e239f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt4693.fir.kt @@ -0,0 +1,8 @@ +enum class MyEnum { + K; + + inline fun doSmth(f: (MyEnum) -> String) : String { + // This function should be inline + return f(K) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt new file mode 100644 index 00000000000..423a1c27326 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt @@ -0,0 +1,16 @@ +// KT-4827 UOE at PackageType.throwException() +// EA-53605 + +public interface TestInterface { +} + +class C { + inner class I { + + } +} + +fun f() { + TestInterface() + C.I() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt498.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt498.fir.kt new file mode 100644 index 00000000000..057b3aaf57e --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt498.fir.kt @@ -0,0 +1,8 @@ +// JAVAC_EXPECTED_FILE +// KT-498 Very strange error in the type checker + +class IdUnavailableException() : Exception() {} + +fun T.getJavaClass() : Class { + return ((this as Object).getClass()) as Class // Some error here, because of Exception() used above. ?!!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt524.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt524.fir.kt new file mode 100644 index 00000000000..f69e5d58442 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt524.fir.kt @@ -0,0 +1,14 @@ +// KT-524 sure() returns T + +package StringBuilder + +//import kotlin.io.* +//import java.io.* + +fun main() { +} + +val Int.bd : StringBuilder get() = StringBuilder(this.toString()) +fun StringBuilder.plus(other : StringBuilder) : StringBuilder = this.append(other).sure1() // !!! + +fun T?.sure1() : T { return if (this != null) this else throw NullPointerException() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt526UnresolvedReferenceInnerStatic.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt526UnresolvedReferenceInnerStatic.fir.kt new file mode 100644 index 00000000000..ceaf5571d30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt526UnresolvedReferenceInnerStatic.fir.kt @@ -0,0 +1,15 @@ +// http://youtrack.jetbrains.net/issue/KT-526 +// KT-526 Unresolved reference for inner static class + +package demo + +class Foo { + companion object { + class Bar() { } + } +} +class User { + fun main() : Unit { + var boo : Foo.Companion.Bar? /* <-- this reference is red */ = Foo.Companion.Bar() + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt5326.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt5326.fir.kt new file mode 100644 index 00000000000..e788a418d21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt5326.fir.kt @@ -0,0 +1,11 @@ +class A { + fun size() = 0 +} + +class Foo(i: Int) + +public fun Foo(c: A) { + val a = Foo(c.size()) // Check no overload resolution ambiguity + val b: Foo = Foo(c.size()) // OK + val c: Foo = Foo(c.size()) // OK +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt new file mode 100644 index 00000000000..bb381e210a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// KT-5362 Compiler crashes on access to extension method from nested class +class Outer { + class Nested{ + fun foo(s: String) = s.extension() + } + + private fun String.extension(): String = this +} + +// EA-64302 - UOE: CodegenContext.getOuterExpression +fun Activity.toast() = Unit +class Activity(){ + class Fragment{ + fun call() = toast() + } +} + +// KT-8814 No error in IDE for invalid invoke of OuterClass.()->Unit in static nested class +public class Manager { + fun task(callback: Manager.() -> Unit): Task { + val task = Task(callback) + return task + } + + class Task(val callback: Manager.() -> Unit) : Runnable { + override public fun run() { + callback() // Manager is not accessible here, but no error is shown + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt549.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt549.fir.kt new file mode 100644 index 00000000000..4f1e0359083 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt549.fir.kt @@ -0,0 +1,17 @@ +//KT-549 type inference failed + +package demo + + fun filter(list : Array, filter : (T) -> Boolean) : List { + val answer = java.util.ArrayList(); + for (l in list) { + if (filter(l)) answer.add(l) + } + return answer; + } + +fun main(args : Array) { + for (a in filter(args, {it.length > 1})) { + System.out.println("Hello, ${a}!") + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt557.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt557.fir.kt new file mode 100644 index 00000000000..c24e96f737d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt557.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// KT-557 Wrong type inference near sure extension function + +fun T?.sure() : T = this!! + +fun Array.length() : Int { + return 0; +} + +fun test(array : Array?) { + array?.sure>().length() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt571.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt571.fir.kt new file mode 100644 index 00000000000..9a6cfce30a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt571.fir.kt @@ -0,0 +1,3 @@ +//KT-571 Type inference failed +fun let(t : T, body : (T) -> R) = body(t) +private fun double(d : Int) : Int = let(d * 2) {it / 10 + it * 2 % 10} diff --git a/compiler/testData/diagnostics/tests/regressions/kt575.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt575.fir.kt new file mode 100644 index 00000000000..45c9def4f26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt575.fir.kt @@ -0,0 +1,32 @@ +// KT-575 Cannot ++ a companion object member + +package kt575 + +class Creature() { + companion object { + var numCreated : Int = 0 + private set + } + + object A { + var bbb : Int + + init { + bbb = 1 + } + } + + class C() { + var ccc : Int + + init { + ccc = 2 + } + } + + init { + Creature.numCreated++ // Error + A.bbb++ + C().ccc++ + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt58.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt58.fir.kt new file mode 100644 index 00000000000..6103492c7df --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt58.fir.kt @@ -0,0 +1,91 @@ +//KT-58 Allow finally around definite returns + +package kt58 + +import java.util.concurrent.locks.Lock + +fun lock(lock : Lock, body : () -> T) : T { + lock.lock() + try { + return body() + } + finally { + lock.unlock(); // we report an error, but we chouldn't + } +} + +//more tests +fun t1() : Int { + try { + return 1 + } + finally { + return 2 + } +} + +fun t2() : Int { + try { + return 1 + } + finally { + doSmth(3) + } +} + +fun t3() : Int { + try { + return 1 + } + catch (e: UnsupportedOperationException) { + doSmth(2) + } + finally { + doSmth(3) + } +} + +fun t4() : Int { + try { + return 1 + } + catch (e: UnsupportedOperationException) { + doSmth(2) + } +} + +fun t5() : Int { + try { + return 1 + } + catch (e: UnsupportedOperationException) { + return 2 + } +} + +fun t6() : Int { + try { + return 1 + } + catch (e: UnsupportedOperationException) { + return 2 + } + finally { + doSmth(3) + } +} + +fun t7() : Int { + try { + doSmth(1) + } + catch (e: UnsupportedOperationException) { + return 2 + } + finally { + doSmth(3) + } +} + +fun doSmth(i: Int) { +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt580.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt580.fir.kt new file mode 100644 index 00000000000..c85036ad700 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt580.fir.kt @@ -0,0 +1,22 @@ +//KT-580 Type inference failed + +package whats.the.difference + +import java.util.* + +fun iarray(vararg a : String) = a // BUG + +fun main() { + val vals = iarray("789", "678", "567") + val diffs = ArrayList() + for (i in vals.indices) { + for (j in i..vals.lastIndex()) // Type inference failed + diffs.add(vals[i].length - vals[j].length) + for (j in i..vals.lastIndex) // Type inference failed + diffs.add(vals[i].length - vals[j].length) + } +} + +fun Array.lastIndex() = size - 1 +val Array.lastIndex : Int get() = size - 1 +val Array.indices : IntRange get() = IntRange(0, lastIndex) diff --git a/compiler/testData/diagnostics/tests/regressions/kt588.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt588.fir.kt new file mode 100644 index 00000000000..4f6637a9eb5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt588.fir.kt @@ -0,0 +1,14 @@ +// JAVAC_EXPECTED_FILE +// KT-588 Unresolved static method + +class Test() : Thread("Test") { + companion object { + fun init2() { + + } + } + override fun run() { + init2() // unresolved + Test.init2() // ok + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt597.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt597.fir.kt new file mode 100644 index 00000000000..2b4251e990d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt597.fir.kt @@ -0,0 +1,19 @@ +//KT-597 Type inference failed + +fun Array?.get(i: Int) : T { + if (this != null) + return this.get(i) // <- inferred type is Any? but &T was excepted + else throw NullPointerException() +} + +operator fun Int?.inc() : Int { + if (this != null) + return this.inc() + else + throw NullPointerException() +} + +fun test() { + var i : Int? = 10 + var i_inc = i++ // <- expected Int?, but returns Any? +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt600.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt600.fir.kt new file mode 100644 index 00000000000..65ed8d40266 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt600.fir.kt @@ -0,0 +1,8 @@ +//KT-600 Problem with 'sure' extension function type inference + +fun T?._sure() : T { if (this != null) return this else throw NullPointerException() } + +fun test() { + val i : Int? = 10 + val i2 : Int = i._sure() // inferred type is Int? but Int was excepted +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt604.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt604.fir.kt new file mode 100644 index 00000000000..43e81d89fde --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt604.fir.kt @@ -0,0 +1,20 @@ +// KT-604 Internal frontend error + +interface ChannelPipeline { + +} + +class DefaultChannelPipeline() : ChannelPipeline { +} + +interface ChannelPipelineFactory{ + fun getPipeline() : ChannelPipeline +} + +class StandardPipelineFactory(val config: ChannelPipeline.()->Unit) : ChannelPipelineFactory { + override fun getPipeline() : ChannelPipeline { + val pipeline = DefaultChannelPipeline() + pipeline.config () + return pipeline + } +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt618.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt618.fir.kt new file mode 100644 index 00000000000..5c823fef416 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt618.fir.kt @@ -0,0 +1,28 @@ +package lol + +class B() { + operator fun plusAssign(other : B) : String { + return "s" + } + operator fun minusAssign(other : B) : String { + return "s" + } + operator fun remAssign(other : B) : String { + return "s" + } + operator fun divAssign(other : B) : String { + return "s" + } + operator fun timesAssign(other : B) : String { + return "s" + } +} + +fun main() { + var c = B() + c += B() + c *= B() + c /= B() + c -= B() + c %= B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt new file mode 100644 index 00000000000..b4cc8300702 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt @@ -0,0 +1,23 @@ +//KT-629 Assignments are parsed as expressions. + +package kt629 + +class A() { + var p = "yeah" + operator fun rem(other : A) : A { + return A(); + } +} + +fun box() : Boolean { + var c = A() + val d = c; + c %= A(); + return (c != d) && (c.p = "yeah") +} + + +fun box2() : Boolean { + var c = A() + return (c.p = "yeah") && true +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt630.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt630.fir.kt new file mode 100644 index 00000000000..2cef7f519a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt630.fir.kt @@ -0,0 +1,6 @@ +// KT-630 Bad type inference + +fun T?.sure() : T = this!! + +val x = "lala".sure() +val s : String = x diff --git a/compiler/testData/diagnostics/tests/regressions/kt6508.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt6508.fir.kt new file mode 100644 index 00000000000..059496b69ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt6508.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +// FILE: foo/View.java + +package foo; + +public class View {} + +// FILE: foo/TextView.java + +package foo; + +public class TextView extends View {} + +// FILE: k.kt + +import foo.View +//import foo.TextView + +fun String.gah(view:View ?) { + if (view is TextView) + view + else TextView() as foo.TextView +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt688.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt688.fir.kt new file mode 100644 index 00000000000..b29056972ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt688.fir.kt @@ -0,0 +1,14 @@ +// KT-668 Failed to resolve generic parameter +open class A() +open class B() : A() { + fun b(): B = B() +} + + +class C() { + fun a(x: (T)->T, y: T): T { + return x(x(y)) + } + + val x: B = a({it.b()}, B()) +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt691.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt691.fir.kt new file mode 100644 index 00000000000..ae9df808ea1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt691.fir.kt @@ -0,0 +1,2 @@ +// KT-691 Allow to create nested namespaces with dot delimiter +package foo.bar.buz diff --git a/compiler/testData/diagnostics/tests/regressions/kt701.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt701.fir.kt new file mode 100644 index 00000000000..509e0f33460 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt701.fir.kt @@ -0,0 +1,17 @@ +// KT-702 Type inference failed +fun getJavaClass() : java.lang.Class { return "" as Class } + +public class Throwables() { + companion object { + public fun propagateIfInstanceOf(throwable : Throwable?, declaredType : Class?) { + if (((throwable != null) && declaredType?.isInstance(throwable)!!)) + { + throw declaredType?.cast(throwable)!! + } + } + public fun propagateIfPossible(throwable : Throwable?) { + propagateIfInstanceOf(throwable, getJavaClass()) //; Type inference failed: Mismatch while expanding constraints + propagateIfInstanceOf(throwable, getJavaClass()) // Type inference failed: Mismatch while expanding constraints + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt716.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt716.fir.kt new file mode 100644 index 00000000000..86e1944ff77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt716.fir.kt @@ -0,0 +1,16 @@ +// KT-716 Type inference failed + +class TypeInfo + +fun typeinfo() : TypeInfo = null as TypeInfo + +fun TypeInfo.getJavaClass() : java.lang.Class { + val t : java.lang.Object = this as java.lang.Object + return t.getClass() as java.lang.Class // inferred type is Object but Serializable was expected +} + +fun getJavaClass() = typeinfo().getJavaClass() + +fun main() { + System.out.println(getJavaClass()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt743.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt743.fir.kt new file mode 100644 index 00000000000..aec66570b8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt743.fir.kt @@ -0,0 +1,7 @@ +//KT-743 Wrong type inference +class List(val head: T, val tail: List? = null) + +fun T?.sure() : T = this!! + +fun List.map(f: (T)-> Q): List? = tail.sure>().map(f) +fun foo(t : T) : T = foo(t) diff --git a/compiler/testData/diagnostics/tests/regressions/kt750.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt750.fir.kt new file mode 100644 index 00000000000..8fc9cf40d2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt750.fir.kt @@ -0,0 +1,10 @@ +//KT-750 Type inference failed: Constraint violation +fun main() { + var i : Int? = Integer.valueOf(100) + var s : Int? = Integer.valueOf(100) + + val o = i.sure() + s.sure() + System.out.println(o) +} + +fun T?.sure() : T = this!! diff --git a/compiler/testData/diagnostics/tests/regressions/kt7585/base.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt7585/base.fir.kt new file mode 100644 index 00000000000..f0170d5a349 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7585/base.fir.kt @@ -0,0 +1,20 @@ +open class A + +class E + +abstract class Wrapper(protected val t: T) + +class MyWrapper(a: A): Wrapper(a) + +// This wrapper is not legal +class TheirWrapper(e: E): Wrapper(e) + +data class Pair(val a: T, val b: T) + +fun foo(): String { + val matrix: Pair> + // It's not legal to do such a thing because E is not derived from A + // But we should not have assertion errors because of it! + matrix = Pair(MyWrapper(A()), TheirWrapper(E())) + return matrix.toString() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt7585/java.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt7585/java.fir.kt new file mode 100644 index 00000000000..c73bcd67b3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7585/java.fir.kt @@ -0,0 +1,30 @@ +// FILE: A.java + +public class A {} + +// FILE: Wrapper.java + +public abstract class Wrapper { + protected T t; + + Wrapper(T t) { this.t = t; } +} + +// FILE: kt7585.kt + +class E + +class MyWrapper(a: A): Wrapper(a) + +// This wrapper is not legal +class TheirWrapper(e: E): Wrapper(e) + +data class Pair(val a: T, val b: T) + +fun foo(): String { + val matrix: Pair> + // It's not legal to do such a thing because E is not derived from A + // But we should not have assertion errors because of it! + matrix = Pair(MyWrapper(A()), TheirWrapper(E())) + return matrix.toString() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt7585/twoparents.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt7585/twoparents.fir.kt new file mode 100644 index 00000000000..9c328541484 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7585/twoparents.fir.kt @@ -0,0 +1,16 @@ +interface X { + fun foo(): Int = 42 +} + +interface Y + +class A: X, Y + +class B: X, Y + +class Out(val x: T) + +fun bar(a: Out, b: Out, f: Boolean): Int { + val x = if (f) a else b + return x.x.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt762.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt762.fir.kt new file mode 100644 index 00000000000..8409b20d947 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt762.fir.kt @@ -0,0 +1,4 @@ +//KT-762 Wrong highlighting in imports (No errors reported on unresolved imports) +import aaa // must be an error + +fun main() {} diff --git a/compiler/testData/diagnostics/tests/regressions/kt7804.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt7804.fir.kt new file mode 100644 index 00000000000..c03b3af14a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7804.fir.kt @@ -0,0 +1,65 @@ +// !WITH_NEW_INFERENCE +// See also KT-7804 (Wrong type inference of kotlin.Any? was for 'a' without explicit type) +fun foo(a: T) = a + +class A + +fun test(v: T): T { + val a = if (v !is A) { + foo(v) as T + } + else { + v + } + + val t: T = a + return t +} + +fun test2(v: T): T { + val a = if (v !is A) { + foo(v) as T + } + else { + v as T + } + + val t: T = a + return t +} + +fun test3(v: T): T { + val a = if (v !is A) { + foo(v) + } + else { + v + } + + val t: T = a + return t +} + +fun test4(v: T): T { + val a: T = if (v !is A) { + foo(v) as T + } + else { + v + } + + val t: T = a + return t +} + +fun test5(v: T): T { + val a: T = if (v !is A) { + foo(v) + } + else { + v + } + + val t: T = a + return t +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt847.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt847.fir.kt new file mode 100644 index 00000000000..0f9ecd9fca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt847.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +fun T.mustBe(t : T) { + "$this must be$as$t" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt860.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt860.fir.kt new file mode 100644 index 00000000000..bcd42bc7ca5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt860.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// KT-860 ConcurrentModificationException in frontend + +package std.util + +import java.util.* + +fun > Iterator.to(container: U) : U { + while(hasNext()) + container.add(next()) + return container +} + +fun Iterator.toArrayList() = to(ArrayList()) diff --git a/compiler/testData/diagnostics/tests/regressions/kt9384.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9384.fir.kt new file mode 100644 index 00000000000..e635089121b --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9384.fir.kt @@ -0,0 +1,11 @@ +fun main(args: Array) { + fun f() = run { + private class C { + private fun foo() { + f().foo(); + + } + } + C() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt new file mode 100644 index 00000000000..e5c89b2cf7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt @@ -0,0 +1,14 @@ +// KT-9620 AssertionError in checkBounds + +interface E1, D> + +interface A +interface B +interface D +interface E2, D<B>> + +// KT-11354 AE from DescriptorResolver + +open class L() + +class M : L>() diff --git a/compiler/testData/diagnostics/tests/regressions/kt9633.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9633.fir.kt new file mode 100644 index 00000000000..21f1bf4be71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9633.fir.kt @@ -0,0 +1,2 @@ +// KT-9633: SOE occurred before +interface A> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt new file mode 100644 index 00000000000..4c9858a1322 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt @@ -0,0 +1,28 @@ +// KT-9682 Overload Resolution Ambiguity after casting to Interface + +open class Foo { + fun bar(): Foo { + return this + } +} + +class Foo2 : Foo(), IFoo + +interface IFoo { + fun bar(): Foo +} + +fun test() { + val foo : Foo = Foo2() + foo as IFoo + foo.bar() // Should be resolved to Foo#bar +} + +interface IFoo2 { + fun bar(): IFoo2 +} + +fun test2(foo: Foo) { + foo as IFoo2 + foo.bar() // should be ambiguity +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt9808.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9808.fir.kt new file mode 100644 index 00000000000..7d35fb2356f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt9808.fir.kt @@ -0,0 +1,8 @@ +// KT-9808 Extension function on object for new resolve +object O + +val foo: O.() -> Unit = null!! + +fun test() { + O.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt b/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt new file mode 100644 index 00000000000..71aa9ab8f50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt @@ -0,0 +1,10 @@ +interface A { fun f() } + +open class P(val z: B) + +class B : A { + override fun f() {} + class C : A by this {} + class D(val x : B = this) + class E : P(this) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.fir.kt b/compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.fir.kt new file mode 100644 index 00000000000..c4746cd8f7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.fir.kt @@ -0,0 +1,7 @@ +object X + +class Y { + fun f(op: X.() -> Unit) { + X.op() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.fir.kt b/compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.fir.kt new file mode 100644 index 00000000000..3864f5105af --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.fir.kt @@ -0,0 +1,7 @@ +import java.util.ArrayList + +fun foo(p: java.util.List) { + p.iterator(); // forcing resolve of java.util.List.iterator() + + ArrayList().iterator(); // this provoked exception in SignaturesPropagationData +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/CycleInTypeArgs.fir.kt b/compiler/testData/diagnostics/tests/resolve/CycleInTypeArgs.fir.kt new file mode 100644 index 00000000000..d62d8547efd --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/CycleInTypeArgs.fir.kt @@ -0,0 +1,3 @@ +class Class1>> + +class Class2>> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.fir.kt b/compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.fir.kt new file mode 100644 index 00000000000..153352100f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.fir.kt @@ -0,0 +1,74 @@ +package test + +// imports should be resolved +import test.topLevelFun +import test.topLevelProperty + +@Deprecated("hidden", level = DeprecationLevel.HIDDEN) +fun topLevelFun(){} + +@Deprecated("hidden", level = DeprecationLevel.HIDDEN) +var topLevelProperty = 1 + +@Deprecated("hidden", level = DeprecationLevel.HIDDEN) +fun String.topLevelExtensionFun(){} + +@Deprecated("hidden", level = DeprecationLevel.HIDDEN) +val String.topLevelExtensionProperty: Int get() = 1 + +open class A { + constructor(p: Int) : this("") {} + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + constructor(s: String){} + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + open fun memberFun(){} + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + val memberProperty = 1 + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + fun String.memberExtensionFun(){} + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + val String.memberExtensionProperty: Int get() = 1 + + fun foo() { + topLevelFun() + topLevelProperty++ + "".topLevelExtensionFun() + "".topLevelExtensionProperty + + memberFun() + memberProperty + "".memberExtensionFun() + "".memberExtensionProperty + + A("") + } +} + +interface I { + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + fun foo1() + + @Deprecated("hidden", level = DeprecationLevel.HIDDEN) + fun foo2() +} + +class X : I { + override fun foo1() { + } +} + +class B : A("") { + // still can override it + override fun memberFun() { + super.memberFun() // but cannot call super :) + } +} + +class C : A { + constructor() : super("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/ambiguityOnPropertiesWithTheSamePackageName.fir.kt b/compiler/testData/diagnostics/tests/resolve/ambiguityOnPropertiesWithTheSamePackageName.fir.kt new file mode 100644 index 00000000000..215e3b619ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/ambiguityOnPropertiesWithTheSamePackageName.fir.kt @@ -0,0 +1,30 @@ +// FILE: a.kt +package a + +class A + +// FILE: b.kt +package b + +import a.A + +val A.d: Int get() = 1 + +// FILE: c.kt +package c + +import a.A + +val A.d: Int get() = 2 + +// FILE: d.kt + +package d + +import a.A +import b.d +import c.d + +fun A.test() { + d +} diff --git a/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt new file mode 100644 index 00000000000..f0bbf4e4823 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(a: Any, f: ()->Int) = f() +fun foo(a: Any, f: (Any)->Int) = f(a) +fun foo(i: Int, f: Int.()->Int) = i.f() + +fun test1() { + foo(1) { -> + this + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.fir.kt b/compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.fir.kt new file mode 100644 index 00000000000..f3eb01d0944 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.fir.kt @@ -0,0 +1,24 @@ +interface IFoo { + fun foo() +} + +interface IBar + +private fun createAnonObject() = + object : IFoo, IBar { + override fun foo() {} + fun qux() {} + } + +private val propOfAnonObject = object : IFoo, IBar { + override fun foo() {} + fun qux() {} + } + +fun useAnonObject() { + createAnonObject().foo() + createAnonObject().qux() + + propOfAnonObject.foo() + propOfAnonObject.qux() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt new file mode 100644 index 00000000000..da3429d6c5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun testWhen(x: Any?) { + val y = when (x) { + null -> "" + else -> ::unresolved + } +} + +fun testWhenWithBraces(x: Any?) { + val z = when(x) { + null -> { "" } + else -> { ::unresolved } + } +} + +fun testIf(x: Any?) { + val y = if (x != null) ::unresolved else null +} + +fun testIfWithBraces(x: Any?) { + val z = if (x != null) { ::unresolved } else { null } +} + +fun testElvis(x: Any?) { + val y = x ?: ::unresolved +} + +fun testExclExcl() { + val y = :: unresolved!! +} + +fun testTry() { + val v = try { ::unresolved } catch (e: Exception) {} +} diff --git a/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.fir.kt b/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.fir.kt new file mode 100644 index 00000000000..7ebe2dacaa1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.fir.kt @@ -0,0 +1,42 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +class B + +fun B.foo(f: (T) -> Unit) {} +fun B.bar(f: (T, T) -> Unit, g: (T, T) -> Unit) {} +fun B.baz(f: (B) -> Unit) {} + +fun number(x: Number) {} +fun Number.foobar() {} + +fun test(b: B) { + b.foo { + it checkType { _() } + it.toInt() + } + + b.foo { x -> + x checkType { _() } + x.toInt() + } + + b.bar({ x, y -> + x checkType { _() } + y checkType { _() } + x.toInt() + y.toInt() + }) { u, w -> + u checkType { _() } + w checkType { _() } + + u.toInt() + w.toInt() + } + + b.foo(::number) + b.foo(Number::foobar) + + b.baz { + b -> b checkType { _>() } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/constructorVsCompanion.fir.kt b/compiler/testData/diagnostics/tests/resolve/constructorVsCompanion.fir.kt new file mode 100644 index 00000000000..1f446ed239b --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/constructorVsCompanion.fir.kt @@ -0,0 +1,23 @@ +class A private constructor() + +class B { + private companion object +} + +class C(val x: Int) + +class D private constructor() { + companion object +} + +class E private constructor() { + companion object { + operator fun invoke(x: Int) = x + } +} + +val a = A +val b = B +val c = C +val d = D +val e = E(42) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType.fir.kt new file mode 100644 index 00000000000..04030ea4324 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType.fir.kt @@ -0,0 +1,57 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +@Target(AnnotationTarget.TYPE) +@DslMarker +annotation class MyDsl + +interface A { + fun foo() +} + +interface B { + fun bar() +} + +fun baz1(x: (@MyDsl A).() -> Unit) {} +fun baz2(x: (@MyDsl B).() -> Unit) {} +fun baz3(x: @MyDsl A.() -> Unit) {} +fun baz4(x: @MyDsl B.() -> Unit) {} + +fun @MyDsl A.baz5() { + baz4 { + bar() + foo() + } +} + +fun main() { + baz1 { + baz2 { + bar() + foo() + } + } + + baz3 { + baz2 { + bar() + foo() + } + } + + baz1 { + baz4 { + bar() + foo() + } + } + + baz3 { + baz4 { + bar() + foo() + } + } + +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType_1_4.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType_1_4.fir.kt new file mode 100644 index 00000000000..8ee13aff80d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedFunctionType_1_4.fir.kt @@ -0,0 +1,58 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +DslMarkerOnFunctionTypeReceiver +// !WITH_NEW_INFERENCE + +@Target(AnnotationTarget.TYPE) +@DslMarker +annotation class MyDsl + +interface A { + fun foo() +} + +interface B { + fun bar() +} + +fun baz1(x: (@MyDsl A).() -> Unit) {} +fun baz2(x: (@MyDsl B).() -> Unit) {} +fun baz3(x: @MyDsl A.() -> Unit) {} +fun baz4(x: @MyDsl B.() -> Unit) {} + +fun @MyDsl A.baz5() { + baz4 { + bar() + foo() + } +} + +fun main() { + baz1 { + baz2 { + bar() + foo() + } + } + + baz3 { + baz2 { + bar() + foo() + } + } + + baz1 { + baz4 { + bar() + foo() + } + } + + baz3 { + baz4 { + bar() + foo() + } + } + +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedTypeArgument.fir.kt new file mode 100644 index 00000000000..6821b6aa407 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/annotatedTypeArgument.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo(x: T.() -> Unit) {} +fun bar(x: E.() -> Unit) {} + +fun test() { + foo<@Ann A> { + a() + bar<@Ann B> { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerOnTypealias.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerOnTypealias.fir.kt new file mode 100644 index 00000000000..763584c4628 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerOnTypealias.fir.kt @@ -0,0 +1,28 @@ +@DslMarker +@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS) +annotation class XMarker + +@XMarker +class Foo + +class Bar + +@XMarker +typealias XBar = Bar + +typealias XXBar = XBar + +fun Foo.foo(body: Foo.() -> Unit) = body() +fun Foo.xbar(body: XBar.() -> Unit) = Bar().body() +fun Foo.xxbar(body: XXBar.() -> Unit) = Bar().body() + +fun test() { + Foo().foo { + xbar { + foo {} + } + xxbar { + foo {} + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerWithTypealiasRecursion.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerWithTypealiasRecursion.fir.kt new file mode 100644 index 00000000000..90e7fefe98d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerWithTypealiasRecursion.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +@DslMarker +@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS) +annotation class XMarker + +@XMarker +class Foo + +class Bar + +typealias YBar = ZBar +typealias ZBar = YBar + +fun Foo.foo(body: Foo.() -> Unit) = body() +fun Foo.zbar(body: ZBar.() -> Unit) = Bar().body() + +fun test() { + Foo().foo { + zbar { + foo {} + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/inheritedMarker.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/inheritedMarker.fir.kt new file mode 100644 index 00000000000..83a3ea54e79 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/inheritedMarker.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +interface Common +interface C : Common +interface D : C + +class A : C { + fun a() = 1 +} + +class B : D { + fun b() = 2 +} + +fun foo(x: A.() -> Unit) {} +fun bar(x: B.() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtension.fir.kt new file mode 100644 index 00000000000..bbed69f4773 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtension.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + fun a() = 1 +} + +@Ann +class B { + fun b() = 2 +} + +fun bar(x: B.() -> Unit) {} + +fun A.test() { + bar { + a() + this@test.a() + b() + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.fir.kt new file mode 100644 index 00000000000..dcdcd748b25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun bar(x: (@Ann B).() -> Unit) {} + +fun @Ann A.test() { + bar { + a() + this@test.a() + b() + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.fir.kt new file mode 100644 index 00000000000..7dd88e1b21c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.fir.kt @@ -0,0 +1,19 @@ +@DslMarker +annotation class MyDsl + +@MyDsl +interface Foo { + val x: Int +} + +val Foo<*>.bad: Int get() = x + +fun Foo<*>.badFun(): Int = x + +val Foo.good: Int get() = x + +fun test(foo: Foo<*>) { + foo.apply { + x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.fir.kt new file mode 100644 index 00000000000..9b3b0501a2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@DslMarker +annotation class MyDsl + +@MyDsl +interface Scope { + val something: A + val value: B +} +fun scoped1(block: Scope.() -> Unit) {} +fun scoped2(block: Scope<*, String>.() -> Unit) {} + +val Scope<*, T>.property: T get() = value + +fun f() { + scoped1 { + value + property + } + scoped2 { + value + property + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.fir.kt new file mode 100644 index 00000000000..8349ec26541 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.fir.kt @@ -0,0 +1,11 @@ +@DslMarker +annotation class AnnMarker + +@AnnMarker +class Inv { + fun bar() {} +} + +fun Inv<*>.foo() { + bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.fir.kt new file mode 100644 index 00000000000..8eb2a6ceed0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.fir.kt @@ -0,0 +1,93 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class L1 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class L2 + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo1(x: (@L1 A).() -> Unit) {} +fun foo2(x: (@L2 A).() -> Unit) {} + +fun foo12(x: (@L1 @L2 A).() -> Unit) {} + +fun bar1(x: (@L1 B).() -> Unit) {} +fun bar2(x: (@L2 B).() -> Unit) {} + +fun bar1t(q: T, x: (@L1 T).() -> Unit) {} + +fun test() { + foo12 { + a() + bar1 { + a() + b() + } + + bar2 { + a() + b() + } + } + + bar1 { + b() + foo12 { + a() + b() + } + } + + bar2 { + b() + foo12 { + a() + b() + } + } + + foo2 { + bar1t(this) { + a() + bar1 { + a() + b() + } + + bar2 { + a() + b() + } + } + } + + bar1 { + b() + foo2 { + bar1t(this) { + a() + b() + } + } + } + + bar2 { + b() + foo2 { + bar1t(this) { + a() + b() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/nestedWithSameReceiver.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/nestedWithSameReceiver.fir.kt new file mode 100644 index 00000000000..9e08430d307 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/nestedWithSameReceiver.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo(x: (@Ann A).() -> Unit) {} +fun bar(x: (@Ann B).() -> Unit) {} + +fun test() { + foo { + a() + foo l1@{ + a() + bar l2@{ + a() + this@l1.a() + b() + + foo l3@{ + a() + b() + this@l2.b() + bar { + a() + this@l3.a() + b() + } + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.fir.kt new file mode 100644 index 00000000000..2c75099988a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.fir.kt @@ -0,0 +1,62 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + var a = 1 +} + +var A.a1: Int + get() = 1 + set(value) {} + +@Ann +class B { + var b = 2 +} + +var B.b1: Int + get() = 1 + set(value) {} + +fun foo(x: A.() -> Unit) {} +fun bar(x: B.() -> Unit) {} + +fun test() { + foo { + a + 1 + a += a + 1 + a++ + + a1 + 1 + a1 += a1 + 1 + a1++ + + bar { + a + 1 + a += a + 1 + a++ + + a1 + 1 + a1 += a1 + 1 + a1++ + + this@foo.a + 1 + this@foo.a += this@foo.a + 1 + this@foo.a++ + + this@foo.a1 + 1 + this@foo.a1 += this@foo.a1 + 1 + this@foo.a1++ + + b + 1 + b += b + 1 + b++ + + b1 + 1 + b1 += b1 + 1 + b1++ + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedClasses.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedClasses.fir.kt new file mode 100644 index 00000000000..dd96e9a7fd4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedClasses.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + fun a() = 1 +} + +@Ann +class B { + fun b() = 2 +} + +fun foo(x: A.() -> Unit) {} +fun bar(x: B.() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedTypes.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedTypes.fir.kt new file mode 100644 index 00000000000..5603ec6df14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/simpleAnnotatedTypes.fir.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo(x: (@Ann A).() -> Unit) {} +fun bar(x: (@Ann B).() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedClasses.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedClasses.fir.kt new file mode 100644 index 00000000000..24d4eb3e602 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedClasses.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + fun a() = 1 +} + +@Ann +class B { + fun b() = 2 +} + +fun foo(x: T.() -> Unit) {} +fun bar(x: E.() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedType.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedType.fir.kt new file mode 100644 index 00000000000..ab79d02f572 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/substitutedReceiverAnnotatedType.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo(x: (@Ann T).() -> Unit) {} +fun bar(x: (@Ann E).() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers.fir.kt new file mode 100644 index 00000000000..62179bd9710 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers.fir.kt @@ -0,0 +1,111 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann3 + +class A { + operator fun B.invoke() {} + + val B.y: D get() = D() +} + +class B + +class C { + operator fun D.invoke() {} + + val D.x: B get() = B() +} + +class D + +fun foo(x: (@Ann1 A).() -> Unit) {} +fun bar(x: (@Ann2 B).() -> Unit) {} +fun baz(x: (@Ann3 C).() -> Unit) {} +fun foo1(x: (@Ann1 D).() -> Unit) {} +fun foo2(x: (@Ann2 D).() -> Unit) {} +fun foo3(x: (@Ann3 D).() -> Unit) {} + +fun test() { + foo { + bar { + baz { + y() + + x() + + with(D()) { + x() + } + D().x() + + foo1 { + x() + y() + + with(A()) { + x() + y() + } + + with(D()) { + x() + } + D().x() + } + + foo2 { + x() + y() + } + + foo3 { + x() + y() + } + } + } + } + + foo1 { + foo { + baz { + bar { + x() + y() + } + } + } + } + + foo2 { + foo { + baz { + bar { + x() + y() + } + } + } + } + + foo3 { + foo { + baz { + bar { + x() + y() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt new file mode 100644 index 00000000000..f92766208d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt @@ -0,0 +1,106 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann3 + +class A { + val B.y: (C.() -> Unit) get() = null!! +} + +class B + +class C { + val D.x: (A.() -> Unit) get() = null!! +} + +class D + +fun foo(x: (@Ann1 A).() -> Unit) {} +fun bar(x: (@Ann2 B).() -> Unit) {} +fun baz(x: (@Ann3 C).() -> Unit) {} +fun foo1(x: (@Ann1 D).() -> Unit) {} +fun foo2(x: (@Ann2 D).() -> Unit) {} +fun foo3(x: (@Ann3 D).() -> Unit) {} + +fun test() { + foo { + bar { + baz { + y() + + x() + + with(D()) { + x() + } + + foo1 { + x() + y() + + with(A()) { + x() + y() + } + + with(D()) { + x() + } + A().x() + } + + foo2 { + x() + y() + } + + foo3 { + x() + y() + } + } + } + } + + foo1 { + foo { + baz { + bar { + x() + y() + } + } + } + } + + foo2 { + foo { + baz { + bar { + x() + y() + } + } + } + } + + foo3 { + foo { + baz { + bar { + x() + y() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/twoImplicitReceivers.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/twoImplicitReceivers.fir.kt new file mode 100644 index 00000000000..6d1cff02306 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/twoImplicitReceivers.fir.kt @@ -0,0 +1,102 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +class A { + fun D.extA() {} +} + +class B { + fun D.extB() {} +} + +class D + +fun foo(x: (@Ann1 A).() -> Unit) {} +fun bar(x: (@Ann2 B).() -> Unit) {} +fun baz(x: (@Ann1 D).() -> Unit) {} + +fun test() { + foo { + bar { + baz { + extA() + extB() + + D().extA() + D().extB() + + with(D()) { + extA() + extB() + } + } + } + } + + foo { + baz { + extA() + D().extA() + + bar { + extA() + extB() + + D().extA() + D().extB() + + with(D()) { + extA() + extB() + } + } + } + } + + baz { + foo { + extA() + D().extA() + + bar { + extA() + extB() + + D().extA() + D().extB() + + with(D()) { + extA() + extB() + } + } + } + } + + baz { + bar { + extB() + + D().extB() + + foo { + extA() + extB() + + D().extA() + D().extB() + + with(D()) { + extA() + extB() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/twoLanguages.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/twoLanguages.fir.kt new file mode 100644 index 00000000000..dded7a3c332 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/twoLanguages.fir.kt @@ -0,0 +1,104 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class L1 + +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class L2 + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo1(x: (@L1 A).() -> Unit) {} +fun foo2(x: (@L2 A).() -> Unit) {} +fun bar1(x: (@L1 B).() -> Unit) {} +fun bar2(x: (@L2 B).() -> Unit) {} + +fun test() { + foo1 { + a() + + foo2 { + a() + + bar1 { + a() + b() + bar2 { + a() + b() + } + } + + bar2 { + a() + b() + } + } + + bar1 { + a() + b() + bar2 { + a() + b() + } + } + + bar2 { + a() + b() + } + } + + foo2 { + a() + + bar1 { + a() + b() + bar2 { + a() + b() + } + } + + bar2 { + a() + b() + } + } + + bar1 { + b() + bar2 { + b() + } + } + + bar2 { + b() + } + + foo1 { + bar1 { + a() + b() + foo2 { + a() + b() + + bar2 { + a() + b() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/unsupportedFeature.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/unsupportedFeature.fir.kt new file mode 100644 index 00000000000..e67767e06d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/unsupportedFeature.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: -DslMarkersSupport +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + fun a() = 1 +} + +@Ann +class B { + fun b() = 2 +} + +fun foo(x: A.() -> Unit) {} +fun bar(x: B.() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/useOfExtensions.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/useOfExtensions.fir.kt new file mode 100644 index 00000000000..67f3907fd21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/useOfExtensions.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A + +fun A.a() = 1 + +@Ann +class B + +fun B.b() = 2 + +fun foo(x: A.() -> Unit) {} +fun bar(x: B.() -> Unit) {} + +fun test() { + foo { + a() + bar { + a() + this@foo.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWith.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWith.fir.kt new file mode 100644 index 00000000000..657f48d8e9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWith.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +annotation class Ann + +@Ann +class A { + fun a() = 1 +} + +@Ann +class B { + fun b() = 2 +} + +fun test(a: A, b: B) { + with(a) l1@{ + a() + with(b) { + a() + this@l1.a() + b() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWithThis.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWithThis.fir.kt new file mode 100644 index 00000000000..91967af6ae4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/usingWithThis.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@DslMarker +@Target(AnnotationTarget.TYPE) +annotation class Ann + +class A { + fun a() = 1 +} + +class B { + fun b() = 2 +} + +fun foo(x: (@Ann A).() -> Unit) {} +fun bar(x: (@Ann B).() -> Unit) {} + +fun test() { + foo { + with(this) l1@{ + a() + bar { + with(this) { + a() + this@l1.a() + b() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.fir.kt b/compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.fir.kt new file mode 100644 index 00000000000..d478dd2a6ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.fir.kt @@ -0,0 +1,33 @@ +// FILE: a.kt +package a + +class A(val b: String) { + companion object { + val c: String = "" + } + + fun mtd() = c.length +} + +// FILE: b.kt +package b + +// FILE: c.kt +package c + +// FILE: test.kt +package test + +import a.A + +fun T.with(f: T.() -> R) = f() + +fun A.extFun1() = b.length + +// fun A.extFun2() = c.length // TODO fix KT-9953 + +val x1 = A("").with { b.length } + +// val x2 = A("").with { c.length } // TODO fix KT-9953 + +val x3 = A.with { c.length } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt b/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt new file mode 100644 index 00000000000..060b8628bd9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt @@ -0,0 +1,10 @@ +package p + +class X(provider: () -> V, trackValue: Boolean) { +} + +class B { + val c = X { + "e" + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdas.fir.kt b/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdas.fir.kt new file mode 100644 index 00000000000..fd41b8a4972 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdas.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(first: () -> T, second: (T) -> R): R = throw Exception() +fun test() { + val r = foo( { 4 }, { "${it + 1}" } ) + r checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.fir.kt b/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.fir.kt new file mode 100644 index 00000000000..c342c179705 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(f: () -> Collection, p: (T) -> Boolean): Collection = throw Exception() + +fun emptyList(): List = throw Exception() + +fun test(): Collection = foo({ emptyList() }, { x -> x > 0 }) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/KT-4372.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/KT-4372.fir.kt new file mode 100644 index 00000000000..b33f336a2af --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/KT-4372.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +//KT-4372 Invalid error position and failing to resolve invoke with receiver from other module + +class Foo { + fun invoke(content: TInner.() -> Unit) { + } +} + +// comment this function to fix the error below +fun Foo.invoke(name: String, content: TInner.() -> Unit) {} + +enum class EnumClass(val x: String) {} +object Y { + val x = javaClass() // javaClass unresolved in any file in this module +} + +//declarations from library +val T.javaClass : Class + get() = throw Exception() + +fun javaClass() : Class = throw Exception() diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.fir.kt new file mode 100644 index 00000000000..dd3251bb346 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Int.invoke(i: Int, a: Any) {} +fun Int.invoke(a: Any, i: Int) {} + +fun foo(i: Int) { + i(1, 1) + + 5(1, 2) +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/invisibleInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/invisibleInvoke.fir.kt new file mode 100644 index 00000000000..b593f3be4c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/invisibleInvoke.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class My { + private operator fun Int.invoke(s: String) {} +} + +fun My.foo(i: Int) { + i("") + 1("") +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.fir.kt new file mode 100644 index 00000000000..027ba798f01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.fir.kt @@ -0,0 +1,11 @@ +fun test1(f: String.() -> Unit) { + (f)() + + f() +} + +fun test2(f: (Int) -> Int) { + 1.f(2) + + 2.(f)(2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.fir.kt new file mode 100644 index 00000000000..0874328e546 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A + +operator fun T.invoke(a: A) {} + +fun foo(s: String, ai: A) { + 1(ai) + + s(ai) + + ""(ai) +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/unresolvedInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/unresolvedInvoke.fir.kt new file mode 100644 index 00000000000..0874f5b7d95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/unresolvedInvoke.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +fun foo(i: Int) { + i() + 1() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/unsafeCallWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/unsafeCallWithInvoke.fir.kt new file mode 100644 index 00000000000..9ec457efedc --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/unsafeCallWithInvoke.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +operator fun String.invoke(i: Int) {} + +fun foo(s: String?) { + s(1) + + (s ?: null)(1) +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt new file mode 100644 index 00000000000..3c2289bab4d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE + +fun test1() { + 1. (fun String.(i: Int) = i )(1) + 1.(label@ fun String.(i: Int) = i )(1) +} + +fun test2(f: String.(Int) -> Unit) { + 11.(f)(1) + 11.(f)() +} + +fun test3() { + fun foo(): String.(Int) -> Unit = {} + + 1.(foo())(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverTypeForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverTypeForInvoke.fir.kt new file mode 100644 index 00000000000..e99d2def1c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverTypeForInvoke.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun String.invoke(i: Int) {} + +fun foo(i: Int) { + i(1) + + 1(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.fir.kt new file mode 100644 index 00000000000..ce28c42c796 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/extensionValueAsNonExtension.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +class A + +fun test(foo: A.() -> Int, a: A) { + val b: Int = foo(a) + val c: Int = (foo)(a) +} + +class B { + val foo: A.() -> Int = null!! + + init { + val b: Int = foo(A()) + } +} + +fun foo(): A.() -> Int { + val b: Int = foo()(A()) + val c: Int = (foo())(A()) + + return null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt new file mode 100644 index 00000000000..5beb96a3b06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Int.invoke(a: Int) {} +fun Int.invoke(a: Int, b: Int) {} + +class SomeClass + +fun test(identifier: SomeClass, fn: String.() -> Unit) { + identifier() + identifier(123) + identifier(1, 2) + 1.fn() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.fir.kt new file mode 100644 index 00000000000..3f929db31fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.fir.kt @@ -0,0 +1,33 @@ +class B + +class A { + operator fun B.invoke() = 4 +} + +class X { + operator fun invoke() = 3 +} + +fun test(a: A, b: B) { + with (a) { + b() + (b)() + } + + X()() + val x = X() + x() + (x)() +} + +fun test(c: () -> String, e: Int.() -> String) { + c() + (c)() + + 3.e() + 3.(e)() + with(3) { + e() + (e)() + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt new file mode 100644 index 00000000000..3a5a8a49df6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +class A(val x: (String.() -> Unit)?) + +fun test(a: A) { + if (a.x != null) { + "".(a.x)() + a.x("") // todo + (a.x)("") + } + "".(a.x)() + a.x("") + (a.x)("") + + with("") { + a.x() + (a.x)() + if (a.x != null) { + a.x() // todo + (a.x)() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.fir.kt new file mode 100644 index 00000000000..f4f9bacf244 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.fir.kt @@ -0,0 +1,61 @@ +class Foo {} + +operator fun Foo.invoke() {} + +//no variable +fun test(foo: Foo) { + foo() +} + +//variable as member +interface A { + val foo: Foo +} + + +fun test(a: A) { + a.foo() + + with (a) { + foo() + } +} + +//variable as extension +interface B { +} +val B.foo: Foo + get() = Foo() + +fun test(b: B) { + b.foo() + + with (b) { + foo() + } +} + +//variable as member extension +interface C + +interface D { + val C.foo: Foo + + fun test(c: C) { + c.foo() + + with (c) { + foo() + } + } +} + +fun test(d: D, c: C) { + with (d) { + c.foo() + + with (c) { + foo() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMember.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMember.fir.kt new file mode 100644 index 00000000000..fd841f6fe7e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMember.fir.kt @@ -0,0 +1,60 @@ +class Foo { + operator fun invoke() {} +} + +//no variable +fun test(foo: Foo) { + foo() +} + +//variable as member +interface A { + val foo: Foo +} + +fun test(a: A) { + a.foo() + + with (a) { + foo() + } +} + +//variable as extension +interface B {} +val B.foo: Foo + get() = Foo() + + +fun test(b: B) { + b.foo() + + with (b) { + foo() + } +} + +//variable as member extension +interface C + +interface D { + val C.foo: Foo + + fun test(c: C) { + c.foo() + + with (c) { + foo() + } + } +} + +fun test(d: D, c: C) { + with (d) { + c.foo() + + with (c) { + foo() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtension.fir.kt new file mode 100644 index 00000000000..803ee1c22b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtension.fir.kt @@ -0,0 +1,123 @@ +class Foo + +//no variable +interface A { + operator fun Foo.invoke() {} + + fun test(foo: Foo) { + foo() + } +} + +//variable as member +interface B { + val foo: Foo +} + +class C { + operator fun Foo.invoke() {} + + fun test(b: B) { + b.foo() + + with (b) { + foo() + } + } +} + +fun test(c: C, b: B) { + with (c) { + b.foo() + + with (b) { + foo() + } + } +} + + +//variable as extension, +interface D { +} +val D.foo: Foo + get() = Foo() + +class E { + operator fun Foo.invoke() {} + + fun test(d: D) { + d.foo() + + with (d) { + foo() + } + } +} + +fun test(e: E, d: D) { + with (e) { + d.foo() + + with (d) { + foo() + } + } +} + +//variable as member extension +interface F + +interface G { + val F.foo: Foo + operator fun Foo.invoke() + + fun test(f: F) { + f.foo() + + with (f) { + foo() + } + } +} + +fun test(g: G, f: F) { + with (g) { + f.foo() + + with (f) { + foo() + } + } +} + +//variable as member extension (2) +interface X + +interface U { + val X.foo: Foo +} + +interface V { + operator fun Foo.invoke() {} + + fun U.test(x: X) { + x.foo() + + with (x) { + foo() + } + } +} + +fun test(u: U, v: V, x: X) { + with (v) { + with (u) { + x.foo() + + with (x) { + foo() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.fir.kt new file mode 100644 index 00000000000..e4dda926053 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.fir.kt @@ -0,0 +1,12 @@ +interface A +interface Foo { + operator fun A.invoke() +} + +fun test(a: A, foo: Foo) { + a.foo() +} + +fun test(a: Int, foo: Int.()->Unit) { + a.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.fir.kt new file mode 100644 index 00000000000..901f589de5d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER + +class C { + fun f() {} +} + +fun C.g(f: (String) -> Unit = { s -> f() }) {} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt new file mode 100644 index 00000000000..72dc0a20891 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt @@ -0,0 +1,84 @@ +// !WITH_NEW_INFERENCE +// FILE: 1.kt +package fooIsExtension + +class A +class B + +val A.foo: B.() -> Unit get() = {} + +fun test(a: A, b: B) { + b.(a.foo)() + (a.foo)(b) + a.foo(b) + + with(a) { + b.foo() + + b.(foo)() + + (b.foo)() + + foo(b) + (foo)(b) + } + + with(b) { + a.foo() + a.(foo)() + + (a.foo)() + + (a.foo)(this) + a.foo(this) + } + + with(a) { + with(b) { + foo() + (foo)() + } + } +} + +// FILE: 1.kt +package fooIsMember + +class A { + val foo: B.() -> Unit get() = {} +} +class B + +fun test(a: A, b: B) { + b.(a.foo)() + (a.foo)(b) + a.foo(b) + + with(a) { + b.foo() + + b.(foo)() + + (b.foo)() + + foo(b) + (foo)(b) + } + + with(b) { + a.foo() + a.(foo)() + + (a.foo)() + + (a.foo)(this) + a.foo(this) + } + + with(a) { + with(b) { + foo() + (foo)() + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt3772.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt3772.fir.kt new file mode 100644 index 00000000000..5e9a39f6280 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt3772.fir.kt @@ -0,0 +1,27 @@ +//KT-3772 Invoke and overload resolution ambiguity +package bar + +open class A { + public operator fun invoke(f: A.() -> Unit) {} +} + +class B { + public operator fun invoke(f: B.() -> Unit) {} +} + +open class C +val C.attr: A + get() = A() + +open class D: C() +val D.attr: B + get() = B() + + +fun main() { + val b = D() + b.attr {} // overload resolution ambiguity + + val d = b.attr + d {} // no error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt3833-invokeInsideNestedClass.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt3833-invokeInsideNestedClass.fir.kt new file mode 100644 index 00000000000..fb4cdeecaa0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt3833-invokeInsideNestedClass.fir.kt @@ -0,0 +1,35 @@ +//KT-3833 Invoke method not working inside companion object? +package m + +class Either1 { + class Left() { + fun match(left: () -> Unit) { + left() + } + } + + inner class Right() { + fun match(right: () -> Unit) { + right() + } + } +} + + +class X { + operator fun invoke() { + } +} + +object Foo{ + val v : X = X() +} + +class C{ + companion object { + fun f(){ + Foo.v() + } + } +} + diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt new file mode 100644 index 00000000000..874d9c980f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt4204-completeNestedCallsForInvoke.fir.kt @@ -0,0 +1,24 @@ +//KT-4204 ConstraintSystem erased after resolution completion +package c + +public abstract class TestBug1() { + + public fun m3(position: Int) { + position(m1().second!!) + } + + public fun m4(position: (Int)->Int) { + position(m1().second) + } + + private abstract fun m1(): Pair + + private fun position(p: Int) {} + +} + +//from library +public class Pair ( + public val first: A, + public val second: B +) diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt4321InvokeOnEnum.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt4321InvokeOnEnum.fir.kt new file mode 100644 index 00000000000..8080c3fec3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt4321InvokeOnEnum.fir.kt @@ -0,0 +1,35 @@ +//KT-4321 invoke() on enum doesn't work + +import DOMElementTestClasses.cls2 + +// use case 1 +enum class DOMElementTestClasses { + cls1, cls2; + + operator fun invoke() {} +} + + +// use case 2 +interface EnumStyleClass { + operator fun invoke() {} +} +enum class TestClasses : EnumStyleClass { + cls +} + +// example +fun main() { + // Kotlin: Expression 'cls1' of type 'DOMElementTestClasses' cannot be invoked as a function + DOMElementTestClasses.cls1() + + // Kotlin: Expression 'cls2' of type 'DOMElementTestClasses' cannot be invoked as a function + cls2() + + // Kotlin: Expression 'cls' of type 'TestClasses' cannot be invoked as a function + TestClasses.cls() + + // All ok + val cls = DOMElementTestClasses.cls2 + cls() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.fir.kt new file mode 100644 index 00000000000..8ec9a31cdf7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt9517.fir.kt @@ -0,0 +1,16 @@ + +//KT-9517 Wrong resolve for invoke convention after smart cast +open class A { + open val foo: () -> Number = null!! +} + +class B: A() { + override val foo: () -> Int + get() = null!! +} + +fun test(a: A) { + if (a is B) { + val foo: Int = a.foo() // B::foo + invoke() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/kt9805.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/kt9805.fir.kt new file mode 100644 index 00000000000..a0e0b9c1208 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/kt9805.fir.kt @@ -0,0 +1,17 @@ +class A { + val foo: B.() -> Unit get() = null!! +} + +class B + +fun test(a: A, b: B) { + with(b) { + a.foo() // here must be error, because a is not extension receiver + + a.foo(this) + + (a.foo)() + + (a.foo)(this) + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt new file mode 100644 index 00000000000..f71a3eceb98 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Int.invoke() {} + +class SomeClass + +fun test(identifier: SomeClass, fn: String.() -> Unit) { + identifier() + identifier(123) + identifier(1, 2) + 1.fn() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/valNamedInvoke.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/valNamedInvoke.fir.kt new file mode 100644 index 00000000000..2c8cfdd48bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/valNamedInvoke.fir.kt @@ -0,0 +1,9 @@ +interface A + +fun foo(invoke: A.()->Unit, a: A) { + a.invoke() +} + +fun bar(invoke: Any.()->Any, a: Any) { + a.invoke() +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.fir.kt new file mode 100644 index 00000000000..cce60dc62a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.fir.kt @@ -0,0 +1,18 @@ +class B + +class A { + operator fun B.invoke() {} +} + +val B.a: () -> Int get() = { 5 } + +fun test(a: A, b: B) { + val x: Int = b.a() + + b.(a)() + + with(b) { + val y: Int = a() + (a)() + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/localObject.fir.kt b/compiler/testData/diagnostics/tests/resolve/localObject.fir.kt new file mode 100644 index 00000000000..098f25c28e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/localObject.fir.kt @@ -0,0 +1,4 @@ +fun foo(): Any { + object Bar + return Bar +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeArgsInFreeExpressionPosition.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeArgsInFreeExpressionPosition.fir.kt new file mode 100644 index 00000000000..23ccbae857e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeArgsInFreeExpressionPosition.fir.kt @@ -0,0 +1,12 @@ +class A { + companion object { + + } +} + +fun use(vararg a: Any?) = a + +fun test() { + use(use(A, null).toString()) +} + diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeUnmappedArguments.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeUnmappedArguments.fir.kt new file mode 100644 index 00000000000..f748d007e89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeUnmappedArguments.fir.kt @@ -0,0 +1,9 @@ +package c + +fun test() { + with (1) l@ { + foo(1, zz = { this@l } ) + } +} + +fun foo(x: Int) = x diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt new file mode 100644 index 00000000000..1ffa3472243 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt @@ -0,0 +1,20 @@ +interface Foo + +class Bar { + operator fun invoke(): Foo = throw Exception() +} + +class A { + val bar = Bar() +} + +fun fooInt(l: Foo) = l + +fun test(bar: Bar, a: A) { + // no elements with error types + fooInt((bar())) + fooInt(if (true) bar() else bar()) + fooInt(label@ bar()) + fooInt(a.bar()) + fooInt(((label@ if (true) (a.bar()) else bar()))) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.fir.kt new file mode 100644 index 00000000000..08eb5f4d3ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +package h + +fun foo(i: Int) = i +fun foo(s: String) = s + +fun test() { + foo(emptyList()) +} + +fun emptyList(): List {throw Exception()} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeUnmappedArguments.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeUnmappedArguments.fir.kt new file mode 100644 index 00000000000..7b787bf145c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeUnmappedArguments.fir.kt @@ -0,0 +1,14 @@ +package c + +fun zzz(i: Int, f: (Int) -> Int) { throw Exception("$i $f")} + +fun test() { + fun foo(): Int = 42 + + fun bar(i: Int) = i + + bar(foo(xx = zzz(11) { j: Int -> j + 7 })) + + bar(zz = foo( + xx = zzz(12) { i: Int -> i + i })) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.fir.kt new file mode 100644 index 00000000000..48e34c01f67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +//KT-5971 Missing error when fun argument is safe call + +fun foo(i: Int) {} + +fun test(s: String?) { + foo(s?.length) +} diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt7597.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt7597.fir.kt new file mode 100644 index 00000000000..9e8cb9218b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt7597.fir.kt @@ -0,0 +1,8 @@ +interface Inv + +fun Inv.reduce2(): S = null!! + +fun test(a: Inv): Int { + val b = 1 + a.reduce2() + return b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/manyInapplicableCandidatesWithLambdas.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/manyInapplicableCandidatesWithLambdas.fir.kt new file mode 100644 index 00000000000..f0b8c73eac2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/manyInapplicableCandidatesWithLambdas.fir.kt @@ -0,0 +1,53 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +class B +class C +class D + +fun A.bar(x: Int = 0) = "" +fun A.bar(x: Int = 0, y: D.() -> Unit) = "" + +fun B.bar(x: Int = 0) = "" +fun B.bar(x: Int = 0, y: D.() -> Unit) = "" + +fun C.bar(x: Int = 0) = "" +fun C.bar(x: Int = 0, y: D.() -> Unit) = "" + +class E { + fun foo() { + // `bar` calls are inapplicable since both E nor D aren't proper receivers + // But prior to this change, every lambda was analyzed repeatedly for every candidate + // Thus, the resulting time was exponential + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + bar { + + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.fir.kt new file mode 100644 index 00000000000..d7b16cc0eb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +class ResolutionCandidate + +class ResolutionTask(val candidate: ResolutionCandidate) + +fun List>.bar(t: ResolutionTask) = t + +public class ResolutionTaskHolder { + fun test(candidate: ResolutionCandidate, tasks: MutableList>) { + tasks.bar(ResolutionTask(candidate)) + tasks.add(ResolutionTask(candidate)) + + //todo the problem is the type of ResolutionTask is inferred as ResolutionTask too early + tasks.bar(ResolutionTask(candidate)) + tasks.add(ResolutionTask(candidate)) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt b/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt new file mode 100644 index 00000000000..3646efb9384 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt @@ -0,0 +1,118 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun noArgs() {} +fun oneLambdaArg(fn: () -> Unit) {} +fun twoLambdaArgs(f1: () -> Unit, f2: () -> Unit) {} +fun varargFn(vararg args: Int) {} + +fun testNoArgs() { + noArgs() + noArgs {} + noArgs() {} + noArgs() // {} + noArgs() /* */ {} + noArgs() /* + block comment, no new line + */ {} + noArgs() + /* + block comment with new line + */ + {} + noArgs() // comment + // comment + {} + noArgs() {} {} + noArgs() {} + {} +} + +fun testLambdaArg() { + oneLambdaArg() + oneLambdaArg {} + oneLambdaArg() + {} + oneLambdaArg() + {} + {} + oneLambdaArg( + {}, + {} + ) + oneLambdaArg() {} + oneLambdaArg() // {} + oneLambdaArg() /* */ {} + oneLambdaArg() /* + block + comment + */ {} + oneLambdaArg() // comment + // comment + {} + oneLambdaArg() {}/* + block comment, no new line + */ {} + oneLambdaArg() {}/* + block comment with new line + */ + {} + oneLambdaArg() {}// comment + // comment + {} + oneLambdaArg() {} {} + oneLambdaArg() {} + {} + oneLambdaArg() {} // comment + {} +} + +fun testVararg() { + varargFn(1,2,3) + varargFn {} + varargFn(1,2,3) {} + varargFn(1,2,3) // {} + varargFn(1,2,3) /* */ {} + varargFn(1,2,3) /* + block comment, no new line + */ {} + varargFn(1,2,3) + /* + block comment with new line + */ {} + varargFn(1,2,3) // comment + // comment + {} + varargFn(1,2,3) {} {} + varargFn(1,2,3) {} + {} +} + +fun testTwoLambdas() { + twoLambdaArgs( + f1 = {}, + f2 = + {} + ) + + fun bar(): () -> Unit { + twoLambdaArgs() + {} + {} + + return if (true) { + twoLambdaArgs({}) + {} + {} + } else { + {} + } + } +} + +fun f1(): (() -> Unit) -> (() -> Unit) -> Unit { + return { l1 -> + l1() + { l2 -> l2() } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt new file mode 100644 index 00000000000..f884ab6fea4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt @@ -0,0 +1,6 @@ +interface MutableMatrix { +} + +fun toMutableMatrix(): MutableMatrix { + return MutableMatrix() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt new file mode 100644 index 00000000000..373bd9da30e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface A + +object B +class C + +fun test() { + val interface_as_fun = A() + val interface_as_val = A + + val object_as_fun = B() + val class_as_val = C +} + +fun bar() { + val typeParameter_as_val = T + val typeParameter_as_fun = T() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt new file mode 100644 index 00000000000..d5a24a8d485 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +object X { + interface A + + object B + class C +} + +fun testX() { + val interface_as_fun = X.A() + val interface_as_val = X.A + + val object_as_fun = X.B() + val class_as_val = X.C +} + +class Y { + interface A + + object B + class C +} + +fun testY() { + val interface_as_fun = Y.A() + val interface_as_val = Y.A + + val object_as_fun = Y.B() + val class_as_val = Y.C +} + +fun test(x: X) { + val interface_as_fun = x.A() + val interface_as_val = x.A + + val object_as_fun = x.B() + val class_as_val = x.C +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/objectLiteralAsArgument.fir.kt b/compiler/testData/diagnostics/tests/resolve/objectLiteralAsArgument.fir.kt new file mode 100644 index 00000000000..9cae82ca8a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/objectLiteralAsArgument.fir.kt @@ -0,0 +1,36 @@ +//If this test hangs, it means something is broken. +object A { + val iii = 42 +} + +//inappropriate but participating in resolve functions +fun foo(s: String, a: Any) = s + a + +fun foo(a: Any, s: String) = s + a +fun foo(i: Int, j: Int) = i + j +fun foo(a: Any, i: Int) = "$a$i" +fun foo(f: (Int) -> Int, i: Int) = f(i) +fun foo(f: (String) -> Int, s: String) = f(s) +fun foo(f: (Any) -> Int, a: Any) = f(a) +fun foo(s: String, f: (String) -> Int) = f(s) +fun foo(a: Any, f: (Any) -> Int) = f(a) +//appropriate function +fun foo(i: Int, f: (Int) -> Int) = f(i) + +fun test() { + foo(1, object : (Int) -> Int { + override fun invoke(x1: Int) = foo( + 2, object : (Int) -> Int { + override fun invoke(x2: Int) = foo( + 3, object : (Int) -> Int { + override fun invoke(x3: Int): Int = foo( + 4, object : (Int) -> Int { + override fun invoke(x4: Int): Int = foo( + 5, object : (Int) -> Int { + override fun invoke(x5: Int): Int = x1 + x2 + x3 + x4 + x5 + A.iii + }) + }) + }) + }) + }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/allLambdas.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/allLambdas.fir.kt new file mode 100644 index 00000000000..b85b6f1d582 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/allLambdas.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object X1 +object X2 + +fun foo(x: T1, f: (T1) -> T1) = X1 +fun foo(xf: () -> T2, f: (T2) -> T2) = X2 + +val test: X2 = foo({ 0 }, { it -> it + 1 }) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/extensionReceiverAndVarargs.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/extensionReceiverAndVarargs.fir.kt new file mode 100644 index 00000000000..ef9bf7b8da9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/extensionReceiverAndVarargs.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Right +object Wrong + +interface IA +interface IB : IA +fun IA.foo(vararg x: Int) = Wrong +fun IB.foo(vararg x: Int) = Right +class CC : IB + +val test7 = CC().foo(1, 2, 3) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericClash.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericClash.fir.kt new file mode 100644 index 00000000000..20d555ddddc --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericClash.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +interface A { + fun foo(x: T) + fun foo(x: String) + + fun baz(x: E, y: String) + fun baz(x: String, y: E) +} + +fun baz(x: E, y: String) {} +fun baz(x: String, y: E) {} + +fun bar(x: A) { + x.foo("") + + x.baz("", "") + baz("", "") +} diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericWithProjection.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericWithProjection.fir.kt new file mode 100644 index 00000000000..0d0742be152 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/genericWithProjection.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -REDUNDANT_PROJECTION + +class In() { + fun f(t : T) {} + fun f(t : Int) = t +} + +fun test1(x: In): Unit = x.f("1") +fun test2(x: In): Unit = x.f("1") +fun test3(x: In): Unit = x.f("1") +fun test4(x: In<*>): Unit = x.f("1") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10472.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10472.fir.kt new file mode 100644 index 00000000000..62c58aaf588 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10472.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Right +object Wrong + +interface A +interface B : A + +fun foo(vararg t: T) = Wrong +fun foo(t: A) = Wrong +fun foo(t: B) = Right + +fun test(b: B): Right = foo(b) diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.fir.kt new file mode 100644 index 00000000000..1fd5e880bc4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +interface AutoCloseable +interface Closeable : AutoCloseable + +fun T1.myUse(f: (T1) -> R1): R1 = f(this) +fun T2.myUse(f: (T2) -> R2): R2 = f(this) + +fun test1(x: Closeable) = x.myUse { 42 } +fun test2(x: Closeable) = x.myUse { 42 } +fun test3(x: Closeable) = x.myUse { 42 } // TODO KT-10681 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.fir.kt new file mode 100644 index 00000000000..6a5f32372ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE + +open class A(val value: T) +class B(value: T) : A(value) + +fun A.foo(block: (T?) -> Unit) { + block(value) +} +fun B.foo(block: (T) -> Unit) { + block(value) +} + +fun main() { + B("string").foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.fir.kt new file mode 100644 index 00000000000..021ff3cea73 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE + +open class A(val value: T) +class B(value: T) : A(value) + +fun A.foo(block: (T?) -> Unit) { + block(value) +} +fun B.foo(block: (T) -> Unit) { + block(value) +} + +fun main() { + B("string").foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.fir.kt new file mode 100644 index 00000000000..3a67bfa5323 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +enum class A { A1 } + +fun > foo(arg: T.() -> Unit) = 1 + +// FILE: b.kt + +package b + +fun foo(arg: T.() -> Unit) = 2 + +// FILE: test.kt + +import a.* +import b.* + +fun test() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.fir.kt new file mode 100644 index 00000000000..69fa18f44ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +enum class A { A1 } + +fun > foo(arg: T.() -> Unit) = 1 + +// FILE: b.kt + +package b + +fun foo(arg: T.() -> Unit) = 2 + +// FILE: test.kt + +import a.* +import b.* + +fun test() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.fir.kt new file mode 100644 index 00000000000..794be2d88fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Right +object Wrong + +fun overloadedFun(c: Any = "", b: String = "", f: Any = "") = Right +fun overloadedFun(b: Any = "", c: Any = "", e: String = "", x: String = "", y: String = "") = Wrong + +val test: Right = overloadedFun(b = "") + diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.fir.kt new file mode 100644 index 00000000000..63f59b6fc34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Right +object Wrong + +fun overloadedFun1(c: Any = "", b: String = "", f: Any = "") = Right +fun overloadedFun1(b: Any = "", c: Any = "", e: String = "") = Wrong + +val test1: Right = overloadedFun1(b = "") +val test1a: Wrong = overloadedFun1(b = "") + +fun overloadedFun2(a: String, b: Any = "") = Right +fun overloadedFun2(a: Any, b: String = "") = Wrong + +val test2: Right = overloadedFun2("") + +fun overloadedFun2a(a: Any, b: String = "") = Wrong +fun overloadedFun2a(a: String, b: Any = "") = Right + +val test2a: Right = overloadedFun2a("") diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.fir.kt new file mode 100644 index 00000000000..dbbc7e4e962 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +fun foo(block: (T?) -> Unit) {} + +// FILE: b.kt + +package b + +fun foo(block: (K) -> Unit) {} + +// FILE: test.kt + +import a.* +import b.* + +fun main() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.fir.kt new file mode 100644 index 00000000000..ef9e1f8de6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +fun foo(block: (T?) -> Unit) {} + +// FILE: b.kt + +package b + +fun foo(block: (K) -> Unit) {} + +// FILE: test.kt + +import a.* +import b.* + +fun main() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.fir.kt new file mode 100644 index 00000000000..67aa60f2c80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Foo1 +object Foo2 + +fun foo(vararg ss: String) = Foo1 +fun foo(x: Any) = Foo2 + +val test1: Foo1 = foo("") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargs.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargs.fir.kt new file mode 100644 index 00000000000..3991c9e26d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargs.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object Right +object Wrong + +fun overloadedFun6(s1: String) = Right +fun overloadedFun6(s1: String, s2: String) = Wrong +fun overloadedFun6(s1: String, s2: String, s3: String) = Wrong +fun overloadedFun6(s: String, vararg ss: String) = Wrong + +val test6: Right = overloadedFun6("") diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsInDifferentPositions.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsInDifferentPositions.fir.kt new file mode 100644 index 00000000000..ba34c23519c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsInDifferentPositions.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +ProhibitAssigningSingleElementsToVarargsInNamedForm +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object X1 +object X2 + +fun overloadedFun(arg: String, vararg args: String) = X1 +fun overloadedFun(arg: String, vararg args: String, flag: Boolean = true) = X2 + +val test1a: X1 = overloadedFun("", "") +val test1b: X1 = overloadedFun("", args = "") +val test1c: X2 = overloadedFun("", "", "", flag = true) + diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsMixed.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsMixed.fir.kt new file mode 100644 index 00000000000..240eac7e794 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsMixed.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +ProhibitAssigningSingleElementsToVarargsInNamedForm +// !DIAGNOSTICS: -UNUSED_PARAMETER + +object X1 +object X2 + +fun overloadedFun5(vararg ss: String) = X1 +fun overloadedFun5(s: String, vararg ss: String) = X2 + +val test1 = overloadedFun5("") +val test2 = overloadedFun5("", "") +val test3: X2 = overloadedFun5(s = "", ss = "") +val test4: X1 = overloadedFun5(ss = "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsWithRecursiveGenerics.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsWithRecursiveGenerics.fir.kt new file mode 100644 index 00000000000..8414bfee2b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargsWithRecursiveGenerics.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: J.java +import java.util.*; + +public class J { + public static > String foo(E1 e) { return ""; } + public static > String foo(E2 e1, E2 e2) { return ""; } + public static > String foo(E3 s1, E3 s2, E3 s3) { return ""; } + public static > int foo(E4... ss) { return 0; } +} + +// FILE: test.kt +enum class X { A } +val a = X.A + +val test0: Int = J.foo() +val test1: String = J.foo(a) +val test2: String = J.foo(a, a) +val test3: String = J.foo(a, a, a) +val test4: Int = J.foo(a, a, a, a) +val test5: Int = J.foo(a, a, a, a, a) diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/withVariance.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/withVariance.fir.kt new file mode 100644 index 00000000000..a0203b1cbcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/withVariance.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +object X1 +object X2 + +class A + +fun A.foo() = X1 +fun A.foo() = X2 + +fun A.test() = foo() // TODO fix constraint system \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/parameterAsDefaultValueInLocalFunction.fir.kt b/compiler/testData/diagnostics/tests/resolve/parameterAsDefaultValueInLocalFunction.fir.kt new file mode 100644 index 00000000000..b0180e74966 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/parameterAsDefaultValueInLocalFunction.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() { + fun bar(x: String, y: String = x) {} + fun baz(x: Int = y, y: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther.fir.kt new file mode 100644 index 00000000000..e92ef718eaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +class A + +class B { + fun foo() = this +} + +fun test(foo: A.() -> Int) { + with(A()) { + foo() checkType { _() } + with(B()) { + foo() checkType { _() } + this.foo() checkType { _() } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther2.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther2.fir.kt new file mode 100644 index 00000000000..ac7e7458842 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/invokeExtensionVsOther2.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +class A { + fun foo() = this +} + +fun test(foo: A.() -> Int) { + with(A()) { + foo() checkType { _() } + this.foo() checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/kt10219.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/kt10219.fir.kt new file mode 100644 index 00000000000..ec8217ed65a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt10219.fir.kt @@ -0,0 +1,22 @@ +// FILE: Calendar.java +public class Calendar { + public void setTimeInMillis(long millis) {} + public long getTimeInMillis() { return 1; } +} + +// FILE: 1.kt +class A + +var A.timeInMillis: String + get() = "" + set(v) {} + +fun a(c: Calendar) { + A().apply { + c.apply { + timeInMillis = 5 // synthesized variable for get|setTimeInMillis + timeInMillis = "" + } + timeInMillis = "" + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/kt10510.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/kt10510.fir.kt new file mode 100644 index 00000000000..383c6940e68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt10510.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +class ClassA { + fun method1() = this + + fun String.method2() { + method1() checkType { _() } + this.method1() checkType { _() } + } +} + +fun String.method1() = this \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/kt9810.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.fir.kt new file mode 100644 index 00000000000..db63cc5e5bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt9810.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// KT-9810 Local variable vs property from implicit receiver + +class A { + val foo = 2 +} + +fun test(foo: String) { + with(A()) { + val g: String = foo // locals win + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/kt9965.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/kt9965.fir.kt new file mode 100644 index 00000000000..0be29b963af --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/kt9965.fir.kt @@ -0,0 +1,20 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +enum class Foo { + FOO; + + companion object { + fun valueOf(something: String) = 2 + + fun values() = 1 + } +} + +fun test() { + Foo.values() checkType { _>() } + Foo.Companion.values() checkType { _() } + + Foo.valueOf("") checkType { _() } + Foo.Companion.valueOf("") checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/localExtVsNonLocalExt.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/localExtVsNonLocalExt.fir.kt new file mode 100644 index 00000000000..f268f5f6600 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/localExtVsNonLocalExt.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + + +class A + +fun A.foo() = this + +fun test(a: A) { + fun A.foo() = 3 + + a.foo() checkType { _() } + with(a) { + foo() checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.fir.kt new file mode 100644 index 00000000000..1bd8872c5b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +class A { + fun foo() = this +} + + +fun test(a: A) { + fun A.foo() = 4 + + a.foo() checkType { _() } + + with(a) { + foo() checkType { _() } + this.foo() checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/staticVsImplicitReceiverMember.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/staticVsImplicitReceiverMember.fir.kt new file mode 100644 index 00000000000..959f6d53415 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/staticVsImplicitReceiverMember.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: A.java +public class A { + public static void foo() {} +} + +// FILE: 1.kt + +class C { + fun foo() = this + + inner class B : A() { + fun test() { + foo() checkType { _() } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/synthesizedMembersVsExtension.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/synthesizedMembersVsExtension.fir.kt new file mode 100644 index 00000000000..1e7e5cd98fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/synthesizedMembersVsExtension.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +data class A(val foo: Int) + +operator fun A.component1(): String = "" + +fun test(a: A) { + val (b) = a + b checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsExtensions.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsExtensions.fir.kt new file mode 100644 index 00000000000..4ef52eb8488 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsExtensions.fir.kt @@ -0,0 +1,29 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: A.java +public class A { + public A getFoo() { return 3; } +} + +// FILE: 1.kt + +private val A.foo: Int get() = 4 + +fun test(a: A) { + a.foo checkType { _() } + with(a) { + foo checkType { _() } + } +} + +class B { + private val A.foo: B get() = this@B + + fun test(a: A) { + a.foo checkType { _() } + with(a) { + foo checkType { _() } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsMembers.fir.kt b/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsMembers.fir.kt new file mode 100644 index 00000000000..83c50b4bd1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/syntheticPropertiesVsMembers.fir.kt @@ -0,0 +1,36 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: A.java +public class A { + public A getFoo() { return 3; } +} + +// FILE: B.java +public class B { + public B getFoo() { return ""; } +} + +// FILE: 1.kt +class C(val foo: C) + +fun test(a: A, b: B, c: C) { + with(a) { + with(b) { + foo checkType { _() } + } + foo checkType { _() } + } + + with(a) { + with(c) { + foo checkType { _() } + } + } + + with(c) { + with(a) { + foo checkType { _() } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.fir.kt new file mode 100644 index 00000000000..02d00521086 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann + +fun bar(block: (T) -> Int) {} + +fun foo() { + bar @Ann @[Ann] { x -> x } + bar @Ann @[Ann] label@{ x -> x } +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveTypeArgsForUnresolvedCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveTypeArgsForUnresolvedCall.fir.kt new file mode 100644 index 00000000000..6baf4a9ebe5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveTypeArgsForUnresolvedCall.fir.kt @@ -0,0 +1,4 @@ +fun foo() { + x.yyy() + x.yyy() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt new file mode 100644 index 00000000000..cf4402b7539 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt @@ -0,0 +1,32 @@ +//If this test hangs, it means something is broken. +object A { + val iii = 42 +} + +//inappropriate but participating in resolve functions +fun foo(s: String, a: Any) = s + a +fun foo(a: Any) = a +fun foo(i: Int) = i +fun foo(a: Any, i: Int, f: ()-> Int) = "$a$i${f()}" +fun foo(f: (Int)->Int, i: Int) = f(i) +fun foo(f: (String)->Int, s: String) = f(s) +fun foo(f: (Any)->Int, a: Any) = f(a) +fun foo(s: String, f: (String, String)->Int) = f(s, s) +//appropriate function +fun foo(i: Int, f: (Int)->Int) = f(i) + +fun id(t: T) = t + +fun test() { + foo(1, id { x1 -> + foo(2, id { x2 -> + foo(3, id { x3 -> + foo(4, id { x4 -> + foo(5, id { x5 -> + x1 + x2 + x3 + x4 + x5 + A.iii + }) + }) + }) + }) + }) +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiterals.fir.kt new file mode 100644 index 00000000000..514962d5bc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiterals.fir.kt @@ -0,0 +1,30 @@ +object A { + val iii = 42 +} + +//inappropriate but participating in resolve functions +//fun foo(s: String, a: Any) = s + a +//fun foo(a: Any, s: String) = s + a +//fun foo(i: Int, j: Int) = i + j +//fun foo(a: Any, i: Int) = "$a$i" +//fun foo(f: (Int)->Int, i: Int) = f(i) +//fun foo(f: (String)->Int, s: String) = f(s) +//fun foo(f: (Any)->Int, a: Any) = f(a) +//fun foo(s: String, f: (String)->Int) = f(s) +//fun foo(a: Any, f: (Any)->Int) = f(a) +//appropriate function +fun foo(i: Int, f: (Int)->Int) = f(i) + +fun test() { + foo(1) { x1: Int -> + foo(2) { x2: Int -> + foo(3) { x3: Int -> + foo(4) { x4: Int -> + foo(5) { x5: Int -> + x1 + x2 + x3 + x4 + x5 + A.iii + } + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralsOverload.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralsOverload.fir.kt new file mode 100644 index 00000000000..7b6e982c94d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralsOverload.fir.kt @@ -0,0 +1,31 @@ +//If this test hangs, it means something is broken. +object A { + val iii = 42 +} + +//inappropriate but participating in resolve functions +fun foo(s: String, a: Any) = s + a +fun foo(a: Any, s: String) = s + a +fun foo(i: Int, j: Int) = i + j +fun foo(a: Any, i: Int) = "$a$i" +fun foo(f: (Int)->Int, i: Int) = f(i) +fun foo(f: (String)->Int, s: String) = f(s) +fun foo(f: (Any)->Int, a: Any) = f(a) +fun foo(s: String, f: (String)->Int) = f(s) +fun foo(a: Any, f: (Any)->Int) = f(a) +//appropriate function +fun foo(i: Int, f: (Int)->Int) = f(i) + +fun test() { + foo(1) { x1: Int -> + foo(2) { x2: Int -> + foo(3) { x3: Int -> + foo(4) { x4: Int -> + foo(5) { x5: Int -> + x1 + x2 + x3 + x4 + x5 + A.iii + } + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithGenerics.fir.kt new file mode 100644 index 00000000000..d77aed83c16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithGenerics.fir.kt @@ -0,0 +1,21 @@ +//If this test hangs, it means something is broken. +package a + +class A { + val testVal : A = A() +} + +//inappropriate but participating in resolve functions +fun foo(a: T, b: T, i: Int) = a +fun foo(a: Any) = a +fun foo(a: T, b: String) = a +fun foo(a: T, b: T, s: String) = a +//appropriate function +fun foo(a: T, b: T) = a + +fun test(a: A) { + //the problem occurs if there are nested function invocations to resolve (resolve for them is repeated now) + //to copy this invocation many times (and to comment/uncomment inappropriate functions) to see the difference + foo(foo(a, foo(a, foo(a, a.testVal))), a) + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithRedeclarationError.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithRedeclarationError.fir.kt new file mode 100644 index 00000000000..e44a56bef9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithRedeclarationError.fir.kt @@ -0,0 +1,34 @@ +//If this test hangs, it means something is broken. +package c + +fun z(view: () -> Unit) {} + +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } +fun x() = z { z { z { z { z { z { z { z { } } } } } } } } + +class x() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt new file mode 100644 index 00000000000..67b4400b312 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt @@ -0,0 +1,36 @@ +// !WITH_NEW_INFERENCE +//If this test hangs, it means something is broken. +package a + +object A { + val iii = 42 +} + +//inappropriate but participating in resolve functions +fun foo(s: String, a: Any) = s + a +fun foo(a: Any, s: String) = s + a +fun foo(i: Int, j: Int) = i + j +fun foo(a: Any, i: Int) = "$a$i" +fun foo(f: (Int) -> Int, i: Int) = f(i) +fun foo(f: (String) -> Int, s: String) = f(s) +fun foo(f: (Any) -> Int, a: Any) = f(a) +fun foo(s: String, f: (String) -> Int) = f(s) +fun foo(a: Any, f: (Any) -> Int) = f(a) +//appropriate function +fun foo(i: Int, f: (Int) -> Int) = f(i) + +fun id(t: T) = t + +fun test() { + foo(1, id(fun(x1: Int) = + foo(2, id(fun(x2: Int) = + foo(3, id(fun(x3: Int) = + foo(4, id(fun(x4: Int) = + foo(5, id(fun(x5: Int) = + x1 + x2 + x3 + x4 + x5 + A.iii + )) + )) + )) + )) + )) +} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.fir.kt new file mode 100644 index 00000000000..89fed6051f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithoutGenerics.fir.kt @@ -0,0 +1,20 @@ +//If this test hangs, it means something is broken. +package c + +class A { + val testVal : A = A() +} + +//inappropriate but participating in resolve functions +fun foo(a: A, b: A, i: Int) = a +fun foo(a: Any) = a +fun foo(a: A, b: Any) = a +fun foo(a: A, b: A, s: String) = a +//appropriate function +fun foo(a: A, b: A) = a + +fun test(a: A) { + //the problem occurs if there are nested function invocations to resolve (resolve for them is repeated now) + //to copy this invocation many times (and to comment/uncomment inappropriate functions) to see the difference + foo(foo(a, foo(a, foo(a, a.testVal))), a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.fir.kt new file mode 100644 index 00000000000..052ad1c675f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -USELESS_ELVIS + +fun test() { + bar(if (true) { + 1 + } else { + 2 + }) + + bar(1 ?: 2) +} + +fun bar(s: String) = s \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt new file mode 100644 index 00000000000..ed8ac74968a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +package a + +interface A +fun doList(l: List) = l +fun doInt(i: Int) = i +fun getList(): List? = null +fun strangeList(f: (T) -> Unit): List = throw Exception("$f") +fun emptyListOfA(): List = throw Exception() + +//------------------------------- + +fun testElvis(a: Int?, b: Int?) { + if (a != null) { + doInt(b ?: a) + } + doList(getList() ?: emptyListOfA()) //should be an error + doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed +} + + +fun testDataFlowInfo1(a: Int?, b: Int?) { + val c: Int = a ?: b!! + doInt(c) + // b is nullable if a != null + b + 1 +} + +fun testDataFlowInfo2(a: Int?, b: Int?) { + doInt(a ?: b!!) + // b is nullable if a != null + b + 1 +} + +fun testTypeMismatch(a: String?, b: Any) { + doInt(a ?: b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt new file mode 100644 index 00000000000..b4f44a1b4e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +package a + +interface A + +fun id(t: T): T = t +fun doList(l: List) = l +fun doInt(i: Int) = i + +fun strangeNullableList(f: (T) -> Unit): List? = throw Exception() +fun emptyNullableListOfA(): List? = null + +//------------------------------- + +fun testExclExcl() { + doList(emptyNullableListOfA()!!) //should be an error here + val l: List = id(emptyNullableListOfA()!!) + + doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase) +} + +fun testDataFlowInfoAfterExclExcl(a: Int?) { + doInt(a!!) + a + 1 +} + +fun testUnnecessaryExclExcl(a: Int) { + doInt(a!!) //should be warning +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/inferenceForElvis.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/inferenceForElvis.fir.kt new file mode 100644 index 00000000000..acf00f5938c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/inferenceForElvis.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !CHECK_TYPE + +fun foo(f: (T) -> Unit): T? = null // T is used only as return type +fun test() { + val x = foo { it checkType { _() }} ?: "" // foo() is inferred as foo, which isn't very good + val y: Any = foo { it checkType { _() } } ?: "" // but for now it's fixed by specifying expected type +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/multipleSuperClasses.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/multipleSuperClasses.fir.kt new file mode 100644 index 00000000000..3df6767a807 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/multipleSuperClasses.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface A +interface B + +interface C: A, B +interface D: A, B +interface E: A, B + +fun foo(c: C?, d: D?, e: E?) { + val test1: A? = c ?: d ?: e + + val test2: B? = if (false) if (true) c else d else e + + val test3: A? = when { + true -> c + else -> when { + true -> d + else -> e + } + } + + val test4: B? = when (1) { + 1 -> c + 2 -> d + else -> e + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.fir.kt new file mode 100644 index 00000000000..05be2916b0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/reportTypeMismatchDeeplyOnBranches.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +package b + +fun bar(i: Int) = i + +fun test(a: Int?, b: Int?) { + bar(if (a == null) return else b) +} + +fun test(a: Int?, b: Int?, c: Int?) { + bar(if (a == null) return else if (b == null) return else c) +} + +fun test(a: Any?, b: Any?, c: Int?) { + bar(if (a == null) if (b == null) c else return else return) +} + +fun test(a: Int?, b: Any?, c: Int?) { + bar(if (a == null) { + return + } else { + if (b == null) { + return + } else { + c + } + }) +} diff --git a/compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.fir.kt b/compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.fir.kt new file mode 100644 index 00000000000..e08e089c0ad --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() { + fun bar(x: List = listOf()) {} +} + +fun listOf(): List = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.fir.kt new file mode 100644 index 00000000000..07fc8b72572 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(t: T) = t + +fun test1() { + foo("") +} + + +fun bar(t: T, r: R) {} + +fun test2() { + bar("", "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/wrongReceiver.fir.kt b/compiler/testData/diagnostics/tests/resolve/wrongReceiver.fir.kt new file mode 100644 index 00000000000..e160c818aca --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/wrongReceiver.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +package some + +class A() + +val Int.some: Int get() = 4 +val Int.foo: Int get() = 4 + +fun Int.extFun() = 4 + +fun String.test() { + some + some.A() + "".some + + foo + "".foo + + extFun() + "".extFun() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/safeCall.fir.kt b/compiler/testData/diagnostics/tests/safeCall.fir.kt new file mode 100644 index 00000000000..d613f2e5768 --- /dev/null +++ b/compiler/testData/diagnostics/tests/safeCall.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE + +fun f(s: String, action: (String.() -> Unit)?) { + s.foo().bar().action() +} + +fun String.foo() = "" + +fun String.bar() = "" + +// -------------------------------------------------------- + +val functions: Map Any> = TODO() + +fun run(name: String) = functions[name]() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.fir.kt b/compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.fir.kt new file mode 100644 index 00000000000..e02f9d480f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt +interface K { + fun foo1(r: Runnable) + fun foo2(r1: Runnable, r2: Runnable) +} +fun test(k: K, r: Runnable) { + k.foo1(r) + k.foo1({}) + + k.foo2(r, r) + k.foo2({}, {}) + k.foo2(r, {}) + k.foo2({}, r) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.fir.kt b/compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.fir.kt new file mode 100644 index 00000000000..85ccf5612eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +NewInference +SamConversionPerArgument +// !CHECK_TYPE +// FILE: J.java +public interface J { + void f_t(F f1, F f2); + void f_r(F f1, F f2); + void f_pr(F> f1, F> f2); +} + +// FILE: F.java +public interface F { + void apply(S s); +} + +// FILE: PR.java +public interface PR {} + +// FILE: 1.kt + +fun test( + j: J, + f_string: F, + f_int: F, + f_pr: F> +) { + j.f_t(f_string) { it checkType { _() } } + j.f_r(f_int) { it checkType { _() } } + j.f_pr(f_pr) { it checkType { _>() } } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.fir.kt b/compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.fir.kt new file mode 100644 index 00000000000..0bf63f43541 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument +// !CHECK_TYPE +// FILE: F.java +public interface F { + void apply(S s); +} + +// FILE: PR.java +public interface PR {} + +// FILE: 1.kt +interface K { + fun f_t(f1: F, f2: F) + fun f_r(f1: F, f2: F) + fun f_pr(f1: F>, f2: F>) +} + +fun test( + k: K, + f_string: F, + f_int: F, + f_pr: F> +) { + k.f_t(f_string) { it checkType { _() } } + k.f_r(f_int) { it checkType { _() } } + k.f_pr(f_pr) { it checkType { _>() } } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/OverloadPriority.fir.kt b/compiler/testData/diagnostics/tests/samConversions/OverloadPriority.fir.kt new file mode 100644 index 00000000000..d89c9c184f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/OverloadPriority.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +NewInference +// !CHECK_TYPE +// FILE: Fn.java +public interface Fn { + R apply(T t); +} + +// FILE: Fn2.java +public interface Fn2 extends Fn {} + +// FILE: J.java +public interface J { + String foo(Fn f, Object o); + int foo(Fn f, String s); // (Any) -> Any <: (String) -> Any <=> String <: Any + + String bas(Fn f, Object o); + int bas(Fn f, String s); // (Any) -> String <: (Any) -> Any <=> String <: Any + + String bar(Fn f); + int bar(Fn2 f); // Fn2 seems more specific one even function type same +} + +// FILE: 1.kt +fun test(j: J) { + j.foo({ it checkType { _() }; "" }, "") checkType { _() } + + j.bas({ it checkType { _() }; "" }, "") checkType { _() } + + // NI: TODO + j.bar { it checkType { _() }; "" } checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.fir.kt b/compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.fir.kt new file mode 100644 index 00000000000..a7eea3f18fe --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument +// !CHECK_TYPE +// FILE: Fn.java +public interface Fn { + R apply(T t); +} + +// FILE: Fn2.java +public interface Fn2 extends Fn {} + +// FILE: 1.kt +interface K { + fun foo(f: Fn): String + fun foo(f: Fn): Int + + fun bas(f: Fn): String + fun bas(f: Fn): Int + + fun bar(f: Fn): String + fun bar(f: Fn2): Int +} + +fun test(k: K) { + k.foo { it checkType { _() }; "" } checkType { _() } + + k.bas { it checkType { _() }; "" } checkType { _() } + + // NI: TODO + k.bar { it checkType { _() }; "" } checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt b/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt new file mode 100644 index 00000000000..9b2b73d56c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// FILE: J.java +public interface J { + public void foo(T r1, T r2); +} + +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt +fun test(j: J, r: Runnable) { + j.foo(r, r) + j.foo(r, {}) + j.foo({}, r) + j.foo({}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt b/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt new file mode 100644 index 00000000000..b50318d674c --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt +interface K { + fun foo(t1: T, t2: T) +} + +fun test(k: K, r: Runnable) { + k.foo(r, r) + k.foo(r, {}) + k.foo({}, r) + k.foo({}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.fir.kt b/compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.fir.kt new file mode 100644 index 00000000000..977da70c817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +NewInference +SamConversionPerArgument +// FILE: J.java +public interface J { + public void foo1(Runnable r); + + public void foo2(Runnable r1, Runnable r2); + + public void foo3(Runnable r1, Runnable r2, Runnable r3); +} + +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt +fun test(j: J, r: Runnable) { + j.foo1(r) + j.foo1({}) + + j.foo2(r, r) + j.foo2({}, {}) + j.foo2(r, {}) + j.foo2({}, r) + + j.foo3(r, r, r) + j.foo3(r, r, {}) + j.foo3(r, {}, r) + j.foo3(r, {}, {}) + j.foo3({}, r, r) + j.foo3({}, r, {}) + j.foo3({}, {}, r) + j.foo3({}, {}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.fir.kt b/compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.fir.kt new file mode 100644 index 00000000000..dfafa0c65a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt + +interface K { + fun foo1(r: Runnable) + fun foo2(r1: Runnable, r2: Runnable) + fun foo3(r1: Runnable, r2: Runnable, r3: Runnable) +} +fun test(k: K, r: Runnable) { + k.foo1(r) + k.foo1({}) + + k.foo2(r, r) + k.foo2({}, {}) + k.foo2(r, {}) + k.foo2({}, r) + + k.foo3(r, r, r) + k.foo3(r, r, {}) + k.foo3(r, {}, r) + k.foo3(r, {}, {}) + k.foo3({}, r, r) + k.foo3({}, r, {}) + k.foo3({}, {}, r) + k.foo3({}, {}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.fir.kt b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.fir.kt new file mode 100644 index 00000000000..65297f5306b --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +NewInference +// FILE: Runnable.java +public interface Runnable { + void run(); +} + +// FILE: 1.kt + +interface K { + fun foo1(r: Runnable) + fun foo2(r1: Runnable, r2: Runnable) + fun foo3(r1: Runnable, r2: Runnable, r3: Runnable) +} +fun test(k: K, r: Runnable) { + k.foo1(r) + k.foo1({}) + + k.foo2(r, r) + k.foo2({}, {}) + k.foo2(r, {}) + k.foo2({}, r) + + k.foo3(r, r, r) + k.foo3(r, r, {}) + k.foo3(r, {}, r) + k.foo3(r, {}, {}) + k.foo3({}, r, r) + k.foo3({}, r, {}) + k.foo3({}, {}, r) + k.foo3({}, {}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.fir.kt b/compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.fir.kt new file mode 100644 index 00000000000..e9597239b3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.fir.kt @@ -0,0 +1,12 @@ +// FILE: root.kt +fun testFun() = "239" + +// FILE: otherPackage.kt +package test + +fun testFun() = 12 + +// FILE: using.kt +import test.* + +val t: String = testFun() diff --git a/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.fir.kt b/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.fir.kt new file mode 100644 index 00000000000..d1cd4c0f388 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.fir.kt @@ -0,0 +1,18 @@ +// FILE: a.kt +package a + +val v = 1 +fun f() = 1 + +// FILE: b.kt +package b + +val v = 1 +fun f() = 1 + +// FILE: main.kt +import a.* +import b.* + +val vv = v +val ff = f() diff --git a/compiler/testData/diagnostics/tests/scopes/NoAmbiguityBetweenRootAndPackage.fir.kt b/compiler/testData/diagnostics/tests/scopes/NoAmbiguityBetweenRootAndPackage.fir.kt new file mode 100644 index 00000000000..da8f87f823a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/NoAmbiguityBetweenRootAndPackage.fir.kt @@ -0,0 +1,12 @@ +// FILE: root.kt +fun testFun() = 12 + +// FILE: otherPackage.kt +package test + +fun testFun() = 12 + +// FILE: using.kt +package test + +val t = testFun() diff --git a/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.fir.kt b/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.fir.kt new file mode 100644 index 00000000000..24f2f70e685 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.fir.kt @@ -0,0 +1,33 @@ +fun devNull(obj: Any?) {} + +open class A { + companion object { + val internal_val = 1 + public val public_val: Int = 2 + private val private_val = 3 + protected val protected_val: Int = 5 + } + + fun fromClass() { + devNull(internal_val) + devNull(public_val) + devNull(private_val) + devNull(protected_val) + } +} + +fun fromOutside() { + devNull(A.internal_val) + devNull(A.public_val) + devNull(A.private_val) + devNull(A.protected_val) +} + +class B: A() { + fun fromSubclass() { + devNull(A.internal_val) + devNull(A.public_val) + devNull(A.private_val) + devNull(A.protected_val) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt b/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt new file mode 100644 index 00000000000..ac6bd941f1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt @@ -0,0 +1,85 @@ +package b + +open class A { + internal open fun foo() {} +} + +class B : A() { + protected override fun foo() {} +} + +class C : A() { + internal override fun foo() {} +} + +//------------ +open class D { + private open fun self() : D = this +} + +class E : D() { + internal override fun self() = this + + fun test() { + val s : E = self() + } +} + +//------------ +open class F { + protected open fun protected_fun() {} +} + +class G : F() { + override fun protected_fun() {} +} + +fun test_fun_stays_protected(g: G) { + g.protected_fun() +} + +//------------ +open class H { + protected open fun pi_fun() {} +} + +class I : H() { + protected override fun pi_fun() {} +} + +class J : H() { + internal override fun pi_fun() {} +} + +class K : H() { + public override fun pi_fun() {} +} + +//------------- +interface T { + public fun foo() {} +} + +open class L : T { + override fun foo() {} +} + +class M : L() { + internal override fun foo() {} +} +//--------------- +interface R { + fun foo() {} +} + +interface P : R { + override fun foo() {} +} + +interface Q : R { + override fun foo() {} +} + +class S : P, Q { + internal override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.fir.kt new file mode 100644 index 00000000000..68ffc3d5a0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +annotation class Ann( + val kc1: KClass<*>, + val kc2: KClass<*>, + val kc3: KClass<*>, + val c: Int, + val cc: Int, + val cn: Int, + val ci: Int, + val t1: Int, + val t2: Int +) + +@Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) +class A { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.fir.kt new file mode 100644 index 00000000000..d26e5b7c9d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +annotation class Ann( + val kc1: KClass<*>, + val kc2: KClass<*>, + val kc3: KClass<*>, + val c: Int, + val cc: Int, + val cn: Int, + val ci: Int, + val t1: Int, + val t2: Int +) + +class A +@Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) +constructor() { + + @Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + constructor(dummy: Int) : this() + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.fir.kt new file mode 100644 index 00000000000..b2c9645be50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + + class Nested + + inner class Inner + + interface Interface +} + +class B where T : Nested, F: Inner, G: Interface { + + class Nested + + inner class Inner + + interface Interface +} + diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.fir.kt new file mode 100644 index 00000000000..a87ecd7dbde --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +class A(impl: Interface) : Nested(), Interface by impl, Inner, I { + + class Nested + + inner class Inner + + interface Interface +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectParents.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectParents.fir.kt new file mode 100644 index 00000000000..4dd7a073951 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectParents.fir.kt @@ -0,0 +1,25 @@ +interface I + +val aImpl: A.Companion.Interface + get() = null!! + +val bImpl: B.Companion.Interface + get() = null!! + +interface A { + companion object : Nested(), Interface by aImpl, I { + + class Nested + + interface Interface + } +} + +class B { + companion object : Nested(), Interface by aImpl, I { + + class Nested + + interface Interface + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectSuperConstructorArguments.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectSuperConstructorArguments.fir.kt new file mode 100644 index 00000000000..6de00281a0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/companionObjectSuperConstructorArguments.fir.kt @@ -0,0 +1,19 @@ +open class S(val a: Any, val b: Any, val c: Any) {} + +interface A { + companion object : S(prop1, prop2, func()) { + val prop1 = 1 + val prop2: Int + get() = 1 + fun func() {} + } +} + +class B { + companion object : S(prop1, prop2, func()) { + val prop1 = 1 + val prop2: Int + get() = 1 + fun func() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt new file mode 100644 index 00000000000..886c5b062cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A( + n: Nested = foo(), + n2: Nested = Nested(), + inn: Inner = null!!, + inn2: Inner = Inner(), + i: Interface = null!!, + c: Int = CONST, + cc: Int = Companion.CONST, + cn: Int = Nested.CONST, + ci: Int = Interface.CONST, + t1: Int = a, + t2: Int = b() +) { + + constructor( + dummy: Int, + n: Nested = foo(), + n2: Nested = Nested(), + inn: Inner = null!!, + inn2: Inner = Inner(), + i: Interface = null!!, + c: Int = CONST, + cc: Int = Companion.CONST, + cn: Int = Nested.CONST, + ci: Int = Interface.CONST, + t1: Int = a, + t2: Int = b() + ) : this( + foo(), + Nested(), + inn, + Inner(), + i, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt new file mode 100644 index 00000000000..b53bcf83750 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) : I + +class A : I by S( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/objectParents.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/objectParents.fir.kt new file mode 100644 index 00000000000..006964e0753 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/objectParents.fir.kt @@ -0,0 +1,11 @@ +interface I + +val aImpl: A.Interface + get() = null!! + +object A : Nested(), Interface by aImpl, I { + + class Nested + + interface Interface +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/objectSuperConstructorArguments.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/objectSuperConstructorArguments.fir.kt new file mode 100644 index 00000000000..f08b997802d --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/objectSuperConstructorArguments.fir.kt @@ -0,0 +1,8 @@ +open class S(val a: Any, val b: Any, val c: Any) {} + +object A : S(prop1, prop2, func()) { + val prop1 = 1 + val prop2: Int + get() = 1 + fun func() {} +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.fir.kt new file mode 100644 index 00000000000..255ac8e7eb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +class A : I by impl { + + companion object { + val impl = object : I {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt new file mode 100644 index 00000000000..4a54b354afe --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) + +class A : S ( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt new file mode 100644 index 00000000000..c20c5465d08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) + +class A : S { + + constructor() : super( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/genericVsNested.fir.kt b/compiler/testData/diagnostics/tests/scopes/genericVsNested.fir.kt new file mode 100644 index 00000000000..afa0b31cac4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/genericVsNested.fir.kt @@ -0,0 +1,57 @@ +class A { + class T + + object E { + init { + T() + } + } + + class F { + init { + T() + } + } + + inner class I { + init { + T() // todo: https://jetbrains.quip.com/hPM5AJcc1nca + } + } + + init { + T() + } +} + +class B { + companion object { + class T; + + init { + T() + } + } + + object E { + init { + T() + } + } + + class F { + init { + T() + } + } + + inner class I { + init { + T() + } + } + + init { + T() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/implicitReceiverMemberVsParameter.fir.kt b/compiler/testData/diagnostics/tests/scopes/implicitReceiverMemberVsParameter.fir.kt new file mode 100644 index 00000000000..b798c1f212e --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/implicitReceiverMemberVsParameter.fir.kt @@ -0,0 +1,5 @@ +class A(val foo: Int) + +fun A.test(foo: String) { + val a: String = foo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/companionObject.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObject.fir.kt new file mode 100644 index 00000000000..f34525428d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObject.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +interface A { + companion object { + fun foo() {} + + class A_ + } +} + +open class B { + companion object { + fun bar() {} + + class B_ + } +} + +class C: B(), A { + init { + foo() + A.foo() + A.Companion.foo() + C.foo() + + A_() + A.A_() + A.Companion.A_() + C.A_() + + bar() + B.bar() + B.Companion.bar() + C.bar() + + B_() + B.B_() + B.Companion.B_() + C.B_() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectAfterJava.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectAfterJava.fir.kt new file mode 100644 index 00000000000..d2a44995123 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectAfterJava.fir.kt @@ -0,0 +1,52 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// FILE: 1.kt +interface A { + companion object { + fun foo() {} + + class A_ + } +} + +open class B { + companion object { + fun bar() {} + + class B_ + } +} + +// FILE: C.java +public class C extends B implements A { + +} + +// FILE: 2.kt +class D: C() { + init { + foo() + A.foo() + A.Companion.foo() + C.foo() + D.foo() + + A_() + A.A_() + A.Companion.A_() + C.A_() + D.A_() + + bar() + B.bar() + B.Companion.bar() + C.bar() + D.bar() + + B_() + B.B_() + B.Companion.B_() + C.B_() + D.B_() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectsOrder.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectsOrder.fir.kt new file mode 100644 index 00000000000..d3102b829fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/companionObjectsOrder.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +open class A { + companion object { + fun bar() = 1 + } + init { + val a: Int = foo() + val b: Int = bar() + } +} + +open class B: A() { + companion object { + fun bar() = "" + } + init { + val a: String = foo() + val b: String = bar() + } +} + +fun A.Companion.foo() = 1 +fun B.Companion.foo() = "" + +class C: A() { + init { + val a: Int = foo() + val b: Int = bar() + } +} + +class D: B() { + init { + val a: String = foo() + val b: String = bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt new file mode 100644 index 00000000000..7db34448a12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt @@ -0,0 +1,66 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +open class A { + inner class B { + fun foo() {} + } + + inner class D + + companion object { + class B { + fun bar() {} + } + + class C + } + + init { + B().foo() + B().bar() + + D() + C() + } +} + +class E: A() { + init { + B().foo() + B().bar() + + D() + C() + } + + object Z { + init { + B().foo() + B().bar() + + D() + C() + } + } +} + +class F: A() { + class B { + fun fas() {} + } + inner class D { + fun f() {} + } + + init { + B().fas() + D().f() + } + + companion object { + init { + B().fas() + D().f() + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/kt3856.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/kt3856.fir.kt new file mode 100644 index 00000000000..90c26194add --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/kt3856.fir.kt @@ -0,0 +1,33 @@ +fun foo(init: A.() -> Unit) { } + +class A { + var x: Int = 0 + companion object { + val f = foo() { + x = 1 + } + } +} + +class B(val a: String) { + fun f() = 0 + companion object { + fun B.bar() = a + f() + } +} + +open class C { + fun bar() {} +} + +class E: C() { + + class D { + init { + with(C()) { + bar() + this.bar() + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/methodsPriority.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/methodsPriority.fir.kt new file mode 100644 index 00000000000..6cb02f88f68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/methodsPriority.fir.kt @@ -0,0 +1,34 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + int foo() {return 1;} +} + +// FILE: 1.kt + +fun foo() = "" + +open class B: A() { + init { + val a: Int = foo() + } +} + +fun test() { + fun foo() = "" + + class B: A() { + init { + val a: Int = foo() // todo + } + } +} + +class E: A() { + fun foo() = A() + + init { + val a: A = foo() // todo: discuss + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedClassesFromInterface.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedClassesFromInterface.fir.kt new file mode 100644 index 00000000000..04981874b40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedClassesFromInterface.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java +public interface A { + public class A_ {} +} + +// FILE: 1.kt +interface B { + class B_ +} + +class X: A { + val a: A_ = A_() + val b: A.A_ = A.A_() + + companion object { + val a: A_ = A_() + } +} + +class Y: B { + val a: B_ = B_() + val b: B.B_ = B.B_() + + companion object { + val b: B_ = B_() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClass.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClass.fir.kt new file mode 100644 index 00000000000..6e079eb502a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClass.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +open class A { + companion object { + class B + } +} + +class C: A() { + val b: B = null!! + + init { + B() + } + + object O { + val b: B = null!! + + init { + B() + } + } + + class K { + val b: B = null!! + + init { + B() + } + } + + inner class I { + val b: B = null!! + + init { + B() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNested.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNested.fir.kt new file mode 100644 index 00000000000..7c2ade5d1f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNested.fir.kt @@ -0,0 +1,95 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +open class A { + class X { + fun A_X() {} + } + + class Y { + fun A_Y() {} + } + + companion object { + class X { + fun A_C_X() {} + } + + class Z { + fun A_C_Z() {} + } + } + + init { + X().A_X() + X().A_C_X() + } +} + +class Simple: A() { + init { + Y().A_Y() + Z().A_C_Z() + } +} + +class B: A() { + class Y { + fun B_Y() {} + } + + class Z { + fun B_Z() {} + } + + init { + X().A_X() + X().A_C_X() + + Y().B_Y() + Y().A_Y() + + Z().B_Z() + Z().A_C_Z() + } + + companion object { + init { + X().A_X() + X().A_C_X() + + Y().B_Y() + Y().A_Y() + + Z().B_Z() + Z().A_C_Z() + } + } +} + +class C: A() { + companion object { + class Y { + fun C_C_Y() {} + } + + class Z { + fun C_C_Z() {} + } + + init { + Y().C_C_Y() + Y().A_Y() + + Z().C_C_Z() + Z().A_C_Z() + } + } + + init { + Y().C_C_Y() + Y().A_Y() + + Z().C_C_Z() + Z().A_C_Z() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNestedJava.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNestedJava.fir.kt new file mode 100644 index 00000000000..d38e63e9ccb --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedCompanionClassVsNestedJava.fir.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +// FILE: 1.kt +open class A { + class Y { + fun A_Y() {} + } + + companion object { + class Z { + fun A_C_Z() {} + } + } +} + +// FILE: B.java +public class B extends A { + class Y { + void B_Y() {} + } + + class Z { + void B_Z() {} + } +} + +// FILE: C.java +public class C extends A {} + +// FILE: 2.kt +class E: B() { + init { + Y().B_Y() + Y().A_Y() + + Z().B_Z() + Z().A_C_Z() + } +} + +class Y: C() { + init { + Y().A_Y() + + Z().A_C_Z() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt new file mode 100644 index 00000000000..88266ce26d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt @@ -0,0 +1,90 @@ +// FILE: A.java +public interface A { + public class A_S { // static + + } +} + +// FILE: B.java +public class B { + public static class B_S { + + } + public class B_ { + + } +} + +// FILE: C.java +public class C extends B implements A { + +} + +// FILE: 1.kt + +class X: A { + val a_s: A_S = null!! + + init { + A_S() + A.A_S() + X.A_S() + } + + object xD { + val a_: A_S = null!! + + init { + A_S() + } + } +} + +class Y: B() { + val b_: B_ = null!! + val b_s: B_S = null!! + + init { + B_() + B.B_() + Y.B_() + + B_S() + B.B_S() + Y.B_S() + } + + object X { + val b_: B_ = null!! + val b_s: B_S = null!! + + init { + B_() + B_S() + } + } +} + +class Z: C() { + val a_s: A_S = null!! + val b_: B_ = null!! + val b_s: B_S = null!! + + init { + A_S() + B_() + B_S() + } + + object X { + val a_s: A_S = null!! + val b_: B_ = null!! + val b_s: B_S = null!! + + init { + A_S() + B_() + B_S() + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt new file mode 100644 index 00000000000..17c7d51f07b --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt @@ -0,0 +1,82 @@ +// FILE: A.java +public interface A { + class A_S { + + } +} + +// FILE: B.java +public class B { + static class B_S { + + } + class B_ { + + } +} + +// FILE: C.java +public class C extends B implements A { + +} + +// FILE: 1.kt +interface E { + class E_S +} + +open class D: C(), E + +// FILE: F.java +public class F extends D { + +} + +// FILE: 2.kt +class X: D() { + init { + B_() + B.B_() + C.B_() + D.B_() + X.B_() + + A_S() + A.A_S() + C.A_S() + D.A_S() + X.A_S() + + B_S() + B.B_S() + C.B_S() + D.B_S() + X.B_S() + + E_S() + E.E_S() + D.E_S() + X.E_S() + } +} + +class Y: F() { + init { + + B_() + F.B_() + Y.B_() + + A_S() + F.A_S() + Y.A_S() + + B_S() + F.B_S() + Y.B_S() + + E_S() + F.E_S() + Y.E_S() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedVsToplevelClass.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedVsToplevelClass.fir.kt new file mode 100644 index 00000000000..6da4e2102e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedVsToplevelClass.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion + +class X { + fun T_X() {} +} + +class Y { + fun T_Y() {} +} + +open class A { + class X { + fun A_X() {} + } + companion object { + class Y { + fun A_C_Y() {} + } + } + + init { + X().A_X() + X().T_X() + + Y().A_C_Y() + Y().T_Y() + } +} + +class B: A() { + init { + X().A_X() + X().T_X() + + Y().A_C_Y() + Y().T_Y() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/severalCompanions.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/severalCompanions.fir.kt new file mode 100644 index 00000000000..875eb4cfbf8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/severalCompanions.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +open class A { + companion object { + fun foo() = 1 + fun bar(a: String) = a + } +} + +open class B: A() { + companion object { + fun foo() = "" + fun bar(a: Int) = a + } +} + +class C: B() { + init { + val a: String = foo() + val b: Int = bar(1) + val c: String = bar("") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_after.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_after.fir.kt new file mode 100644 index 00000000000..4e52edab6a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_after.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: J2.java +public class J2 extends A { + public static void boo() {} +} + +// FILE: test.kt +open class A { + companion object : J() { + fun bar() {} + } +} + +class B : J2() { + init { + foo() + bar() + boo() + } + + fun test2() { + foo() + bar() + boo() + } + + object O { + fun test() { + foo() + bar() + boo() + } + } + + companion object { + init { + foo() + bar() + boo() + } + + fun test() { + foo() + bar() + boo() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_before.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_before.fir.kt new file mode 100644 index 00000000000..ebf633574e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ_before.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: J2.java +public class J2 extends A { + public static void boo() {} +} + +// FILE: test.kt +open class A { + companion object : J() { + fun bar() {} + } +} + +class B : J2() { + init { + foo() + bar() + boo() + } + + fun test2() { + foo() + bar() + boo() + } + + object O { + fun test() { + foo() + bar() + boo() + } + } + + companion object { + init { + foo() + bar() + boo() + } + + fun test() { + foo() + bar() + boo() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_after.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_after.fir.kt new file mode 100644 index 00000000000..aa556c2c09a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_after.fir.kt @@ -0,0 +1,46 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +open class A { + companion object : J() { + fun bar() {} + } +} + +class B : A() { + init { + foo() + bar() + } + + fun test2() { + foo() + bar() + } + + object O { + fun test() { + foo() + bar() + } + } + + companion object { + init { + foo() + bar() + } + + fun test() { + foo() + bar() + } + + fun bar() {} + } +} + diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_before.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_before.fir.kt new file mode 100644 index 00000000000..28daf2d8470 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass_before.fir.kt @@ -0,0 +1,46 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +open class A { + companion object : J() { + fun bar() {} + } +} + +class B : A() { + init { + foo() + bar() + } + + fun test2() { + foo() + bar() + } + + object O { + fun test() { + foo() + bar() + } + } + + companion object { + init { + foo() + bar() + } + + fun test() { + foo() + bar() + } + + fun bar() {} + } +} + diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_after.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_after.fir.kt new file mode 100644 index 00000000000..0df97ac7ee2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_after.fir.kt @@ -0,0 +1,54 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +open class A : J() { + init { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun test1() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun baz(): T = null!! + + object O { + fun test() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + } + + companion object : A() { + init { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun test() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_before.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_before.fir.kt new file mode 100644 index 00000000000..1f60f0f8568 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass_before.fir.kt @@ -0,0 +1,54 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +open class A : J() { + init { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun test1() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun baz(): T = null!! + + object O { + fun test() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + } + + companion object : A() { + init { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun test() { + foo() + bar() + val a: Int = baz() + val b: T = baz() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_after.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_after.fir.kt new file mode 100644 index 00000000000..d7a1bdd320f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_after.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt + +open class B : J() { + fun baz() {} +} + +class A { + init { + foo() + bar() + baz() + } + + fun test1() { + foo() + bar() + baz() + } + + object O { + fun test() { + foo() + bar() + baz() + } + } + + + companion object : B() { + init { + foo() + bar() + baz() + } + + fun test() { + foo() + bar() + baz() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_before.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_before.fir.kt new file mode 100644 index 00000000000..79bd44e5627 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin_before.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt + +open class B : J() { + fun baz() {} +} + +class A { + init { + foo() + bar() + baz() + } + + fun test1() { + foo() + bar() + baz() + } + + object O { + fun test() { + foo() + bar() + baz() + } + } + + + companion object : B() { + init { + foo() + bar() + baz() + } + + fun test() { + foo() + bar() + baz() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_after.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_after.fir.kt new file mode 100644 index 00000000000..2abf7f10610 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_after.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +class A { + init { + foo() + bar() + } + + fun test1() { + foo() + bar() + } + + object O { + fun test() { + foo() + bar() + } + } + + companion object : J() { + init { + foo() + bar() + } + + fun test() { + foo() + bar() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_before.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_before.fir.kt new file mode 100644 index 00000000000..2e585f6aa21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava_before.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion +// FILE: J.java +public class J { + public static void foo() {} +} + +// FILE: test.kt +class A { + init { + foo() + bar() + } + + fun test1() { + foo() + bar() + } + + object O { + fun test() { + foo() + bar() + } + } + + companion object : J() { + init { + foo() + bar() + } + + fun test() { + foo() + bar() + } + + fun bar() {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/hidePrivateByPublic.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/hidePrivateByPublic.fir.kt new file mode 100644 index 00000000000..1c704061339 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/hidePrivateByPublic.fir.kt @@ -0,0 +1,36 @@ +// FILE: A.java + +class A { + private static int a = 1; + private static void foo() {} + + protected static int b = 1; + protected static void bar() {} +} + +// FILE: B.java + +class B extends A { + public static int a = 1; + public static void foo() {} + public static void foo(int i) {} + + public static int b = 1; + public static void bar() {} + public static void bar(int i) {} +} + +// FILE: test.kt + +fun test() { + A.a + A.foo() + A.b + A.bar() + B.a + B.foo() + B.foo(1) + B.b + B.bar() + B.bar(1) +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/jjkj.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/jjkj.fir.kt new file mode 100644 index 00000000000..eacac7619af --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/jjkj.fir.kt @@ -0,0 +1,43 @@ +// FILE: I.java + +public interface I { + int a = 1; +} + +// FILE: C.java + +public class C implements I { + static int b = 1; + static void bar() {} +} + +// FILE: K.kt + +open class K : C() + +// FILE: D.java + +public class D extends K { + static int c = 1; + static void baz() {} +} + +// FILE: test.kt + +fun test() { + I.a + + C.a + C.b + C.bar() + + K.a + K.b + K.bar() + + D.a + D.b + D.c + D.bar() + D.baz() +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/kjk.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/kjk.fir.kt new file mode 100644 index 00000000000..cfda01f129f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/kjk.fir.kt @@ -0,0 +1,37 @@ +// FILE: K.kt + +open class K { + companion object { + fun foo() {} + } +} + +// FILE: D.java + +class D extends K { + static int b = 1; + static void bar() {} +} + +// FILE: K.kt + +class K2 { + companion object { + fun baz() {} + } +} + +// FILE: test.kt + +fun test() { + K.foo() + + D.b + D.bar() + D.foo() + + K2.b + K2.bar() + K2.foo() + K2.baz() +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/localVsStatic.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/localVsStatic.fir.kt new file mode 100644 index 00000000000..6c66335bc88 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/localVsStatic.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + public static int foo() {return 1;} +} + +// FILE: 1.kt + +fun foo() = "" + +class B: A() { + init { + val a: Int = foo() + } +} + +// FILE: 2.kt +fun test() { + fun foo() = "" + + class B: A() { + init { + val a: Int = foo() // todo + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash0.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash0.fir.kt new file mode 100644 index 00000000000..679562e8170 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash0.fir.kt @@ -0,0 +1,32 @@ +// FILE: A.java + +public interface A { + int field = 1; +} + +// FILE: B.java + +public interface B { + String field = 1; +} + +// FILE: E.java + +public class E implements A, B { +} + +// FILE: O.java + +public class O implements A, B { + public static double field = 1; +} + +// FILE: test.kt + +fun test() { + A.field + B.field + + E.field + O.field +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash1.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash1.fir.kt new file mode 100644 index 00000000000..5738aa2bdd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash1.fir.kt @@ -0,0 +1,32 @@ +// FILE: A.java + +public interface A { + int field = 1; +} + +// FILE: B.java + +public interface B extends A { + String field = 1; +} + +// FILE: E.java + +public class E implements A, B { +} + +// FILE: O.java + +public class O implements A, B { + public static double field = 1; +} + +// FILE: test.kt + +fun test() { + A.field + B.field + + E.field + O.field +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash2.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash2.fir.kt new file mode 100644 index 00000000000..ed9da65f567 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash2.fir.kt @@ -0,0 +1,66 @@ +// FILE: A.java + +public interface A { + int field = 1; +} + +// FILE: B.java + +public interface B { + String field = 1; +} + +// FILE: C.java + +public interface C extends A { +} + +// FILE: D.java + +public interface D extends B { +} + +// FILE: E.java + +public class E implements C, D { +} + +// FILE: EE.java + +public class EE extends E { +} + +// FILE: EO.java + +public class EO extends E { + public static double field = 1; +} + +// FILE: O.java + +public class O implements C, D { + public static double field = 1; +} + +// FILE: OO.java + +public class OO extends O { +} + +// FILE: test.kt + +fun test() { + A.field + B.field + + C.field + D.field + + E.field + O.field + + EE.field + EO.field + + OO.field +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/oneInterfaceManyTimes.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/oneInterfaceManyTimes.fir.kt new file mode 100644 index 00000000000..5c20a0227ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/oneInterfaceManyTimes.fir.kt @@ -0,0 +1,55 @@ +// FILE: I.java + +public interface I { + int a = 1; +} + +// FILE: C.java + +public class C implements I { + static int b = 1; + static void bar() {} +} + +// FILE: K.kt + +open class K : C(), I + +// FILE: D.java + +public class D extends K implements I { + static int c = 1; + static void baz() {} +} + +// FILE: E.java + +public class E extends D implements I { + static int a = 1; +} + +// FILE: test.kt + +fun test() { + I.a + + C.a + C.b + C.bar() + + K.a + K.b + K.bar() + + D.a + D.b + D.c + D.bar() + D.baz() + + E.a + E.b + E.c + E.bar() + E.baz() +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/overloadStatic.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/overloadStatic.fir.kt new file mode 100644 index 00000000000..a4111820f3f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/overloadStatic.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + static void foo() {} + static int bar() { return 1; } +} + +// FILE: B.java +public class B extends A { + static void foo() {} + static long bar() { return 1; } +} + +// FILE: 1.kt +class E: B() { + init { + foo() + val a: Long = bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticFunVsImport.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticFunVsImport.fir.kt new file mode 100644 index 00000000000..39dbe26c492 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticFunVsImport.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + static void foo() {} + static int bar() {return 1;} +} + +// FILE: B.java +public class B extends A {} + +// FILE: C.java +public class C { + static void bar() {} +} + +// FILE: 1.kt +import A.foo +import B.bar + +class E: A() { + init { + foo() + bar() + } +} + +class F: B() { + init { + foo() + bar() + } +} + +// FILE: 2.kt +import C.bar + +class Z: A() { + init { + val a: Int = bar() + } +} + +// FILE: 3.kt +import C.* + +class Q: A() { + init { + val a: Int = bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticPropertyVsImport.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticPropertyVsImport.fir.kt new file mode 100644 index 00000000000..f6e807ba3e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticPropertyVsImport.fir.kt @@ -0,0 +1,59 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + static byte foo = 1; + static int bar = 2; +} + +// FILE: B.java +public class B extends A {} + +// FILE: C.java +public class C { + static long bar = 3; +} + +// FILE: 1.kt +import A.foo +import B.bar + +class E: A() { + init { + foo + bar + } +} + +class F: B() { + init { + foo + bar + } +} + +// FILE: 2.kt +import C.bar + +class Z: A() { + init { + val a: Int = bar + } +} + +// FILE: 3.kt +import C.* + +class Q: A() { + init { + val a: Int = bar + } +} + +// FILE: 4.kt +val bar = "" + +class W: A() { + init { + val a: Int = bar + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsCompanion.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsCompanion.fir.kt new file mode 100644 index 00000000000..10b07d1924a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsCompanion.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + static void foo() {} +} + +// FILE: 1.kt +open class B : A() { + companion object { + fun foo() = 1 + } + + init { + val a: Int = foo() + } +} + +class C: B() { + init { + val a: Int = foo() + } +} + +// FILE: X.java +public class X extends B { + static double foo() { + return 1.0; + } +} + +// FILE: 2.kt +class Y: X() { + init { + val a: Double = foo() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsMember.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsMember.fir.kt new file mode 100644 index 00000000000..bf858b10100 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsMember.fir.kt @@ -0,0 +1,69 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java +public class A { + public static int foo() { return 1; } + public static int bar = 1; +} + +// FILE: 1.kt + +class B: A() { + companion object { + init { + val a: Int = foo() + val b: Int = bar + } + } + + init { + val a: Int = foo() + val b: Int = bar + } +} + +open class C: A() { + val bar = "" + fun foo() = "" + + init { + val a: String = foo() + val b: String = bar + } +} + +class E: C() { + init { + val a: String = foo() + val b: String = bar + } +} + +open class F: A() { + companion object { + val bar = "" + fun foo() = "" + + init { + val a: String = foo() + val b: String = bar + } + } + init { + val a: String = foo() + val b: String = bar + } +} + +class G: F() { + companion object { + init { + val a: String = foo() + val b: String = bar + } + } + + init { + val a: String = foo() + val b: String = bar + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsOuter.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsOuter.fir.kt new file mode 100644 index 00000000000..b991bb9c2c4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticVsOuter.fir.kt @@ -0,0 +1,19 @@ +// FILE: A.java +public class A { + public static int foo() {return 1;} +} + +// FILE: B.java +public class B extends A { + public static int foo() {return 1;} +} + +// FILE: 1.kt + +fun foo() = "" + +class C: B() { + init { + val a: Int = foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjava.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjava.fir.kt new file mode 100644 index 00000000000..fa3a9af13a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjava.fir.kt @@ -0,0 +1,51 @@ +// FILE: A.java +public class A { + public static void foo() {} +} + +// FILE: B.java +public class B extends A { + public static void bar() {} +} + +// FILE: 1.kt +open class X: A() { + init { + foo() + A.foo() + } +} + +open class Y: B() { + init { + foo() + A.foo() + B.foo() + + bar() + B.bar() + } +} + +class XN: X() { + init { + foo() + A.foo() + X.foo() + XN.foo() + } +} + +class YN: Y() { + init { + foo() + A.foo() + Y.foo() + YN.foo() + + bar() + B.bar() + Y.bar() + YN.bar() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjavaAfterKotlin.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjavaAfterKotlin.fir.kt new file mode 100644 index 00000000000..ebd3679cbb5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjavaAfterKotlin.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java +public class A { + public static void foo() {} +} + +// FILE: 1.kt +open class B: A() + +// FILE: C.java +public class C extends B { + public static void bar() {} +} + +// FILE: 2.kt +class D: C() { + init { + foo() + A.foo() + B.foo() + C.foo() + D.foo() + + bar() + C.bar() + D.bar() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt new file mode 100644 index 00000000000..acf064229ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt @@ -0,0 +1,31 @@ +// NI_EXPECTED_FILE + +package i + +val List.length = size + +val List.length1 : Int get() = size + +val String.bd = this + "!" + +val String.bd1 : String get() = this + "!" + + +class A { + val ii : Int = 1 +} + +val A.foo = ii + +val A.foo1 : Int get() = ii + + +class C { + inner class D {} +} + +val C.foo : C.D = D() + +val C.bar : C.D = C().D() + +val C.foo1 : C.D get() = D() diff --git a/compiler/testData/diagnostics/tests/scopes/invisibleSetter.fir.kt b/compiler/testData/diagnostics/tests/scopes/invisibleSetter.fir.kt new file mode 100644 index 00000000000..d37a025755f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/invisibleSetter.fir.kt @@ -0,0 +1,9 @@ +class A { + public var x: Int = 0 + private set +} + +fun main() { + val a = A() + a.x = 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1078.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1078.fir.kt new file mode 100644 index 00000000000..aef363bfa9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1078.fir.kt @@ -0,0 +1,16 @@ +//KT-1078 Problem with visibility in do-while + +package kt1078 + +fun test() : B { + do { + val x = foo() + } while(x.bar()) // x is not visible here! + return B() +} + +class B() { + fun bar() = true +} + +fun foo() = B() diff --git a/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt new file mode 100644 index 00000000000..546784bb76e --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt @@ -0,0 +1,19 @@ +//FILE:a.kt +//KT-1080 Don't use previously imported packages while resolving import references + +package kt1080 + +import reflect.Constructor + +import b.* +import d +import d.Test +import b.d + +class Some: Test() + +//FILE:b.kt + +package b.d + +public open class Test \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1244.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1244.fir.kt new file mode 100644 index 00000000000..60cec2541c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1244.fir.kt @@ -0,0 +1,13 @@ +//KT-1244 Frontend allows access to private members of other classes + +package kt1244 + +class A { + private var a = "" +} + +class B() { + init { + A().a = "Hello" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1248.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1248.fir.kt new file mode 100644 index 00000000000..a083534a2b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1248.fir.kt @@ -0,0 +1,12 @@ +//KT-1248 Control visibility of overrides needed +package kt1248 + +interface ParseResult { + public val success : Boolean + public val value : T +} + +class Success(internal override val value : T) : ParseResult { + internal override val success : Boolean = true +} + diff --git a/compiler/testData/diagnostics/tests/scopes/kt151.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt151.fir.kt new file mode 100644 index 00000000000..01a0da63151 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt151.fir.kt @@ -0,0 +1,40 @@ +//KT-151 Inherit visibility when overriding +package kt151 + +open class A { + protected open fun x() {} +} + +class B : A() { + override fun x() {} // No visibility modifier required +} + +fun test(b: B) { + b.x() +} + + +//more tests +open class C { + internal open fun foo() {} +} + +interface T { + fun foo() {} +} + +class D : C(), T { + protected override fun foo() {} +} + +class E : C(), T { + internal override fun foo() {} +} + +class F : C(), T { + private override fun foo() {} +} + +class G : C(), T { + public override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1579.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1579.fir.kt new file mode 100644 index 00000000000..6c1ef8f6c63 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1579.fir.kt @@ -0,0 +1,10 @@ +//FILE:a.kt +//KT-1579 Can't import nested class/interface +package lib +interface WithInner { + interface Inner { + } +} +//FILE:b.kt +package user +import lib.WithInner.Inner \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1579_map_entry.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1579_map_entry.fir.kt new file mode 100644 index 00000000000..f9bb0d33c84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1579_map_entry.fir.kt @@ -0,0 +1,19 @@ +//FILE:a.kt +//+JDK +package a +import kotlin.collections.Map.* + +fun foo(b : Entry) = b + +//FILE:b.kt +//+JDK +package b + +import kotlin.collections.Map.Entry +fun bar(b : Entry) = b + +//FILE:c.kt +//+JDK +package c + +fun fff(b: Map.Entry) = b \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1580.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1580.fir.kt new file mode 100644 index 00000000000..925f7dab9b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1580.fir.kt @@ -0,0 +1,15 @@ +//FILE:a.kt +//KT-1580 Can't access nested class/interface from other package +package lib +interface WithInner { + interface Inner { + } +} + +//FILE:b.kt +package user + +import lib.WithInner + +fun main(a : WithInner, b : WithInner.Inner) { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1642.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1642.fir.kt new file mode 100644 index 00000000000..54819f5e0ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1642.fir.kt @@ -0,0 +1,9 @@ +//FILE:a.kt +//KT-1642 kotlin subpackages hide Java's toplevel packages +package a.java + +//FILE:b.kt +//+JDK +package a + +import java.util.ArrayList \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1738.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1738.fir.kt new file mode 100644 index 00000000000..1a47ec37bf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1738.fir.kt @@ -0,0 +1,11 @@ +//KT-1738 Make it possible to define visibility for constructor parameters which become properties + +package kt1738 + +class A(private var i: Int, var j: Int) { +} + +fun test(a: A) { + a.i++ + a.j++ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1805.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1805.fir.kt new file mode 100644 index 00000000000..62dd30d6aa1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1805.fir.kt @@ -0,0 +1,20 @@ +package kt1805 +//KT-1805 Better diagnostic for access to private field of parent class + +open class Some { + private val privateField = 12 +} + +class SomeSubclass : Some() { + fun test() { + this.privateField // 1. Unresolved reference + } +} + +fun test() { + val s2 = Some() + s2.privateField // 2. Can't access to 'privateField' in Some + + val s1 = SomeSubclass() + s1.privateField // 3. Unresolved reference +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1806.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1806.fir.kt new file mode 100644 index 00000000000..657f069c623 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1806.fir.kt @@ -0,0 +1,24 @@ +//KT-1806 accessing private member in object class/anonymous object is not highlighted as error +package kt1806 + +object MyObject { + private var message: String = "'Static'" + +} + +fun test1() { + + doSmth(MyObject.message) +} + +class Test { + private val MyObject1 = object { + private var message: String = "'Static'" + } + + fun test2() { + doSmth(MyObject1.message) + } +} + +fun doSmth(s: String) = s \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1822.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1822.fir.kt new file mode 100644 index 00000000000..ed18d966a00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1822.fir.kt @@ -0,0 +1,30 @@ +//KT-1822 Error 'cannot infer visibility' required +package kt1822 + +open class C { + internal open fun foo() {} +} + +interface T { + protected fun foo() {} +} + +class G : C(), T { + override fun foo() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases +} + +open class A { + internal open fun foo() {} +} + +interface B { + protected fun foo() {} +} + +interface D { + public fun foo() {} +} + +class E : A(), B, D { + override fun foo() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1942.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1942.fir.kt new file mode 100644 index 00000000000..c5bca2a4f52 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1942.fir.kt @@ -0,0 +1,19 @@ +//FILE:a/C.java +//KT-1942 Package local members from Java are visible in subclasses +package a; + +public class C { + int myValue; +} + +//FILE:d.kt + +package d + +import a.C + +class A : C() { + fun test() { + val v = myValue + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/kt2262.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt2262.fir.kt new file mode 100644 index 00000000000..c78be35d876 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt2262.fir.kt @@ -0,0 +1,16 @@ +package kt2262 + +//KT-2262 Cannot access protected member from inner class of subclass + +abstract class Foo { + protected val color: String = "red" +} + +class Bar : Foo() { + protected val i: Int = 1 + + inner class Baz { + val copy = color // INVISIBLE_MEMBER: Cannot access 'color' in 'Bar' + val j = i + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt new file mode 100644 index 00000000000..9dc7be2c959 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt @@ -0,0 +1,49 @@ +package kt_250_617_10 + +import java.util.ArrayList +import java.util.HashMap + +//KT-250 Incorrect variable resolve in constructor arguments of superclass +open class A(val x: Int) +class B(y: Int) : A(x) //x is resolved as a property in a, so no error is generated + +//KT-617 Prohibit dollars in call to superclass constructors +open class M(p: Int) +class N(val p: Int) : A($p) + +//KT-10 Don't allow to use properties in supertype initializers +open class Element() +class TextElement(name: String) : Element() + +abstract class Tag(val name : String) { + val children = ArrayList() + val attributes = HashMap() +} + +abstract class TagWithText(name : String) : Tag(name) { + operator fun String.unaryPlus() { + children.add(TextElement(this)) + } +} + +open class BodyTag(name : String) : TagWithText(name) { +} + +class Body() : BodyTag(name) { // Must be an error! +} +class Body1() : BodyTag(this.name) { // Must be an error! +} + +//more tests + +open class X(p: Int, r: Int) { + val s = "s" +} + +class Y(i: Int) : X(i, rrr) { + val rrr = 3 +} + +class Z(val i: Int) : X(s, x) { + val x = 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt323.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt323.fir.kt new file mode 100644 index 00000000000..e1cf65d75ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt323.fir.kt @@ -0,0 +1,18 @@ +//KT-323 Handle visibility interactions with overriding +package kt323 + +open class A { + open var a : Int = 0 +} + +class B : A() { + override val a = 34 + + var b : Int + public get() = 23 + set(i: Int) {} + + protected var c : Int + get() = 23 + private set(i: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt37.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt37.fir.kt new file mode 100644 index 00000000000..f97b49359ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt37.fir.kt @@ -0,0 +1,16 @@ +//KT-37 Typechecker doesn't complain about accessing non-public property +package kt37 + +class C() { + private var f: Int + + init { + f = 610 + } +} + +fun box(): String { + val c = C() + if (c.f != 610) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt587.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt587.fir.kt new file mode 100644 index 00000000000..9e4b325ea89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt587.fir.kt @@ -0,0 +1,11 @@ +// KT-587 Unresolved reference + +class Main { + companion object { + class States() { + companion object { + public val N: States = States() // : States unresolved + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/kt900-1.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt900-1.fir.kt new file mode 100644 index 00000000000..e6f71feeacb --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt900-1.fir.kt @@ -0,0 +1,24 @@ +// import all members from companion object +package c + +import c.A.Companion.B +import c.M.* + +fun foo() { + val b: B = B() + var r: R = R() +} + +class A() { + companion object { + class B() { + companion object { + } + } + } +} + +object M { + fun foo() {} + class R() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt900-2.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt900-2.fir.kt new file mode 100644 index 00000000000..2decad45f6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt900-2.fir.kt @@ -0,0 +1,33 @@ +package d + +//import from objects before properties resolve + +import d.A.* +import d.M.R +import d.M.R.bar +import d.M.T +import d.M.Y + +var r: T = T() +val y: T = Y + +fun f() { + bar() + R.bar() + B.foo() +} + +object M { + object R { + fun bar() {} + } + open class T() {} + + object Y : T() {} +} + +object A { + object B { + fun foo() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt900.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt900.fir.kt new file mode 100644 index 00000000000..8aab758b541 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt900.fir.kt @@ -0,0 +1,69 @@ +//FILE:a.kt +//KT-900 Inaccessible class should be unresolved + +package a + +fun foo() { + val b : B = B() //only B() is unresolved, but in ": B" and "B.foo()" B should also be unresolved + B.foo() + + P.foo() + + M.bar() +} + +class A() { + companion object { + class B() { + companion object { + fun foo() {} + } + } + + object P { + fun foo() {} + } + } +} + +object N { + object M { + fun bar() {} + } +} + +//FILE:b.kt +package b + +import b.N.M +import b.A.Companion.P +import b.A.Companion.B + +fun foo() { + val b : B = B() + B.foo() + + P.foo() + + M.bar() +} + +class A() { + companion object { + class B() { + companion object { + fun foo() {} + } + } + + object P { + fun foo() {} + } + } +} + +object N { + object M { + fun bar() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt939.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt939.fir.kt new file mode 100644 index 00000000000..6abc2f93dfa --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt939.fir.kt @@ -0,0 +1,18 @@ +package kt939 + +//KT-939 CommonSupertypes erases scopes associated to types + +fun compare(o1 : String?, o2 : String?) : Int { + val l1 = o1?.length ?: 0 + val l2 = o2?.length ?: 0 + return l1 - l2 // '-' is unresolved, because the type of l1 is Int with an empty member scope +} + +//KT-1117 Unresolved reference to multiply sign + +fun test() { + (System.getProperty("path.separator")?.length ?: 4) * 55 + 5 + + val x = System.getProperty("path.separator")?.length ?: 4 + x * 55 + 5 +} diff --git a/compiler/testData/diagnostics/tests/scopes/kt9430.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt9430.fir.kt new file mode 100644 index 00000000000..6ae08ad0b74 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt9430.fir.kt @@ -0,0 +1,16 @@ +open class A { + protected fun foo() {} +} + +class B: A() + +class C: A() { + fun bar() { + A().foo() + B().foo() + } +} + +class D { + fun qux() { B().foo() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/complexCompanion.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/complexCompanion.fir.kt new file mode 100644 index 00000000000..d21b87baa85 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/complexCompanion.fir.kt @@ -0,0 +1,18 @@ +open class A { + protected fun foo() {} + + init { + B.foo() // Ok, receiver (B.Companion) is subtype of A + (B.Companion).foo() + } +} + +class B { + companion object : A() +} + +class C: A() { + init { + B.foo() // Error: receiver is not suitable + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructors.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructors.fir.kt new file mode 100644 index 00000000000..bdb52a79479 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructors.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A protected constructor(x: Int) { + protected constructor() : this(1) + protected constructor(x: String) : this(2) + public constructor(x: Double) : this(3) +} + +fun foo() { + A() + A(1.0) +} + +class B1 : A(1) {} +class B2 : A() {} +class B3 : A("") {} + +class B4 : A { + constructor() : super(1) + constructor(x: Int) : super() + constructor(x: Int, y: Int) : super("") +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructorsInner.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructorsInner.fir.kt new file mode 100644 index 00000000000..d2fdff585a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/constructorsInner.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class Outer { + inner open class A protected constructor(x: Int) { + protected constructor() : this(1) + + protected constructor(x: String) : this(2) + } + + inner class B1 : A(1) {} + inner class B2 : A() {} + inner class B3 : A("") {} + + inner class B4 : A { + constructor() : super(1) + constructor(x: Int) : super() + constructor(x: Int, y: Int) : super("") + } +} + diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerClassInJava.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerClassInJava.fir.kt new file mode 100644 index 00000000000..ef6809e9dba --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerClassInJava.fir.kt @@ -0,0 +1,24 @@ +// FILE: p1/BaseClass.java + +package p1; + +public class BaseClass { + protected class ProtSubClass { + public ProtSubClass() {} + } +} + +// FILE: k1/main.kt +package k1 + +import p1.BaseClass + +class Foo : BaseClass() { + + fun foo() { + ProtSubClass() + super.ProtSubClass() + } + + private val v1: BaseClass.ProtSubClass = ProtSubClass() +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerProtectedClass.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerProtectedClass.fir.kt new file mode 100644 index 00000000000..e0e8817a654 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/innerProtectedClass.fir.kt @@ -0,0 +1,13 @@ +open class BaseClass() { + protected class Nested(val x: Int, protected val y: Int) + + protected fun foo() = Nested(1, 2) +} + +class Foo : BaseClass() { + fun bar() { + val f = foo() + f.x + f.y + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/javaInheritedInKotlin.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/javaInheritedInKotlin.fir.kt new file mode 100644 index 00000000000..f1aa94d4fbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/javaInheritedInKotlin.fir.kt @@ -0,0 +1,58 @@ +// FILE: bar/JavaClass.java + +package bar; + +public class JavaClass { + protected void foo() {} + protected static void bar1() {} + protected static void bar2() {} + + protected String field = ""; + protected static String CONST1 = ""; + protected static String CONST2 = ""; + +} + +// FILE: foo/JavaClassSamePackage.java +package foo; + +public class JavaClassSamePackage extends bar.JavaClass { + protected static void bar2() {} + protected static String CONST2 = ""; +} + +// FILE: foo/main.kt +package foo + +import bar.JavaClass + +class KotlinClass : JavaClass() { + fun baz() { + foo() // OK + } +} + +class KotlinClass2 : JavaClass() { + override fun foo() {} + + val field: String = "abc" +} + +fun test(a: KotlinClass, b: KotlinClass2) { + a.foo() // Error, protected_and_package declared in different package + b.foo() // Error, protected visibility in same package (but could be protected_and_package) + + a.field + + JavaClass.bar1() + JavaClass.CONST1 + + KotlinClass.bar1() // Currently it's unresolved, but it should be prohibited even in case it would be resolved + KotlinClass.CONST1 + + JavaClassSamePackage.bar1() + JavaClassSamePackage.bar2() + + JavaClassSamePackage.CONST1 + JavaClassSamePackage.CONST2 +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/kt7971.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/kt7971.fir.kt new file mode 100644 index 00000000000..ba80133817d --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/kt7971.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE +// FILE: module1/AbstractModule.java +package module1; + +public abstract class AbstractModule { + protected S bind(Class clazz) { return null; } +} + +// FILE: module2/main.kt +package module2 + +import module1.* + +fun javaClass(): Class = null!! + +public class AppServiceModule : AbstractModule() { + inline fun AbstractModule.bind() { + val x = bind(javaClass()) + + x checkType { _() } // check that Class receiver is used instead of extension one + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructor.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructor.fir.kt new file mode 100644 index 00000000000..2ab8196cd5d --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructor.fir.kt @@ -0,0 +1,27 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A protected constructor(x: Int) { + protected constructor() : this(1) + public constructor(x: Double) : this(3) +} + +class B4 : A(1) { + init { + A() + A(1) + A(5.0) + } + + fun foo() { + A() + A(1) + A(5.0) + + object : A() {} + object : A(1) {} + object : A(5.0) {} + + class Local : A() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaDifferentPackage.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaDifferentPackage.fir.kt new file mode 100644 index 00000000000..679c584e96c --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaDifferentPackage.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: abc/A.java +package abc; +public class A { + protected A() {} + protected A(int x) {} + public A(double x) {} +} + +// FILE: main.kt +import abc.* + +class B4 : A(1) { + init { + A() + A(1) + A(5.0) + } + + fun foo() { + A() + A(1) + A(5.0) + + object : A() {} + object : A(1) {} + object : A(5.0) {} + + class Local : A() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaSamePackage.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaSamePackage.fir.kt new file mode 100644 index 00000000000..bf4789a773e --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/nonSuperCallConstructorJavaSamePackage.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java +public class A { + protected A() {} + protected A(int x) {} + public A(double x) {} +} + +// FILE: main.kt + +class B4 : A(1) { + init { + A() + A(1) + A(5.0) + } + + fun foo() { + A() + A(1) + A(5.0) + + object : A() {} + object : A(1) {} + object : A(5.0) {} + + class Local : A() + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.fir.kt new file mode 100644 index 00000000000..2a48ebec1a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.fir.kt @@ -0,0 +1,15 @@ +open class A { + open protected fun foo() { } + open protected fun foobaz() { } + + fun bar(x: B) { + x.foo() // OK, foo declared in A + x.baz() // Declared in B + x.foobaz() // Declared in B + } +} + +class B : A() { + protected fun baz() {} + override fun foobaz() {} +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/smartcastOnExtensionReceiver.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/smartcastOnExtensionReceiver.fir.kt new file mode 100644 index 00000000000..54b92ee84c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/smartcastOnExtensionReceiver.fir.kt @@ -0,0 +1,9 @@ +abstract class A { + abstract protected fun T.foo() + + fun bar(x: T?) { + if (x != null) { + x.foo() + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticPropertyExtensions.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticPropertyExtensions.fir.kt new file mode 100644 index 00000000000..52bdddb16ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticPropertyExtensions.fir.kt @@ -0,0 +1,45 @@ +// FILE: abc/A.java +package abc; +public class A { + public int getAbc() {} + protected int getFoo() { return 1; } + + public String getBar() { return ""; } + protected void setBar(String x) { } +} + +// FILE: main.kt +import abc.A + +class Data(var x: A) + +class B : A() { + fun baz(a: A, b: B, d: Data) { + foo + bar = bar + "" + + b.foo + b.bar = b.bar + "" + + a.foo + // TODO: should be INVISIBLE_SETTER + a.bar = a.bar + "" + + if (a is B) { + a.foo + a.bar = a.bar + "" + } + + if (d.x is B) { + d.x.abc // Ok + d.x.foo + // TODO: should be INVISIBLE_SETTER + d.x.bar = d.x.bar + "" + } + } +} + +fun baz(a: A) { + a.foo + a.bar = a.bar + "" +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.fir.kt new file mode 100644 index 00000000000..a36bbbcebd6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.fir.kt @@ -0,0 +1,31 @@ +// !WITH_NEW_INFERENCE +// FILE: abc/A.java +package abc; +public class A { + protected void foo(Runnable x) {} +} + +// FILE: main.kt +import abc.A; + +class Data(var x: A) + +class B : A() { + fun baz(a: A, b: B, d: Data) { + a.foo { } + + b.foo { } + + if (a is B) { + a.foo {} + } + + if (d.x is B) { + d.x.foo {} + } + } +} + +fun baz(a: A) { + a.foo { } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/unstableSmartCast.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/unstableSmartCast.fir.kt new file mode 100644 index 00000000000..afa407fe22f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/unstableSmartCast.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +open class BaseOuter { + protected fun foo() = 1 + protected fun bar() { } +} + +class Foo(var base: BaseOuter) + +fun BaseOuter.foo(): String = "" + +class Derived : BaseOuter() { + fun test(foo: Foo) { + if (foo.base is Derived) { + foo.base.foo() checkType { _() } // Resolved to extension + foo.base.bar() + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/withSmartcast.fir.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/withSmartcast.fir.kt new file mode 100644 index 00000000000..e6f83a964cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/withSmartcast.fir.kt @@ -0,0 +1,30 @@ +open class Base { + open protected fun foo() {} + open protected fun bar() {} + + open protected var x: Int = 1 + open var y: Int = 1 + protected set +} + +class Derived : Base() { + override fun bar() { } + + protected fun baz(x: Base) { + x.foo() + x.bar() + + x.x = x.x + 1 + x.y = x.y + 1 + + if (x is Derived) { + x.foo() + x.bar() + x.baz(x) + + x.x = x.x + 1 + // TODO: Should be smart cast + x.y = x.y + 1 + } + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/sameClassNameResolve.fir.kt b/compiler/testData/diagnostics/tests/scopes/sameClassNameResolve.fir.kt new file mode 100644 index 00000000000..79d3a50776a --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/sameClassNameResolve.fir.kt @@ -0,0 +1,10 @@ +// FILE: SameClassNameResolveTest.kt +package test + +open class Base +class SubBase: Base() + +// FILE: SameClassNameResolveRoot.kt + +open class Base +class SubBase: Base() diff --git a/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt new file mode 100644 index 00000000000..8e128007ae8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt @@ -0,0 +1,20 @@ +package c + +interface B { + fun bar() {} +} + +class C() { + fun bar() { + } +} + +fun test(a : Any?) { + if (a is B) { + if (a is C) { + a.bar(); + } + } +} + +fun Any?.bar() {} diff --git a/compiler/testData/diagnostics/tests/scopes/visibility.fir.kt b/compiler/testData/diagnostics/tests/scopes/visibility.fir.kt new file mode 100644 index 00000000000..a6c408dbc7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/visibility.fir.kt @@ -0,0 +1,95 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +//FILE:a.kt +package test_visibility + +protected class ProtectedClass +protected interface ProtectedTrait + +protected val protected_val : Int = 4 +protected fun protected_fun() {} + +private val private_val : Int = 4 +private fun private_fun() {} + +val internal_val : Int = 34 +fun internal_fun() {} + +fun test1() { + private_fun(); +} + +class Y { + fun test2() { + private_fun(); + } +} + +class A { + private val i = 23 + private val v: B = B() + private fun f(i: Int): B = B() + + fun test() { + doSmth(i) + } +} + +class B { + fun bMethod() {} +} + +fun test3(a: A) { + a.v //todo .bMethod() + a.f(0, 1) //todo .bMethod() +} + +interface T + +open class C : T { + protected var i : Int = 34 + fun test5() { + doSmth(i) + } +} + +fun test4(c: C) { + c.i++ +} + +class D : C() { + val j = i + fun test6() { + doSmth(i) + } +} + +class E : C() { + fun test7() { + doSmth(i) + } +} + +class F : C() { + fun test8(c: C) { + doSmth(c.i) + } +} + +class G : T { + fun test8(c: C) { + doSmth(c.i) + } +} + +fun doSmth(i: Int) = i + +//FILE:b.kt +package test_visibility2 + +import test_visibility.* + +fun test() { + internal_fun() + private_fun() +} diff --git a/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt b/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt new file mode 100644 index 00000000000..e17a0496bd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE +//FILE:a.kt +package a + +private open class A { + fun bar() {} +} + +private fun foo() {} + +fun makeA() = A() + +private object PO {} + +//FILE:b.kt +//+JDK +package b + +import a.A +import a.foo +import a.makeA +import a.PO + +fun test() { + val y = makeA() + y.bar() + foo() + + val u : A = A() + val a : java.util.Arrays.ArrayList; + + val po = PO +} + +class B : A() {} + +class Q { + class W { + fun foo() { + val y = makeA() //assure that 'makeA' is visible + } + } +} + +//check that 'toString' can be invoked without specifying return type +class NewClass : java.util.ArrayList() { + public override fun toString() = "a" +} diff --git a/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt b/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt new file mode 100644 index 00000000000..cfcf09a19a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +//FILE:file1.kt +package a + +private open class A { + fun bar() {} +} + +private var x: Int = 10 + +private fun foo() {} + +private fun bar() { + val y = x + x = 20 +} + +fun makeA() = A() + +private object PO {} + +//FILE:file2.kt +package a + +fun test() { + val y = makeA() + y.bar() + foo() + + val u : A = A() + + val z = x + x = 30 + + val po = PO +} + +class B : A() {} + +class Q { + class W { + fun foo() { + val y = makeA() //assure that 'makeA' is visible + } + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/DerivedTopLevel.fir.kt b/compiler/testData/diagnostics/tests/sealed/DerivedTopLevel.fir.kt new file mode 100644 index 00000000000..f766faf3d9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/DerivedTopLevel.fir.kt @@ -0,0 +1,10 @@ +sealed class Base + +class Derived: Base() { + class Derived2: Base() +} + +fun test() { + class Local: Base() +} + diff --git a/compiler/testData/diagnostics/tests/sealed/DoubleInner.fir.kt b/compiler/testData/diagnostics/tests/sealed/DoubleInner.fir.kt new file mode 100644 index 00000000000..a4be675f925 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/DoubleInner.fir.kt @@ -0,0 +1,9 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + // It's ALLOWED to inherit Sealed also here + object Fourth: Sealed(78) + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.fir.kt new file mode 100644 index 00000000000..afef06f3764 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnRoot.fir.kt @@ -0,0 +1,23 @@ +sealed class Stmt + +class ForStmt : Stmt() + +sealed class Expr : Stmt() { + object BinExpr : Expr() +} + +fun test(x: Stmt): String = + when (x) { + is Expr -> "expr" + is Stmt -> "stmt" + } + +fun test2(x: Stmt): String = + when (x) { + is Expr -> "expr" + } + +fun test3(x: Expr): String = + when (x) { + is Stmt -> "stmt" + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTree.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTree.fir.kt new file mode 100644 index 00000000000..d19eb6011fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTree.fir.kt @@ -0,0 +1,34 @@ +sealed class Base { + sealed class A : Base() { + object A1 : A() + sealed class A2 : A() + } + sealed class B : Base() { + sealed class B1 : B() + object B2 : B() + } + + fun foo() = when (this) { + is A -> 1 + is B.B1 -> 2 + B.B2 -> 3 + // No else required + } + + fun bar() = when (this) { + is A -> 1 + is B.B1 -> 2 + } + + fun baz() = when (this) { + is A -> 1 + B.B2 -> 3 + // No else required (no possible B1 instances) + } + + fun negated() = when (this) { + !is A -> 1 + A.A1 -> 2 + is A.A2 -> 3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTriangleStar.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTriangleStar.fir.kt new file mode 100644 index 00000000000..68a39439d7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnTriangleStar.fir.kt @@ -0,0 +1,24 @@ +sealed class A +sealed class B : A() + +class C : B() +class D : B() + +fun test(a: A): Any { + return when (a) { + is C -> "" + is D -> "" + } +} + +fun test2(a: A): Any { + return when (a) { + is B -> "" + } +} + +fun test3(a: A): Any { + return when (a) { + is D -> "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhen.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhen.fir.kt new file mode 100644 index 00000000000..cd9a104257f --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhen.fir.kt @@ -0,0 +1,16 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.First -> 1 + is Sealed.NonFirst -> 0 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenDoubleInner.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenDoubleInner.fir.kt new file mode 100644 index 00000000000..1a4fc73d191 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenDoubleInner.fir.kt @@ -0,0 +1,16 @@ +sealed class Sealed() { + object First: Sealed() + open class NonFirst: Sealed() { + object Second: NonFirst() + object Third: NonFirst() + // It's ALLOWED to inherit Sealed also from here + object Fourth: Sealed() + } +} + +fun foo(s: Sealed) = when(s) { + Sealed.First -> 1 + is Sealed.NonFirst -> 2 + Sealed.NonFirst.Fourth -> 4 + // no else required +} diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenMultipleInner.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenMultipleInner.fir.kt new file mode 100644 index 00000000000..5c46abf6f29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenMultipleInner.fir.kt @@ -0,0 +1,47 @@ +sealed class Sealed() { + object First: Sealed() + open class NonFirst: Sealed() { + class NonSecond: NonFirst() { + object Third: Sealed() + class NonThird: Sealed() { + object Fourth: NonFirst() + class Fifth: Sealed() + } + } + object Second: Sealed() + } +} + +fun foo(s: Sealed) = when(s) { + Sealed.First -> 1 + is Sealed.NonFirst -> 2 + Sealed.NonFirst.Second -> 4 + Sealed.NonFirst.NonSecond.Third -> 6 + is Sealed.NonFirst.NonSecond.NonThird -> 8 + is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10 + // no else required +} + +fun fooWithElse(s: Sealed) = when(s) { + Sealed.First -> 1 + Sealed.NonFirst.NonSecond.Third -> 6 + is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10 + else -> 0 +} + +fun fooWithoutElse(s: Sealed) = when(s) { + Sealed.First -> 1 + is Sealed.NonFirst -> 2 + Sealed.NonFirst.NonSecond.Third -> 6 + is Sealed.NonFirst.NonSecond.NonThird -> 8 + is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10 +} + +fun barWithoutElse(s: Sealed) = when(s) { + Sealed.First -> 1 + is Sealed.NonFirst -> 2 + Sealed.NonFirst.Second -> 4 + is Sealed.NonFirst.NonSecond.NonThird -> 8 + is Sealed.NonFirst.NonSecond.NonThird.Fifth -> 10 +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegated.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegated.fir.kt new file mode 100644 index 00000000000..1e0f78ef81c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegated.fir.kt @@ -0,0 +1,16 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.First -> 1 + !is Sealed.First -> 0 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt new file mode 100644 index 00000000000..949ccc9b67c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt @@ -0,0 +1,17 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } + object Last: Sealed(78) +} + +fun foo(s: Sealed): Int { + return when(s) { + !is Sealed.First -> 1 + !is Sealed.Last -> 0 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNestedSealed.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNestedSealed.fir.kt new file mode 100644 index 00000000000..7e1f8c828a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNestedSealed.fir.kt @@ -0,0 +1,20 @@ +sealed class Sealed { + object First: Sealed() + sealed class NonFirst { + object Second: NonFirst() + object Third: NonFirst() + object Fourth: Sealed() + } +} + +fun foo(s: Sealed, nf: Sealed.NonFirst): Int { + val si = when(s) { + Sealed.First -> 1 + Sealed.NonFirst.Fourth -> 4 + } + val nfi = when(nf) { + Sealed.NonFirst.Second -> 2 + Sealed.NonFirst.Third -> 3 + } + return si + nfi +} diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNullable.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNullable.fir.kt new file mode 100644 index 00000000000..38c493ca263 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenOnNullable.fir.kt @@ -0,0 +1,17 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed?): Int { + return when(s) { + is Sealed.First -> 1 + is Sealed.NonFirst -> 0 + null -> -1 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithAdditionalMember.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithAdditionalMember.fir.kt new file mode 100644 index 00000000000..1f12821e8ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithAdditionalMember.fir.kt @@ -0,0 +1,18 @@ +sealed class Sealed(val x: Int) { + data class Tuple(val x: Int, val y: Int) + object First: Sealed(12) + open class NonFirst(tuple: Tuple): Sealed(tuple.x) { + val y: Int = tuple.y + object Second: NonFirst(Tuple(34, 2)) + object Third: NonFirst(Tuple(56, 3)) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.First -> 1 + is Sealed.NonFirst -> 0 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithElse.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithElse.fir.kt new file mode 100644 index 00000000000..711f599a637 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithElse.fir.kt @@ -0,0 +1,15 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.NonFirst -> 0 + else -> -1 + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/Local.fir.kt b/compiler/testData/diagnostics/tests/sealed/Local.fir.kt new file mode 100644 index 00000000000..f6559a21f25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/Local.fir.kt @@ -0,0 +1,13 @@ +sealed class Sealed { + object First: Sealed() + open class NonFirst: Sealed() { + object Second: NonFirst() + object Third: NonFirst() + fun foo(): Int { + val s = object: Sealed() {} + class Local: Sealed() {} + return s.hashCode() + } + } + val p: Sealed = object: Sealed() {} +} diff --git a/compiler/testData/diagnostics/tests/sealed/LocalSealed.fir.kt b/compiler/testData/diagnostics/tests/sealed/LocalSealed.fir.kt new file mode 100644 index 00000000000..add2fe130d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/LocalSealed.fir.kt @@ -0,0 +1,3 @@ +fun foo() { + sealed class My +} diff --git a/compiler/testData/diagnostics/tests/sealed/NestedSealed.fir.kt b/compiler/testData/diagnostics/tests/sealed/NestedSealed.fir.kt new file mode 100644 index 00000000000..a4b0fe5e47b --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NestedSealed.fir.kt @@ -0,0 +1,45 @@ +// See KT-10648: Exhaustiveness check does not work with nested sealed hierarchy +sealed class Base { + sealed class A : Base() { + class A1 : A() + class A2 : A() + } + sealed class B : Base() { + class B1 : B() + class B2 : B() + } +} + +fun foo(b: Base) = when (b) { + is Base.A -> when(b) { + is Base.A.A1 -> 1 + is Base.A.A2 -> 2 + } + is Base.B -> when(b) { + is Base.B.B1 -> 3 + is Base.B.B2 -> 4 + } +} + +fun bar(b: Base?) = if (b == null) 0 else when (b) { + is Base.A -> when(b) { + is Base.A.A1 -> 1 + is Base.A.A2 -> 2 + } + is Base.B -> when(b) { + is Base.B.B1 -> 3 + is Base.B.B2 -> 4 + } +} + +fun gav(b: Base?) = when (b) { + null -> 0 + is Base.A -> when(b) { + is Base.A.A1 -> 1 + is Base.A.A2 -> 2 + } + is Base.B -> when(b) { + is Base.B.B1 -> 3 + is Base.B.B2 -> 4 + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverConstructed.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverConstructed.fir.kt new file mode 100644 index 00000000000..b2093a68dc8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverConstructed.fir.kt @@ -0,0 +1,3 @@ +sealed class Base { + fun foo() = Base() +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverDerivedFromNested.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverDerivedFromNested.fir.kt new file mode 100644 index 00000000000..05adf4bfab5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverDerivedFromNested.fir.kt @@ -0,0 +1,9 @@ +class A { + sealed class Base +} + +class Derived : A.Base() + +fun test() { + class DerivedLocal : A.Base() +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverEnum.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverEnum.fir.kt new file mode 100644 index 00000000000..8317d7a4c34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverEnum.fir.kt @@ -0,0 +1,6 @@ +sealed enum class SealedEnum { + FIRST, + SECOND; + + class Derived: SealedEnum() +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverFinal.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverFinal.fir.kt new file mode 100644 index 00000000000..13fb5481e51 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverFinal.fir.kt @@ -0,0 +1,3 @@ +final sealed class Base { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/NeverInterface.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverInterface.fir.kt new file mode 100644 index 00000000000..d70b4d3f01b --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverInterface.fir.kt @@ -0,0 +1,3 @@ +sealed interface Base { + +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverObject.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverObject.fir.kt new file mode 100644 index 00000000000..7fb9dd4ce14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverObject.fir.kt @@ -0,0 +1,3 @@ +sealed object Sealed { + +} diff --git a/compiler/testData/diagnostics/tests/sealed/NeverOpen.fir.kt b/compiler/testData/diagnostics/tests/sealed/NeverOpen.fir.kt new file mode 100644 index 00000000000..34e4caa6ed7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NeverOpen.fir.kt @@ -0,0 +1,3 @@ +open sealed class Base { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhen.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhen.fir.kt new file mode 100644 index 00000000000..9c5be055bd6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhen.fir.kt @@ -0,0 +1,14 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.NonFirst -> 0 + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenNegated.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenNegated.fir.kt new file mode 100644 index 00000000000..77cbfbf26c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenNegated.fir.kt @@ -0,0 +1,14 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + !is Sealed.NonFirst -> 1 + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAdditionalCase.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAdditionalCase.fir.kt new file mode 100644 index 00000000000..e2d3b79c3c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAdditionalCase.fir.kt @@ -0,0 +1,22 @@ +sealed class Sealed(val x: Int) { + interface ITuple { + val x: Int + val y: Int + } + class Tuple(override val x: Int, override val y: Int): ITuple + object First: Sealed(12) + open class NonFirst(tuple: Tuple): Sealed(tuple.x), ITuple { + override val y: Int = tuple.y + object Second: NonFirst(Tuple(34, 2)) + class Third: NonFirst(Tuple(56, 3)) + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.First -> 1 + !is Sealed.ITuple -> 0 + // else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.fir.kt new file mode 100644 index 00000000000..e9e4eed0755 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NonExhaustiveWhenWithAnyCase.fir.kt @@ -0,0 +1,15 @@ +sealed class Sealed { + object First: Sealed() + open class NonFirst: Sealed() { + object Second: NonFirst() + object Third: NonFirst() + } +} + +fun foo(s: Sealed): Int { + return when(s) { + is Sealed.First -> 1 + !is Any -> 0 + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt new file mode 100644 index 00000000000..56541013112 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt @@ -0,0 +1,7 @@ +sealed class Sealed protected constructor(val x: Int) { + object FIRST : Sealed() + + public constructor(): this(42) + + constructor(y: Int, z: Int): this(y + z) +} diff --git a/compiler/testData/diagnostics/tests/sealed/NotFinal.fir.kt b/compiler/testData/diagnostics/tests/sealed/NotFinal.fir.kt new file mode 100644 index 00000000000..0cf7cf13a5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/NotFinal.fir.kt @@ -0,0 +1,10 @@ +// See KT-9244 + +sealed class Foo { + class Bar : Foo() + class Baz : Foo() +} + +// The following warning seems incorrect here +// "Foo is a final type, and thus a value of the type parameter is predetermined" +fun doit(arg: T): T = arg \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/OperationWhen.fir.kt b/compiler/testData/diagnostics/tests/sealed/OperationWhen.fir.kt new file mode 100644 index 00000000000..c45fa8412f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/OperationWhen.fir.kt @@ -0,0 +1,20 @@ +sealed class Operation(val left: Int, val right: Int) { + abstract fun exec(): Int + class Plus(left: Int, right: Int): Operation(left, right) { + override fun exec(): Int = left + right + } + class Minus(left: Int, right: Int): Operation(left, right) { + override fun exec(): Int = left - right + } + class Times(left: Int, right: Int): Operation(left, right) { + override fun exec(): Int = left * right + } + class Slash(left: Int, right: Int): Operation(left, right) { + override fun exec(): Int = left / right + } +} + +fun priority(op: Operation) = when(op) { + is Operation.Plus, is Operation.Minus -> 1 + is Operation.Times, is Operation.Slash -> 2 +} diff --git a/compiler/testData/diagnostics/tests/sealed/RedundantAbstract.fir.kt b/compiler/testData/diagnostics/tests/sealed/RedundantAbstract.fir.kt new file mode 100644 index 00000000000..4a90ee701d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/RedundantAbstract.fir.kt @@ -0,0 +1,3 @@ +abstract sealed class Base { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/TreeWhen.fir.kt b/compiler/testData/diagnostics/tests/sealed/TreeWhen.fir.kt new file mode 100644 index 00000000000..be3b48e407c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/TreeWhen.fir.kt @@ -0,0 +1,13 @@ +sealed class Tree { + object Empty: Tree() + class Leaf(val x: Int): Tree() + class Node(val left: Tree, val right: Tree): Tree() + + fun max(): Int { + when(this) { + is Empty -> return -1 + is Leaf -> return this.x + is Node -> return this.left.max() + } + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctional.fir.kt b/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctional.fir.kt new file mode 100644 index 00000000000..38c058814d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctional.fir.kt @@ -0,0 +1,11 @@ +sealed class Tree { + object Empty: Tree() + class Leaf(val x: Int): Tree() + class Node(val left: Tree, val right: Tree): Tree() + + fun max(): Int = when(this) { + is Empty -> -1 + is Leaf -> this.x + is Node -> this.left.max() + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctionalNoIs.fir.kt b/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctionalNoIs.fir.kt new file mode 100644 index 00000000000..c2d43bfb3cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/TreeWhenFunctionalNoIs.fir.kt @@ -0,0 +1,23 @@ +sealed class Tree { + object Empty: Tree() + class Leaf(val x: Int): Tree() + class Node(val left: Tree, val right: Tree): Tree() + + fun max(): Int = when(this) { + Empty -> -1 + is Leaf -> this.x + is Node -> this.left.max() + } + + fun maxIsClass(): Int = when(this) { + Empty -> -1 + Leaf -> 0 + is Node -> this.left.max() + } + + fun maxWithElse(): Int = when(this) { + is Leaf -> this.x + is Node -> this.left.max() + else -> -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/WhenOnEmptySealed.fir.kt b/compiler/testData/diagnostics/tests/sealed/WhenOnEmptySealed.fir.kt new file mode 100644 index 00000000000..9271a1b4474 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/WhenOnEmptySealed.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +sealed class Sealed { + +} + +fun foo(s: Sealed): Int { + return when(s) { + // We do not return anything, so else branch must be here + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/WithInterface.fir.kt b/compiler/testData/diagnostics/tests/sealed/WithInterface.fir.kt new file mode 100644 index 00000000000..d1b2b3641d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/WithInterface.fir.kt @@ -0,0 +1,10 @@ +interface Parent +interface Child : Parent + +sealed class Page : Parent { + object One : Page(), Child + object Two : Page(), Child +} + +// Ok: page is a Parent so it can be easily a Child +fun test(page: Page): Boolean = page is Child diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/argumentsResolveInBodyAndDelegationCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/argumentsResolveInBodyAndDelegationCall.fir.kt new file mode 100644 index 00000000000..b7444d2bdaf --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/argumentsResolveInBodyAndDelegationCall.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(open val parentProp: Int) +val global: Int = 1 +class A : B { + val myProp: Int = 1 + override val parentProp = 1 + + constructor(x: Int, y: Int = global): super(x + y + global) { + foo(x, y, myProp) + x + y + myProp + parentProp + super.parentProp + } + constructor(x: Double, y: Int): this(x.toInt() + y, x.toInt() * y) { + foo(x.toInt(), y, myProp) + x + y + myProp + parentProp + super.parentProp + } + constructor(x: String, y: Int): super(x) { + foo(x, y, myProp) + x + y + myProp + parentProp + super.parentProp + } + constructor(x: B, y: Int = global2): this("", x) { + x.parentProp + y + myProp + parentProp + super.parentProp + } + + fun foo(x: Int, y: Int, z: Int) = x +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/classInitializersWithoutPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/classInitializersWithoutPrimary.fir.kt new file mode 100644 index 00000000000..30c8fe5f432 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/classInitializersWithoutPrimary.fir.kt @@ -0,0 +1,4 @@ +class A { + constructor() + init {} +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/companionObjectScope.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/companionObjectScope.fir.kt new file mode 100644 index 00000000000..4c912288c9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/companionObjectScope.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + companion object { + fun foo(): Int = 1 + val prop = 2 + val C = 3 + } + object B { + fun bar(): Int = 4 + val prop = 5 + } + object C { + } + + constructor(x: Int) + constructor() : this(foo() + prop + B.bar() + B.prop + C) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.fir.kt new file mode 100644 index 00000000000..84046fb59e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.fir.kt @@ -0,0 +1,28 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// NI_EXPECTED_FILE +class A(x: Int) { + constructor(x: Double): this(1) + constructor(x: String): this(1) +} +val x1: A = A(1) +val x2: A = A(1.0) +val x3: A = A("abc") + +class B { + constructor(x: String) + constructor(x: R) +} + +val y1: B = B(1) +val y2: B = B("") +val y3: B = B(1) +val y4: B = B("") + +val y5: B = B(1) +val y6: B = B("") +val y7: B = B(1) +val y8: B = B("") + +val y9 = B(1) +val y10 = B("") diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt new file mode 100644 index 00000000000..6ed018c439c --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt @@ -0,0 +1,20 @@ +object A { + constructor() + init {} +} + +enum class B { + X() { + constructor() + } +} + +class C { + companion object { + constructor() + } +} + +val anonObject = object { + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt new file mode 100644 index 00000000000..08d09a765ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt @@ -0,0 +1,3 @@ +interface A { + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/ctrsAnnotationResolve.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/ctrsAnnotationResolve.fir.kt new file mode 100644 index 00000000000..126437ad8ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/ctrsAnnotationResolve.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +annotation class Ann1 +annotation class Ann2(val x: Int) + +class A { + @Ann1 + constructor() + @Ann2 + constructor(x1: Int) + @Ann2(2) + constructor(x1: Int, x2: Int) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt new file mode 100644 index 00000000000..f96d9d0191b --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A1 { + constructor(): this() +} + +class A2(x: Byte) { + constructor(x1: Int): this(x1, 1) + constructor(x1: Int, x2: Int): this(x1, x2, 2) + constructor(x1: Int, x2: Int, x3: Int): this(x1) + + // delegating to previously declared cycle + constructor(x1: Double): this(1) + + + // delegating to cycle declared after + constructor(x1: String): this(1L) + + constructor(x1: Long): this(x1, 1L) + constructor(x1: Long, x2: Long): this(x1, x2, 2L) + constructor(x1: Long, x2: Long, x3: Long): this(x1) + + // no cycle, just call to primary constuctor + constructor(x1: Double, x2: Double): this(x1, x2, 1.0) + constructor(x1: Double, x2: Double, x3: Double): this(x1, x2, x3, 1.0) + constructor(x1: Double, x2: Double, x3: Double, x4: Double): this(1.toByte()) + + constructor(): this("x", "y") + + constructor(x1: String, x2: String): this(x1, x2, "") + constructor(x1: String, x2: String, x3: String): this(x1, x2) +} + +open class B(x: Byte) +class A : B { + // no cycle, just call to super constuctor + constructor(x1: Double, x2: Double): this(x1, x2, 1.0) + constructor(x1: Double, x2: Double, x3: Double): this(x1, x2, x3, 1.0) + constructor(x1: Double, x2: Double, x3: Double, x4: Double): super(1.toByte()) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/dataClasses.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/dataClasses.fir.kt new file mode 100644 index 00000000000..5c47d816dbc --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/dataClasses.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A1(val x: String) { + constructor(): this("") +} + +data class A2(val y: String, val z: Int) { + constructor(x: String): this(x, 0) +} + +data class A3 { + constructor() +} + +data class A4 internal constructor() diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/dataFlowInDelegationCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/dataFlowInDelegationCall.fir.kt new file mode 100644 index 00000000000..e49226fe865 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/dataFlowInDelegationCall.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + constructor(x: Any, y: Any, z: Any) + constructor(x: String?, y: String?): this(x!!, x.length.toString() + y!!, "") { + x.length + y.length + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/delegationByWithoutPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/delegationByWithoutPrimary.fir.kt new file mode 100644 index 00000000000..6058e862c1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/delegationByWithoutPrimary.fir.kt @@ -0,0 +1,6 @@ +interface A +class AImpl : A + +class B : A by AImpl() { + constructor() +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/enums.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/enums.fir.kt new file mode 100644 index 00000000000..b8e60603d80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/enums.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +enum class A { + W(1), X(1, 2), Y(3.0), Z(""), E(); + + constructor() + constructor(x: Int) + constructor(x: Int, y: Int): this(x+y) + constructor(x: Double): this(x.toInt(), 1) + constructor(x: String): super(x, 1) +} + +enum class B(x: Int) { + W(1), X(1, 2), Y(3.0), Z(""); + + constructor(x: Int, y: Int): this(x+y) + constructor(x: Double): this(x.toInt(), 1) + constructor(x: String): super(x, 1) +} + +enum class C { + EMPTY(); // may be we should avoid explicit call here + constructor() +} + +enum class D(val prop: Int) { + X(123) { + override fun f() = 1 + }, + Y() { + override fun f() = prop + }, + Z("abc") { + override fun f() = prop + }; + + constructor(): this(1) + constructor(x: String): this(x.length) + + abstract fun f(): Int +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.fir.kt new file mode 100644 index 00000000000..f3baa777222 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B0(x: Int) + +class A0 : B0 { + constructor() + constructor(x: Int) : super() +} + +// -------------------------- + +open class B1 { + constructor(x: Int = 1) + constructor() +} + +class A1 : B1 { + constructor() + constructor(x: Int) : super() +} + +// -------------------------- + +open class B2 { + constructor(x: Int) + constructor(x: String) +} + +class A2 : B2 { + constructor() + constructor(x: Int) : super() +} + +// -------------------------- + +open class B3 { + private constructor() +} + +class A3 : B3 { + constructor() + constructor(x: Int) : super() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.fir.kt new file mode 100644 index 00000000000..71ffad646e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A(x: Int) { + constructor() +} +open class B(x: Int) +class C(x: Int) : B(x) { + constructor(): super(1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt new file mode 100644 index 00000000000..8dc957d4d5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE +open class B(x: T, y: T) { + constructor(x: T): this(x, x) + constructor(): this(null!!, null!!) +} + +class A0 : B { + constructor() + constructor(x: String): super(x) + constructor(x: String, y: String): super(x, y) +} + +class A1 : B { + constructor() + constructor(x: R): super(x) + constructor(x: R, y: R): super(x, y) +} + +class A2 { + constructor(t: R, i: Int) : this(i, 1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt new file mode 100644 index 00000000000..e39d3bb67b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +open class B(x: R1, y: R2) + +class A0 { + constructor(x: T1, y: T2): this(x, y) + + constructor(x: T1, y: T2, z: T2): this(x, 1) // ok, delegates to constructor(x: T1, y: Int) + + constructor(x: T1, y: Int): this(x, "") + constructor(x: T1): this(x, 1) + constructor(x: T1, y: T2, z: String): this(y, x) +} + +class A1 : B { + constructor(x: T1, y: T2): super(x, y) + constructor(x: T1, y: Int): super(x, y) + constructor(x: T1, y: T1, z: T1): super(x, y) +} + +class A2 : B { + constructor(x: T1, y: T2): super(x, y) + constructor(x: T1, y: Int): super(x, y) + constructor(x: T1, y: T1, z: T1): super(x, y) + constructor(x: T1, y: T2, z: String): super(y, 1) +} + diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/generics3.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/generics3.fir.kt new file mode 100644 index 00000000000..d5466da6c22 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/generics3.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B { + constructor(x: X, y: Y) + constructor(x: X, s: String) + constructor(y: Y, i: Int) : this(y, "") +} + +class A : B { + constructor(x: T1, y: T2): super(x, y) + constructor(x: T2, y: T2, z: String): super(x, y) + + constructor(x: T2, z: String, z1: String): super(x, "") + constructor(x: T2, z: String, z1: String, z2: String): super(x, 1) + constructor(x: T1, z: String, z1: String, z2: String, z3: String): super(x, "") + constructor(x: T1, z: String, z1: String, z2: String, z3: String, z4: String): super(x, 1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt new file mode 100644 index 00000000000..2153e3f94e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Base(p: Any?) { + fun foo1(t: T) {} +} + +class D: Base("") { + inner class B : Base { + constructor() : super(foo1("")) + constructor(x: Int) : super(foo1(1)) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt new file mode 100644 index 00000000000..f16da07a325 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Base(p: Any?) { + fun foo1(t: T) {} +} + +class D: Base(1) { + inner class B : Base { + constructor() : super(foo1(1)) + constructor(x: Int) : super(this@B.foo1(1)) + constructor(x: Int, y: Int) : super(this@D.foo1(1)) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt new file mode 100644 index 00000000000..ba8a1560feb --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class Base(p: Any?) { + fun foo1() {} +} + +fun Base.foo() { + class B : Base { + constructor() : super(foo1()) + constructor(x: Int) : super(this@foo.foo1()) + constructor(x: Int, y: Int) : super(this@B.foo1()) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt new file mode 100644 index 00000000000..d0f53ae4f08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class Base(p: Any?) { + fun foo1(t: T) {} +} + +fun Base.foo() { + class B : Base { + constructor() : super(foo1("")) + constructor(x: Int) : super(foo1(1)) + constructor(x: Int, y: Int) : super(this@foo.foo1(12)) + constructor(x: Int, y: Int, z: Int) : super(this@B.foo1("")) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt new file mode 100644 index 00000000000..76c24c1b31d --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(x: Outer) = 1 +class Outer { + inner class Inner { + val prop = 1 + } + + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + Inner().prop + this.Inner().prop) : + this(x + Inner().prop + this.Inner().prop) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt new file mode 100644 index 00000000000..1a01acc6fb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun A.foobar() = 3 + +class A { + fun foo() = 1 + constructor(x: () -> Int) + constructor() : this( + { + foo() + + this.foo() + + this@A.foo() + + foobar() + }) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt new file mode 100644 index 00000000000..f67d2a5ec49 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + fun foo() = 1 + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + foo() + this.foo()) : + this(x + foo() + this.foo()) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt new file mode 100644 index 00000000000..dd0522dc156 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun A.foobar() = 3 + +class A { + fun foo() = 1 + constructor(x: Any?) + constructor() : this(object { + fun bar() = foo() + this@A.foo() + + foobar() + super@A.hashCode() + }) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt new file mode 100644 index 00000000000..3c312d74e40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun A.foobar() = 3 + +class A { + fun foo() = 1 + constructor( x: Any = object { + fun bar() = foo() + this@A.foo() + + foobar() + }) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt new file mode 100644 index 00000000000..4fe0347386c --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt @@ -0,0 +1,13 @@ +open class C(val x: Int) + +class D : C { + constructor() : super( + { + val s = "" + s() + ""() + 42 + }()) + + operator fun String.invoke() { } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt new file mode 100644 index 00000000000..8fe392bd885 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(x: A) = 1 + +class A { + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + foo(this) + foo(this@A)) : + this(x + foo(this) + foo(this@A)) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt new file mode 100644 index 00000000000..73c5b28e651 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + val prop = 1 + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + prop + this.prop) : + this(x + prop + this.prop) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt new file mode 100644 index 00000000000..d6b566fc562 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Int) +class A : B { + val prop = 1 + constructor(x: Int, y: Int = x + prop + this.prop) : + super(x + prop + this.prop) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt new file mode 100644 index 00000000000..ba91b894ba4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Int) { + fun foo() = 1 +} +class A : B { + constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : + super(x + foo() + this.foo() + super.foo()) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt new file mode 100644 index 00000000000..3e7a6494ba1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Int) { + open fun foo() = 1 +} +class A : B { + override fun foo() = 2 + constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : + super(x + foo() + this.foo() + super.foo()) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt new file mode 100644 index 00000000000..9c5d9ee7b9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(val prop: Int) +class A : B { + constructor(x: Int, y: Int = x + prop + this.prop + super.prop) : + super(x + prop + this.prop + super.prop) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt new file mode 100644 index 00000000000..67d31be0d8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun A.foobar() = 1 +val A.prop: Int get() = 2 + +class A { + constructor(x: Int) + constructor() : this( + foobar() + + this.foobar() + + prop + + this.prop + + this@A.prop + ) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterInstance.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterInstance.fir.kt new file mode 100644 index 00000000000..2ae3abd1d32 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterInstance.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(x: Outer) = 1 +class Outer { + inner class Inner { + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + foo(this@Outer)) : this(x + foo(this@Outer)) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterProperty.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterProperty.fir.kt new file mode 100644 index 00000000000..f429be3cf36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/usingOuterProperty.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class Outer { + val prop = 1 + inner class Inner { + constructor(x: Int) + constructor(x: Int, y: Int, z: Int = x + prop + this@Outer.prop) : this(x + prop + this@Outer.prop) + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt new file mode 100644 index 00000000000..eb42f37c72a --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Int) +class A : B(1) { + constructor(): super(1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt new file mode 100644 index 00000000000..479505b025f --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class A(p1: String) + +class B() : A("") { + constructor(s: String) { + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/initializationFromOtherInstance.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/initializationFromOtherInstance.fir.kt new file mode 100644 index 00000000000..783a39e61ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/initializationFromOtherInstance.fir.kt @@ -0,0 +1,15 @@ +class A { + val x: Int + val y: Int + constructor(x: Int, y: Int) { + this.x = x + this.y = y + } + constructor(other: A) { + x = other.x + y = other.y + } +} +class A1(val x: Int, val y: Int) { + constructor(other: A1): this(other.x, other.y) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt new file mode 100644 index 00000000000..e97067195db --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt @@ -0,0 +1,3 @@ +class X(val t: T) { + constructor(t: String): this(t) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.fir.kt new file mode 100644 index 00000000000..9b32c097368 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6993.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +class X(val t: T) { + constructor(t: T, i: Int) : this(i) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt new file mode 100644 index 00000000000..f7e886bc963 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class X { + constructor(t: T, i: Int): this(i, 1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/lambdaInDelegation.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/lambdaInDelegation.fir.kt new file mode 100644 index 00000000000..c89b547890c --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/lambdaInDelegation.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + constructor(block: (T1) -> T2) + constructor(x: T2): this({ x }) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt new file mode 100644 index 00000000000..a9321da314d --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.fir.kt @@ -0,0 +1,7 @@ +class A { + open inner class Inner + + class Nested : Inner { + constructor() + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/noDefaultIfEmptySecondary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/noDefaultIfEmptySecondary.fir.kt new file mode 100644 index 00000000000..8cacea8d87e --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/noDefaultIfEmptySecondary.fir.kt @@ -0,0 +1,4 @@ +// do not report generate empty synthetic constructor by primary as it leads to CONFLICTING_JVM_DECLARATIONS +class A(val x: Int = 1, val y: Int = 2) { + constructor(): this(0, 0) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/noPrimaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/noPrimaryConstructor.fir.kt new file mode 100644 index 00000000000..c2b72c83e13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/noPrimaryConstructor.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + constructor(x: Int) +} + +val x = A() diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/noSupertypeInitWithSecondaryConstructors.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/noSupertypeInitWithSecondaryConstructors.fir.kt new file mode 100644 index 00000000000..7b5fe15c5e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/noSupertypeInitWithSecondaryConstructors.fir.kt @@ -0,0 +1,6 @@ +open class B +interface C +interface D +class A : C, B, D { + constructor() +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithPrimary.fir.kt new file mode 100644 index 00000000000..81e856b0233 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithPrimary.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A(val w: Char) { + val x: Int + var y: Int + val z: Int + val v = -1 + + val uninitialized: Int + val overinitialized: Int + + constructor(): this('a') { + y = 1 + + overinitialized = 2 + uninitialized = 3 + } + + // anonymous + init { + x = 4 + z = 5 + overinitialized = 6 + } + + constructor(a: Int): this('b') { + y = 7 + } + + // anonymous + init { + y = 8 + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithoutPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithoutPrimary.fir.kt new file mode 100644 index 00000000000..b484ac7f7bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/propertyInitializationWithoutPrimary.fir.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + val x: Int + var y: Int + val z: Int + val v = -1 + + val uninitialized: Int + val overinitialized: Int + + constructor() { + x = 1 + y = 2 + + overinitialized = 3 + uninitialized = 4 + } + + constructor(a: Int): super() { + x = 5 + y = 6 + } + + constructor(x: String): this() { + y = 7 + uninitialized = 8 + } + + //anonymous + init { + z = 9 + overinitialized = 10 + } + + // anonymous + init { + y = 12 + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt new file mode 100644 index 00000000000..b4275c2bd23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A(x: String = "", y: String = "") { + constructor(x: String, y: String): this(x, y) + constructor(): this("", "") + constructor(): this("", "") +} + +class B { + constructor(x: Int) +} + +fun B(x: Int) {} + +class Outer { + class A(x: String = "", y: String = "") { + constructor(x: String, y: String): this(x, y) + constructor(): this("", "") + constructor(): this("", "") + } + + class B { + constructor(x: Int) + } + + fun B(x: Int) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.fir.kt new file mode 100644 index 00000000000..b5b147b0085 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.fir.kt @@ -0,0 +1,11 @@ +class A +class A { + constructor() +} + +class B +class Outer { + class B { + constructor() + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/reportResolutionErrorOnImplicitOnce.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/reportResolutionErrorOnImplicitOnce.fir.kt new file mode 100644 index 00000000000..85667e1cc22 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/reportResolutionErrorOnImplicitOnce.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class A(p1: String, p2: String, p3: String, p4: String, p5: String) + +class B : A { + constructor(s: String) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/resolvePropertyInitializerWithoutPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/resolvePropertyInitializerWithoutPrimary.fir.kt new file mode 100644 index 00000000000..c49f6814c5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/resolvePropertyInitializerWithoutPrimary.fir.kt @@ -0,0 +1,4 @@ +class A { + val prop: Int = "" + constructor() +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt new file mode 100644 index 00000000000..44f330699d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +class A { + init { + return + return 1 + } + constructor() { + if (1 == 1) { + return + return 1 + } + return + return foo() + } + + fun foo(): Int = 1 +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.fir.kt new file mode 100644 index 00000000000..28338060b30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + constructor(): super(1) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.fir.kt new file mode 100644 index 00000000000..76db3f69e6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Double) { + constructor(x: Int): this(1.0) + constructor(x: String): this(1.0) +} +interface C +class A : B, C { + constructor(): super(' ') + constructor(x: Int) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/thisNonExisting.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/thisNonExisting.fir.kt new file mode 100644 index 00000000000..38fda4d75df --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/thisNonExisting.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +class A { + constructor(x: Int) {} + constructor(x: String) {} + constructor(): this('a') {} +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/unreachableCode.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/unreachableCode.fir.kt new file mode 100644 index 00000000000..34d183bf40d --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/unreachableCode.fir.kt @@ -0,0 +1,38 @@ +class A0 { + val x: Int + constructor() { + if (1 == 1) { + return + } + x = 1 + } + constructor(arg: Int) { + x = arg + } +} + +class A1 { + val x: Int + constructor() { + if (1 == 1) { + return + } else null!! + x = 1 + } +} + +class A2 { + val x: Int + constructor() { + if (1 == 1) { + x = 1 + return + } + else { + x = 2 + } + } + constructor(arg: Int) { + x = arg + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithPrimary.fir.kt new file mode 100644 index 00000000000..17b476a0238 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithPrimary.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A(val w: Int) { + val x: Int + val useUnitialized = x + + y + + v + var y: Int + val v = -1 + val useInitialized = useUnitialized + v + w + + val uninitialized: Int + + constructor(): this(1) { + x + y + v + uninitialized + w + } + + // anonymous + init { + x + y + v + uninitialized + w + x = 1 + x + y + v + uninitialized + w + } + + // anonymous + init { + x + y + v + uninitialized + w + y = 7 + x + y + v + uninitialized + w + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithoutPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithoutPrimary.fir.kt new file mode 100644 index 00000000000..e99f7fa2722 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/useOfPropertiesWithoutPrimary.fir.kt @@ -0,0 +1,46 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + val x: Int + val useUnitialized = x + // reported on each secondary constructor + y + + v + var y: Int + val v = -1 + + val useInitialized = useUnitialized + v + + val uninitialized: Int + + constructor() { + x = 1 + y = 2 + + x + y + v + uninitialized + + uninitialized = 3 + + x + y + v + uninitialized + } + + constructor(a: Int): super() { + x + y + v + uninitialized + x = 4 + y = 5 + + x + y + v + uninitialized + } + + constructor(x: String): this() { + x + y + v + uninitialized + } + + //anonymous + init { + y + } + + // anonymous + init { + y = 9 + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/valOrValAndModifiersInCtr.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/valOrValAndModifiersInCtr.fir.kt new file mode 100644 index 00000000000..c922826f602 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/valOrValAndModifiersInCtr.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + constructor( + val x: Int, y: Int, + var z: Int, + public a: Int) +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToPrimary.fir.kt new file mode 100644 index 00000000000..8dd2ca4f47f --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToPrimary.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun array(vararg x: T): Array = null!! + +open class B(vararg y: String) { + constructor(x: Int): this(x.toString(), *array("1"), "2") +} + +class A : B { + constructor(x: String, y: String): super(x, *array("3"), y) + constructor(x: String): super(x) + constructor(): super() +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToSecondary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToSecondary.fir.kt new file mode 100644 index 00000000000..1baecabc09f --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/varargsInDelegationCallToSecondary.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun array(vararg x: T): Array = null!! + +open class B(x: Int) { + constructor(vararg y: String): this(y[0].length) +} + +class A : B { + constructor(x: String, y: String): super(x, *array("q"), y) + constructor(x: String): super(x) + constructor(): super() +} + +val b1 = B() +val b2 = B("1", "2", "3") +val b3 = B("1", *array("2", "3"), "4") +val b4 = B(1) diff --git a/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.fir.kt b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.fir.kt new file mode 100644 index 00000000000..db1e3857bcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.fir.kt @@ -0,0 +1,15 @@ +fun readLine() = "x" + +fun foo() { + var line = "" + + while (line != null) { + line = readLine() + + if (line != null) { + bar() + } + } +} + +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt b/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt new file mode 100644 index 00000000000..df6def7435a --- /dev/null +++ b/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt @@ -0,0 +1,23 @@ +fun testEquals(x: Int) { + if (x == null) {} + if (x == (null)) {} + if (x == foo@ null) {} +} + +fun testEqualsFlipped(x: Int) { + if (null == x) {} + if ((null) == x) {} + if (foo@ null == x) {} +} + +fun testNotEquals(x: Int) { + if (x != null) {} + if (x != (null)) {} + if (x != foo@ null) {} +} + +fun testNotEqualsFlipped(x: Int) { + if (null != x) {} + if ((null) != x) {} + if (foo@ null != x) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.fir.kt new file mode 100644 index 00000000000..611cba7c02b --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowLambdaParameter.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo1(i: (Int) -> Unit) {} +fun foo2(i: (Int, Int) -> Unit) {} +fun foo3(i: (Pair) -> Unit) {} + +fun bar(x: Int, y: Int) { + foo1 { x -> x } + foo2 { x: Int, y: Int -> x + y } + foo3 { (x, y) -> x + y } +} + +data class Pair(val a: Int, val b: Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowMultiDeclarationWithFunParameter.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowMultiDeclarationWithFunParameter.fir.kt new file mode 100644 index 00000000000..07545f7fd7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowMultiDeclarationWithFunParameter.fir.kt @@ -0,0 +1,14 @@ +class A { + operator fun component1() = 42 + operator fun component2() = 42 +} + +fun foo(a: A, c: Int) { + val (a, b) = a + val arr = Array(2) { A() } + for ((c, d) in arr) { + + } + + val e = a.toString() + b + c +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt new file mode 100644 index 00000000000..8b55c6d58ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInFunctionBody.fir.kt @@ -0,0 +1,4 @@ +fun f(p: Int): Int { + val p = 2 + return p +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt new file mode 100644 index 00000000000..1b2cec3f6e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.fir.kt @@ -0,0 +1,7 @@ +fun f(i: Int) { + for (j in 1..100) { + { + var i = 12 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInClosure.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInClosure.fir.kt new file mode 100644 index 00000000000..6490b74f72d --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInClosure.fir.kt @@ -0,0 +1,3 @@ +val i = 17 + +val f: () -> Int = { var i = 17; i } diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFor.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFor.fir.kt new file mode 100644 index 00000000000..e0d4766e89f --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFor.fir.kt @@ -0,0 +1,11 @@ +class RedefinePropertyInFor() { + + var i = 1 + + fun ff() { + for (i in 0..10) { + } + } + +} + diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFunction.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFunction.fir.kt new file mode 100644 index 00000000000..cacf415e65e --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowPropertyInFunction.fir.kt @@ -0,0 +1,10 @@ +class RedefinePropertyInFunction() { + + var i = 17 + + fun f(): Int { + var i = 18 + return i + } + +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInFor.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInFor.fir.kt new file mode 100644 index 00000000000..20a792522e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInFor.fir.kt @@ -0,0 +1,6 @@ +fun ff(): Int { + var i = 1 + for (i in 0..10) { + } + return i +} diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt new file mode 100644 index 00000000000..8346a2e57e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.fir.kt @@ -0,0 +1,7 @@ +fun ff(): Int { + var i = 1 + { + val i = 2 + } + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt new file mode 100644 index 00000000000..80db73b0a0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.fir.kt @@ -0,0 +1,5 @@ +fun f(): Int { + var i = 17 + { var i = 18 } + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.fir.kt b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.fir.kt new file mode 100644 index 00000000000..127cef7c3f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.fir.kt @@ -0,0 +1,5 @@ +fun ff(): Int { + var i = 1 + { i: Int -> i } + return i +} diff --git a/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.fir.kt b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.fir.kt new file mode 100644 index 00000000000..bb390470e40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/shadowing/noNameShadowingForSimpleParameters.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_ANONYMOUS_PARAMETER + +open class Base { + open fun foo(name: String) {} +} + +fun test1(name: String) { + class Local : Base() { + override fun foo(name: String) { + } + } +} + +fun test2(param: String) { + fun local(param: String) {} +} + +fun test3(param: String) { + fun local() { + fff { param -> } + } +} + +fun fff(x: (y: String) -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/afterBinaryExpr.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/afterBinaryExpr.fir.kt new file mode 100644 index 00000000000..5e3a87c5f02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/afterBinaryExpr.fir.kt @@ -0,0 +1,14 @@ +package o + +class A { + infix fun foo(b: B) = b +} + +class B { + fun bar() {} +} + +fun test(a: A, b: B?) { + a foo b!! + b.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt new file mode 100644 index 00000000000..bfd506229e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNull.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +fun foo(): String { + var s: String? + s = null + s?.length + s.length + if (s == null) return s!! + var t: String? = "y" + if (t == null) t = "x" + var x: Int? = null + if (x == null) x += null + return t + s +} + +fun String?.gav() {} + +fun bar(s: String?) { + if (s != null) return + s.gav() + s as? String + s as String? + s as String +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt new file mode 100644 index 00000000000..8e2f08fde2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/alwaysNullWithJava.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// FILE: My.java + +public class My { + static public My create() { return new My(); } + public void foo() {} +} + +// FILE: Test.kt + +fun test() { + val my = My.create() + if (my == null) { + my.foo() + } +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOff.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOff.fir.kt new file mode 100644 index 00000000000..f3c2e9eb6a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOff.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: -SafeCastCheckBoundSmartCasts + +interface SomeClass { + val data: Any? +} + +interface SomeSubClass : SomeClass { + val foo: Any? +} + +fun g(a: SomeClass?) { + if (a as? SomeSubClass != null) { + // 'a' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + (a as SomeSubClass).foo + } + val b = (a as? SomeSubClass)?.foo + if (b != null) { + // 'a' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + (a as SomeSubClass).foo + } + val c = a as? SomeSubClass + if (c != null) { + // 'a' and 'c' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + c.hashCode() + c.foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt new file mode 100644 index 00000000000..0f44fb8b2b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +SafeCastCheckBoundSmartCasts + +interface SomeClass { + val data: Any? +} + +interface SomeSubClass : SomeClass { + val foo: Any? +} + +fun g(a: SomeClass?) { + if (a as? SomeSubClass != null) { + // 'a' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + (a as SomeSubClass).foo + } + val b = (a as? SomeSubClass)?.foo + if (b != null) { + // 'a' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + (a as SomeSubClass).foo + } + val c = a as? SomeSubClass + if (c != null) { + // 'a' and 'c' can be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + c.hashCode() + c.foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/impossible.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/impossible.fir.kt new file mode 100644 index 00000000000..0650f50ccb1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/impossible.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +SafeCastCheckBoundSmartCasts +// See KT-20752 + +class Unstable { + val first: String? get() = null +} + +class StringList { + fun remove(s: String) = s +} + +fun StringList.remove(s: String?) = s ?: "" + +fun foo(list: StringList, arg: Unstable) { + list.remove(arg.first) + if (arg.first as? String != null) { + // Should be still resolved to extension, without smart cast or smart cast impossible + list.remove(arg.first) + } + val s = arg.first as? String + if (s != null) { + // Should be still resolved to extension, without smart cast or smart cast impossible + list.remove(arg.first) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/insideCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/insideCall.fir.kt new file mode 100644 index 00000000000..1ef1dbf1d94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/insideCall.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +SafeCastCheckBoundSmartCasts +// See KT-19007 + +// Stub +fun String.indexOf(arg: String) = this.length - arg.length + +// Stub +fun String.toLowerCase() = this + +fun foo(a: Any) { + // Should compile in 1.2 + (a as? String)?.indexOf(a.toLowerCase()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.fir.kt new file mode 100644 index 00000000000..5ec02b900d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +class Item(val link: String?) + +fun test(item: Item) { + if (item.link != null) { + val href: String = item.link + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt new file mode 100644 index 00000000000..ed43d37e403 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt @@ -0,0 +1,68 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +SafeCastCheckBoundSmartCasts +interface SomeClass { + val data: Any? +} + +interface SomeSubClass : SomeClass { + val foo: Any? +} + +object Impl : SomeSubClass { + override val data = "" + override val foo = 42 +} + +fun g(a: SomeClass?) { + var b = (a as? SomeSubClass)?.foo + b = "Hello" + if (b != null) { + // 'a' cannot be cast to SomeSubClass! + a.hashCode() + a.foo + (a as? SomeSubClass).foo + (a as SomeSubClass).foo + } + var c = a as? SomeSubClass + c = Impl + if (c != null) { + // 'a' cannot be cast to SomeSubClass + a.hashCode() + a.foo + (a as? SomeSubClass).foo + c.hashCode() + c.foo + } +} + +fun f(a: SomeClass?) { + var aa = a + + if (aa as? SomeSubClass != null) { + aa = null + // 'aa' cannot be cast to SomeSubClass + aa.hashCode() + aa.foo + (aa as? SomeSubClass).foo + (aa as SomeSubClass).foo + } + val b = (aa as? SomeSubClass)?.foo + aa = null + if (b != null) { + // 'aa' cannot be cast to SomeSubClass + aa.hashCode() + aa.foo + (aa as? SomeSubClass).foo + (aa as SomeSubClass).foo + } + aa = a + val c = aa as? SomeSubClass + if (c != null) { + // 'c' can be cast to SomeSubClass + aa.hashCode() + aa.foo + (aa as? SomeSubClass).foo + c.hashCode() + c.foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/classObjectMember.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/classObjectMember.fir.kt new file mode 100644 index 00000000000..179c6e4cb9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/classObjectMember.fir.kt @@ -0,0 +1,22 @@ +open class T { + val x : Int? = null +} + +class A { + companion object: T() { + } +} + +class B { + companion object: T() { + } +} + +fun test() { + if (A.x != null) { + useInt(A.x) + useInt(B.x) + } +} + +fun useInt(i: Int) = i \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.fir.kt new file mode 100644 index 00000000000..75dad0ee21b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.fir.kt @@ -0,0 +1,13 @@ +package foo + +fun dispatch(request: Request) { + val url = request.getRequestURI() as String + + if (request.getMethod()?.length != 0) { + } +} + +interface Request { + fun getRequestURI(): String? + fun getMethod(): String? +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.fir.kt new file mode 100644 index 00000000000..bd37527174d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/comparisonUnderAnd.fir.kt @@ -0,0 +1,39 @@ +// !WITH_NEW_INFERENCE +fun foo(x : String?, y : String?) { + if (y != null && x == y) { + // Both not null + x.length + y.length + } + else { + x.length + y.length + } + if (y != null || x == y) { + x.length + y.length + } + else { + // y == null but x != y + x.length + y.length + } + if (y == null && x != y) { + // y == null but x != y + x.length + y.length + } + else { + x.length + y.length + } + if (y == null || x != y) { + x.length + y.length + } + else { + // Both not null + x.length + y.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/complexComparison.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/complexComparison.fir.kt new file mode 100644 index 00000000000..99865dcca58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/complexComparison.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +fun foo(x: String?, y: String?, z: String?, w: String?) { + if (x != null && y != null && (x == z || y == z)) + z.length + else + z.length + if (x != null || y != null || (x != z && y != z)) + z.length + else + z.length + if (x == null || y == null || (x != z && y != z)) + z.length + else + z.length + if (x != null && y == x && z == y && w == z) + w.length + else + w.length + if ((x != null && y == x) || (z != null && y == z)) + y.length + else + y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.fir.kt new file mode 100644 index 00000000000..9ae92c920f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.fir.kt @@ -0,0 +1,55 @@ +fun foo(x: String?, y: String?, z: String?) { + if ((x!!.hashCode() == 0 || y!!.hashCode() == 1) && z!!.hashCode() == 2) { + x.length + y.length + // condition is true => z!! after and is called + z.length + } + else { + x.length + y.length + z.length + } + // First element is always analyzed + x.length + var xx = y ?: z + if ((xx!!.hashCode() == 0 && y!!.hashCode() == 1) || z!!.hashCode() == 2) { + xx.length + y.length + z.length + } + else { + xx.length + y.length + // condition is false => z!! after or is called + z.length + } + // First element is always analyzed + x.length + xx = y ?: z + if (xx!!.hashCode() == 0 && y!!.hashCode() == 1 && z!!.hashCode() == 2) { + // all three are called + xx.length + y.length + z.length + } + else { + xx.length + y.length + z.length + } + // First element is always analyzed + x.length + xx = y ?: z + if (xx!!.hashCode() == 0 || y!!.hashCode() == 1 || z!!.hashCode() == 2) { + xx.length + y.length + z.length + } + else { + // all three are called + xx.length + y.length + z.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.fir.kt new file mode 100644 index 00000000000..ecd89d2641a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.fir.kt @@ -0,0 +1,7 @@ +package aaa + +fun bar(a: Int, b: Int) {} + +fun foo(a: Int?) { + bar(a!!, a) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/doubleLambdaArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/doubleLambdaArgument.fir.kt new file mode 100644 index 00000000000..b889bb2c9b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/doubleLambdaArgument.fir.kt @@ -0,0 +1,10 @@ +interface Foo +fun foo(): Foo? = null + +val foo: Foo = run { + run { + val x = foo() + if (x == null) throw Exception() + x + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOff.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOff.fir.kt new file mode 100644 index 00000000000..e8d3d7a6e55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOff.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: -BooleanElvisBoundSmartCasts + +interface Order { + val expired: Boolean? + + fun notExpired(): Boolean + + fun doSomething() +} + +fun foo(o: Any) { + val order = o as? Order + if (order?.expired ?: false) { + order.doSomething() + } + else { + + } + if (order?.notExpired() ?: false) { + order.doSomething() + } +} + +fun bar(o: Any) { + val order = o as? Order + if (order?.expired ?: true) { + + } + else { + order!!.doSomething() + } + if (order?.notExpired() ?: true) { + + } + else { + order!!.doSomething() + } +} + +fun baz(o: Boolean?) { + if (o ?: false) { + o.hashCode() + } + if (o ?: true) { + + } + else { + o.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt new file mode 100644 index 00000000000..b1b04eac84d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis/basicOn.fir.kt @@ -0,0 +1,50 @@ +// !LANGUAGE: +BooleanElvisBoundSmartCasts + +interface Order { + val expired: Boolean? + + fun notExpired(): Boolean + + fun doSomething() +} + +fun foo(o: Any) { + val order = o as? Order + if (order?.expired ?: false) { + order.doSomething() + } + else { + + } + if (order?.notExpired() ?: false) { + order.doSomething() + } +} + +fun bar(o: Any) { + val order = o as? Order + if (order?.expired ?: true) { + + } + else { + order!!.doSomething() + } + if (order?.notExpired() ?: true) { + + } + else { + order!!.doSomething() + } +} + +fun baz(o: Boolean?) { + if (o ?: false) { + o.hashCode() + } + if (o ?: true) { + + } + else { + o.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.fir.kt new file mode 100644 index 00000000000..cbce948f70f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.fir.kt @@ -0,0 +1,41 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +BooleanElvisBoundSmartCasts +// See KT-20752 + +class Unstable { + val first: String? get() = null +} + +class StringList { + fun remove(s: String) = s +} + +fun StringList.remove(s: String?) = s ?: "" + +fun String.isEmpty() = this == "" + +fun foo(list: StringList, arg: Unstable) { + list.remove(arg.first) + if (arg.first?.isEmpty() ?: false) { + // Should be still resolved to extension, without smart cast or smart cast impossible + list.remove(arg.first) + } +} + +class UnstableBoolean { + val first: Boolean? get() = null +} + +class BooleanList { + fun remove(b: Boolean) = b +} + +fun BooleanList.remove(b: Boolean?) = b ?: false + +fun bar(list: BooleanList, arg: UnstableBoolean) { + list.remove(arg.first) + if (arg.first ?: false) { + // Should be still resolved to extension, without smart cast or smart cast impossible + list.remove(arg.first) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisExclExcl.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExcl.fir.kt new file mode 100644 index 00000000000..1b9e8c144a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExcl.fir.kt @@ -0,0 +1,9 @@ +// Based on KT-9100 +fun test(x: Any?, y: Any?): Any { + val z = x ?: y!! + y.hashCode() + // !! / ?. is necessary here, because y!! above may not be executed + y?.hashCode() + y!!.hashCode() + return z +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclMerge.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclMerge.fir.kt new file mode 100644 index 00000000000..c23b235a6fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclMerge.fir.kt @@ -0,0 +1,6 @@ +fun test(x: Any?): Any { + val z = x ?: x!! + // x is not null in both branches + x.hashCode() + return z +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclPlatform.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclPlatform.fir.kt new file mode 100644 index 00000000000..52d8720b9af --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisExclExclPlatform.fir.kt @@ -0,0 +1,27 @@ +// FILE: p/My.java + +package p; + +import org.jetbrains.annotations.*; + +class My { + @Nullable static String create() { + return ""; + } +} + +// FILE: test.kt + +package p + +fun bar(x: String) = x + +fun test(x: String?): Any { + val y = My.create() + val z = x ?: y!! + bar(y) + // !! / ?. is necessary here, because y!! above may not be executed + y?.hashCode() + y!!.hashCode() + return z +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisExprNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisExprNotNull.fir.kt new file mode 100644 index 00000000000..4a86b04553d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisExprNotNull.fir.kt @@ -0,0 +1,37 @@ +// !WITH_NEW_INFERENCE +fun foo(s: Any?): String { + val t = when { + // To resolve: String U Nothing? = String? + s is String -> s + else -> null + } ?: "" + return t +} + +fun bar(s: Any?): String { + // To resolve: String U Nothing? = String? + val t = (if (s == null) { + null + } + else { + val u: Any? = null + if (u !is String) return "" + u + }) ?: "xyz" + // Ideally we should have smart cast to String here + return t +} + +fun baz(s: String?, r: String?): String { + val t = r ?: when { + s != null -> s + else -> "" + } + return t +} + +fun withNull(s: String?): String { + val t = s ?: null + // Error: nullable + return t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.fir.kt new file mode 100644 index 00000000000..646d4e00d2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.fir.kt @@ -0,0 +1,11 @@ +class C { + fun foo() {} +} + +fun test(a: C?, nn: () -> Nothing?) { + a ?: nn() + a.foo() + + a ?: return + a.foo() +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.fir.kt new file mode 100644 index 00000000000..946c75ff9cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// KT-5335 + +fun foo(p1: String?, p2: String?) { + if (p2 != null) { + val v = p1 ?: p2 + val size = v.length + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_after.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_after.fir.kt new file mode 100644 index 00000000000..e85df63e2f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_after.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +SoundSmartcastForEnumEntries +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +enum class Message(val text: String?) { + HELLO("hello"), + WORLD("world"), + NOTHING(null) +} + +fun printMessages() { + Message.HELLO.text!! + Message.HELLO.text.length + + Message.NOTHING.text.length + + Message.NOTHING.text!! + Message.NOTHING.text.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.fir.kt new file mode 100644 index 00000000000..85e9d6542f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -SoundSmartcastForEnumEntries +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +enum class Message(val text: String?) { + HELLO("hello"), + WORLD("world"), + NOTHING(null) +} + +fun printMessages() { + Message.HELLO.text!! + Message.HELLO.text.length + + Message.NOTHING.text.length + + Message.NOTHING.text!! + Message.NOTHING.text.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt new file mode 100644 index 00000000000..1de64d0d3b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/equals.fir.kt @@ -0,0 +1,25 @@ +fun foo(x: String?) = x + +class Test + +class TestWithEquals { + override fun equals(other: Any?) = super.equals(other) +} + +fun bar(i: Test?) { + if (i == null) foo(i) +} + +fun bar(i: TestWithEquals?) { + if (i == null) foo(i) + if (null == i) foo(i) + when (i) { + null -> foo(i) + } +} + +fun gav(i: TestWithEquals?, j: TestWithEquals?) { + if (j == null) { + if (i == j) foo(i) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/exclUnderAnd.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/exclUnderAnd.fir.kt new file mode 100644 index 00000000000..8b32be493ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/exclUnderAnd.fir.kt @@ -0,0 +1,13 @@ +class D(val a: String, val b: Boolean) + +fun foo(p: Boolean, v: D?): String { + if (p && v!!.b) v.a + else v.a + if (p && v!! == D("?", false)) v.a + else v.a + if (p || v!!.b) v.a + else v.a + if (p || v!! == D("?", false)) v.a + else v.a + return "" +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/explicitDefaultGetter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/explicitDefaultGetter.fir.kt new file mode 100644 index 00000000000..9b688c538ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/explicitDefaultGetter.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +class ExplicitAccessorForAnnotation { + val tt: String? = "good" + get + + fun foo(): String { + if (tt is String) { + return tt + } + return "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/extensionSafeCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/extensionSafeCall.fir.kt new file mode 100644 index 00000000000..36e4758349e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/extensionSafeCall.fir.kt @@ -0,0 +1,13 @@ +class Your + +fun Your.foo() = Any() + +fun T?.let(f: (T) -> Unit) { + if (this != null) f(this) +} + +fun test(your: Your?) { + (your?.foo() as? Any)?.let {} + // strange smart cast to 'Your' at this point + your.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/fakeSmartCastOnEquality.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/fakeSmartCastOnEquality.fir.kt new file mode 100644 index 00000000000..63e29c46afd --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/fakeSmartCastOnEquality.fir.kt @@ -0,0 +1,95 @@ +abstract class Base { + override fun equals(other: Any?) = other is Base +} + +class Derived1 : Base() { + fun foo() {} +} + +class Derived2 : Base() + +fun check(x1: Derived1, x: Base) { + if (x1 == x) { + // Smart cast here will provoke CCA + x.foo() + } + if (x1 === x) { + // OK + x.foo() + } + if (x1 !== x) {} else { + // OK + x.foo() + } +} + +class FinalClass { // <-- 'equals' on instances of this class is useful for smart casts + fun use() {} + + fun equals(x: Int): Boolean = x > 42 +} + +fun foo(x: FinalClass?, y: Any) { + if (x == y) { + // OK + x.hashCode() + // OK + y.use() + } + when (x) { + // OK (equals from FinalClass) + y -> y.use() + } + when (y) { + // ERROR (equals from Any) + x -> y.use() + } +} + +open class OpenClass { + override fun equals(other: Any?) = other is OpenClass +} + +interface Dummy // should not influence anything + +class FinalClass2 : Dummy, OpenClass() { // but here not + fun use() {} +} + +fun bar(x: FinalClass2?, y: Any) { + if (x == y) { + // OK + x.hashCode() + // ERROR + y.use() + } +} + +open class OpenClass2 // and here too + +fun bar(x: OpenClass2?, y: Any) { + if (x == y) { + // OK + x.hashCode() + // ERROR + y.use() + } +} + +sealed class Sealed { + override fun equals(other: Any?) = other is Sealed + + class Sealed1 : Sealed() { + fun gav() {} + } + + object Sealed2 : Sealed() + + fun check(arg: Sealed1) { + if (arg == this) { + // Smart cast here will provoke CCA + this.gav() + gav() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/falseReceiverSmartCast.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/falseReceiverSmartCast.fir.kt new file mode 100644 index 00000000000..2f6711d7a70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/falseReceiverSmartCast.fir.kt @@ -0,0 +1,15 @@ +open class SuperFoo { + public fun bar(): String { + if (this is Foo) { + superFoo() + return baz() + } + return baz() + } + + public fun baz() = "OK" +} + +class Foo : SuperFoo() { + public fun superFoo() {} +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/falseUnnecessaryCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/falseUnnecessaryCall.fir.kt new file mode 100644 index 00000000000..90df45ae42b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/falseUnnecessaryCall.fir.kt @@ -0,0 +1,11 @@ +// See KT-10276 + +class Bar() { + var test: String? = null + fun foo() { + if (test != null) { + // No warning: test is a mutable property + test?.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.fir.kt new file mode 100644 index 00000000000..af571c2a743 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNNECESSARY_NOT_NULL_ASSERTION +// See KT-9126: Variable change does not affect data flow info for its fields + +class My(val x: Int?) + +fun foo() { + var y: My? = My(42) + if (y!!.x != null) { + y = My(null) + y!!.x.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/fieldInGetter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/fieldInGetter.fir.kt new file mode 100644 index 00000000000..98cc0be686a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/fieldInGetter.fir.kt @@ -0,0 +1,5 @@ +val x: Int? = 0 + get() { + if (field != null) return field.hashCode() + return null + } diff --git a/compiler/testData/diagnostics/tests/smartCasts/fieldPlus.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/fieldPlus.fir.kt new file mode 100644 index 00000000000..ee986476817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/fieldPlus.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNNECESSARY_NOT_NULL_ASSERTION +// Advancement of KT-9126 + +class My(val x: Int?) { + operator fun plus(y: My) = if (this.x != null) this else y +} + +fun foo() { + var y: My? = My(42) + if (y!!.x != null) { + y = My(null) + (y + My(0)).x.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.fir.kt new file mode 100644 index 00000000000..9dae20755e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.fir.kt @@ -0,0 +1,7 @@ +// See also KT-7801 +class A + +fun test(v: T): T { + val a: T = if (v !is A) v else v + return a +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/genericSet.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/genericSet.fir.kt new file mode 100644 index 00000000000..349daeb25a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/genericSet.fir.kt @@ -0,0 +1,7 @@ +class Wrapper(var x: T) + +inline fun change(w: Wrapper, x: Any?) { + if (x is T) { + w.x = x + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/ifCascadeExprNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ifCascadeExprNotNull.fir.kt new file mode 100644 index 00000000000..563e1c1bf03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ifCascadeExprNotNull.fir.kt @@ -0,0 +1,14 @@ +fun baz(s: String?): String { + val t = if (s == null) { + "" + } + else if (s == "") { + val u: String? = null + if (u == null) return "" + u + } + else { + s + } + return t +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/ifExprInConditionNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ifExprInConditionNonNull.fir.kt new file mode 100644 index 00000000000..10a55ca5ab2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ifExprInConditionNonNull.fir.kt @@ -0,0 +1,11 @@ +fun baz(s: String?, b: Boolean?): String { + val t = if (if (b == null) return "" else b) { + if (s == null) return "" + s + } + else { + if (s != null) return s + "" + } + return t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/ifExprInWhenSubjectNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ifExprInWhenSubjectNonNull.fir.kt new file mode 100644 index 00000000000..946abe223a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ifExprInWhenSubjectNonNull.fir.kt @@ -0,0 +1,11 @@ +fun baz(s: String?, u: String?): String { + val t = when(if (u == null) return "" else u) { + "abc" -> u + "" -> { + if (s == null) return "" + s + } + else -> u + } + return t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/ifExprNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ifExprNonNull.fir.kt new file mode 100644 index 00000000000..ddc82cc4d68 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ifExprNonNull.fir.kt @@ -0,0 +1,19 @@ +fun baz(s: String?): String { + // If String type is given explicitly, problem disappears + val t = if (s == null) { + "" + } + else { + val u: String? = null + if (u == null) return "" + // !! is detected as unnecessary here + u + } + return t +} + +fun foo(s: String?): String { + if (s == null) return "" + val t = if (s == "abc") s else "xyz" + return t +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/ifWhenExprNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ifWhenExprNonNull.fir.kt new file mode 100644 index 00000000000..bef5189c355 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ifWhenExprNonNull.fir.kt @@ -0,0 +1,13 @@ +fun baz(s: String?): String { + val t = if (s == null) { + "" + } + else { + val u: String? = null + when (u) { + null -> "" + else -> u + } + } + return t +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.fir.kt new file mode 100644 index 00000000000..62d0141a968 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.fir.kt @@ -0,0 +1,29 @@ +open class A { + class B : A() { + val a = "FAIL" + } + + class C : A() { + val a = "FATAL" + } + + fun foo(): String { + if (this is B) return a + else if (this is C) return a + return "OK" + } +} + +fun A?.bar() { + if (this != null) foo() +} + +fun A.gav() = if (this is A.B) a else "" + +class C { + fun A?.complex(): String { + if (this is A.B) return a + else if (this != null) return foo() + else return "" + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitToGrandSon.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitToGrandSon.fir.kt new file mode 100644 index 00000000000..aa90fc31447 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitToGrandSon.fir.kt @@ -0,0 +1,11 @@ +open class A { + open fun foo() = "FAIL" + + fun bar() = if (this is C) foo() else "FAIL" +} + +open class B : A() + +open class C : B() { + override fun foo() = "OK" +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.fir.kt new file mode 100644 index 00000000000..aea96ca9533 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/incDecToNull.fir.kt @@ -0,0 +1,10 @@ +class IncDec { + operator fun inc(): Unit {} +} + +fun foo(): IncDec { + var x = IncDec() + x = x++ + x++ + return x +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/dependentOnPrevArg.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/dependentOnPrevArg.fir.kt new file mode 100644 index 00000000000..8df11c2d476 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/dependentOnPrevArg.fir.kt @@ -0,0 +1,7 @@ +package a + +fun foo(u: T, v: T): T = u + +fun test(s: String?) { + val r: String = foo(s!!, s) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.fir.kt new file mode 100644 index 00000000000..5bfb285c232 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.fir.kt @@ -0,0 +1,61 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +package a + +fun id(t: T): T = t + +fun two(u: T, v: T): T = u + +fun three(a: T, b: T, c: T): T = c + +interface A +interface B: A +interface C: A + +fun test(a: A, b: B, c: C) { + if (a is B && a is C) { + val d: C = id(a) + val e: Any = id(a) + val f = id(a) + checkSubtype(f) + val g = two(a, b) + checkSubtype(g) + checkSubtype(g) + + // smart cast isn't needed, but is reported due to KT-4294 + val h: Any = two(a, b) + + val k = three(a, b, c) + checkSubtype(k) + checkSubtype(k) + val l: Int = three(a, b, c) + + use(d, e, f, g, h, k, l) + } +} + +fun foo(t: T, l: MutableList): T = t + +fun testErrorMessages(a: A, ml: MutableList) { + if (a is B && a is C) { + foo(a, ml) + } + + if(a is C) { + foo(a, ml) + } +} + +fun rr(s: String?) { + if (s != null) { + val l = arrayListOf("", s) + checkSubtype>(l) + checkSubtype>(l) + } +} + +//from library +fun arrayListOf(vararg values: T): MutableList = throw Exception() + +fun use(vararg a: Any) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.fir.kt new file mode 100644 index 00000000000..3e8b55e329b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun foo(s : String?, b : Boolean) { + if (s == null) return + + val s1 = if (b) "" else s + s1 checkType { _() } + + val s2 = s + s2 checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt new file mode 100644 index 00000000000..4e0ea846b5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.fir.kt @@ -0,0 +1,40 @@ +//KT-1355 Type inference fails with smartcast and generic function +//tests for Map.set +package a + +import java.util.HashMap + +fun foo(map: MutableMap, value: String?) { + if (value != null) { + map.put(1, value) //ok + map.set(1, value) //type inference failed + map[1] = value //type inference failed + } +} + +//--------------------------- + +public data class Tag(public var tagName: String) { + public val attributes: MutableMap = HashMap() + public val contents: MutableList = arrayListOf() + + public var id: String? + get() = attributes["id"] + set(value) { + if(value == null) { + attributes.remove("id") + } + else { + attributes["id"] = value!! + attributes["id"] = value + } + } +} + + +//from library +operator fun MutableMap.set(key : K, value : V) = this.put(key, value) + +fun arrayListOf(vararg values: T): MutableList = throw Exception() + + diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt25432.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt25432.fir.kt new file mode 100644 index 00000000000..0349104af9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt25432.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// ISSUE: KT-25432 + +class Data(val s: T) + +fun test(d: Data) { + if (d.s is String) { + d.s.length + } +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt2746.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2746.fir.kt new file mode 100644 index 00000000000..d7a7381c7d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2746.fir.kt @@ -0,0 +1,18 @@ +//KT-2746 Do.smartcasts in inference + +class C(t :T) + +fun test1(a: Any) { + if (a is String) { + val c: C = C(a) + } +} + + +fun f(t :T): C = C(t) + +fun test2(a: Any) { + if (a is String) { + val c1: C = f(a) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt new file mode 100644 index 00000000000..404e80ba754 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.fir.kt @@ -0,0 +1,20 @@ +//KT-2851 Type inference failed passing in not-null after smart-cast value in Pair +package a + +fun main() { + val value: String? = "" + if (value != null) { + foo(Pair("val", value)) + foo(Pair("val", value!!)) + foo(Pair("val", value)) + } +} + +fun foo(map: Pair) {} + + +//from library +public class Pair ( + public val first: A, + public val second: B +) diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt29767.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt29767.fir.kt new file mode 100644 index 00000000000..e2b74b41c29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt29767.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +// ISSUE: KT-29767 + +fun test(a: MutableList?) { + if (a != null) { + val b = a[0] // no SMARTCAST diagnostic + if (b != null) { + b.inc() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.fir.kt new file mode 100644 index 00000000000..a293d1cb1e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.fir.kt @@ -0,0 +1,22 @@ +interface PsiElement { + fun getText(): String + fun getParent(): PsiElement +} + +interface JetExpression : PsiElement + +fun foo1(e: PsiElement) { + var current: PsiElement? = e + var first = true + while (current != null) { + if (current is JetExpression && first) { + // Smartcast is possible here + println(current.getText()) + } + + current = current.getParent() + } +} + +//from library +fun println(any: Any?): Nothing = throw Exception("$any") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt4403.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4403.fir.kt new file mode 100644 index 00000000000..89c463b18ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4403.fir.kt @@ -0,0 +1,11 @@ +//KT-4403 Wrong "type mismatch" on smart cast with inference + +interface A +interface B : A + +fun T.f(): T = this + +fun test(a: A) { + if (a !is B) return + val c = a.f() // type mismatch +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt4415.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4415.fir.kt new file mode 100644 index 00000000000..8ef9bc2f460 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4415.fir.kt @@ -0,0 +1,17 @@ +//KT-4415 Class Auto-Cast Bug + +interface SelfJson + +object A { + fun find(clz:Class<*>){ } + + fun toJson2(obj:Any){ + if(obj is SelfJson){ + // A.find( (obj as SelfJson).javaClass) // OK + A.find( obj.javaClass ) // ERROR: Type mismatch: inferred type is kotlin.Any but SelfJson was expected + } + } +} + +//from library +val T.javaClass : Class get() = throw Exception() diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt6242.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt6242.fir.kt new file mode 100644 index 00000000000..84346be5de6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt6242.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +inline fun foo(block: () -> T):T = block() + +fun baz() { + val x: String = foo { + val task: String? = null + if (task == null) { + return + } else task + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.fir.kt new file mode 100644 index 00000000000..c298ad299c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.fir.kt @@ -0,0 +1,13 @@ +interface A +interface B + +class Test { + fun test(a: A?, b: B, list: MutableList>) { + if (a != null) { + list.add(a to b) + } + } +} + +class Pair(val first: A, val second: B) +infix fun A.to(that: B) = Pair(this, that) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt new file mode 100644 index 00000000000..a833621f989 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt @@ -0,0 +1,13 @@ +interface A { + fun foo(): E +} + +interface B { + fun foo(): Q +} + +fun test(c: Any) { + if (c is B && c is A) { + c.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt new file mode 100644 index 00000000000..3c5dc3b8e9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence +} + +interface B { + fun foo(): String? +} + +fun test(c: Any) { + if (c is B && c is A) { + c.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt new file mode 100644 index 00000000000..d44c1402af0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt @@ -0,0 +1,53 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE +// FILE: A.java +public interface A { + String foo(); +} + +// FILE: main.kt + +interface B { + fun foo(): String? +} + +interface C { + fun foo(): String +} + +fun foo(x: Any?) { + if (x is A && x is B) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is B && x is A) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is A && x is C) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is C && x is A) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is A && x is B && x is C) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is B && x is A && x is C) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } + + if (x is B && x is C && x is A) { + x.foo().checkType { _() } + x.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificSetter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificSetter.fir.kt new file mode 100644 index 00000000000..dedf3dd462d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificSetter.fir.kt @@ -0,0 +1,15 @@ +open class A { + open var value: Int = 4 + protected set +} + +class MutableA : A() { + override var value: Int = 4 + public set +} + +fun test(myA: A) { + if (myA is MutableA) { + myA.value = 5 + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificVisibility.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificVisibility.fir.kt new file mode 100644 index 00000000000..7fba012cc4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/moreSpecificVisibility.fir.kt @@ -0,0 +1,16 @@ +abstract class A { + abstract protected fun foo(): String + abstract protected val bar: String +} + +interface B { + fun foo(): String + val bar: String +} + +fun test(x: A) { + if (x is B) { + x.foo() + x.bar + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt new file mode 100644 index 00000000000..3563574ea66 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt @@ -0,0 +1,19 @@ +// !CHECK_TYPE + +interface Common { + fun foo(): CharSequence? +} + +interface A : Common { + override fun foo(): CharSequence +} + +interface B : Common { + override fun foo(): String +} + +fun test(c: Common) { + if (c is B && c is A) { + c.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt new file mode 100644 index 00000000000..3b35a6c40c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence? +} + +interface B { + fun foo(): String +} + +fun test(c: Any) { + if (c is B && c is A) { + c.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt new file mode 100644 index 00000000000..30a57852fbc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE + +interface A { + val foo: Any? +} + +interface C: A { + override val foo: String? +} +interface B: A { + override var foo: String +} + +fun test(a: A) { + if (a is B && a is C) { + a.foo = "" + a.foo = null + + a.foo.checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt new file mode 100644 index 00000000000..d899c00e3c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt @@ -0,0 +1,20 @@ +// !CHECK_TYPE + +interface A { + val foo: Any? +} + +interface C: A { + override val foo: String +} +interface B: A { + override var foo: String? +} + +fun test(a: A) { + if (a is B && a is C) { + a.foo = "" + a.foo = null + a.foo + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/refineReturnType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/refineReturnType.fir.kt new file mode 100644 index 00000000000..3d28cf54515 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/refineReturnType.fir.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence? +} + +interface B : A { + override fun foo(): String +} + +fun test(a: A) { + if (a is B) { + a.foo() + a.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/simple.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/simple.fir.kt new file mode 100644 index 00000000000..27b0b8f0f0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/simple.fir.kt @@ -0,0 +1,12 @@ +interface A { + fun foo() +} + +interface C: A +interface B: A + +fun test(c: C) { + if (c is B) { + c.foo() // OVERLOAD_RESOLUTION_AMBIGUITY: B.foo() and C.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt new file mode 100644 index 00000000000..c2a22a07fa2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt @@ -0,0 +1,38 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +interface A { + fun foo(): CharSequence? + fun baz(x: Any) {} +} + +interface B { + fun foo(): String + fun baz(x: Int): String ="" + fun baz(x: Int, y: Int) {} + + fun foobar(): CharSequence? +} + +interface C { + fun foo(): String + fun baz(x: Int): String ="" + fun baz(x: Int, y: Int) {} + + fun foobar(): String +} + +var x: A = null!! + +fun test() { + x.foo().checkType { _() } + + if (x is B && x is C) { + x.foo().checkType { _() } + x.baz("") + x.baz(1).checkType { _() } + x.baz(1, 2) + + x.foobar().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt new file mode 100644 index 00000000000..300e51b8910 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface A { + fun foo(): E +} + +interface B { + fun foo(): W +} + +fun test(c: Any) { + if (c is B && c is A) { + c.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParametersNoSmartCast.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParametersNoSmartCast.fir.kt new file mode 100644 index 00000000000..d17eaa3f9a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParametersNoSmartCast.fir.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface A { + fun foo(): E +} + +interface B : A { + override fun foo(): W +} + +fun test(a: A) { + if (a is B) { + a.foo().checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10232.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10232.fir.kt new file mode 100644 index 00000000000..00840f11164 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10232.fir.kt @@ -0,0 +1,15 @@ +// Type inference failed after smart cast + +interface A +interface B : A + +fun foo(b: A) = b + +fun test(a: A) { + if (a is Any) { + // Error:(9, 9) Kotlin: Type inference failed: fun foo(b: A): kotlin.Unit + // cannot be applied to (A) + foo(a) + } + foo(a) // ok +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10444.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10444.fir.kt new file mode 100644 index 00000000000..97af8b97801 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10444.fir.kt @@ -0,0 +1,35 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// KT-10444 Do not ignore smart (unchecked) casts to the same classifier + +class Qwe(val a: T?) { + fun test1(obj: Any) { + obj as Qwe + check(obj.a) + } + + fun test1(obj: Qwe<*>) { + obj as Qwe + check(obj.a) + } + + fun check(a: T?) { + } +} + +open class Foo +open class Bar(open val a: T?, open val b: T?) { + @Suppress("UNCHECKED_CAST") + fun compare(obj: Any) { + if (obj !is Bar<*>) { + throw IllegalArgumentException() + } + if (System.currentTimeMillis() > 100) { + val b = (obj as Bar).b + if (b == null) throw IllegalArgumentException() + check(obj.a, b) + } + } + fun check(a: T?, b: T) { + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10483.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10483.fir.kt new file mode 100644 index 00000000000..370f2ca6299 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10483.fir.kt @@ -0,0 +1,17 @@ +interface A +class B : A { + operator fun invoke() = this +} + +class C : A + +operator fun C.invoke(): B = B() + +fun foo(arg: A): B? { + if (arg is B) return arg() + + if (arg is C) return arg() + + return null +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt1461.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt1461.fir.kt new file mode 100644 index 00000000000..bda384bf859 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt1461.fir.kt @@ -0,0 +1,18 @@ +//KT-1461 Front-end complains on overload resolution when superclass property is accessed from string template and implicit type cast is performed +package f + +open class Super(val property : String) {} + +class Sub(str : String) : Super(str) {} + +fun foo(sup : Super, sub : Sub) { + if (sup is Sub) { + println("${sup.property}") + println(sup.property) + } + println("${sub.property}") + println(sub.property) +} + +//from library +fun println(message : Any?) { throw Exception() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt2422.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt2422.fir.kt new file mode 100644 index 00000000000..09602746baa --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt2422.fir.kt @@ -0,0 +1,23 @@ +package bar + +class Test { + val foo: Int? = null + fun foo(o: Test) = foo == null && o.foo == null // ERROR warning: o.test == null is always true + + fun bar(a: Test, b: Test) { + if (a.foo != null) { + useInt(b.foo) + } + if (a.foo != null) { + useInt(foo) + } + if (this.foo != null) { + useInt(foo) + } + if (foo != null) { + useInt(this.foo) + } + } + + fun useInt(i: Int) = i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt27221.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt27221.fir.kt new file mode 100644 index 00000000000..5ff5d106d13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt27221.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +sealed class A +sealed class B : A() +sealed class C : B() +object BB : B() +object CC : C() + +fun foo(a: A) { + if (a is B) { + if (a is C) { + val t = when (a) { + is CC -> "CC" + } + } + } +} + +fun foo2(a: A) { + if (a is C) { + if (a is B) { + val t = when (a) { + is CC -> "CC" + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt27221_2.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt27221_2.fir.kt new file mode 100644 index 00000000000..91d54894917 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt27221_2.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +sealed class A +sealed class B : A() +sealed class C : B() +sealed class D : C() +object BB : B() +object CC : C() +object DD : D() + +fun foo1(a: A) { + if (a is B) { + if (a is D) { + if (a is C) { + val t = + when (a) { + is DD -> "DD" + } + } + } + } +} + +fun foo2(a: A) { + if (a is B) { + if (a is D) { + if (a is C) { + val t = + when (a) { + is DD -> "DD" + } + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt new file mode 100644 index 00000000000..337c36e7ba1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +sealed class A +sealed class B : A() +sealed class C : A() +object BB : B() +object CC : C() + +fun foo(a: A) { + if (a is B) { + if (a is C) { + val t = when (a) { + is CC -> "CC" + } + } + } +} + +fun foo2(a: A) { + if (a is C) { + if (a is B) { + val t = when (a) { + is CC -> "CC" + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt new file mode 100644 index 00000000000..aa67f2a7f65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt2865.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +operator fun MutableMap.set(k: K, v: V) {} + +fun foo(a: MutableMap, x: String?) { + a[x!!] = x + a[x] = x!! +} + +fun foo1(a: MutableMap, x: String?) { + a[x] = x!! + a[x!!] = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt30826.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt30826.fir.kt new file mode 100644 index 00000000000..e61914a5daf --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt30826.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// Issue: KT-30826 + +interface I1 +interface I2 { + fun foo() {} +} + +class A : I1, I2 + +fun foo(x: I1?) { + var y = x + y as I2 + val bar = { + y.foo() // NPE in NI, smartcast impossible in OI + } + y = null + bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt30927.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt30927.fir.kt new file mode 100644 index 00000000000..9ae3e219581 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt30927.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +fun case_0() { + val z: Any? = 10 + val y = z.run { + this as Int + this // error in NI: required Int, found Any?; just inferred to Any? in OI + } + y checkType { _() } + y checkType { _() } +} + +fun case_1(z: Any?) { + val y = z.run { + when (this) { + is String -> return@run this // type mismatch in the new inference (required String, found Any?) + is Float -> "" + else -> return@run "" + } + } + y checkType { _() } + y checkType { _() } + // y is inferred to Any? +} + +fun case_2(z: Any?) { + val y = z.run { + when (this) { + is String -> this + is Float -> "" + else -> return@run "" + } + } + y checkType { _() } + // y is inferred to String +} + +fun case_3(z: Any?) { + val y = z.let { + when (it) { + is String -> return@let it + is Float -> "" + else -> return@let "" + } + } + y checkType { _() } + y checkType { _() } + // y is inferred to String +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3224.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3224.fir.kt new file mode 100644 index 00000000000..1bd312dc7b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3224.fir.kt @@ -0,0 +1,8 @@ +// Works already in M11 + +fun test(c : Class<*>) { + val sc = c as Class + // No ambiguous overload + c.getAnnotations(); + sc.getAnnotations(); +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3244.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3244.fir.kt new file mode 100644 index 00000000000..a8d568a972e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3244.fir.kt @@ -0,0 +1,12 @@ +// Should work already in M11 + +open class A(val s : String) +class B(s : String) : A(s) + +fun test(a : A): String? { + if (a is B) { + // Earlier (14.01.2013) reported overload ambiguity over s + return a.s + } + return null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3572.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3572.fir.kt new file mode 100644 index 00000000000..fc792d1ca81 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3572.fir.kt @@ -0,0 +1,17 @@ +interface Printer { + fun print() +} + +class OKPrinter : Printer { + override fun print() { } +} + +class MyClass(var printer: Printer) + + +fun main(m: MyClass) { + if (m.printer is OKPrinter) { + // We do not need smart cast here, so we should not get SMARTCAST_IMPOSSIBLE + m.printer.print() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3711.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3711.fir.kt new file mode 100644 index 00000000000..947722ee64c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3711.fir.kt @@ -0,0 +1,9 @@ +data class StringPair(val first: String, val second: String) + +infix fun String.to(second: String) = StringPair(this, second) + +fun f(a: String?) { + if (a != null) { + val b: StringPair = a to a + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3899.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3899.fir.kt new file mode 100644 index 00000000000..23fc330973c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3899.fir.kt @@ -0,0 +1,13 @@ +data class StringPair(val first: String, val second: String) + +infix fun String.to(second: String) = StringPair(this, second) + +fun hashMapOf(pair: StringPair): MutableMap { +} + +fun F() : MutableMap { + val value: String? = "xyz" + if (value == null) throw Error() + // Smart cast should be here + return hashMapOf("sss" to value) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt3993.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt3993.fir.kt new file mode 100644 index 00000000000..764114ff550 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt3993.fir.kt @@ -0,0 +1,10 @@ +class User(val login : Boolean) {} + +fun currentAccess(user: User?): Int { + return when { + user == null -> 0 + // We should get smartcast here + user.login -> 1 + else -> -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt5427.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt5427.fir.kt new file mode 100644 index 00000000000..f5315db2e30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt5427.fir.kt @@ -0,0 +1,5 @@ +fun foo(p: String?): Int { + // We should get smart cast here + val x = if (p != null) { p } else "a" + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt5455.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt5455.fir.kt new file mode 100644 index 00000000000..64211fc04e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt5455.fir.kt @@ -0,0 +1,28 @@ +//KT-5455 Need warning about redundant type cast +fun foo(o: Any): Int { + if (o is String) { + return (o as String).length + } + return -1 +} + +open class A { + fun foo() {} +} +class B: A() + +fun test(a: Any?) { + if (a is B) { + (a as A).foo() + } +} + +fun test1(a: B) { + (a as A?)?.foo() +} + +fun test2(b: B?) { + if (b != null) { + (b as A).foo() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt6819.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt6819.fir.kt new file mode 100644 index 00000000000..0428d84174b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt6819.fir.kt @@ -0,0 +1,7 @@ +public fun test(o: String?): Boolean { + return when { + // Data flow info should propagate from o == null to o.length + o == null, o.length == 0 -> false + else -> true + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt7561.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt7561.fir.kt new file mode 100644 index 00000000000..c16095a30dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt7561.fir.kt @@ -0,0 +1,15 @@ +// Test for a potential byte code mistake for a postfix operation on a smart casted variable +public fun box() : Int { + var i : Int? + i = 10 + val ii: Int = i + // k also should be Int + val k : Int = i++ + // KT-7561: both i and i++ should be Int, otherwise VerifyError can arise here + // VerifyError reason: byte code tries to store (i++) result which is Int (smart cast) + // into a j which is Int? + val j = i++ + // and m also + val m = ++i + return j + k + m + i + ii +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgument.fir.kt new file mode 100644 index 00000000000..9c9803814f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgument.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE + +inline fun foo(t1: T, t2: T) = t1 ?: t2 + +inline fun bar(l: (T) -> Unit): T = null!! + +fun use() { + var x: Int? + x = 5 + // Write is AFTER + x.hashCode() + // x is nullable at the second argument + foo(bar { x = null }, x!!) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgumentFun.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgumentFun.fir.kt new file mode 100644 index 00000000000..393424290e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgumentFun.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// See KT-9143: smart cast on a variable nulled inside a lambda argument +inline fun foo(t1: T, t2: T) = t1 ?: t2 + +inline fun bar(l: (T) -> Unit): T = null!! + +fun use() { + var x: Int? + x = 5 + // Write to x is AFTER + x.hashCode() + // No smart cast should be here! + foo(bar { x = null }, x.hashCode()) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentNoSubstitutedReturn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentNoSubstitutedReturn.fir.kt new file mode 100644 index 00000000000..fcb5ef96cc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentNoSubstitutedReturn.fir.kt @@ -0,0 +1,19 @@ +class Indexed(val x: T, val y: Int) + +class Value(val x: T) + +interface WithValue { + fun value(): Value +} + +class Singleton(val x: T) : WithValue { + override fun value() = Value(x) +} + +class WithValueIndexed(val f: () -> Value) : WithValue> { + override fun value() = Value(Indexed(f().x, 0)) +} + +fun Singleton.indexed(): WithValue> { + return WithValueIndexed { value() } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithBoundWithoutType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithBoundWithoutType.fir.kt new file mode 100644 index 00000000000..2dbb729062c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithBoundWithoutType.fir.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +interface Foo +interface Bar : Foo + +fun foo(): Foo? = null +fun bar(): Bar? = null + +fun run(f: () -> T): T = f() + +val foo: Foo = run { + val x = bar() + if (x == null) throw Exception() + x +} + +val foofoo: Foo = run { + val x = foo() + if (x == null) throw Exception() + x +} + +val bar: Bar = run { + val x = foo() + if (x == null) throw Exception() + x +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithExpectedGenericType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithExpectedGenericType.fir.kt new file mode 100644 index 00000000000..e466b8b4e9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithExpectedGenericType.fir.kt @@ -0,0 +1,8 @@ +class My(val y: T?) { + + fun get(): T = run { + val x = y + if (x == null) throw Exception() + x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutType.fir.kt new file mode 100644 index 00000000000..7b2b5b376c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutType.fir.kt @@ -0,0 +1,20 @@ +// See KT-5385: no smart cast in a literal without given type arguments + +interface Foo +fun foo(): Foo? = null + +val foo: Foo = run { + val x = foo() + if (x == null) throw Exception() + x +} + +// Basic non-lambda case + +fun repeat(arg: T): T = arg + +fun bar(): Foo { + val x = foo() + if (x == null) throw Exception() + return repeat(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIf.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIf.fir.kt new file mode 100644 index 00000000000..e320b6dfccc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIf.fir.kt @@ -0,0 +1,13 @@ +// See also KT-7800 + +fun foo(): Int { + val x: Int = 1.let { + val value: Int? = null + if (value == null) { + return@let 1 + } + + value // smart-cast should be here + } + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIfMerge.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIfMerge.fir.kt new file mode 100644 index 00000000000..8d37f33a443 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeIfMerge.fir.kt @@ -0,0 +1,14 @@ +// See also KT-7817 + +fun synchronized(lock: Any, block: () -> R): R = block() + +class My { + val test: String + get() = synchronized(this) { + var x: String? = "" + if (x == null) { + x = "s" + } + x + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeWhen.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeWhen.fir.kt new file mode 100644 index 00000000000..b25bc8f4ecb --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaArgumentWithoutTypeWhen.fir.kt @@ -0,0 +1,13 @@ +// See KT-10223 + +inline fun using(input: Any?, f: (Any?) -> T): T = f(input) + +val input: Any? = null + +// Error:(32, 24) Type inference failed. Expected type mismatch: inferred type is kotlin.Any? but kotlin.String was expected +val test4: String = using(input) { + when (it) { + is String -> it + else -> throw RuntimeException() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaCall.fir.kt new file mode 100644 index 00000000000..0f0616ed0e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaCall.fir.kt @@ -0,0 +1,6 @@ +// See KT-9134: smart cast is not provided inside lambda call +fun bar(): Int = { + var i: Int? + i = 42 + i +}() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaCallAnnotated.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaCallAnnotated.fir.kt new file mode 100644 index 00000000000..14f7ab96fe5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaCallAnnotated.fir.kt @@ -0,0 +1,11 @@ +// See KT-9134: smart cast is not provided inside lambda call + +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class My + +fun bar(): Int = @My { + var i: Int? + i = 42 + i +}() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifies.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifies.fir.kt new file mode 100644 index 00000000000..19428eaa994 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifies.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(arg: Int?) { + run { + var x = arg + if (x == null) return@run + x.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInLoop.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInLoop.fir.kt new file mode 100644 index 00000000000..60e5cb8c9c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInLoop.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(arg: Int?) { + run { + var x = arg + while (x != null) { + x = x.hashCode() + if (x == 0) x = null + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInSecondary.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInSecondary.fir.kt new file mode 100644 index 00000000000..9bfbf765432 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesInSecondary.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class My { + constructor(arg: Int?) { + run { + var x = arg + if (x == null) return@run + x.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesWithDirectEq.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesWithDirectEq.fir.kt new file mode 100644 index 00000000000..e6c59d3ce79 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaDeclaresAndModifiesWithDirectEq.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(arg: Int?) = run { + var x = arg + if (x == null) return@run + x.hashCode() +} + +class My { + fun foo(arg: Int?) = run { + var x = arg + if (x == null) return@run + x.hashCode() + } + + fun Int?.bar() = run { + var x = this + if (x == null) return@run + x.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/lambdaUsesOwnerModifies.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/lambdaUsesOwnerModifies.fir.kt new file mode 100644 index 00000000000..e33c1f9c5f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/lambdaUsesOwnerModifies.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(arg: Int?) { + var x = arg + if (x == null) return + run { + // Not safe: x = null later in the owner + x.hashCode() + } + x = null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/level_1_0.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/level_1_0.fir.kt new file mode 100644 index 00000000000..c171d454ae6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/level_1_0.fir.kt @@ -0,0 +1,52 @@ +// !LANGUAGE: -SafeCallBoundSmartCasts + +fun foo(arg: Int?) { + val x = arg + if (x != null) { + arg.hashCode() + } + val y: Any? = arg + if (y != null) { + arg.hashCode() + } + val yy: Any? + yy = arg + if (yy != null) { + arg.hashCode() + } + var z = arg + z = z?.let { 42 } + if (z != null) { + arg.hashCode() + } +} + +fun kt6840_1(s: String?) { + val hash = s?.hashCode() + if (hash != null) { + s.length + } +} + +fun kt6840_2(s: String?) { + if (s?.hashCode() != null) { + s.length + } +} + +fun kt1635(s: String?) { + s?.hashCode()!! + s.hashCode() +} + +fun kt2127() { + val s: String? = "" + if (s?.length != null) { + s.hashCode() + } +} + +fun kt3356(s: String?): Int { + if (s?.length != 1) return 0 + return s.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/localClassChanges.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localClassChanges.fir.kt new file mode 100644 index 00000000000..badc7eea0b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localClassChanges.fir.kt @@ -0,0 +1,15 @@ +fun trans(n: Int, f: () -> Boolean) = if (f()) n else null + +fun foo() { + var i: Int? = 5 + if (i != null) { + class Changing { + fun bar() { + i = null + } + } + i.hashCode() + Changing().bar() + i.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyAfter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyAfter.fir.kt new file mode 100644 index 00000000000..71c37998cfd --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyAfter.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ProhibitSmartcastsOnLocalDelegatedProperty + +class AlternatingDelegate { + var counter: Int = 0 + operator fun getValue(thisRef: Any?, property: KProperty<*>): Any? = + if (counter++ % 2 == 0) 42 else "" +} + +fun failsWithClassCastException() { + val sometimesNotInt: Any? by AlternatingDelegate() + + if (sometimesNotInt is Int) { + sometimesNotInt.inc() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyBefore.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyBefore.fir.kt new file mode 100644 index 00000000000..ef0139a1c22 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localDelegatedPropertyBefore.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProhibitSmartcastsOnLocalDelegatedProperty + +class AlternatingDelegate { + var counter: Int = 0 + operator fun getValue(thisRef: Any?, property: KProperty<*>): Any? = + if (counter++ % 2 == 0) 42 else "" +} + +fun failsWithClassCastException() { + val sometimesNotInt: Any? by AlternatingDelegate() + + if (sometimesNotInt is Int) { + sometimesNotInt.inc() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/localFunBetween.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localFunBetween.fir.kt new file mode 100644 index 00000000000..cc8959fd1d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localFunBetween.fir.kt @@ -0,0 +1,15 @@ +open class Base +class Derived: Base() + +fun bar(derived: Derived) = derived + +fun trans(n: Int, f: (Int) -> Boolean) = if (f(n)) n else null + +fun foo() { + val base: Base = Derived() + if (base is Derived) { + fun can(n: Int) = n > 0 + trans(42, ::can) + bar(base) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/localFunChanges.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localFunChanges.fir.kt new file mode 100644 index 00000000000..ab64f87ef3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localFunChanges.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +fun trans(n: Int, f: () -> Boolean) = if (f()) n else null + +fun foo() { + var i: Int? = 5 + if (i != null) { + fun can(): Boolean { + i = null + return true + } + i.hashCode() + trans(i, ::can) + i.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/localObjectChanges.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/localObjectChanges.fir.kt new file mode 100644 index 00000000000..fdcd38ed392 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/localObjectChanges.fir.kt @@ -0,0 +1,15 @@ +fun trans(n: Int, f: () -> Boolean) = if (f()) n else null + +fun foo() { + var i: Int? = 5 + if (i != null) { + // Write is AFTER this place + i.hashCode() + object { + fun bar() { + i = null + } + }.bar() + i.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/WhileTrueWithBreakInIfCondition.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/WhileTrueWithBreakInIfCondition.fir.kt new file mode 100644 index 00000000000..6845ef8007c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/WhileTrueWithBreakInIfCondition.fir.kt @@ -0,0 +1,13 @@ +fun checkJump(x: Int?, y: Int?) { + while (true) { + if (x ?: break == 0) { + y!! + } else { + y!! + } + // Ok + y.hashCode() + } + // Smart cast here is erroneous: y is nullable + y.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/assignElvisIfBreakInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/assignElvisIfBreakInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..9111346bc48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/assignElvisIfBreakInsideWhileTrue.fir.kt @@ -0,0 +1,11 @@ +public fun foo(x: String?, y: String?): Int { + while (true) { + val z = x ?: if (y == null) break else y + // z is not null in both branches + z.length + // y is nullable if x != null + y.length + } + // y is null because of the break + return y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/assignWhenInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/assignWhenInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..0b12ef102a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/assignWhenInsideWhileTrue.fir.kt @@ -0,0 +1,17 @@ +// !CHECK_TYPE + +public fun foo(x: String?): Int { + var y: Any + loop@ while (true) { + y = when (x) { + null -> break@loop + "abc" -> return 0 + "xyz" -> return 1 + else -> x.length + } + // y is always Int after when + checkSubtype(y) + } + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakBetweenInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakBetweenInsideDoWhile.fir.kt new file mode 100644 index 00000000000..a9e1d123967 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakBetweenInsideDoWhile.fir.kt @@ -0,0 +1,16 @@ +fun bar(): Boolean { return true } + +fun gav(w: String, arg: Any, z: String): String +{ return if (arg is String) arg else if (z != "") z else w } + +public fun foo(x: String?, z: String?, w: String?): Int { + do { + gav(w!!, if (x == null) break else x, z!!) + } while (bar()) + // w is not null because of w!! + w.length + // z is nullable despite of z!! + z.length + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakFirstInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakFirstInsideDoWhile.fir.kt new file mode 100644 index 00000000000..d1a1765e5c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakFirstInsideDoWhile.fir.kt @@ -0,0 +1,13 @@ +fun bar(): Boolean { return true } + +fun gav(arg: Any, z: String): String { return if (arg is String) arg else z } + +public fun foo(x: String?, z: String?): Int { + do { + gav(if (x == null) break else x, z!!) + } while (bar()) + // z is nullable despite of z!! + z.length + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakInsideDoWhile.fir.kt new file mode 100644 index 00000000000..a77c2dcad2a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakInsideDoWhile.fir.kt @@ -0,0 +1,14 @@ +fun bar(): Boolean { return true } + +fun gav(arg: Any): String { return if (arg is String) arg else "" } + +public fun foo(x: String?): Int { + var y: Any + do { + y = "" + y = gav(if (x == null) break else x) + } while (bar()) + y.hashCode() + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakSecondInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakSecondInsideDoWhile.fir.kt new file mode 100644 index 00000000000..a7b8ba39bb1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakSecondInsideDoWhile.fir.kt @@ -0,0 +1,13 @@ +fun bar(): Boolean { return true } + +fun gav(z: String, arg: Any): String { return if (arg is String) arg else z } + +public fun foo(x: String?, z: String?): Int { + do { + gav(z!!, if (x == null) break else x) + } while (bar()) + // z is not null because of z!! + z.length + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakThirdInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakThirdInsideDoWhile.fir.kt new file mode 100644 index 00000000000..b45f2842eeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/callBreakThirdInsideDoWhile.fir.kt @@ -0,0 +1,16 @@ +fun bar(): Boolean { return true } + +fun gav(z: String, w: String, arg: Any): String +{ return if (arg is String) arg else if (z != "") z else w } + +public fun foo(x: String?, z: String?, w: String?): Int { + do { + gav(z!!, w!!, if (x == null) break else x) + } while (bar()) + // w is not null because of w!! + w.length + // z is not null because of z!! + z.length + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhile.fir.kt new file mode 100644 index 00000000000..3b245261700 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhile.fir.kt @@ -0,0 +1,11 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // See KT-6283 + do { + p!!.length + } while (!x()) + // Do-while loop is executed at least once, so + // p should be not null here + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileBreak.fir.kt new file mode 100644 index 00000000000..6b913fd94a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileBreak.fir.kt @@ -0,0 +1,11 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // See KT-6283 + do { + p!!.length + if (p == "abc") break + } while (!x()) + // p should be smart casted despite of break + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileContinue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileContinue.fir.kt new file mode 100644 index 00000000000..7d95fc89506 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileContinue.fir.kt @@ -0,0 +1,11 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // See KT-6283 + do { + p!!.length + if (p == "abc") continue + } while (!x()) + // p should be smart casted despite of continue + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyBreak.fir.kt new file mode 100644 index 00000000000..dea1d2e8b1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyBreak.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +fun y(): Boolean { return false } + +public fun foo(p: String?): Int { + do { + if (y()) break + // We do not always reach this statement + p!!.length + } while (!x()) + // Here we have do while loop but p is still nullable due to break before + return p.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyContinue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyContinue.fir.kt new file mode 100644 index 00000000000..00461db0c84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileEarlyContinue.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +fun y(): Boolean { return false } + +public fun foo(p: String?): Int { + do { + if (y()) continue + // We do not always reach this statement + p!!.length + } while (!x()) + // Here we have do while loop but p is still nullable due to continue before + return p.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInCondition.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInCondition.fir.kt new file mode 100644 index 00000000000..d4a9d4136db --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInCondition.fir.kt @@ -0,0 +1,5 @@ +fun foo(s: String?): Int { + do { + } while (s!!.length > 0) + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInConditionWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInConditionWithBreak.fir.kt new file mode 100644 index 00000000000..5729e3b9e2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileInConditionWithBreak.fir.kt @@ -0,0 +1,9 @@ +fun bar(): Boolean { return true } + +fun foo(s: String?): Int { + do { + if (bar()) break + } while (s!!.length > 0) + // This call is unsafe due to break + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileLiteral.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileLiteral.fir.kt new file mode 100644 index 00000000000..a9b264cab1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileLiteral.fir.kt @@ -0,0 +1,10 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // Exotic variant with unused literal + do { -> + p!!.length + } while (!x()) + // Literal is not called so p.length is unsafe + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNotNullBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNotNullBreak.fir.kt new file mode 100644 index 00000000000..8a5997a41d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNotNullBreak.fir.kt @@ -0,0 +1,10 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // See KT-6283 + do { + if (p != null) break + } while (!x()) + // p can be null despite of the break + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNull.fir.kt new file mode 100644 index 00000000000..92da461b994 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNull.fir.kt @@ -0,0 +1,5 @@ +fun foo(s: String?): Int { + do { + } while (s==null) + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNullWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNullWithBreak.fir.kt new file mode 100644 index 00000000000..5692b83191a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/doWhileNullWithBreak.fir.kt @@ -0,0 +1,9 @@ +fun bar(): Boolean { return true } + +fun foo(s: String?): Int { + do { + if (bar()) break + } while (s==null) + // This call is unsafe due to break + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/elvisBreakInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisBreakInsideDoWhile.fir.kt new file mode 100644 index 00000000000..fdc21aa554b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisBreakInsideDoWhile.fir.kt @@ -0,0 +1,10 @@ +public fun foo(x: String?): Int { + do { + // After the check, smart cast should work + x ?: break + // x is not null in both branches + x.length + } while (true) + // x is null because of the break + return x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/elvisIfBreakInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisIfBreakInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..0a74bf6f435 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisIfBreakInsideWhileTrue.fir.kt @@ -0,0 +1,9 @@ +public fun foo(x: String?, y: String?): Int { + while (true) { + x ?: if (y == null) break + // y is nullable if x != null + y.length + } + // y is null because of the break + return y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/elvisInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisInsideDoWhile.fir.kt new file mode 100644 index 00000000000..8247222dc83 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisInsideDoWhile.fir.kt @@ -0,0 +1,9 @@ +public fun foo(x: String?): Int { + do { + // After the check, smart cast should work + x ?: x!!.length + // x is not null in both branches + if (x.length == 0) break + } while (true) + return x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/elvisLeftBreakInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisLeftBreakInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..7aa1f53bdca --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/elvisLeftBreakInsideWhileTrue.fir.kt @@ -0,0 +1,9 @@ +public fun foo(x: String?, y: String?): Int { + while (true) { + (if (x != null) break else y) ?: y!! + // y is not null in both branches but it's hard to determine + y.length + } + // y can be null because of the break + return y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifBlockInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBlockInsideDoWhile.fir.kt new file mode 100644 index 00000000000..01d2e73edae --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBlockInsideDoWhile.fir.kt @@ -0,0 +1,12 @@ +public fun foo(p: String?, y: String?): Int { + do { + // After the check, smart cast should work + if (y == null) { + "null".toString() + break + } + y.length + p!!.length + } while (true) + return y?.length ?: -1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideDoWhile.fir.kt new file mode 100644 index 00000000000..48e4c8a2b03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideDoWhile.fir.kt @@ -0,0 +1,14 @@ +fun bar(): Boolean { return true } + +public fun foo(x: String?): Int { + var y: Any + do { + // This and hashCode() below are needed just to prevent + // UNINITIALIZED_VARIABLE, UNUSED_VALUE, ... + y = "" + y = if (x == null) break else x + } while (bar()) + y.hashCode() + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..3a4519f7069 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakAssignInsideWhileTrue.fir.kt @@ -0,0 +1,10 @@ +public fun foo(x: String?): Int { + var y: Any + while (true) { + y = if (x == null) break else x + } + // In future we can infer this initialization + y.hashCode() + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakExprInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakExprInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..a3220877033 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifBreakExprInsideWhileTrue.fir.kt @@ -0,0 +1,10 @@ +public fun foo(x: String?): Int { + while (true) { + // After the check, smart cast should work + val y = if (x == null) break else x + // y is not null in both branches + y.length + } + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifElseBlockInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifElseBlockInsideDoWhile.fir.kt new file mode 100644 index 00000000000..cade2f2d781 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifElseBlockInsideDoWhile.fir.kt @@ -0,0 +1,15 @@ +public fun foo(x: String?, y: String?): Int { + do { + // After the check, smart cast should work + if (x != null) { + if (x == "abc") break + y!!.length + } else { + y!!.length + } + // y!! in both branches + y.length + } while (true) + // break is possible before so !! is necessary + return y!!.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/ifInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/ifInsideDoWhile.fir.kt new file mode 100644 index 00000000000..a111dc42d93 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/ifInsideDoWhile.fir.kt @@ -0,0 +1,9 @@ +public fun foo(p: String?, y: String?): Int { + do { + // After the check, smart cast should work + if (y == null) break + y.length + p!!.length + } while (true) + return y?.length ?: -1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/leftElvisBreakInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/leftElvisBreakInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..5015104c49a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/leftElvisBreakInsideWhileTrue.fir.kt @@ -0,0 +1,11 @@ +public fun foo(x: String?, y: String?): Int { + while (true) { + val z = (if (y == null) break else x) ?: y + // z is not null in both branches + z.length + // y is not null in both branches + y.length + } + // y is null because of the break + return y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhile.fir.kt new file mode 100644 index 00000000000..19529e706b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhile.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?): Int { + do { + do { + p!!.length + } while (r == null) + } while (!x()) + // Auto cast possible + r.length + // Auto cast possible + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhileWithLongContinue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhileWithLongContinue.fir.kt new file mode 100644 index 00000000000..6564b86a853 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedDoWhileWithLongContinue.fir.kt @@ -0,0 +1,14 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?): Int { + outer@ do { + do { + p!!.length + if (!x()) continue@outer + } while (r == null) + } while (!x()) + // Auto cast NOT possible due to long continue + r.length + // Auto cast possible + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoops.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoops.fir.kt new file mode 100644 index 00000000000..225304cab01 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoops.fir.kt @@ -0,0 +1,17 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?, q: String?): Int { + while(true) { + q!!.length + do { + do { + p!!.length + } while (!x()) + } while (r == null) + if (!x()) break + } + // Smart cast is possible everywhere + r.length + q.length + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsShort.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsShort.fir.kt new file mode 100644 index 00000000000..cdb92f855d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsShort.fir.kt @@ -0,0 +1,15 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?, q: String?): Int { + while(true) { + q!!.length + do { + p!!.length + } while (r == null) + if (!x()) break + } + // Smart cast is possible everywhere + r.length + q.length + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithBreak.fir.kt new file mode 100644 index 00000000000..82a688b33ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithBreak.fir.kt @@ -0,0 +1,18 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?, q: String?): Int { + while(true) { + q!!.length + do { + while(true) { + p!!.length + if (x()) break + } + } while (r == null) + if (!x()) break + } + // Smart cast is possible everywhere + r.length + q.length + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongBreak.fir.kt new file mode 100644 index 00000000000..a2a469d11d5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongBreak.fir.kt @@ -0,0 +1,20 @@ +fun x(p: String): Boolean { return p == "abc" } + +public fun foo(p: String?, r: String?, q: String?): Int { + while(true) { + q!!.length + loop@ do { + while(true) { + p!!.length + if (x(p)) break@loop + if (x(q)) break + } + } while (r == null) + if (!x(p)) break + } + // Long break allows r == null + r.length + // Smart cast is possible + q.length + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongContinue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongContinue.fir.kt new file mode 100644 index 00000000000..8cde16df1b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/nestedLoopsWithLongContinue.fir.kt @@ -0,0 +1,19 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?, r: String?, q: String?): Int { + outer@ while(true) { + q!!.length + do { + if (x()) continue@outer + do { + p!!.length + } while (!x()) + } while (r == null) + if (!x()) break + } + // Smart cast is possible only for q + q.length + // But not possible for the others + r.length + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/plusAssignWhenInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/plusAssignWhenInsideDoWhile.fir.kt new file mode 100644 index 00000000000..c19bcee7f8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/plusAssignWhenInsideDoWhile.fir.kt @@ -0,0 +1,22 @@ +// !CHECK_TYPE + +fun bar(): Boolean { return true } + +public fun foo(x: String?): Int { + var y: Int? + y = 0 + loop@ do { + y += when (x) { + null -> break@loop + "abc" -> return 0 + "xyz" -> return 1 + else -> x.length + } + // y is always Int after when + checkSubtype(y) + } while (bar()) + // y is always Int even here + checkSubtype(y) + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallBreakInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallBreakInsideDoWhile.fir.kt new file mode 100644 index 00000000000..c4a3c5e1d0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallBreakInsideDoWhile.fir.kt @@ -0,0 +1,14 @@ +fun foo(x: String): String? = x + +fun calc(x: String?, y: String?): Int { + do { + // Smart cast because of x!! in receiver + foo(x!!)?.subSequence(0, if (x.length > 0) 5 else break) + y!!.length + // x is not null in condition but we do not see it yet + } while (x.length > 0) + // y is nullable because of break + y.length + // x is not null, at least in theory + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallInsideDoWhile.fir.kt new file mode 100644 index 00000000000..5f301359454 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/safeCallInsideDoWhile.fir.kt @@ -0,0 +1,12 @@ +fun foo(x: String): String? = x + +fun calc(x: String?): Int { + do { + // Smart cast because of x!! in receiver + foo(x!!)?.subSequence(0, x.length) + // Smart cast because of x!! in receiver + if (x.length == 0) break + } while (true) + // Here x is also not null + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/useInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/useInsideDoWhile.fir.kt new file mode 100644 index 00000000000..ddc8e8f03d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/useInsideDoWhile.fir.kt @@ -0,0 +1,9 @@ +public fun foo(p: String?, y: String?): Int { + do { + // After this !!, y. should be smartcasted in loop as well as outside + y!!.length + if (p == null) break + y.length + } while (true) + return y.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whenInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whenInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..28f75d8ae24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whenInsideWhileTrue.fir.kt @@ -0,0 +1,12 @@ +public fun foo(x: String?): Int { + loop@ while (true) { + when (x) { + null -> break@loop + "abc" -> return 0 + "xyz" -> return 1 + else -> x.length + } + } + // x is null because of the break + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whenReturnInsideWhileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whenReturnInsideWhileTrue.fir.kt new file mode 100644 index 00000000000..07ffb4833d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whenReturnInsideWhileTrue.fir.kt @@ -0,0 +1,13 @@ +public fun foo(x: String?): Int { + loop@ while (true) { + when (x) { + null -> return -1 + "abc" -> return 0 + "xyz" -> return 1 + else -> break@loop + } + } + // x is not null because of the break + // but we are not able to detect it + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileInCondition.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileInCondition.fir.kt new file mode 100644 index 00000000000..f3f5223aa45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileInCondition.fir.kt @@ -0,0 +1,6 @@ +fun foo(s: String?): Int { + while (s!!.length > 0) { + s.length + } + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileInConditionWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileInConditionWithBreak.fir.kt new file mode 100644 index 00000000000..8cf1d3e44ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileInConditionWithBreak.fir.kt @@ -0,0 +1,9 @@ +fun bar(): Boolean { return true } + +fun foo(s: String?): Int { + while (s!!.length > 0) { + s.length + if (bar()) break + } + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNull.fir.kt new file mode 100644 index 00000000000..1482762bde8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNull.fir.kt @@ -0,0 +1,5 @@ +fun foo(s: String?): Int { + while (s==null) { + } + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullAssignToSomething.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullAssignToSomething.fir.kt new file mode 100644 index 00000000000..276b68eeccc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullAssignToSomething.fir.kt @@ -0,0 +1,9 @@ +fun main() { + var result: String? = null + var i = 0 + while (result == null) { + if (i == 10) result = "non null" + else i++ + } + result.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullWithBreak.fir.kt new file mode 100644 index 00000000000..c52d962227f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullWithBreak.fir.kt @@ -0,0 +1,9 @@ +fun bar(): Boolean { return true } + +fun foo(s: String?): Int { + while (s==null) { + if (bar()) break + } + // Call is unsafe due to break + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileSimple.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileSimple.fir.kt new file mode 100644 index 00000000000..cfe59782992 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileSimple.fir.kt @@ -0,0 +1,10 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + while(x()) { + p!!.length + if (x()) break + } + // p is nullable because it's possible loop body is not executed at all + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrivial.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrivial.fir.kt new file mode 100644 index 00000000000..3eeedc78531 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrivial.fir.kt @@ -0,0 +1,11 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // Like whileTrue but 2 == 2 is in use + while(2 == 2) { + p!!.length + if (x()) break + } + // Smart cast should not work in this case, see KT-6284 + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrue.fir.kt new file mode 100644 index 00000000000..8c2d11b4383 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrue.fir.kt @@ -0,0 +1,12 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + // KT-6284 + while(true) { + p!!.length + if (x()) break + } + // while (true) loop body is executed at least once + // so p is not null here + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueBreakReturn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueBreakReturn.fir.kt new file mode 100644 index 00000000000..26d79bd116d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueBreakReturn.fir.kt @@ -0,0 +1,12 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + while(true) { + if (x()) break + if (p==null) return -1 + // p is not null + p.length + } + // p can be null because break is earlier than return + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueEarlyBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueEarlyBreak.fir.kt new file mode 100644 index 00000000000..08daf2b657e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueEarlyBreak.fir.kt @@ -0,0 +1,11 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + while(true) { + if (x()) break + // We do not always reach this statement + p!!.length + } + // Here we have while (true) loop but p is nullable due to break before + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueReturn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueReturn.fir.kt new file mode 100644 index 00000000000..8bd84422c70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileTrueReturn.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(p: String?): Int { + while(true) { + if (p==null) return -1 + if (x()) break + // p is not null + p.length + } + // while (true) loop body with return is executed at least once + // so p is not null here + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakAfter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakAfter.fir.kt new file mode 100644 index 00000000000..949f54a32c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakAfter.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +SoundSmartcastFromLoopConditionForLoopAssignedVariables + +fun foo() { + var x: String? = "123" + while (x!!.length < 42) { + x = null + break + + } + // TODO: this testdata fixates undesired behavior (it should be an unsafe call) + x.length // 'x' is unsoundly smartcasted here +} + +fun bar() { + var x: List? = ArrayList(1) + for (i in x!!) { + x = null + break + + } + // TODO: this testdata fixates undesired behavior (it should be an unsafe call) + x.size // 'x' is unsoundly smartcasted here +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakBefore.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakBefore.fir.kt new file mode 100644 index 00000000000..0b651c5beea --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/loops/whileWithAssertInConditionAndBreakBefore.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -SoundSmartcastFromLoopConditionForLoopAssignedVariables + +fun foo() { + var x: String? = "123" + while (x!!.length < 42) { + x = null + break + + } + x.length // 'x' is unsoundly smartcasted here +} + +fun bar() { + var x: List? = ArrayList(1) + for (i in x!!) { + x = null + break + + } + x.size // 'x' is unsoundly smartcasted here +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/multipleResolvedCalls.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/multipleResolvedCalls.fir.kt new file mode 100644 index 00000000000..e5b0430f05a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/multipleResolvedCalls.fir.kt @@ -0,0 +1,19 @@ +interface I1 +interface I2 +interface I3 +interface I4 +interface I5 + +operator fun I1.component1() = 1 +operator fun I2.component2() = 2 +operator fun I3.component3() = 3 +operator fun I4.component4() = 4 +operator fun I5.component5() = 5 + +fun test(x: Any): Int { + if (x is I1 && x is I2 && x is I3 && x is I4 && x is I5) { + val (t1, t2, t3, t4, t5) = x + return t1 + t2 + t3 + t4 + t5 + } + else return 0 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.fir.kt new file mode 100644 index 00000000000..4cba8e94eee --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.fir.kt @@ -0,0 +1,25 @@ +//FILE: bar.kt +package bar + +val i: Int? = 2 + +//FILE: foo.kt +package foo + +val i: Int? = 1 + +class A(val i: Int?) { + fun testUseFromClass() { + if (foo.i != null) { + useInt(i) + } + } +} + +fun testUseFromOtherPackage() { + if (bar.i != null) { + useInt(i) + } +} + +fun useInt(i: Int) = i \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.fir.kt new file mode 100644 index 00000000000..9a38cbf1172 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.fir.kt @@ -0,0 +1,7 @@ +fun Any?.foo() {} + +fun test(a: Any?) { + if (a != null) { + a.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.fir.kt new file mode 100644 index 00000000000..5fc238ca174 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.fir.kt @@ -0,0 +1,6 @@ +fun bar(x: Int?): Int { + if (x != null) return -1 + if (x == null) return -2 + // Should be unreachable + return 2 + 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/assignment.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/assignment.fir.kt new file mode 100644 index 00000000000..b6b86473309 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/assignment.fir.kt @@ -0,0 +1,19 @@ +// See KT-6293: Smart cast doesn't work after object literal +abstract class Runnable { + abstract fun run() +} + +fun foo(): Int { + val c: Int? = null + if (c is Int) { + var k: Runnable + val d: Int = c + k = object: Runnable() { + override fun run() = Unit + } + // Unnecessary but not important smart cast + k.run() + return c + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/base.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/base.fir.kt new file mode 100644 index 00000000000..61491a9761a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/base.fir.kt @@ -0,0 +1,19 @@ +// See KT-6293: Smart cast doesn't work after object literal +abstract class Runnable { + abstract fun run() +} + +fun foo(): Int { + val c: Int? = null + if (c is Int) { + val d: Int = c + // This object breaks data flow info propagation + val k = object: Runnable() { + override fun run() = Unit + } + k.run() + // Smart cast should work but error is reported + return c + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/captured.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/captured.fir.kt new file mode 100644 index 00000000000..e720d23fd1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/captured.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +abstract class Runnable { + abstract fun run() +} + +fun foo(): Int { + val c: Int? = null + var a: Int? + if (c is Int) { + a = 2 + val k = object: Runnable() { + init { + a = null + } + override fun run() = Unit + } + k.run() + val d: Int = c + // a is captured so smart cast is not possible + return d + a + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexcl.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexcl.fir.kt new file mode 100644 index 00000000000..a6e7d8391bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexcl.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +abstract class Runnable { + abstract fun run() +} + +fun foo(): Int { + val c: Int? = null + val a: Int? = 1 + if (c is Int) { + val k = object: Runnable() { + init { + a!!.toInt() + } + override fun run() = Unit + } + k.run() + val d: Int = c + // a is not null because of k constructor, but we do not know it + return a + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclArgument.fir.kt new file mode 100644 index 00000000000..98186b9a1c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclArgument.fir.kt @@ -0,0 +1,17 @@ +abstract class Runnable(val arg: Int) { + abstract fun run(): Int +} + +fun foo(): Int { + val c: Int? = null + val a: Int? = 1 + if (c is Int) { + val k = object: Runnable(a!!) { + override fun run() = arg + } + k.run() + val d: Int = c + return a + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclTwoArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclTwoArgument.fir.kt new file mode 100644 index 00000000000..0ed5e29c566 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/exclexclTwoArgument.fir.kt @@ -0,0 +1,21 @@ +abstract class Runnable(val arg: Int) { + abstract fun run(): Int +} + +interface Wrapper { + fun run(): Int +} + +fun foo(): Int { + val c: Int? = null + val a: Int? = 1 + if (c is Int) { + val k = object: Wrapper, Runnable(a!!) { + override fun run() = arg + } + k.run() + val d: Int = c + return a + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/kt7110.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/kt7110.fir.kt new file mode 100644 index 00000000000..9db5e130a9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/kt7110.fir.kt @@ -0,0 +1,11 @@ +// Anonymous object's initialization does not affect smart casts + +abstract class A(val s: String) { + fun bar(): String = s +} + +fun foo(o: String?): Int { + val a = object : A(o!!){} + a.bar() + return o.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/receiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/receiver.fir.kt new file mode 100644 index 00000000000..b741cb13a11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/objectLiterals/receiver.fir.kt @@ -0,0 +1,16 @@ +// See KT-6293: Smart cast doesn't work after object literal +abstract class Runnable { + abstract fun run() +} + +fun foo(): Int { + val c: Int? = null + if (c is Int) { + val d: Int = c + object: Runnable() { + override fun run() = Unit + }.run() + return c + d + } + else return -1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/openInSealed.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/openInSealed.fir.kt new file mode 100644 index 00000000000..8b0160f3ba6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/openInSealed.fir.kt @@ -0,0 +1,8 @@ +sealed class My(open val x: Int?) { + init { + if (x != null) { + // Should be error: property is open + x.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/ownerDeclaresBothModifies.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/ownerDeclaresBothModifies.fir.kt new file mode 100644 index 00000000000..e6df621d176 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/ownerDeclaresBothModifies.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun foo(arg: Int?) { + var x = arg + if (x == null) return + run { + // Unsafe because of owner modification + x.hashCode() + x = null + } + if (x != null) x = 42 + // Unsafe because of lambda + x.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/propertyAsCondition.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/propertyAsCondition.fir.kt new file mode 100644 index 00000000000..bb0861c837a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/propertyAsCondition.fir.kt @@ -0,0 +1,30 @@ +// See also: KT-11998 +data class My(val x: Boolean?) + +fun doIt() {} + +fun foo(my: My) { + if (my.x != null) { + // my.x should be smart-cast + if (my.x) doIt() + when (my.x) { + true -> doIt() + } + when { + my.x -> doIt() + } + } +} + +fun bar(x: Boolean?) { + if (x != null) { + // x should be smart-cast + if (x) doIt() + when (x) { + true -> doIt() + } + when { + x -> doIt() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/propertyToNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/propertyToNotNull.fir.kt new file mode 100644 index 00000000000..7b54582ba92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/propertyToNotNull.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +class Immutable(val x: String?) { + fun foo(): String { + if (x != null) return x + return "" + } +} + +class Mutable(var y: String?) { + fun foo(): String { + if (y != null) return y + return "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/customGetter.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/customGetter.fir.kt new file mode 100644 index 00000000000..094ffda8ced --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/customGetter.fir.kt @@ -0,0 +1,13 @@ +public class X { + private val x : String? = null + public val y: CharSequence? + get() = x?.subSequence(0, 1) + public fun fn(): Int { + if (y != null) + // With non-default getter smartcast is not possible + return y.length + else + return 0 + } +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.fir.kt new file mode 100644 index 00000000000..e589ef8a50a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/delegate.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String? { + return null + } +} + +class Example { + private val p: String? by Delegate() + + public val r: String? = "xyz" + + public fun foo(): String { + // Smart cast is not possible if property is delegated + return if (p != null) p else "" + } + + public fun bar(): String { + // But is possible for non-delegated value property even if it's public + return if (r != null) r else "" + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt4409.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt4409.fir.kt new file mode 100644 index 00000000000..66d57db2a66 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt4409.fir.kt @@ -0,0 +1,13 @@ +public interface A { + public val x: Any +} + +public class B(override public val x: Any) : A { + fun foo(): Int { + if (x is String) { + return x.length + } else { + return 0 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt5502.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt5502.fir.kt new file mode 100644 index 00000000000..9cf8732a1d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/kt5502.fir.kt @@ -0,0 +1,16 @@ +// NB: should work after KT-5907 / KT-4450 fix + +val currentTimeMillis = 1234L + +public class Foo(protected val maxParsingTimeInMillis: Long?) { + + var parsingStartTimeStamp = 0L + + protected fun checkForParsingTimeout(): Boolean { + if (maxParsingTimeInMillis == null) + return true + if (currentTimeMillis - parsingStartTimeStamp > maxParsingTimeInMillis) + return false + return true + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/open.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/open.fir.kt new file mode 100644 index 00000000000..cb56a5826d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/open.fir.kt @@ -0,0 +1,11 @@ +public open class A() { + public open val foo: Int? = 1 +} + +infix fun Int.bar(i: Int) = i + +fun test() { + val p = A() + // For open value properties, smart casts should not work + if (p.foo is Int) p.foo bar 11 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.fir.kt new file mode 100644 index 00000000000..3b467593ed3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.fir.kt @@ -0,0 +1,35 @@ +// MODULE: m1 +// FILE: a.kt + +package a + +public class X { + public val x : String? = null +} + +// MODULE: m2(m1) +// FILE: b.kt + +package b + +import a.X + +public fun X.gav(): Int { + if (x != null) + // Smart cast is not possible if definition is in another module + return x.length + else + return 0 +} + +// FILE: c.kt + +package a + +public fun X.gav(): Int { + if (x != null) + // Even if it's in the same package + return x.length + else + return 0 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/protected.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/protected.fir.kt new file mode 100644 index 00000000000..72e2a2cee5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/protected.fir.kt @@ -0,0 +1,17 @@ +public open class X { + protected val x : String? = null + public fun fn(): Int { + if (x != null) + // Smartcast is possible for protected value property in the same class + return x.length + else + return 0 + } +} + +public class Y: X() { + public fun bar(): Int { + // Smartcast is possible even in derived class + return if (x != null) x.length else 0 + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/simple.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/simple.fir.kt new file mode 100644 index 00000000000..f831485d65d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/simple.fir.kt @@ -0,0 +1,12 @@ +public class X { + public val x : String? = null + public fun fn(): Int { + if (x != null) + // Smartcast is possible because it's value property with default getter + // used in the same module + return x.length + else + return 0 + } +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/var.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/var.fir.kt new file mode 100644 index 00000000000..ffff8aba67a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/var.fir.kt @@ -0,0 +1,15 @@ +public class X { + public var x : String? = null + private var y: String? = "abc" + public fun fn(): Int { + if (x != null) + // Smartcast is not possible for variable properties + return x.length + else if (y != null) + // Even if they are private + return y.length + else + return 0 + } +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/safeAs.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safeAs.fir.kt new file mode 100644 index 00000000000..c5e38bcad56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safeAs.fir.kt @@ -0,0 +1,17 @@ +// See also KT-10992: we should have no errors for all unsafe hashCode() calls + +fun foo(arg: Any?) { + val x = arg as? Any ?: return + arg.hashCode() + x.hashCode() +} + +fun bar(arg: Any?) { + arg as? Any ?: return + arg.hashCode() +} + +fun gav(arg: Any?) { + arg as? String ?: return + arg.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/anotherVal.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/anotherVal.fir.kt new file mode 100644 index 00000000000..c8e1e81570d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/anotherVal.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE + +fun calc(x: List?, y: Int?): Int { + x?.get(y!! - 1) + // y!! above should not provide smart cast here + val yy: Int = y + return yy + (x?.size ?: 0) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt new file mode 100644 index 00000000000..381263e32e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/argument.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?): Int { + // After KT-5840 fix !! assertion should become unnecessary here + x?.get(x!!.size - 1) + // x?. or x!! above should not provide smart cast here + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainAndUse.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainAndUse.fir.kt new file mode 100644 index 00000000000..9942d29c85b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainAndUse.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?): Int { + // x should be non-null in arguments list, despite of a chain + x?.subList(0, 1)?.get(x.size) + // But not here! + return x!!.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainInChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainInChain.fir.kt new file mode 100644 index 00000000000..b9f9fe049c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainInChain.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?, y: List?) { + // x and y should be non-null in arguments list, despite of a chains + x?.subList(y?.subList(1, 2)?.get(y.size) ?: 0, + y?.get(0) ?: 1) // But safe call is NECESSARY here for y + ?.get(x.size) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.fir.kt new file mode 100644 index 00000000000..188d1a4eb5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/chainMixedUnsafe.fir.kt @@ -0,0 +1,5 @@ +fun calc(x: List?): Int { + // x is not-null only inside subList + x?.subList(0, x.size - 1).get(x.size) + return x!!.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/doubleCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/doubleCall.fir.kt new file mode 100644 index 00000000000..5590814b6c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/doubleCall.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?): Int { + // x should be non-null in arguments list, including inner call + x?.get(x.get(x.size - 1).length) + // but not also here! + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/extension.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/extension.fir.kt new file mode 100644 index 00000000000..e953979c425 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/extension.fir.kt @@ -0,0 +1,6 @@ +fun String.foo(arg: Int) = this[arg] + +fun calc(x: String?) { + // x should be non-null in arguments list + x?.foo(x.length - 1) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/extensionCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/extensionCall.fir.kt new file mode 100644 index 00000000000..d40d400286f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/extensionCall.fir.kt @@ -0,0 +1,6 @@ +fun String.bar(s: String) = s + +fun foo(s: String?) { + s?.bar(s) + s?.get(s.length) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.fir.kt new file mode 100644 index 00000000000..ae1b9ea8cd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.fir.kt @@ -0,0 +1,7 @@ +fun foo(y: Int) = y + +fun calc(x: List?): Int { + foo(x!!.size) + // Here we should have smart cast because of x!!, despite of KT-7204 fixed + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseChain.fir.kt new file mode 100644 index 00000000000..314b1002ee4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseChain.fir.kt @@ -0,0 +1,4 @@ +fun calc(x: List?, y: Int?) { + // Smart cast should work here despite of KT-7204 fixed + x?.subList(0, y!!)?.get(y) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseExtension.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseExtension.fir.kt new file mode 100644 index 00000000000..4b7fe96a863 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseExtension.fir.kt @@ -0,0 +1,7 @@ +fun String.foo(y: Int) = y + +fun calc(x: List?): Int { + "abc".foo(x!!.size) + // Here we should have smart cast because of x!!, despite of KT-7204 fixed + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseSecondArgument.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseSecondArgument.fir.kt new file mode 100644 index 00000000000..91ac2daecbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/falseSecondArgument.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE + +fun calc(x: List?, y: Int?): Int { + x?.subList(y!! - 1, y) + // y!! above should not provide smart cast here + return y +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/innerReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/innerReceiver.fir.kt new file mode 100644 index 00000000000..b1016ada479 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/innerReceiver.fir.kt @@ -0,0 +1,8 @@ +fun foo(x: String): String? = x + +fun calc(x: String?, y: String?): Int { + // Smart cast because of y!! in receiver + x?.subSequence(y!!.subSequence(0, 1).length, y.length) + // No smart cast possible + return y.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideCall.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideCall.fir.kt new file mode 100644 index 00000000000..054e32c21f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideCall.fir.kt @@ -0,0 +1,8 @@ +fun foo(y: Int): Int { + return y + 1 +} + +fun calc(x: List?): Int { + // x should be non-null in arguments list + return foo(x?.get(x.size - 1)!!.length) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideIfExpr.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideIfExpr.fir.kt new file mode 100644 index 00000000000..4593c469564 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/insideIfExpr.fir.kt @@ -0,0 +1,43 @@ +// See KT-11007: Wrong smart cast to not-null type after safe calls in if / when expression + +val String.copy: String + get() = this + +fun foo() { + val s: String? = null + val ss = if (true) { + s?.length + } else { + s?.length + } + ss.hashCode() // Smart-cast to Int, should be unsafe call + val sss = if (true) { + s?.copy + } + else { + s?.copy + } + sss.length +} + +class My { + val String.copy2: String + get() = this + + fun foo() { + val s: String? = null + val ss = if (true) { + s?.length + } else { + s?.length + } + ss.hashCode() + val sss = if (true) { + s?.copy2 + } + else { + s?.copy2 + } + sss.length + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/longChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/longChain.fir.kt new file mode 100644 index 00000000000..e72c14c1a71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/longChain.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?) { + // x should be non-null in arguments list, despite of a chain + x?.subList(0, x.size)?. + subList(0, x.size)?. + get(x.size) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiver.fir.kt new file mode 100644 index 00000000000..fc765b7bd64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiver.fir.kt @@ -0,0 +1,13 @@ +// See KT-10056 +class Foo(val bar: String) + +fun test(foo: Foo?) { + foo?.bar.let { + // Error, foo?.bar is nullable + it.length + // Error, foo is nullable + foo.bar.length + // Correct + foo?.bar?.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverInLongChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverInLongChain.fir.kt new file mode 100644 index 00000000000..eaa94bcd0f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverInLongChain.fir.kt @@ -0,0 +1,42 @@ +class Bar(val gav: String) + +class Foo(val bar: Bar, val nbar: Bar?) { + fun baz(s: String) = if (s != "") Bar(s) else null +} + +fun String?.call(f: (String?) -> String?) = f(this) + +fun String.notNullLet(f: (String) -> Unit) = f(this) + +fun test(foo: Foo?) { + foo?.bar?.gav.let { + // Error, foo?.bar?.gav is nullable + it.length + // Error, foo is nullable + foo.bar.gav.length + // Correct + foo?.bar?.gav?.length + } + foo?.bar?.gav.call { it }?.notNullLet { + foo.hashCode() + foo.bar.hashCode() + } +} + +fun testNotNull(foo: Foo) { + val s: String? = "" + foo.baz(s!!)?.gav.let { + it.length + // Ok because of foo. + s.length.hashCode() + } +} + +fun testNullable(foo: Foo?) { + val s: String? = "" + foo?.baz(s!!)?.gav.let { + it.length + // Ok because of foo?. + s?.length?.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithExclExcl.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithExclExcl.fir.kt new file mode 100644 index 00000000000..a3800971019 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithExclExcl.fir.kt @@ -0,0 +1,11 @@ +class Foo(val bar: String?) + +fun test(foo: Foo?) { + foo!!.bar.let { + // Correct + foo.bar?.length + // Unnecessary + foo?.bar?.length + } + foo.bar?.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithFlexible.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithFlexible.fir.kt new file mode 100644 index 00000000000..0743b51b49d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithFlexible.fir.kt @@ -0,0 +1,25 @@ +// FILE: Foo.java +public class Foo { + public String bar; + + private Foo(String bar) { + this.bar = bar; + } + + public static Foo create(String bar) { + return new Foo(bar); + } +} + +// FILE: Test.kt +fun test() { + val foo = Foo.create(null) + foo?.bar.let { + // Error, foo?.bar is nullable + it.length + // Foo is nullable but flexible, so call is considered safe here + foo.bar.length + // Correct + foo?.bar?.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/property.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/property.fir.kt new file mode 100644 index 00000000000..626690ecb20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/property.fir.kt @@ -0,0 +1,6 @@ +data class MyClass(val x: String?) + +fun foo(y: MyClass): Int { + val z = y.x?.subSequence(0, y.x.length) + return z?.length ?: -1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt new file mode 100644 index 00000000000..1cf8604ce26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/propertyChain.fir.kt @@ -0,0 +1,14 @@ +// See KT-7290 +class MyClass(val x: String?) +fun foo(y: MyClass?): Int { + // x here is smartcast but y is not + val z = y?.x?.subSequence(0, y.x.length) + // !! is necessary here + y!!.x + return z?.length ?: -1 +} +fun bar(y: MyClass?) { + y?.x!!.length + // !! is NOT necessary here, because y?.x != null + y!!.x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiver.fir.kt new file mode 100644 index 00000000000..22f9dbd5fd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiver.fir.kt @@ -0,0 +1,8 @@ +fun foo(x: String): String? = x + +fun calc(x: String?): Int { + // Smart cast because of x!! in receiver + foo(x!!)?.subSequence(0, x.length) + // Smart cast because of x!! in receiver + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChain.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChain.fir.kt new file mode 100644 index 00000000000..550cbf63d58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChain.fir.kt @@ -0,0 +1,8 @@ +fun foo(x: String): String? = x + +fun calc(x: String?): Int { + // Smart cast because of x!! in receiver + foo(x!!)?.subSequence(0, x.length)?.length + // Smart cast because of x!! in receiver + return x.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChainFalse.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChainFalse.fir.kt new file mode 100644 index 00000000000..347cb784791 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/receiverAndChainFalse.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE + +fun foo(x: String): String? = x + +fun calc(x: String?, y: Int?): Int { + // Smart cast because of x!! in receiver + foo(x!!)?.subSequence(y!!, x.length)?.length + // No smart cast possible + return y +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt new file mode 100644 index 00000000000..6434bbd9bd8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/safeAccessReceiverNotNull.fir.kt @@ -0,0 +1,136 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: -SafeCastCheckBoundSmartCasts -BooleanElvisBoundSmartCasts +// A set of examples for +// "If the result of a safe call is not null, understand that its receiver is not null" +// and some other improvements for nullability detection + +fun kt6840_1(s: String?) { + val hash = s?.hashCode() + if (hash != null) { + s.length + } +} + +fun kt6840_2(s: String?) { + if (s?.hashCode() != null) { + s.length + } +} + +fun kt1635(s: String?) { + s?.hashCode()!! + s.hashCode() +} + +fun kt2127() { + val s: String? = "" + if (s?.length != null) { + s.hashCode() + } +} + +fun kt3356(s: String?): Int { + if (s?.length != 1) return 0 + return s.length +} + +open class SomeClass(val data: Any) + +class SubClass(val extra: Any, data: Any) : SomeClass(data) + +fun kt4565_1(a: SomeClass?) { + val data = a?.data + if (data != null) { + data.hashCode() + a.hashCode() + a.data.hashCode() + } + if (a?.data != null) { + // To be supported (?!) + data.hashCode() + a.hashCode() + a.data.hashCode() + } + if (a?.data is String) { + a.data.length + data.length + } +} + +fun kt4565_2(a: SomeClass?) { + // To be supported + if (a as? SubClass != null) { + a.extra.hashCode() + } + val extra = (a as? SubClass)?.extra + if (extra != null) { + a.extra.hashCode() + } +} + +class A(val y: Int) + +fun kt7491_1() { + val x: A? = A(42) + val z = x?.y ?: return + x.y +} + +fun getA(): A? = null +fun useA(a: A): Int = a.hashCode() + +fun kt7491_2() { + val a = getA() + (a?.let { useA(a) } ?: a.y ).toString() +} + +fun String.correct() = true + +fun kt8492(s: String?) { + if (s?.correct() ?: false) { + // To be supported + s.length + } +} + +fun kt11085(prop: String?) { + when (prop?.hashCode()) { + 1 -> prop.length + } +} + +class HttpExchange(val code: String) + +fun kt11313(arg: HttpExchange?) { + when (arg?.code) { + "GET" -> handleGet(arg) + "POST" -> handlePost(arg) + } +} + +fun handleGet(arg: HttpExchange) = arg + +fun handlePost(arg: HttpExchange) = arg + +class Wrapper { + fun unwrap(): String? = "Something not consistent" +} + +fun falsePositive(w: Wrapper) { + if (w.unwrap() != null) { + // Here we should NOT have smart cast + w.unwrap().length + } +} + +class Invokable(val x: String) { + operator fun invoke() = x +} + +class InvokableProperty(val i: Invokable) + +fun checkInvokable(ip: InvokableProperty?) { + if (ip?.i() == "Hello") { + ip.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/simple.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/simple.fir.kt new file mode 100644 index 00000000000..31d8b7c2458 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/simple.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?): Int { + // x should be non-null in arguments list + x?.get(x.size - 1) + // but not also here! + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/simpleNullableReceiver.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/simpleNullableReceiver.fir.kt new file mode 100644 index 00000000000..a829e21c633 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/simpleNullableReceiver.fir.kt @@ -0,0 +1,6 @@ +fun Any?.foo(my: My) = my === this + +class My(val x: Any) + +// my is nullable in brackets because Any?.foo has nullable receiver +fun foo(my: My?) = my?.x.foo(my) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/safecalls/twoArgs.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/safecalls/twoArgs.fir.kt new file mode 100644 index 00000000000..7017e9b2446 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/safecalls/twoArgs.fir.kt @@ -0,0 +1,6 @@ +fun calc(x: List?): Int { + // x should be non-null in arguments list + x?.subList(x.size - 1, x.size) + // but not also here! + return x.size +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.fir.kt new file mode 100644 index 00000000000..1b761aebe4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo(y: Any?) { + if (y is T?) { + if (y != null) { + bar(y) + } + } +} + +fun bar(x: CharSequence) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.fir.kt new file mode 100644 index 00000000000..6e31afb37a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.fir.kt @@ -0,0 +1,9 @@ +fun baz(s: String?): String { + val t = if (s != null) s + else { + val u: String? = null + if (u == null) return "" + u + } + return t +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.fir.kt new file mode 100644 index 00000000000..53b68bb314c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.fir.kt @@ -0,0 +1,8 @@ +/* + Here element has type Captured(*) because of resolution for `iterator()` on this. + and where we resolve `destination.add(element)` we approximate element to `Any` with smart cast to `R`. + */ +inline fun > Array<*>.filterIsInstanceTo(destination: C): C { + for (element in this) if (element is R) destination.add(element) + return destination +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.fir.kt new file mode 100644 index 00000000000..2be38a24617 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.fir.kt @@ -0,0 +1,15 @@ +fun foo(s: String) = s.length + +fun baz(s: String?, r: String?): Int { + return foo(r ?: when { + s != null -> s + else -> "" + }) +} + +fun bar(s: String?, r: String?): Int { + return (r ?: when { + s != null -> s + else -> "" + }).length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastOnIf.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnIf.fir.kt new file mode 100644 index 00000000000..341b1fd7e56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnIf.fir.kt @@ -0,0 +1,10 @@ +fun baz(s: String?): Int { + return if (s == null) { + "" + } + else { + val u: String? = null + if (u == null) return 0 + u + }.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.fir.kt new file mode 100644 index 00000000000..9a1e791282b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.fir.kt @@ -0,0 +1,20 @@ +// Smart casts on complex expressions +fun baz(s: String?): Int { + if (s == null) return 0 + return when(s) { + "abc" -> s + else -> "xyz" + }.length +} + +var ss: String? = null + +fun bar(): Int { + if (ss == null) return 0 + // ss cannot be smart casted, so an error here + return when(ss) { + "abc" -> ss + else -> "xyz" + }.length +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastOnSameFieldOfDifferentInstances.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastOnSameFieldOfDifferentInstances.fir.kt new file mode 100644 index 00000000000..b30d0201804 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastOnSameFieldOfDifferentInstances.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// See KT-27260 + +class A(val x: String?) { + fun foo(other: A) { + when { + x == null && other.x == null -> "1" + x.length > 0 -> "2" + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.fir.kt new file mode 100644 index 00000000000..618f5b66a69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.fir.kt @@ -0,0 +1,36 @@ +package foo + +class A(val i: Int?) { + fun test1() { + if (this@A.i != null) { + useInt(this.i) + useInt(i) + } + } + + inner class B { + fun test2() { + if (i != null) { + useInt(this@A.i) + } + } + } +} + +fun A.foo() { + if (this@foo.i != null) { + useInt(this.i) + useInt(i) + } +} + +fun test3() { + useFunction { + if(i != null) { + useInt(this.i) + } + } +} + +fun useInt(i: Int) = i +fun useFunction(f: A.() -> Unit) = f \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/thisWithLabelAsReceiverPart.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/thisWithLabelAsReceiverPart.fir.kt new file mode 100644 index 00000000000..bdbc0aa44f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/thisWithLabelAsReceiverPart.fir.kt @@ -0,0 +1,39 @@ +package foo + +class C(val i: Int?) {} + +class A(val c: C) { + fun test1() { + if (this@A.c.i != null) { + useInt(this.c.i) + useInt(c.i) + } + } + + inner class B { + fun test2() { + if (c.i != null) { + useInt(this@A.c.i) + } + } + } +} + +fun A.foo() { + if (this@foo.c.i != null) { + useInt(this.c.i) + useInt(c.i) + } +} + +fun test3() { + useFunction { + if(c.i != null) { + useInt(this.c.i) + } + } +} + +fun useInt(i: Int) = i +fun useFunction(f: A.() -> Unit) = f + diff --git a/compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.fir.kt new file mode 100644 index 00000000000..9963912df7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/threeImplicitReceivers.fir.kt @@ -0,0 +1,27 @@ +interface IA +interface IB +interface IC + +object Host : IB + +object Prop : IA { + val Host.foo: Callee get() = Callee +} + +object Callee + +object Invoke : IC { + operator fun Callee.invoke() { } +} + +fun test(a: IA, b: IB, c: IC) { + with(a) lambdaA@{ + with(b) lambdaB@{ + with(c) lambdaC@{ + if (this@lambdaA is Prop && this@lambdaB is Host && this@lambdaC is Invoke) { + foo() + } + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/twoImplicitReceivers.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/twoImplicitReceivers.fir.kt new file mode 100644 index 00000000000..789ca3c61ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/twoImplicitReceivers.fir.kt @@ -0,0 +1,18 @@ +interface IA +interface IB + +object A : IA { + fun B.foo() { } +} + +object B : IB + +fun test(a: IA, b: IB) { + with(a) lambda1@{ + with(b) lambda2@{ + if (this@lambda1 is A && this@lambda2 is B) { + foo() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/typeDegradation.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/typeDegradation.fir.kt new file mode 100644 index 00000000000..8431470f568 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/typeDegradation.fir.kt @@ -0,0 +1,17 @@ +open class VeryBase + +open class Base : VeryBase() + +class Derived : Base() { + fun original(): VeryBase = this +} + +class Another : Base() + +fun foo(d: Derived, a: Another?): Base? { + // d is compared with d.original(): VeryBase but should retain its own type + if (d.original() != d) return null + // ad should be of type Base, not VeryBase + val ad = a ?: d + return ad +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/typeInComparison.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/typeInComparison.fir.kt new file mode 100644 index 00000000000..d2481f8146e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/typeInComparison.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +fun foo(): Int { + val x: Any? = null + val y = 2 + if (x == y) { + return x + y + } + return y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.fir.kt new file mode 100644 index 00000000000..b229ad774f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.fir.kt @@ -0,0 +1,18 @@ +class Foo(var x: Int?) { + init { + if (x != null) { + val y = x + // Error: x is not stable, Type(y) = Int? + x.hashCode() + y.hashCode() + if (y == x) { + // Still error + y.hashCode() + } + if (x == null && y != x) { + // Still error + y.hashCode() + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/unstableToStableTypes.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/unstableToStableTypes.fir.kt new file mode 100644 index 00000000000..75893bf35b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/unstableToStableTypes.fir.kt @@ -0,0 +1,22 @@ +class Bar { + fun bar() {} +} + +class Foo(var x: Any) { + init { + if (x is Bar) { + val y = x + // Error: x is not stable, Type(y) = Any + x.bar() + y.bar() + if (y == x) { + // Still error + y.bar() + } + if (x !is Bar && y != x) { + // Still error + y.bar() + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varChangedInInitializer.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varChangedInInitializer.fir.kt new file mode 100644 index 00000000000..6ca3b6fbe3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varChangedInInitializer.fir.kt @@ -0,0 +1,7 @@ +class My { + init { + var y: Int? + y = 42 + y.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varChangedInLocalInitializer.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varChangedInLocalInitializer.fir.kt new file mode 100644 index 00000000000..73cb4c48328 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varChangedInLocalInitializer.fir.kt @@ -0,0 +1,10 @@ +fun foo() { + class My { + val x: Int + init { + var y: Int? + y = 42 + x = y.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varInAccessor.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varInAccessor.fir.kt new file mode 100644 index 00000000000..31b12be35ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varInAccessor.fir.kt @@ -0,0 +1,17 @@ +var x: Int = 0 + get() { + var y: Int? = null + if (y != null) { + return y.hashCode() + } + return field + } + set(param) { + var y: Int? = null + if (y != null) { + field = y.hashCode() + } + else { + field = param + } + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varInInitNoPrimary.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varInInitNoPrimary.fir.kt new file mode 100644 index 00000000000..e5981c2c85b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varInInitNoPrimary.fir.kt @@ -0,0 +1,22 @@ +class Your { + init { + var y: String? = "xyz" + if (y != null) { + // Bug that should be fixed + // Problem: descriptorToDeclaration cannot get here init block by its descriptor + // See PreliminaryDeclarationVisitor.getVisitorByVariable + y.hashCode() + } + } + + constructor() +} + +class Normal { + init { + var y: String? = "xyz" + if (y != null) { + y.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varInInitializer.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varInInitializer.fir.kt new file mode 100644 index 00000000000..9db530e6266 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varInInitializer.fir.kt @@ -0,0 +1,12 @@ +class My { + val x: Int + init { + var y: Int? = null + if (y != null) { + x = y.hashCode() + } + else { + x = 0 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varInSecondaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varInSecondaryConstructor.fir.kt new file mode 100644 index 00000000000..f9986bbc05c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varInSecondaryConstructor.fir.kt @@ -0,0 +1,10 @@ +class My(val z: Int) { + var x: Int = 0 + constructor(arg: Int?): this(arg ?: 42) { + var y: Int? + y = arg + if (y != null) { + x = y + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varInsideLocalFun.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varInsideLocalFun.fir.kt new file mode 100644 index 00000000000..907f31dd2a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varInsideLocalFun.fir.kt @@ -0,0 +1,17 @@ +// Based on KT-8643 +public class MyClass +{ + fun main() { + var str: String? = null + + if (str != null) + callback { + // Nodoby writes str, smart cast is possible + method1(str) + } + } + + inline fun callback(foo: () ->Unit) = foo() + + fun method1(str: String) = str +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/accessorAndFunction.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/accessorAndFunction.fir.kt new file mode 100644 index 00000000000..8d4e295e1ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/accessorAndFunction.fir.kt @@ -0,0 +1,23 @@ +class My { + + val y: Int + get() { + var x: Int? + x = 3 + return x.hashCode() + } + + fun test() { + var x: Int? + x = 2 + x.hashCode() + fun bb() { + var x: Any? + x = 4 + x.hashCode() + } + x = 4 + // Really smart cast is possible but name shadowing by bb() prevents it + x.hashCode() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/assignment.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/assignment.fir.kt new file mode 100644 index 00000000000..0c157cd4b30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/assignment.fir.kt @@ -0,0 +1,10 @@ +fun foo() { + var v: Any = 42 + v.length() + v = "abc" + v.length + v = 42 + v.length() + v = "abc" + v.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/assignmentConversion.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/assignmentConversion.fir.kt new file mode 100644 index 00000000000..d1b35b3fd20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/assignmentConversion.fir.kt @@ -0,0 +1,35 @@ +fun foo(x: String) = x + +fun test1() { + var c: Any? = "XXX" + if (c !is String) return + + val newC: String? = "YYY" + if (newC != null) { + c = newC + } + foo(c) +} + +fun test2() { + var c: Any? = "XXX" + if (c !is String) return + + val newC: String? = "YYY" + if (newC is String) { + c = newC + } + foo(c) +} + +fun test3() { + var c: Any? = "XXX" + if (c !is String) return + + val newC: String? = "YYY" + if (newC == null) return + c = newC + + foo(c) +} + diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.fir.kt new file mode 100644 index 00000000000..95a78781df3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.fir.kt @@ -0,0 +1,12 @@ +fun x(): Boolean { return true } + +public fun foo(pp: Any): Int { + var p = pp + do { + (p as String).length + if (p == "abc") break + p = 42 + } while (!x()) + // Smart cast is NOT possible here + return p.length() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhile.fir.kt new file mode 100644 index 00000000000..9d04156c7d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhile.fir.kt @@ -0,0 +1,15 @@ +public fun foo(xx: Any): Int { + var x = xx + do { + var y: Any + // After the check, smart cast should work + if (x is String) { + y = "xyz" + } else { + y = "abc" + } + // y!! in both branches + y.length + } while (!(x is String)) + return x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhileWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhileWithBreak.fir.kt new file mode 100644 index 00000000000..d4b85792f05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhileWithBreak.fir.kt @@ -0,0 +1,16 @@ +public fun foo(xx: Any): Int { + var x = xx + do { + var y: Any + // After the check, smart cast should work + if (x is String) { + break + } else { + y = "abc" + } + // y!! in both branches + y.length + } while (true) + // We could have smart cast here but with break it's hard to detect + return x.length() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.fir.kt new file mode 100644 index 00000000000..04df688e9a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifNullAssignment.fir.kt @@ -0,0 +1,73 @@ +// !WITH_NEW_INFERENCE +// See KT-13468, KT-13765 + +fun basic(): String { + var current: String? = null + current = if (current == null) "bar" else current + return current +} + +fun foo(flag: Boolean) { + var x: String? = null + + if (x == null) { + x = if (flag) "34" else "12" + } + + x.hashCode() +} + +fun bar(flag: Boolean) { + var x: String? = null + + if (x == null) { + x = when { + flag -> "34" + else -> "12" + } + } + + x.hashCode() +} + +fun baz(flag: Boolean) { + var x: String? = null + + if (x == null) { + x = if (flag) { + "34" + } else { + "12" + } + } + + x.hashCode() +} + +fun gav(flag: Boolean, arg: String?) { + var x: String? = null + + if (x == null) { + x = arg ?: if (flag) { + "34" + } else { + "12" + } + } + + x.hashCode() +} + +fun gau(flag: Boolean, arg: String?) { + var x: String? = null + + if (x == null) { + x = if (flag) { + arg ?: "34" + } else { + arg ?: "12" + } + } + + x.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIs.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIs.fir.kt new file mode 100644 index 00000000000..f05dbb4bff5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIs.fir.kt @@ -0,0 +1,9 @@ +public fun bar(s: String) { + System.out.println("Length of $s is ${s.length}") +} + +public fun foo() { + var s: Any = "not null" + if (s is String) + bar(s) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsAnd.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsAnd.fir.kt new file mode 100644 index 00000000000..dacc37f47a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsAnd.fir.kt @@ -0,0 +1,13 @@ +// See KT-5737 +fun get(): Any { + return "abc" +} + +fun foo(): Int { + var ss: Any = get() + + return if (ss is String && ss.length > 0) + 1 + else + 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsChanged.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsChanged.fir.kt new file mode 100644 index 00000000000..5f0fd9dcaf3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsChanged.fir.kt @@ -0,0 +1,11 @@ +public fun bar(s: String) { + System.out.println("Length of $s is ${s.length}") +} + +public fun foo() { + var s: Any = "not null" + if (s is String) { + s = 42 + bar(s) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/inPropertySam.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/inPropertySam.fir.kt new file mode 100644 index 00000000000..c25b82199a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/inPropertySam.fir.kt @@ -0,0 +1,18 @@ +// FILE: My.java + +public interface My { + String foo(String arg); +} + +// FILE: test.kt + +class Your { + val x = My() { + arg: String? -> + var y = arg + val z: String + if (y != null) z = y + else z = "42" + z + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/infix.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/infix.fir.kt new file mode 100644 index 00000000000..5b7085f2d4a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/infix.fir.kt @@ -0,0 +1,11 @@ +// See KT-774 +fun box() : Int { + var a : Any = 1 + var d = 1 + + if (a is Int) { + return a + d + } else { + return 2 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/initialization.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/initialization.fir.kt new file mode 100644 index 00000000000..3c3b0d72337 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/initialization.fir.kt @@ -0,0 +1,8 @@ +fun foo() { + var v: Any = "xyz" + // It is possible in principle to provide smart cast here + // but now we decide that v is Any + v.length() + v = 42 + v.length() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/kt7599.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/kt7599.fir.kt new file mode 100644 index 00000000000..7bd807aadbc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/kt7599.fir.kt @@ -0,0 +1,23 @@ +interface A { + fun ok(): Boolean +} + +class B: A { + override fun ok(): Boolean { return true } +} + +class C: A { + override fun ok(): Boolean { return false } +} + +fun foo(): Boolean { + var v: A + v = B() + // No smart cast needed, but not a problem if ever + if (v.ok()) { + v = C() + } + // No smart cast needed, and no smart cast possible! + // We cannot choose between B and C + return v.ok() +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.fir.kt new file mode 100644 index 00000000000..5c49ba03947 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: Int, f: () -> Unit, y: Int) {} + +fun bar() { + var x: Int? + x = 4 + foo(x, { x = null; x.hashCode() }, x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/property.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/property.fir.kt new file mode 100644 index 00000000000..85c74542a9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/property.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +class MyClass(var p: String?) + +fun bar(s: String): Int { + return s.length +} + +fun foo(m: MyClass): Int { + m.p = "xyz" + return bar(m.p) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/propertyNotNeeded.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/propertyNotNeeded.fir.kt new file mode 100644 index 00000000000..631449c8f14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/propertyNotNeeded.fir.kt @@ -0,0 +1,10 @@ +class MyClass(var p: String?) + +fun bar(s: String?): Int { + return s?.length ?: -1 +} + +fun foo(m: MyClass): Int { + m.p = "xyz" + return bar(m.p) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtype.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtype.fir.kt new file mode 100644 index 00000000000..2563e8c449f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtype.fir.kt @@ -0,0 +1,10 @@ +class MyClass(var p: Any) + +fun bar(s: Any): Int { + return s.hashCode() +} + +fun foo(m: MyClass): Int { + m.p = "xyz" + return bar(m.p) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMember.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMember.fir.kt new file mode 100644 index 00000000000..a47fce835c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMember.fir.kt @@ -0,0 +1,10 @@ +fun bar(s: Any): Int { + return s.hashCode() +} + +class MyClass(var p: Any) { + fun foo(): Int { + p = "xyz" + return bar(p) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMemberCheck.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMemberCheck.fir.kt new file mode 100644 index 00000000000..1575866e196 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMemberCheck.fir.kt @@ -0,0 +1,13 @@ +fun bar(s: Any): Int { + return s.hashCode() +} + +class MyClass(var p: Any) { + fun foo(): Int { + p = "xyz" + if (p is String) { + return bar(p) + } + return -1 + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/varAsUse.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/varAsUse.fir.kt new file mode 100644 index 00000000000..b86fa4b3d11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/varAsUse.fir.kt @@ -0,0 +1,9 @@ +fun get(): Any { + return "" +} + +fun foo(): Int { + var c: Any = get() + (c as String).length + return c.length // Previous line should make as unnecessary here. +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/varChangedInLoop.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/varChangedInLoop.fir.kt new file mode 100644 index 00000000000..3146821521a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/varChangedInLoop.fir.kt @@ -0,0 +1,9 @@ +public fun foo() { + var i: Any = 1 + if (i is Int) { + while (i != 10) { + i++ // Here smart cast should not be performed due to a successor + i = "" + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/varNotChangedInLoop.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/varNotChangedInLoop.fir.kt new file mode 100644 index 00000000000..1a2eee01965 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/varNotChangedInLoop.fir.kt @@ -0,0 +1,8 @@ +public fun foo() { + var i: Any = 1 + if (i is Int) { + while (i != 10) { + i++ + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/whileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/whileTrue.fir.kt new file mode 100644 index 00000000000..3bbf2191c1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/whileTrue.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(pp: Any): Int { + var p = pp + while(true) { + (p as String).length + if (x()) break + p = 42 + } + // Smart cast is NOT possible here + // (we could provide it but p = 42 makes it difficult to understand) + return p.length() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/whileWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/whileWithBreak.fir.kt new file mode 100644 index 00000000000..b34bb73ed5e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/whileWithBreak.fir.kt @@ -0,0 +1,17 @@ +fun String.next(): String { + return "abc" +} + +fun list(start: String) { + var e: Any? = start + if (e==null) return + while (e is String) { + // Smart cast due to the loop condition + if (e.length == 0) + break + // We still have smart cast here despite of a break + e = e.next() + } + // e can never be null but we do not know it + e.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.fir.kt new file mode 100644 index 00000000000..58a8a768091 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.fir.kt @@ -0,0 +1,28 @@ +class Bar { + fun next(): Bar? { + if (2 == 4) + return this + else + return null + } +} + +fun foo(): Bar { + var x: Bar? = Bar() + var y: Bar? + y = Bar() + while (x != null) { + // Here call is unsafe because of inner loop + y.next() + while (y != null) { + if (x == y) + // x is not null because of outer while + return x + // y is not null because of inner while + y = y.next() + } + // x is not null because of outer while + x = x.next() + } + return Bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.fir.kt new file mode 100644 index 00000000000..3149478be42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE +fun foo() { + var v: String? = null + v.length + v = "abc" + v.length + v = null + v.length + v = "abc" + v.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializer.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializer.fir.kt new file mode 100644 index 00000000000..60589b26bb1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializer.fir.kt @@ -0,0 +1,20 @@ +fun foo(arg: Int?) { + val x = arg + if (x != null) { + arg.hashCode() + } + val y: Any? = arg + if (y != null) { + arg.hashCode() + } + val yy: Any? + yy = arg + if (yy != null) { + arg.hashCode() + } + var z = arg + z = z?.let { 42 } + if (z != null) { + arg.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializerWrong.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializerWrong.fir.kt new file mode 100644 index 00000000000..7acef4daacf --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/boundInitializerWrong.fir.kt @@ -0,0 +1,46 @@ +// !WITH_NEW_INFERENCE +// KT-15792 and related + +fun foo() { + var x: String? = "" + val y = x + x = null + if (y != null) { + x.hashCode() + } +} + +fun foo2() { + var x: String? = "" + val y = x + if (y != null) { + x.hashCode() + } +} + +fun bar(s: String?) { + var ss = s + val hashCode = ss?.hashCode() + ss = null + if (hashCode != null) { + ss.hashCode() + } +} + +fun bar2(s: String?) { + var ss = s + val hashCode = ss?.hashCode() + if (hashCode != null) { + ss.hashCode() + } +} + +class Some(var s: String?) + +fun baz(arg: Some?) { + val ss = arg?.s + if (ss != null) { + arg.hashCode() + arg.s.hashCode() + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.fir.kt new file mode 100644 index 00000000000..5a017f5d5b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +CapturedInClosureSmartCasts + +fun run(f: () -> Unit) = f() + +fun foo(s: String?) { + var x: String? = null + if (s != null) { + x = s + } + if (x != null) { + run { + x.hashCode() + } + } +} + +fun bar(s: String?) { + var x = s + if (x != null) { + run { + x.hashCode() + } + } +} + +fun baz(s: String?) { + var x = s + if (x != null) { + run { + x.hashCode() + } + run { + x.hashCode() + x = null + } + } +} + +fun gaz(s: String?) { + var x = s + if (x != null) { + run { + x.hashCode() + x = null + } + run { + x.hashCode() + } + } +} + +fun gav(s: String?) { + var x = s + if (x != null) { + run { + x.hashCode() + } + x = null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureOff.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureOff.fir.kt new file mode 100644 index 00000000000..74294986b9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureOff.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -CapturedInClosureSmartCasts + +fun run(f: () -> Unit) = f() + +fun foo(s: String?) { + var x: String? = null + if (s != null) { + x = s + } + if (x != null) { + run { + x.hashCode() + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithBreak.fir.kt new file mode 100644 index 00000000000..3b1b5feabe3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithBreak.fir.kt @@ -0,0 +1,21 @@ +data class SomeObject(val n: SomeObject?) { + fun doSomething(): Boolean = true + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject) { + var e: SomeObject? + e = start + do { + // In theory smart cast is possible here + // But in practice we have a loop with changing e + // ?: should we "or" entrance type info with condition type info? + if (!e.doSomething()) + break + // Smart cast here is still not possible + e = e.next() + } while (e != null) + // e can be null because of next() + e.doSomething() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.fir.kt new file mode 100644 index 00000000000..2b916f90fb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.fir.kt @@ -0,0 +1,12 @@ +fun x(): Boolean { return true } + +public fun foo(pp: String?): Int { + var p = pp + do { + p!!.length + if (p == "abc") break + p = null + } while (!x()) + // Smart cast is NOT possible here + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.fir.kt new file mode 100644 index 00000000000..40a920e0373 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +data class SomeObject(val n: SomeObject?) { + fun doSomething() {} + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject): SomeObject { + var e: SomeObject? = start + for (i in 0..42) { + // Unsafe calls because of nullable e at the beginning + e.doSomething() + e = e.next() + } + // Smart cast is not possible here due to next() + return e +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithBreak.fir.kt new file mode 100644 index 00000000000..dd368ad85c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithBreak.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +data class SomeObject(val n: SomeObject?) { + fun doSomething() {} + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject): SomeObject { + var e: SomeObject? = start + for (i in 0..42) { + if (e == null) + break + // Smart casts are possible because of the break before + e.doSomething() + e = e.next() + } + return e +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithContinue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithContinue.fir.kt new file mode 100644 index 00000000000..67fec6fb985 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithContinue.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +data class SomeObject(val n: SomeObject?) { + fun doSomething() {} + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject): SomeObject { + var e: SomeObject? = start + for (i in 0..42) { + if (e == null) + continue + // Smart casts are possible because of the continue before + e.doSomething() + e = e.next() + } + return e +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNull.fir.kt new file mode 100644 index 00000000000..7143c2bbc4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNull.fir.kt @@ -0,0 +1,9 @@ +public fun fooNotNull(s: String) { + System.out.println("Length of $s is ${s.length}") +} + +public fun foo() { + var s: String? = "not null" + if (s != null) + fooNotNull(s) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.fir.kt new file mode 100644 index 00000000000..ce7f4a7dcb5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.fir.kt @@ -0,0 +1,13 @@ +// See KT-5737 +fun get(): String? { + return "abc" +} + +fun foo(): Int { + var ss:String? = get() + + return if (ss != null && ss.length > 0) + 1 + else + 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.fir.kt new file mode 100644 index 00000000000..8278d95575c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.fir.kt @@ -0,0 +1,12 @@ +public fun fooNotNull(s: String) { + System.out.println("Length of $s is ${s.length}") +} + +public fun foo() { + var s: String? = "not null" + if (s == null) { + // Coming soon + } else { + fooNotNull(s) + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullReturn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullReturn.fir.kt new file mode 100644 index 00000000000..91bc2229578 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullReturn.fir.kt @@ -0,0 +1,11 @@ +public fun fooNotNull(s: String) { + System.out.println("Length of $s is ${s.length}") +} + +public fun foo() { + var s: String? = "not null" + if (s == null) { + return + } + fooNotNull(s) +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.fir.kt new file mode 100644 index 00000000000..e371be59aee --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.fir.kt @@ -0,0 +1,21 @@ +// See KT-969 +fun f() { + var s: String? + s = "a" + var s1 = "" // String � ? + if (s != null) { // Redundant + s1.length + // We can do smartcast here and below + s1 = s.toString() // return String? + s1.length + s1 = s + s1.length + // It's just an assignment without smartcast + val s2 = s + // But smartcast can be done here + s2.length + // And also here + val s3 = s.toString() + s3.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infiniteWhileWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infiniteWhileWithBreak.fir.kt new file mode 100644 index 00000000000..f13e2013809 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infiniteWhileWithBreak.fir.kt @@ -0,0 +1,20 @@ +data class SomeObject(val n: SomeObject?) { + fun doSomething(): Boolean = true + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject) { + var e: SomeObject? + e = start + // This comparison is senseless + while (e != null) { + // Smart cast because of the loop condition + if (!e.doSomething()) + break + // We still have smart cast here despite of a break + e = e.next() + } + // e can be null because of next() + e.doSomething() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.fir.kt new file mode 100644 index 00000000000..e748ef6da47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.fir.kt @@ -0,0 +1,11 @@ +// See KT-774 +fun box() : Int { + var a : Int? = 1 + var d = 1 + + if (a == null) { + return 2 + } else { + return a + d + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initInTryReturnInCatch.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initInTryReturnInCatch.fir.kt new file mode 100644 index 00000000000..0788bc8222c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initInTryReturnInCatch.fir.kt @@ -0,0 +1,80 @@ +// !WITH_NEW_INFERENCE +// JAVAC_EXPECTED_FILE +// See also KT-10735 +fun test() { + var a: Int? + try { + a = 3 + } + catch (e: Exception) { + return + } + a.hashCode() // a is never null here +} +class A: Exception() +class B: Exception() +fun test2() { + var a: Int? + try { + a = 4 + } + catch (e: A) { + return + } + catch (e: B) { + return + } + a.hashCode() // a is never null here +} +fun test3() { + var a: Int? = null + try { + a = 5 + } + catch (e: A) { + // do nothing + } + catch (e: B) { + return + } + a.hashCode() // a is nullable here +} +fun test4() { + var a: Int? = null + try { + // do nothing + } + catch (e: A) { + return + } + catch (e: B) { + return + } + a.hashCode() // a is nullable here +} +fun test5() { + var a: Int?// = null + try { + a = 3 + } + catch (e: Exception) { + return + } + finally { + a = 5 + } + a.hashCode() // a is never null here +} +fun test6() { + var a: Int?// = null + try { + a = 3 + } + catch (e: Exception) { + return + } + finally { + a = null + } + a.hashCode() // a is null here +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.fir.kt new file mode 100644 index 00000000000..6f206aa7d26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +fun foo() { + var v: String? = "xyz" + // It is possible in principle to provide smart cast here + v.length + v = null + v.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.fir.kt new file mode 100644 index 00000000000..4c248fff2d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.fir.kt @@ -0,0 +1,14 @@ +data class SomeObject(val n: SomeObject?) { + fun doSomething() {} + fun next(): SomeObject? = n +} + + +fun list(start: SomeObject) { + var e: SomeObject? = start + while (e != null) { + // While condition makes both smart casts possible + e.doSomething() + e = e.next() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedDoWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedDoWhile.fir.kt new file mode 100644 index 00000000000..e08d47a1ce4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedDoWhile.fir.kt @@ -0,0 +1,15 @@ +fun x(): Boolean { return true } + +public fun foo(pp: String?, rr: String?): Int { + var p = pp + var r = rr + do { + do { + p!!.length + } while (r == null) + } while (!x()) + // Auto cast possible + r.length + // Auto cast possible + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedLoops.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedLoops.fir.kt new file mode 100644 index 00000000000..076b4f3bced --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedLoops.fir.kt @@ -0,0 +1,19 @@ +fun x(): Boolean { return true } + +public fun foo(qq: String?): Int { + var q = qq + while(true) { + q!!.length + var r = q + do { + var p = r + do { + // p = r, r = q and q is not null + p.length + } while (!x()) + } while (r == null) // r = q and q is not null + if (!x()) break + } + // Smart cast is possible + return q.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedWhile.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedWhile.fir.kt new file mode 100644 index 00000000000..828d2c611d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedWhile.fir.kt @@ -0,0 +1,27 @@ +class Bar { + fun next(): Bar? { + if (2 == 4) + return this + else + return null + } +} + +fun foo(): Bar { + var x: Bar? = Bar() + var y: Bar? = Bar() + while (x != null) { + // Here call is unsafe because of initialization and also inner loop + y.next() + while (y != null) { + if (x == y) + // x is not null because of outer while + return x + // y is not null because of inner while + y = y.next() + } + // x is not null because of outer while + x = x.next() + } + return Bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/plusplusMinusminus.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/plusplusMinusminus.fir.kt new file mode 100644 index 00000000000..dc2a9386d1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/plusplusMinusminus.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +fun foo(arg: Int?): Int { + var i = arg + if (i != null && i++ == 5) { + return i-- + i + } + return 0 +} + +operator fun Long?.inc() = this?.let { it + 1 } + +fun bar(arg: Long?): Long { + var i = arg + if (i++ == 5L) { + return i-- + i + } + if (i++ == 7L) { + return i++ + i + } + return 0L +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.fir.kt new file mode 100644 index 00000000000..f596b8eb5ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNotnullClassIncrement.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +class MyClass + +operator fun MyClass.inc(): MyClass { return null!! } + +public fun box() : MyClass? { + var i : MyClass? + i = MyClass() + // type of j can be inferred as MyClass() + var j = i++ + j.hashCode() + return i +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableClassIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableClassIncrement.fir.kt new file mode 100644 index 00000000000..4dcd2429965 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableClassIncrement.fir.kt @@ -0,0 +1,12 @@ +class MyClass + +// Correct at compile time but wrong at run-time +operator fun MyClass?.inc(): MyClass? { return null } + +public fun box() : MyClass? { + var i : MyClass? + i = MyClass() + var j = i++ + j.hashCode() + return i +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableIncrement.fir.kt new file mode 100644 index 00000000000..6dbcb1dd091 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/postfixNullableIncrement.fir.kt @@ -0,0 +1,8 @@ +operator fun Int?.inc(): Int? { return this } + +public fun box(arg: Int?) : Int? { + var i : Int? = arg + var j = i++ + j.toInt() + return i +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.fir.kt new file mode 100644 index 00000000000..b6221b848ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNotnullClassIncrement.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +class MyClass + +operator fun MyClass.inc(): MyClass { return null!! } + +public fun box() { + var i : MyClass? + i = MyClass() + // Type of j should be inferred as MyClass? + var j = ++i + // j is null so call is unsafe + j.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableClassIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableClassIncrement.fir.kt new file mode 100644 index 00000000000..b4bb5a201ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableClassIncrement.fir.kt @@ -0,0 +1,13 @@ +class MyClass + +// Correct at compile time but wrong at run-time +operator fun MyClass?.inc(): MyClass? { return null } + +public fun box() { + var i : MyClass? + i = MyClass() + // type of j should be MyClass? + var j = ++i + // j is null so call should be unsafe + j.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableIncrement.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableIncrement.fir.kt new file mode 100644 index 00000000000..25f99500d48 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/prefixNullableIncrement.fir.kt @@ -0,0 +1,8 @@ +operator fun Int?.inc(): Int? { return this } + +public fun box(arg: Int?) : Int? { + var i = arg + var j = ++i + j.toInt() + return ++j +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNotNullInTry.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNotNullInTry.fir.kt new file mode 100644 index 00000000000..9fd03ec7f93 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNotNullInTry.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +SoundSmartCastsAfterTry + +fun bar(arg: Any?) = arg + +fun foo() { + var s: String? + s = null + try { + s = "Test" + } catch (ex: Exception) {} + bar(s) + if (s != null) { } + s.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTry.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTry.fir.kt new file mode 100644 index 00000000000..71d9ce5881d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTry.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +SoundSmartCastsAfterTry + +fun foo() { + var s: String? + s = "Test" + try { + s = null + } catch (ex: Exception) {} + s.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryFinally.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryFinally.fir.kt new file mode 100644 index 00000000000..fa0415c2556 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryFinally.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +SoundSmartCastsAfterTry + +fun bar() {} + +fun foo() { + var s: String? + s = "Test" + try { + s = null + } + catch (ex: Exception) {} + finally { + bar() + } + s.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryUnsound.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryUnsound.fir.kt new file mode 100644 index 00000000000..f6f286f9e36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setNullInTryUnsound.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: -SoundSmartCastsAfterTry + +fun foo() { + var s: String? + s = "Test" + try { + s = null + } catch (ex: Exception) {} + s.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setSameInTry.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setSameInTry.fir.kt new file mode 100644 index 00000000000..9794a3c7487 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/setSameInTry.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +SoundSmartCastsAfterTry + +fun foo() { + var s: String? + s = "Test" + try { + s = "Other" + } catch (ex: Exception) {} + // Problem: here we do not see that 's' is always not-null + s.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.fir.kt new file mode 100644 index 00000000000..97a21e52d45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.fir.kt @@ -0,0 +1,16 @@ +// FILE: J.java + +class J { + static String foo() { return "abc"; } +} + +// FILE: test.kt + +fun bar() { + var v: String? + v = J.foo() + v.length + gav(v) +} + +fun gav(v: String) = v \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.fir.kt new file mode 100644 index 00000000000..d996a398daa --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.fir.kt @@ -0,0 +1,12 @@ +fun String?.foo(): String { + return this ?: "" +} + +class MyClass { + private var s: String? = null + + fun bar(): String { + s = "42" + return s.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithBranch.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithBranch.fir.kt new file mode 100644 index 00000000000..5827bba34e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithBranch.fir.kt @@ -0,0 +1,12 @@ +fun String?.foo(): String { + return this ?: "" +} + +class MyClass { + fun bar(): String { + var s: String? = null + if (4 < 2) + s = "42" + return s.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithMap.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithMap.fir.kt new file mode 100644 index 00000000000..5265503fc10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithMap.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +fun create(): Map = null!! + +operator fun Map.iterator(): Iterator> = null!! + +operator fun Map.Entry.component1() = key + +operator fun Map.Entry.component2() = value + +class MyClass { + private var m: Map? = null + fun foo(): Int { + var res = 0 + m = create() + // See KT-7428 + for ((k, v) in m) + res += (k.length + v.length) + return res + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInClosure.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInClosure.fir.kt new file mode 100644 index 00000000000..ad11d03afd1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInClosure.fir.kt @@ -0,0 +1,17 @@ +public fun foo() { + var s: String? = "" + fun closure(): Int { + if (s == "") { + s = null + return -1 + } else if (s == null) { + return -2 + } else { + return s.length // Here smartcast is possible, at least in principle + } + } + if (s != null) { + System.out.println(closure()) + System.out.println(s.length) // Here smartcast is not possible due to a closure predecessor + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.fir.kt new file mode 100644 index 00000000000..508d7330612 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// See also KT-7186 + +fun IntArray.forEachIndexed( op: (i: Int, value: Int) -> Unit) { + for (i in 0..this.size) + op(i, this[i]) +} + +fun max(a: IntArray): Int? { + var maxI: Int? = null + a.forEachIndexed { i, value -> + if (maxI == null || value >= a[maxI]) + maxI = i + } + return maxI +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInSafeClosure.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInSafeClosure.fir.kt new file mode 100644 index 00000000000..9140c8f49c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInSafeClosure.fir.kt @@ -0,0 +1,15 @@ +public fun foo() { + var s: String? = "" + fun closure(): Int { + if (s == null) { + return -1 + } else { + return 0 + } + } + if (s != null) { + System.out.println(closure()) + // Smart cast is possible, nobody modifies s + System.out.println(s.length) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.fir.kt new file mode 100644 index 00000000000..b0e56a1b8bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.fir.kt @@ -0,0 +1,9 @@ +public fun foo() { + var i: Int? = 1 + if (i != null) { + while (i != 10) { + i++ // Here smart cast should not be performed due to a successor + i = null + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.fir.kt new file mode 100644 index 00000000000..b12378d27a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.fir.kt @@ -0,0 +1,9 @@ +fun get(): String? { + return "" +} + +fun foo(): Int { + var c: String? = get() + c!!.length + return c.length // Previous line should make !! unnecessary here. +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt new file mode 100644 index 00000000000..2cb01a3ef43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +fun foo(): Int { + var i: Int? = 42 + i = null + return i + 1 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNotChangedInLoop.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNotChangedInLoop.fir.kt new file mode 100644 index 00000000000..b36be19bf86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNotChangedInLoop.fir.kt @@ -0,0 +1,8 @@ +public fun foo() { + var i: Int? = 1 + if (i != null) { + while (i != 10) { + i++ + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.fir.kt new file mode 100644 index 00000000000..4fbd84ed5f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +fun foo(): Int { + var s: String? = "abc" + s = null + return s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrue.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrue.fir.kt new file mode 100644 index 00000000000..964baa75abc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrue.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(pp: String?): Int { + var p = pp + while(true) { + p!!.length + if (x()) break + p = null + } + // Smart cast is NOT possible here + // (we could provide it but p = null makes it much harder) + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBracketSet.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBracketSet.fir.kt new file mode 100644 index 00000000000..2fe1af49ac4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBracketSet.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(pp: String?): Int { + var p = pp + while(true) { + p!!.length + if (x()) break + (((p))) = null + } + // Smart cast is NOT possible here + // (we could provide it but p = null makes it much harder) + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBrackets.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBrackets.fir.kt new file mode 100644 index 00000000000..2c3a154ffdf --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrueWithBrackets.fir.kt @@ -0,0 +1,13 @@ +fun x(): Boolean { return true } + +public fun foo(pp: String?): Int { + var p = pp + while(true) { + p!!.length + if (x()) break + (p) = null + } + // Smart cast is NOT possible here + // (we could provide it but p = null makes it much harder) + return p.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileWithBreak.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileWithBreak.fir.kt new file mode 100644 index 00000000000..0d5e3c38d9f --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileWithBreak.fir.kt @@ -0,0 +1,17 @@ +data class SomeObject(val n: SomeObject?) { + fun doSomething(): Boolean = true + fun next(): SomeObject? = n +} + +fun list(start: SomeObject) { + var e: SomeObject? = start + while (e != null) { + // Smart cast due to the loop condition + if (!e.doSomething()) + break + // We still have smart cast here despite of a break + e = e.next() + } + // e can be null because of next() + e.doSomething() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/whenExprNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/whenExprNonNull.fir.kt new file mode 100644 index 00000000000..8f9a8e31649 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/whenExprNonNull.fir.kt @@ -0,0 +1,18 @@ +fun baz(s: String?): String { + if (s == null) return "" + // if explicit type String is given for t, problem disappears + val t = when(s) { + // !! is detected as unnecessary here + "abc" -> s + else -> "xyz" + } + return t +} + +fun foo(s: String?): String { + val t = when { + s != null -> s + else -> "" + } + return t +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/whenIfExprNonNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/whenIfExprNonNull.fir.kt new file mode 100644 index 00000000000..36f60e69c1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/whenIfExprNonNull.fir.kt @@ -0,0 +1,13 @@ +fun baz(s: String?, u: String?): String { + val t = when(s) { + is String -> { + if (u == null) return s + u + } + else -> { + if (u == null) return "" + u + } + } + return t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossible.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossible.fir.kt new file mode 100644 index 00000000000..a679b102d71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossible.fir.kt @@ -0,0 +1,10 @@ +// See KT-10061 + +class My { + val x: Int? get() = 42 +} + +fun foo(my: My) { + my.x!! + when (my.x) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossibleJava.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossibleJava.fir.kt new file mode 100644 index 00000000000..955e071a1d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/whenSubjectImpossibleJava.fir.kt @@ -0,0 +1,11 @@ +// See KT-10061 +// FILE: My.java +public class My { + String getSomething() { return "xyz"; } +} + +// FILE: My.kt +fun foo(my: My) { + my.something!! + when (my.something) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt new file mode 100644 index 00000000000..a5c28aa873c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/annotations.fir.kt @@ -0,0 +1,11 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +annotation class Anno1(val s: String) + +annotation class Anno2 @SinceKotlin("1.1") constructor() + + +@Anno1("") +@Anno2 +fun t1() {} diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt new file mode 100644 index 00000000000..64b5a3678bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/classesAndConstructors.fir.kt @@ -0,0 +1,23 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +open class Foo + +class Bar @SinceKotlin("1.1") constructor() + +@SinceKotlin("1.0") +class Baz @SinceKotlin("1.1") constructor() + +@SinceKotlin("1.1") +class Quux @SinceKotlin("1.0") constructor() + +fun t1(): Foo = Foo() + +// TODO: do not report API_NOT_AVAILABLE twice +fun t2() = object : Foo() {} + +fun t3(): Bar? = Bar() + +fun t4(): Baz = Baz() + +fun t5(): Quux = Quux() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/overriddenMembers.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/overriddenMembers.fir.kt new file mode 100644 index 00000000000..a7a245388c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/overriddenMembers.fir.kt @@ -0,0 +1,34 @@ +// !API_VERSION: 1.0 +// FILE: J.java + +public interface J { + void foo(); +} + +// FILE: test.kt + +interface I10 { + @SinceKotlin("1.0") + fun foo() +} + +interface I11 { + @SinceKotlin("1.1") + fun foo() +} + +fun f1(x: I10) = x.foo() +fun f2(x: I11) = x.foo() +fun f3(x: J) = x.foo() + +interface BothI1 : I10, I11 +fun f4(x: BothI1) = x.foo() + +interface BothI2 : I11, I10 +fun f5(x: BothI2) = x.foo() + +interface JAndI10 : J, I10 +fun f6(x: JAndI10) = x.foo() + +interface JAndI11 : J, I11 +fun f7(x: JAndI11) = x.foo() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.fir.kt new file mode 100644 index 00000000000..fa394d768ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.fir.kt @@ -0,0 +1,48 @@ +// !API_VERSION: 1.0 + +val v1: String + @SinceKotlin("1.1") + get() = "" + +@SinceKotlin("1.1") +val v2 = "" + +var v3: String + @SinceKotlin("1.1") + get() = "" + set(value) {} + +var v4: String + get() = "" + @SinceKotlin("1.1") + set(value) {} + +var v5: String + @SinceKotlin("1.1") + get() = "" + @SinceKotlin("1.1") + set(value) {} + +@SinceKotlin("1.1") +var v6: String + get() = "" + set(value) {} + +@SinceKotlin("1.0") +val v7: String + @SinceKotlin("1.1") + get() = "" + +fun test() { + v1 + v2 + v3 + v3 = "" + v4 + v4 = "" + v5 + v5 = "" + v6 + v6 = "" + v7 +} diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/simpleMembers.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/simpleMembers.fir.kt new file mode 100644 index 00000000000..69a4086b5a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/simpleMembers.fir.kt @@ -0,0 +1,19 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +fun f() {} + +@SinceKotlin("1.1") +var p = Unit + +@SinceKotlin("1.1.2") +fun z() {} + + +fun t1() = f() + +fun t2() = p + +fun t3() { p = Unit } + +fun t4() { z() } diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/sinceOldVersionIsOK.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/sinceOldVersionIsOK.fir.kt new file mode 100644 index 00000000000..6d35fbdbbb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/sinceOldVersionIsOK.fir.kt @@ -0,0 +1,18 @@ +// !API_VERSION: 1.1 + +@SinceKotlin("0.9") +fun ok1() {} + +@SinceKotlin("1.0") +fun ok2() {} + +@SinceKotlin("1.1") +fun ok3() {} + +@SinceKotlin("0.9.9") +fun ok4() {} + +fun t1() = ok1() +fun t2() = ok2() +fun t3() = ok3() +fun t4() = ok4() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsCompanionObjects.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsCompanionObjects.fir.kt new file mode 100644 index 00000000000..402e126017c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsCompanionObjects.fir.kt @@ -0,0 +1,15 @@ +// !API_VERSION: 1.0 + +class C { + @SinceKotlin("1.1") + companion object { + val x = 42 + } +} + +typealias CA = C + +val test1 = CA +val test2 = CA.Companion +val test3 = CA.x +val test4 = CA.Companion.x diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt new file mode 100644 index 00000000000..9eb127a0378 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsConstructors.fir.kt @@ -0,0 +1,20 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +open class C1 + +typealias C1_Alias = C1 + +open class C2(val x: Int) { + @SinceKotlin("1.1") + constructor() : this(0) +} + +typealias C2_Alias = C2 + +val test1 = C1_Alias() +val test2 = C2_Alias() + +class Test3 : C1_Alias() + +class Test4 : C2_Alias() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt new file mode 100644 index 00000000000..2b1f84d53ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsObjects.fir.kt @@ -0,0 +1,11 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +object Since_1_1 { + val x = 42 +} + +typealias Since_1_1_Alias = Since_1_1 + +val test1 = Since_1_1_Alias +val test2 = Since_1_1_Alias.x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt new file mode 100644 index 00000000000..ae3d59b28bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesAsTypes.fir.kt @@ -0,0 +1,21 @@ +// !API_VERSION: 1.0 + +@SinceKotlin("1.1") +class Since_1_1 + +class C + +typealias Since_1_1_Alias = Since_1_1 + +typealias L = List + +@SinceKotlin("1.1") +typealias C_1_1_Alias = C + +fun test1(x: Since_1_1_Alias) = x + +fun test2(x: C_1_1_Alias) = x + +fun test3(x: List) = x + +fun test4(x: L) = x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt new file mode 100644 index 00000000000..9c530c9909f --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/typealiasesOnImport.fir.kt @@ -0,0 +1,18 @@ +// !API_VERSION: 1.0 + +// FILE: a.kt +package a + +@SinceKotlin("1.1") +class Since_1_1 + +typealias Since_1_1_Alias = Since_1_1 + +@SinceKotlin("1.1") +typealias Alias_1_1 = String + +// FILE: b.kt +package b + +import a.Since_1_1_Alias +import a.Alias_1_1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/inlineFunctionAlways.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/inlineFunctionAlways.fir.kt new file mode 100644 index 00000000000..c6d1216532e --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/inlineFunctionAlways.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// !LANGUAGE: -InlineProperties + +inline fun String.test() { +} + +inline fun test() { +} + +class A { + inline fun String.test() { + } + + inline fun test() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noBigFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noBigFunctionTypes.fir.kt new file mode 100644 index 00000000000..2f55c492f1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noBigFunctionTypes.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: -FunctionTypesWithBigArity +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A + +fun foo( + p00: A, p01: A, p02: A, p03: A, p04: A, p05: A, p06: A, p07: A, p08: A, p09: A, + p10: A, p11: A, p12: A, p13: A, p14: A, p15: A, p16: A, p17: A, p18: A, p19: A, + p20: A, p21: A, p22: A, p23: A, p24: A, p25: A, p26: A, p27: A, p28: A, p29: A +) {} + +fun bar(x: Any) {} + +fun test( + w: (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) -> Unit, + vararg x: Function30<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, Unit> +) { + bar(::foo) + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundCallableReference.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundCallableReference.fir.kt new file mode 100644 index 00000000000..fb99289ec37 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundCallableReference.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: -BoundCallableReferences + +class C { companion object } +val ok1 = C::hashCode +val fail1 = C.Companion::hashCode + +object O { + class Y { + companion object + } +} +val fail2 = O::hashCode +val ok2 = O::Y +val ok3 = O.Y::hashCode + +enum class E { + Entry +} +val ok4 = E.Entry::hashCode + +fun hashCode() {} + +val fail3 = ""::hashCode +val fail4 = (C)::hashCode +val fail5 = (C.Companion)::hashCode diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundClassLiteral.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundClassLiteral.fir.kt new file mode 100644 index 00000000000..12d5a76b87e --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/boundClassLiteral.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: -BoundCallableReferences + +class C { companion object } +val ok1 = C::class +val ok2 = C.Companion::class + +object O +val ok3 = O::class + +enum class E { + Entry +} +val ok4 = E.Entry::class + +val fail1 = ""::class +val fail2 = String?::class +val fail3 = (C)::class +val fail4 = (C.Companion)::class diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassLiteralInKClassExtension.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassLiteralInKClassExtension.fir.kt new file mode 100644 index 00000000000..7655e84d0b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassLiteralInKClassExtension.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: -BoundCallableReferences +// !DIAGNOSTICS: -UNCHECKED_CAST + +import kotlin.reflect.KClass + +val KClass.java: Class get() = null!! + +val KClass.javaObjectType: Class + get() { + return java.lang.Class::class.java as Class + } diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassReferenceInKClassExtension.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassReferenceInKClassExtension.fir.kt new file mode 100644 index 00000000000..13462c5f330 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noBoundCallableReferences/qualifiedJavaClassReferenceInKClassExtension.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: -BoundCallableReferences + +import kotlin.reflect.KClass + +val KClass.java: Class get() = null!! + +val KClass.foo: Any? + get() { + return java.lang.Integer::hashCode + } diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.fir.kt new file mode 100644 index 00000000000..afe35203131 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: -CallableReferencesToClassMembersWithEmptyLHS + +class A { + fun memberFunction() {} + val memberProperty: Int get() = 42 + + fun test() { + (::memberFunction)() + (::extensionFunction)() + (::memberProperty)() + (::extensionProperty)() + } + + inner class B { + fun memberFunction() { } + val memberProperty: Int get() = 43 + + fun test() { + (::memberFunction)() + (::extensionFunction)() + (::memberProperty)() + (::extensionProperty)() + } + } +} + +fun A.extensionFunction() {} +val A.extensionProperty: Int get() = 44 diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.fir.kt new file mode 100644 index 00000000000..4a83ee84a13 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: -DataClassInheritance + +interface Allowed + +open class NotAllowed + +abstract data class Base(val x: Int) + +class Derived: Base(42) + +data class Nasty(val z: Int, val y: Int): Base(z) + +data class Complex(val y: Int): Allowed, NotAllowed() + + + +interface AbstractEqualsHashCodeToString { + override fun equals(other: Any?): Boolean + override fun hashCode(): Int + override fun toString(): String +} + +data class ImplInterface(val s: String) : AbstractEqualsHashCodeToString diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noInlineProperty.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noInlineProperty.fir.kt new file mode 100644 index 00000000000..417acde382f --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noInlineProperty.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: -InlineProperties +var value: Int = 0 + +inline var z: Int + get() = ++value + set(p: Int) { value = p } + + +var z2: Int + inline get() = ++value + inline set(p: Int) { value = p } diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt new file mode 100644 index 00000000000..9426f1ed15a --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: -LocalDelegatedProperties +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): Int = 1 +} + +fun foo(): Int { + val prop: Int by Delegate() + + val prop2: Int by 123 + + val obj = object { + fun v(): Int { + val prop3: Int by Delegate() + return prop3 + } + } + + return prop + prop2 + obj.v() +} diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt new file mode 100644 index 00000000000..3032aaa5e43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt @@ -0,0 +1,7 @@ +expect fun foo1() +expect val bar1 = 42 +expect class Baz1 + +actual fun foo2() = 42 +actual val bar2: Int +actual interface Baz2 diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noTopLevelSealedInheritance.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noTopLevelSealedInheritance.fir.kt new file mode 100644 index 00000000000..1e1cc9ad267 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noTopLevelSealedInheritance.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: -TopLevelSealedInheritance + +sealed class Base + +class Derived : Base() diff --git a/compiler/testData/diagnostics/tests/substitutions/kt1558-short.fir.kt b/compiler/testData/diagnostics/tests/substitutions/kt1558-short.fir.kt new file mode 100644 index 00000000000..daee244f735 --- /dev/null +++ b/compiler/testData/diagnostics/tests/substitutions/kt1558-short.fir.kt @@ -0,0 +1,5 @@ +fun List<*>.toArray(ar: Array): Array = ar + +fun testArrays(ci : List) { + ci.toArray(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/substitutions/kt4887.fir.kt b/compiler/testData/diagnostics/tests/substitutions/kt4887.fir.kt new file mode 100644 index 00000000000..777fa655cc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/substitutions/kt4887.fir.kt @@ -0,0 +1,8 @@ +package h + +public class MyClass(param: MyClass) { + fun test() { + val result: MyClass? = null + MyClass(result as MyClass) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/substitutions/starProjections.fir.kt b/compiler/testData/diagnostics/tests/substitutions/starProjections.fir.kt new file mode 100644 index 00000000000..c3acdadbf5f --- /dev/null +++ b/compiler/testData/diagnostics/tests/substitutions/starProjections.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +interface A> { + fun r(): R + fun t(): T +} + +fun testA(a: A<*, *>) { + a.r().checkType { _() } + a.t().checkType { _>() } +} + +interface B, T>> { + fun r(): R + fun t(): T +} + +fun testB(b: B<*, *>) { + b.r().checkType { _() } + b.t().checkType { _, *>>() } + + b.t().r().size +} + diff --git a/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithAmbiguity.fir.kt new file mode 100644 index 00000000000..fb10e0b812c --- /dev/null +++ b/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithAmbiguity.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// FILE: foo.kt +package foo + +fun f(l: List) {} + +// FILE: bar.kt +package bar + +fun f(l: List) {} + +// FILE: main.kt + +import foo.* +import bar.* + +fun test(l: List) { + f(l) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithErrorTypes.fir.kt b/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithErrorTypes.fir.kt new file mode 100644 index 00000000000..89c3f648ab8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/substitutions/upperBoundsSubstitutionForOverloadResolutionWithErrorTypes.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS -UNUSED_PARAMETER +fun f1(l: List1): T {throw Exception()} // ERROR type here +fun f1(l: List2): T {throw Exception()} // ERROR type here +fun f1(c: Collection): T{throw Exception()} + +fun test(l: List) { + f1(l) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.fir.kt b/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.fir.kt new file mode 100644 index 00000000000..9a3efab4a69 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.fir.kt @@ -0,0 +1,24 @@ +class A : Double.() -> Unit { + override fun invoke(p1: Double) {} +} + +class B : Int.(Double) -> Unit { + override fun invoke(p1: Int, p2: Double) {} +} + +open class C {} + +abstract class A0 : C.() -> Int +abstract class A1 : C.(Int) -> Int +abstract class A2 : C.(Int, String) -> Int + +open class D {} + +abstract class B0 : D.() -> Int +abstract class B1 : D.(C) -> Int +abstract class B2 : D.(T, C) -> T + +interface E {} + +abstract class C0: C(), Int.() -> Double +abstract class C1: C(), E, Int.(C) -> Double \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/findClosestCorrespondingSupertype.fir.kt b/compiler/testData/diagnostics/tests/subtyping/findClosestCorrespondingSupertype.fir.kt new file mode 100644 index 00000000000..30bd7887a92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/findClosestCorrespondingSupertype.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +interface X +interface A: X +interface B : A, X + +fun foo(x: B) { + // Checks that when checking subtypes we search closes corresponding constructor (e.g. with BFS) + val y: X = x +} diff --git a/compiler/testData/diagnostics/tests/subtyping/functionTypeAsSuperType.fir.kt b/compiler/testData/diagnostics/tests/subtyping/functionTypeAsSuperType.fir.kt new file mode 100644 index 00000000000..c52250c1c84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/functionTypeAsSuperType.fir.kt @@ -0,0 +1,45 @@ +class A : () -> Unit { + override fun invoke() {} +} + +class AA : Function0 { + override fun invoke() {} +} + +class B : (Double) -> Unit { + override fun invoke(p1: Double) {} +} + +class BB : Function1 { + override fun invoke(p1: Double) {} +} + +open class C {} + +abstract class A0 : (C) -> Int +abstract class A1 : Function1 + +abstract class A2 : (C, Int) -> Int +abstract class A3 : Function2 + +abstract class A4 : (Int, C, String) -> Int +abstract class A5 : Function3 + +open class D {} + +abstract class B0 : (D) -> Int +abstract class B1 : Function1, Int> + +abstract class B2 : (D, C) -> Int +abstract class B3 : Function2, C, Int> + +abstract class B4 : (D, C) -> T +abstract class B5 : Function2, C, T> + +interface E {} + +abstract class C0: C(), (Int) -> Double +abstract class C1: C(), Function1 + +abstract class C2: C(), E, (Int, C) -> Double +abstract class C3: C(), E, Function2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/invariantArgumentForTypeParameterWithMultipleBounds.fir.kt b/compiler/testData/diagnostics/tests/subtyping/invariantArgumentForTypeParameterWithMultipleBounds.fir.kt new file mode 100644 index 00000000000..1f48345b327 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/invariantArgumentForTypeParameterWithMultipleBounds.fir.kt @@ -0,0 +1,18 @@ +import java.io.Serializable + +class A where T : Cloneable, T : Serializable + +interface CS1 : Cloneable, Serializable +interface CS2 : CS1 + +interface I1 { + fun foo(): A +} + +interface I2 : I1 { + override fun foo(): A +} + +interface I3 : I1 { + override fun foo(): A +} diff --git a/compiler/testData/diagnostics/tests/subtyping/javaAndKotlinSuperType.fir.kt b/compiler/testData/diagnostics/tests/subtyping/javaAndKotlinSuperType.fir.kt new file mode 100644 index 00000000000..8f0cd59d18a --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/javaAndKotlinSuperType.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: A.java +public interface A { +} + +// FILE: B.java +public class B implements A { +} + +// FILE: 1.kt +class C: B() + +class D: B(), A +class E: B(), A + +fun eatAString(a: A) {} +fun eatAStringN(a: A) {} + +fun test(b: B, c: C, d: D, e: E) { + eatAString(b) + eatAString(c) + eatAString(d) + eatAString(e) + + eatAStringN(b) + eatAStringN(c) + eatAStringN(d) + eatAStringN(e) +} + +// FILE: 3.kt + +interface X : A +interface Y: X +interface Z: X + +class W: B(), Z + +fun test2(w: W) { + eatAString(w) + eatAStringN(w) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/kt-1457.fir.kt b/compiler/testData/diagnostics/tests/subtyping/kt-1457.fir.kt new file mode 100644 index 00000000000..7c0768cc801 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/kt-1457.fir.kt @@ -0,0 +1,12 @@ +// !CHECK_TYPE +// JAVAC_EXPECTED_FILE + +import java.util.ArrayList + +class Pair(val a: A, val b: B) + +class MyListOfPairs : ArrayList>() { } + +fun test() { + checkSubtype>>(MyListOfPairs()) +} diff --git a/compiler/testData/diagnostics/tests/subtyping/kt2069.fir.kt b/compiler/testData/diagnostics/tests/subtyping/kt2069.fir.kt new file mode 100644 index 00000000000..c2c70d7bcb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/kt2069.fir.kt @@ -0,0 +1,14 @@ +//KT-2069 Cannot call super method when superclass has type parameters +package kt2069 + +interface T1 { + fun foo() {} +} + +class T : T1 { + fun bar() { + super.foo() + } + + companion object {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/kt2744.fir.kt b/compiler/testData/diagnostics/tests/subtyping/kt2744.fir.kt new file mode 100644 index 00000000000..eb1496c3f65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/kt2744.fir.kt @@ -0,0 +1,3 @@ +class X : S + +fun f(l: List) {} diff --git a/compiler/testData/diagnostics/tests/subtyping/kt304.fir.kt b/compiler/testData/diagnostics/tests/subtyping/kt304.fir.kt new file mode 100644 index 00000000000..aab7fe69d26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/kt304.fir.kt @@ -0,0 +1,7 @@ +//KT-304: Resolve supertype reference to class anyway + +open class Foo() : Bar() { +} + +open class Bar() { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt b/compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt new file mode 100644 index 00000000000..2d736b76b07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt @@ -0,0 +1,9 @@ +interface Super { + var v: CharSequence + val v2: CharSequence +} + +class Sub: Super { + override var v: String = "fail" + override val v2: String = "ok" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/localAnonymousObjects.fir.kt b/compiler/testData/diagnostics/tests/subtyping/localAnonymousObjects.fir.kt new file mode 100644 index 00000000000..c730c51833c --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/localAnonymousObjects.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE +fun test() { + var x = object {} + x = object {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/localClasses.fir.kt b/compiler/testData/diagnostics/tests/subtyping/localClasses.fir.kt new file mode 100644 index 00000000000..9306dd94882 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/localClasses.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER + +package p + +private fun foo(a: Int) = run { + class A + A() +} + +private fun foo() = run { + class A + A() +} + +fun test() { + var x = foo(1) + x = foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.fir.kt b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.fir.kt new file mode 100644 index 00000000000..f13a0613b9a --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.fir.kt @@ -0,0 +1,6 @@ +class Test { + private var x = object {}; + init { + x = object {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/nestedIntoLocalClasses.fir.kt b/compiler/testData/diagnostics/tests/subtyping/nestedIntoLocalClasses.fir.kt new file mode 100644 index 00000000000..bcd2f8e1689 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/nestedIntoLocalClasses.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER + +package p + +private fun foo(a: Int) = run { + object { + inner class A + fun foo() = A() + }.foo() +} + +private fun foo() = run { + object { + inner class A + fun foo() = A() + }.foo() +} + +fun test() { + var x = foo(1) + x = foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.fir.kt b/compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.fir.kt new file mode 100644 index 00000000000..cfd165e6e6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER + +package p + +private fun foo(a: Int) = run { + class A { + inner class B + } + A().B() +} + +private fun foo() = run { + class A { + inner class B + } + A().B() +} + +fun test() { + var x = foo(1) + x = foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/topLevelAnonymousObjects.fir.kt b/compiler/testData/diagnostics/tests/subtyping/topLevelAnonymousObjects.fir.kt new file mode 100644 index 00000000000..61a12cefa27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/topLevelAnonymousObjects.fir.kt @@ -0,0 +1,5 @@ +private var x = object {} + +fun test() { + x = object {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/unresolvedSupertype.fir.kt b/compiler/testData/diagnostics/tests/subtyping/unresolvedSupertype.fir.kt new file mode 100644 index 00000000000..077053d4845 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/unresolvedSupertype.fir.kt @@ -0,0 +1,7 @@ +interface A1 : B + +interface A2 : B() + +class A3 : B, B + +enum class A4 : B diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnAnonymousObjectInVariable.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnAnonymousObjectInVariable.fir.kt new file mode 100644 index 00000000000..d623e09277f --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnAnonymousObjectInVariable.fir.kt @@ -0,0 +1,4 @@ +@Suppress("warnings") +val anonymous = object { + fun foo(p: String?? = "" as String) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt new file mode 100644 index 00000000000..ee06a9d6554 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.fir.kt @@ -0,0 +1,7 @@ +@Suppress("warnings") +class C { + fun foo(p: String??) { + // Make sure errors are not suppressed: + p = "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClassObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClassObject.fir.kt new file mode 100644 index 00000000000..5ada7c89028 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClassObject.fir.kt @@ -0,0 +1,6 @@ +class C { + @Suppress("warnings") + companion object { + val foo: String?? = null as Nothing? + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnExpression.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnExpression.fir.kt new file mode 100644 index 00000000000..609b38cd708 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnExpression.fir.kt @@ -0,0 +1,4 @@ +fun foo() { + @Suppress("warnings") + ("" as String??) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFile.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFile.fir.kt new file mode 100644 index 00000000000..463e8a93fa4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFile.fir.kt @@ -0,0 +1,7 @@ +@file:Suppress("warnings") + +class C { + companion object { + val foo: String?? = null as Nothing? + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFunction.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFunction.fir.kt new file mode 100644 index 00000000000..e3417c31183 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFunction.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("warnings") + fun foo(p: String??) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnObject.fir.kt new file mode 100644 index 00000000000..e7a06b4fbc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnObject.fir.kt @@ -0,0 +1,4 @@ +@Suppress("warnings") +object C { + fun foo(p: String??) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnParameter.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnParameter.fir.kt new file mode 100644 index 00000000000..de0d798413e --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnParameter.fir.kt @@ -0,0 +1,3 @@ +class C { + fun foo(@Suppress("warnings") p: String?? = "" as String) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnProperty.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnProperty.fir.kt new file mode 100644 index 00000000000..d3bbb1f20b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnProperty.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("warnings") + val foo: String?? = null as Nothing? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnPropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnPropertyAccessor.fir.kt new file mode 100644 index 00000000000..c79c536c4f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnPropertyAccessor.fir.kt @@ -0,0 +1,5 @@ +class C { + val foo: String? + @Suppress("warnings") + get(): String?? = null as Nothing? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/mixed.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/mixed.fir.kt new file mode 100644 index 00000000000..910a1fed437 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/mixed.fir.kt @@ -0,0 +1,5 @@ +@Suppress("REDUNDANT_NULLABLE") +class C { + @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") + fun foo(): String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClass.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClass.fir.kt new file mode 100644 index 00000000000..e5383f85c76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClass.fir.kt @@ -0,0 +1,4 @@ +@Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") +class C { + fun foo(): String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClassObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClassObject.fir.kt new file mode 100644 index 00000000000..cbd26d1e736 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onClassObject.fir.kt @@ -0,0 +1,6 @@ +class C { + @Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") + companion object { + val foo: String?? = ""!! as String?? + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onExpression.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onExpression.fir.kt new file mode 100644 index 00000000000..6f5db5ebad7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onExpression.fir.kt @@ -0,0 +1,4 @@ +fun foo(): Any? { + @Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") + return ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onFunction.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onFunction.fir.kt new file mode 100644 index 00000000000..8b67439ea4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onFunction.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") + fun foo(): String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onObject.fir.kt new file mode 100644 index 00000000000..19d79d33090 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onObject.fir.kt @@ -0,0 +1,4 @@ +@Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") +object C { + fun foo(): String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onParameter.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onParameter.fir.kt new file mode 100644 index 00000000000..c3042fbe2ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onParameter.fir.kt @@ -0,0 +1,3 @@ +class C { + fun foo(@Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") p: String?? = ""!! as String??) = p +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onProperty.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onProperty.fir.kt new file mode 100644 index 00000000000..7ef41bda7f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onProperty.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") + val foo: String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/manyWarnings/onPropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onPropertyAccessor.fir.kt new file mode 100644 index 00000000000..d2efda027b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/manyWarnings/onPropertyAccessor.fir.kt @@ -0,0 +1,5 @@ +class C { + val foo: String? + @Suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") + get(): String?? = ""!! as String?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.fir.kt new file mode 100644 index 00000000000..0662798c80a --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.fir.kt @@ -0,0 +1,60 @@ +fun foo(x: Array, y: IntArray, block: (T, Int) -> Int) { + var r: Any? + + @Suppress("UNCHECKED_CAST") + // comment + /* comment */ + r = block(x[0] as T, "" as Int) + + // to prevent unused assignment diagnostic for the above statement + r.hashCode() + + var i = 1 + + if (i != 1) { + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + } + + if (i != 1) + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + + if (i != 2) + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + else + @Suppress("UNCHECKED_CAST") + i += block(x[1] as T, "" as Int).toInt() + + while (i != 1) + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + + do + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + while (i != 1) + + for (j in 1..100) + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + + when (i) { + 1 -> + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + } + + val l: () -> Unit = { + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + } + l() + + // many empty new lines + @Suppress("UNCHECKED_CAST") + + + y[i] += block(x[0] as T, "" as Int).toInt() +} diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt new file mode 100644 index 00000000000..27ef5dbd823 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt @@ -0,0 +1,19 @@ +fun foo(x: Array, block: (T, Int) -> Int) { + var r: Any? + + @Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int) + + // to prevent unused assignment diagnostic for the above statement + r.hashCode() + + var i = 1 + + if (i != 1) { + @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() + } + + if (i != 1) @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + + if (i != 1) @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() +} diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.fir.kt new file mode 100644 index 00000000000..bc71b4b2ecf --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.fir.kt @@ -0,0 +1,4 @@ +@Suppress("REDUNDANT_NULLABLE") +class C { + fun foo(): String?? = null as Nothing?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onClassObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onClassObject.fir.kt new file mode 100644 index 00000000000..6ef18f496d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onClassObject.fir.kt @@ -0,0 +1,6 @@ +class C { + @Suppress("REDUNDANT_NULLABLE") + companion object { + val foo: String?? = null as Nothing?? + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onExpression.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onExpression.fir.kt new file mode 100644 index 00000000000..17c2f78894e --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onExpression.fir.kt @@ -0,0 +1,4 @@ +fun foo(): Any? { + @Suppress("REDUNDANT_NULLABLE") + return null as Nothing?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onFunction.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onFunction.fir.kt new file mode 100644 index 00000000000..d8af00a55c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onFunction.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("REDUNDANT_NULLABLE") + fun foo(): String?? = null as Nothing?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onLocalVariable.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onLocalVariable.fir.kt new file mode 100644 index 00000000000..36faabbcce5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onLocalVariable.fir.kt @@ -0,0 +1,7 @@ +class C { + fun foo(): Any? { + @Suppress("REDUNDANT_NULLABLE") + val v: String?? = null as Nothing?? + return v + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onObject.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onObject.fir.kt new file mode 100644 index 00000000000..b23994c8df0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onObject.fir.kt @@ -0,0 +1,4 @@ +@Suppress("REDUNDANT_NULLABLE") +object C { + fun foo(): String?? = null as Nothing?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onParameter.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onParameter.fir.kt new file mode 100644 index 00000000000..d475ca24ef6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onParameter.fir.kt @@ -0,0 +1,3 @@ +class C { + fun foo(@Suppress("REDUNDANT_NULLABLE") p: String?? = null as Nothing??) = p +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onProperty.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onProperty.fir.kt new file mode 100644 index 00000000000..e34ce0bd122 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onProperty.fir.kt @@ -0,0 +1,4 @@ +class C { + @Suppress("REDUNDANT_NULLABLE") + val foo: String?? = null as Nothing? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onPropertyAccessor.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onPropertyAccessor.fir.kt new file mode 100644 index 00000000000..06b586d33d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onPropertyAccessor.fir.kt @@ -0,0 +1,5 @@ +class C { + val foo: String? + @Suppress("REDUNDANT_NULLABLE") + get(): String?? = null as Nothing?? +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/AbbreviationName.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/AbbreviationName.fir.kt new file mode 100644 index 00000000000..112e586c4da --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/AbbreviationName.fir.kt @@ -0,0 +1,20 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.url = javaClass.url + "/" + javaClass.htmlFile += "1" + + javaClass.URL + javaClass.uRL + javaClass.HTMLFile + javaClass.hTMLFile + javaClass.htmlfile +} + +// FILE: JavaClass.java +public class JavaClass { + public String getURL() { return true; } + public void setURL(String value) { } + + public String getHTMLFile() { return true; } + public void setHTMLFile(String value) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt new file mode 100644 index 00000000000..0be689aa089 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Bases.fir.kt @@ -0,0 +1,31 @@ +// FILE: KotlinFile.kt +open class KotlinClass1 : JavaClass1() { + public fun getSomethingKotlin1(): Int = 1 +} + +class KotlinClass2 : JavaClass2() { + public fun getSomethingKotlin2(): Int = 1 +} + +fun foo(k: KotlinClass2) { + useInt(k.getSomething1()) + useInt(k.something1) + useInt(k.getSomething2()) + useInt(k.something2) + useInt(k.getSomethingKotlin1()) + useInt(k.getSomethingKotlin2()) + k.somethingKotlin1 + k.somethingKotlin2 +} + +fun useInt(i: Int) {} + +// FILE: JavaClass1.java +public class JavaClass1 { + public int getSomething1() { return 1; } +} + +// FILE: JavaClass2.java +public class JavaClass2 extends KotlinClass1 { + public int getSomething2() { return 1; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/CompiledClass.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/CompiledClass.fir.kt new file mode 100644 index 00000000000..5415a21cea7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/CompiledClass.fir.kt @@ -0,0 +1,6 @@ +// FILE: KotlinFile.kt +import java.io.File + +fun foo(file: File) { + file.absolutePath.length +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt new file mode 100644 index 00000000000..83e9aa56d6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt @@ -0,0 +1,48 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something1 + + javaClass.something2 + javaClass.something2 = 1 + javaClass.something2++ + + javaClass.something3 + javaClass.something3 = 1 + javaClass.something3++ + + javaClass.something4 + javaClass.something4 = 1 + javaClass.something4++ + + javaClass.something5 + javaClass.something5 = 1 + javaClass.something5++ +} + +// FILE: JavaClass.java +public class JavaClass { + @Deprecated + public int getSomething1() { return 1; } + + @Deprecated + public int getSomething2() { return 1; } + public void setSomething2(int value) { } + + public int getSomething3() { return 1; } + @Deprecated + public void setSomething3(int value) { } + + @Deprecated + public int getSomething4() { return 1; } + @Deprecated + public void setSomething4(int value) { } + + /** + * @deprecated Bla-bla-bla + */ + public int getSomething5() { return 1; } + /** + * @deprecated Ha-ha-ha + */ + public void setSomething5(int value) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseGetters.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseGetters.fir.kt new file mode 100644 index 00000000000..15970ed546e --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseGetters.fir.kt @@ -0,0 +1,21 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something1 + javaClass.something2 + javaClass.somethingStatic + javaClass.somethingVoid + javaClass.ter +} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething1(int p) { return p; } + + public T getSomething2() { return null; } + + public static int getSomethingStatic() { return 1; } + + public void getSomethingVoid() { } + + public int getter() { return 1; } +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseSetters.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseSetters.fir.kt new file mode 100644 index 00000000000..5d34a5a2fc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FalseSetters.fir.kt @@ -0,0 +1,26 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something1++ + javaClass.something2++ + javaClass.something3++ + javaClass.something4++ + javaClass.something5 = null +} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething1() { return 1; } + public void setSomething1(int value, char c) { } + + public int getSomething2() { return 1; } + public void setSomething2(String value) { } + + public int getSomething3() { return 1; } + public void setSomething3(int value) { return value; } + + public int getSomething4() { return 1; } + public static void setSomething4(int value) { } + + public int[] getSomething5() { return null; } + public void setSomething5(int... value) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.fir.kt new file mode 100644 index 00000000000..d329ecc0d80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/FromTwoBases.fir.kt @@ -0,0 +1,19 @@ +// FILE: KotlinFile.kt + +interface C : A, B + +fun foo(c: C) { + c.setSomething(c.getSomething() + 1) + c.something++ +} + +// FILE: A.java +public interface A { + int getSomething(); +} + +// FILE: B.java +public interface B { + int getSomething(); + void setSomething(int value); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GenericClass.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GenericClass.fir.kt new file mode 100644 index 00000000000..3d0b46e41d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GenericClass.fir.kt @@ -0,0 +1,10 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something += "x" +} + +// FILE: JavaClass.java +public class JavaClass { + public T getSomething() { return null; } + public void setSomething(T value) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetA.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetA.fir.kt new file mode 100644 index 00000000000..cd35f02613d --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetA.fir.kt @@ -0,0 +1,10 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.a + javaClass.A +} + +// FILE: JavaClass.java +public class JavaClass { + public int getA() { return 1; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt new file mode 100644 index 00000000000..e8c069e2d88 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Getter.fir.kt @@ -0,0 +1,20 @@ +// FILE: KotlinFile.kt +class KotlinClass { + public fun getSomething(): Int = 1 +} + +fun foo(javaClass: JavaClass, kotlinClass: KotlinClass) { + useInt(javaClass.getSomething()) + useInt(javaClass.something) + javaClass.something = 1 + javaClass.Something + useInt(kotlinClass.getSomething()) + kotlinClass.something +} + +fun useInt(i: Int) {} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething() { return 1; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetterAndSetter.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetterAndSetter.fir.kt new file mode 100644 index 00000000000..3bc634c4e43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/GetterAndSetter.fir.kt @@ -0,0 +1,14 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something1++ + javaClass.something2++ +} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething1() { return 1; } + public void setSomething1(int value) { } + + public int getSomething2() { return 1; } + public JavaClass setSomething2(int value) { return this; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/ImplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/ImplicitReceiver.fir.kt new file mode 100644 index 00000000000..084edcc7941 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/ImplicitReceiver.fir.kt @@ -0,0 +1,12 @@ +// FILE: KotlinFile.kt +fun JavaClass.foo() { + useInt(getSomething()) + useInt(something) +} + +fun useInt(i: Int) {} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething() { return 1; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/IsNaming.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/IsNaming.fir.kt new file mode 100644 index 00000000000..e133b761ebf --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/IsNaming.fir.kt @@ -0,0 +1,37 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.isSomething = !javaClass.isSomething + javaClass.isSomething2 = !javaClass.isSomething2 + + javaClass.something + javaClass.isSomethingWrong + javaClass.somethingWrong + + javaClass.issueFlag + javaClass.isSueFlag +} + +// FILE: JavaClass.java +public class JavaClass { + public boolean isSomething() { + return true; + } + + public void setSomething(boolean value) { + } + + public boolean getIsSomething2() { + return true; + } + + public void setIsSomething2(boolean value) { + } + + public int isSomethingWrong() { + return 1; + } + + public boolean issueFlag() { + return true; + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/JavaOverridesKotlin.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/JavaOverridesKotlin.fir.kt new file mode 100644 index 00000000000..e1da3da8032 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/JavaOverridesKotlin.fir.kt @@ -0,0 +1,29 @@ +// FILE: KotlinFile.kt +open class KotlinClass { + public open fun getSomething1(): Int = 1 + + public open fun setSomething2(value: Int) {} +} + +fun foo(javaClass: JavaClass) { + useInt(javaClass.getSomething1()) + useInt(javaClass.something1) + + javaClass.setSomething2(javaClass.getSomething2() + 1) + javaClass.something2 = javaClass.something2 + 1 +} + +fun useInt(i: Int) {} + +// FILE: JavaClass.java +public class JavaClass extends KotlinClass implements JavaInterface { + public int getSomething1() { return 1; } + + public int getSomething2() { return 1; } + public void setSomething2(int value) {} +} + +// FILE: JavaInterface.java +public class JavaInterface { + int getSomething2(); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt new file mode 100644 index 00000000000..fe8193d4d92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava.fir.kt @@ -0,0 +1,52 @@ +// FILE: KotlinFile.kt +abstract class KotlinClass : JavaClass(), KotlinInterface, JavaInterface { + override fun getSomething1(): Int = 1 + override fun getSomething3(): String = "" + override fun setSomething4(value: String) {} + override fun getSomething5(): String = "" +} + +interface KotlinInterface { + public fun getSomething1(): Int + public fun getSomething4(): String +} + +fun foo(k: KotlinClass) { + useInt(k.getSomething1()) + useInt(k.something1) + + useInt(k.getSomething2()) + useInt(k.something2) + + useString(k.getSomething3()) + useString(k.something3) + + k.setSomething4("") + k.something4 += "" + k.setSomething4(null) + k.something4 = null + + useString(k.getSomething5()) + useString(k.something5) + k.setSomething5(1) + k.something5 = 1 +} + +fun useInt(i: Int) {} +fun useString(i: String) {} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomething1() { return 1; } + public int getSomething2() { return 1; } + public Object getSomething3() { return null; } +} + +// FILE: JavaInterface.java +public interface JavaInterface { + String getSomething4(); + void setSomething4(String value); + + Object getSomething5(); + void setSomething5(Object value); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava2.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava2.fir.kt new file mode 100644 index 00000000000..458b84bfd6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava2.fir.kt @@ -0,0 +1,25 @@ +// FILE: KotlinFile.kt +abstract class KotlinClass : JavaInterface1, JavaInterface2 { + override fun getSomething(): String = "" +} + +fun foo(k: KotlinClass) { + useString(k.getSomething()) + useString(k.something) + if (k.something == null) return + + k.setSomething(1) + k.something = 1 +} + +fun useString(i: String) {} + +// FILE: JavaInterface1.java +public interface JavaInterface1 { + String getSomething(); +} + +// FILE: JavaInterface2.java +public interface JavaInterface2 { + void setSomething(int value); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava3.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava3.fir.kt new file mode 100644 index 00000000000..94a68b1f39e --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava3.fir.kt @@ -0,0 +1,25 @@ +// FILE: KotlinFile.kt +abstract class KotlinClass : JavaInterface1, JavaInterface2 { + override fun getSomething(): String = "" +} + +fun foo(k: KotlinClass) { + useString(k.getSomething()) + useString(k.something) + if (k.something == null) return + + k.setSomething("") + k.something = "" +} + +fun useString(i: String) {} + +// FILE: JavaInterface1.java +public interface JavaInterface1 { + String getSomething(); +} + +// FILE: JavaInterface2.java +public interface JavaInterface2 { + void setSomething(String value); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava4.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava4.fir.kt new file mode 100644 index 00000000000..86376249db7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava4.fir.kt @@ -0,0 +1,28 @@ +// FILE: KotlinFile.kt +abstract class KotlinClass : JavaInterface3 { + override fun getSomething(): String = "" +} + +fun foo(k: KotlinClass) { + useString(k.getSomething()) + useString(k.something) + if (k.something == null) return + + k.setSomething("") + k.something = "" +} + +fun useString(i: String) {} + +// FILE: JavaInterface1.java +public interface JavaInterface1 { + String getSomething(); +} + +// FILE: JavaInterface2.java +public interface JavaInterface2 { + void setSomething(String value); +} + +// FILE: JavaInterface3.java +public interface JavaInterface3 extends JavaInterface1, JavaInterface2 {} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava5.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava5.fir.kt new file mode 100644 index 00000000000..0c1ffd3f4bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/KotlinOverridesJava5.fir.kt @@ -0,0 +1,29 @@ +// FILE: KotlinFile.kt +abstract class KotlinClass : JavaInterface3 { + override fun getSomething(): String = "" +} + +fun foo(k: KotlinClass) { + useString(k.getSomething()) + useString(k.something) + if (k.something == null) return + + k.setSomething("") + k.something = "" +} + +fun useString(i: String) {} + +// FILE: JavaInterface1.java +public interface JavaInterface1 { + String getSomething(); +} + +// FILE: JavaInterface2.java +public interface JavaInterface2 { + String getSomething(); + void setSomething(String value); +} + +// FILE: JavaInterface3.java +public interface JavaInterface3 extends JavaInterface1, JavaInterface2 {} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyAscii.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyAscii.fir.kt new file mode 100644 index 00000000000..182df416a0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyAscii.fir.kt @@ -0,0 +1,22 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.КакоеТоСвойство = javaClass.КакоеТоСвойство + 1 + javaClass.какоеТоСвойство + + javaClass.КУ + javaClass.ку +} + +// FILE: JavaClass.java +public class JavaClass { + public int getКакоеТоСвойство() { + return 0; + } + + public void setКакоеТоСвойство(int value) { + } + + public int getКУ() { + return 0; + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyPublic.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyPublic.fir.kt new file mode 100644 index 00000000000..90bc8cff6ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OnlyPublic.fir.kt @@ -0,0 +1,22 @@ +// FILE: KotlinFile.kt +package k + +import JavaClass + +fun foo(javaClass: JavaClass) { + javaClass.somethingPublic + javaClass.somethingProtected + javaClass.somethingPrivate + javaClass.somethingPackage + javaClass.somethingPublic = 1 +} + +// FILE: JavaClass.java +public class JavaClass { + public int getSomethingPublic() { return 1; } + protected int getSomethingProtected() { return 1; } + private int getSomethingPrivate() { return 1; } + int getSomethingPackage() { return 1; } + + protected void setSomethingPublic(int value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.fir.kt new file mode 100644 index 00000000000..e0e96602473 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/OverrideGetterOnly.fir.kt @@ -0,0 +1,22 @@ +// FILE: KotlinFile.kt + +fun foo(o: JavaClass2) { + useString(o.something) + o.something = "" + o.setSomething(1) + o.something = 1 // we generate extension property for JavaClass2 with more specific type + o.something += "1" +} + +fun useString(i: String) {} + +// FILE: JavaClass1.java +public class JavaClass1 { + public Object getSomething() { return null; } + public void setSomething(Object value) { } +} + +// FILE: JavaClass2.java +public class JavaClass2 extends JavaClass1 { + public String getSomething() { return ""; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.fir.kt new file mode 100644 index 00000000000..1d33ecdeeb6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterHasHigherAccess.fir.kt @@ -0,0 +1,16 @@ +// FILE: KotlinFile.kt +package k + +import JavaClass + +fun foo(javaClass: JavaClass) { + val v = javaClass.something + javaClass.something = 1 + javaClass.something++ +} + +// FILE: JavaClass.java +public class JavaClass { + protected int getSomething() { return 1; } + public void setSomething(int value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterOnly.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterOnly.fir.kt new file mode 100644 index 00000000000..9d3bef5eabe --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SetterOnly.fir.kt @@ -0,0 +1,9 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.something = 1 +} + +// FILE: JavaClass.java +public class JavaClass { + public void setSomething(int value) { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCast.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCast.fir.kt new file mode 100644 index 00000000000..ab63b80a7a0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCast.fir.kt @@ -0,0 +1,28 @@ +// FILE: KotlinFile.kt +fun foo(o: JavaInterface2): Int { + if (o is JavaClass) { + o.something++ + return o.x + o.something2 + } + return 0 +} + +// FILE: JavaClass.java +public abstract class JavaClass extends BaseClass implements JavaInterface { + public int getSomething() { return 1; } + public void setSomething(int value) { } +} + +// FILE: BaseClass.java +public abstract class BaseClass implements JavaInterface { +} + +// FILE: JavaInterface.java +public interface JavaInterface { + int getX(); +} + +// FILE: JavaInterface2.java +public interface JavaInterface2 { + int getSomething2(); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCastImplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCastImplicitReceiver.fir.kt new file mode 100644 index 00000000000..7da8bd686ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SmartCastImplicitReceiver.fir.kt @@ -0,0 +1,23 @@ +// FILE: KotlinFile.kt +fun Any.foo(): Int { + if (this is JavaClass) { + something++ + return x + } + return 0 +} + +// FILE: JavaClass.java +public abstract class JavaClass extends BaseClass implements JavaInterface { + public int getSomething() { return 1; } + public void setSomething(int value) { } +} + +// FILE: BaseClass.java +public abstract class BaseClass implements JavaInterface { +} + +// FILE: JavaInterface.java +public interface JavaInterface { + int getX(); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt new file mode 100644 index 00000000000..2d20cf8e244 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/SyntheticJavaPropertyReference.fir.kt @@ -0,0 +1,9 @@ +// FILE: KotlinFile.kt + +fun bar() = JavaClass::foo + +// FILE: JavaClass.java + +public class JavaClass { + public String getFoo() {} +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeAnnotation.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeAnnotation.fir.kt new file mode 100644 index 00000000000..65a01fde9de --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeAnnotation.fir.kt @@ -0,0 +1,13 @@ +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.getSomething().length + javaClass.something.length +} + +// FILE: JavaClass.java +import org.jetbrains.annotations.*; + +public class JavaClass { + @Nullable + public String getSomething() { return null; } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeParameterReceiver.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeParameterReceiver.fir.kt new file mode 100644 index 00000000000..c106a07c6da --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/TypeParameterReceiver.fir.kt @@ -0,0 +1,16 @@ +// FILE: KotlinFile.kt + +fun foo(t: T) { + t.setSomething(t.getSomething() + 1) + t.something++ +} + +// FILE: A.java +public interface A { + int getSomething(); +} + +// FILE: B.java +public interface B extends A { + void setSomething(int value); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt new file mode 100644 index 00000000000..4f27061bd0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt @@ -0,0 +1,22 @@ +// FILE: KotlinFile.kt +public interface I { + public fun doIt() +} + +fun foo(javaClass: JavaClass) { + javaClass.doSomething1 { bar() } + javaClass.doSomething2 { bar() } +} + +fun bar(){} + +// FILE: JavaClass.java +public class JavaClass { + @Deprecated + public void doSomething1(Runnable runnable) { runnable.run(); } + + /** + * @deprecated + */ + public void doSomething2(Runnable runnable) { runnable.run(); } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.fir.kt new file mode 100644 index 00000000000..9240e501a88 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.fir.kt @@ -0,0 +1,14 @@ +// JAVAC_EXPECTED_FILE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass): String { + return javaClass.doSomething("", 1) { s: String -> "" } +} + +// FILE: JavaClass.java +public class JavaClass { + public T doSomething(T t, int anInt, I i) { return t; } +} + +interface I { + T doIt(T t); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethod.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethod.fir.kt new file mode 100644 index 00000000000..26ff1b49544 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethod.fir.kt @@ -0,0 +1,14 @@ +// JAVAC_EXPECTED_FILE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass): String { + return javaClass.doSomething("") { it } +} + +// FILE: JavaClass.java +public class JavaClass { + public T doSomething(T t, I i) { return i.run(t); } +} + +interface I { + T run(T t); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethodInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethodInGenericClass.fir.kt new file mode 100644 index 00000000000..009c4d007bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericMethodInGenericClass.fir.kt @@ -0,0 +1,16 @@ +// JAVAC_EXPECTED_FILE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + val a: String = javaClass.doSomething1("", 1) { p: String -> p } + val b: String = javaClass.doSomething2("", 1, true) { p: Int -> p } +} + +// FILE: JavaClass.java +public class JavaClass { + public T doSomething1(T t, X x, I i) { return i.run(t); } + public T doSomething2(T t, X x, boolean p, I i) { return i.run(t); } +} + +interface I { + T run(T t); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/InnerClassInGeneric.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/InnerClassInGeneric.fir.kt new file mode 100644 index 00000000000..b5b053046f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/InnerClassInGeneric.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass): Int { + val inner = javaClass.createInner() + return inner.doSomething(1, "") { } +} + +// FILE: JavaClass.java +public class JavaClass { + public Inner createInner() { + return new Inner(); + } + + public interface Inner{ + public T doSomething(T t, X x, Runnable runnable); + } +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/NoNamedArgsAllowed.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/NoNamedArgsAllowed.fir.kt new file mode 100644 index 00000000000..ea53ff62635 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/NoNamedArgsAllowed.fir.kt @@ -0,0 +1,14 @@ +// !WITH_NEW_INFERENCE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.doSomething(p = 1) { + bar() + } +} + +fun bar(){} + +// FILE: JavaClass.java +public class JavaClass { + public void doSomething(int p, Runnable runnable) { runnable.run(); } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PackageLocal.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PackageLocal.fir.kt new file mode 100644 index 00000000000..fadb8efd770 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PackageLocal.fir.kt @@ -0,0 +1,18 @@ +// FILE: KotlinFile1.kt +package k + +import JavaClass + +fun foo(javaClass: JavaClass) { + javaClass.doSomething { } +} + +// FILE: KotlinFile2.kt +fun foo(javaClass: JavaClass) { + javaClass.doSomething { } +} + +// FILE: JavaClass.java +public class JavaClass { + void doSomething(Runnable runnable) { runnable.run(); } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt new file mode 100644 index 00000000000..eece4ba7e9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ParameterTypeAnnotation.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// FILE: KotlinFile.kt +fun foo(javaInterface: JavaInterface) { + javaInterface.doIt(null) { } + javaInterface.doIt("", null) +} + +// FILE: JavaInterface.java +import org.jetbrains.annotations.*; + +public interface JavaInterface { + void doIt(@NotNull String s, @NotNull Runnable runnable); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PassNull.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PassNull.fir.kt new file mode 100644 index 00000000000..1bda1a5b3c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/PassNull.fir.kt @@ -0,0 +1,10 @@ +// FILE: KotlinFile.kt +fun foo(javaInterface: JavaInterface) { + javaInterface.doIt(null, null) { } + javaInterface.doIt("", { }, null) +} + +// FILE: JavaInterface.java +public interface JavaInterface { + void doIt(String s, Runnable runnable1, Runnable runnable2); +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Private.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Private.fir.kt new file mode 100644 index 00000000000..de8bd65a4ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Private.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +// FILE: KotlinFile.kt +fun foo(javaClass: JavaClass) { + javaClass.doSomething { } +} + +// FILE: JavaClass.java +public class JavaClass { + private void doSomething(Runnable runnable) { runnable.run(); } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Protected.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Protected.fir.kt new file mode 100644 index 00000000000..4b93a1419dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Protected.fir.kt @@ -0,0 +1,24 @@ +// FILE: KotlinFile.kt +package k + +import JavaClass + +fun foo(javaClass: JavaClass) { + javaClass.doSomething { + bar() + } +} + +class X : JavaClass() { + fun foo(other: JavaClass) { + doSomething { bar() } + other.doSomething { bar() } + } +} + +fun bar(){} + +// FILE: JavaClass.java +public class JavaClass { + protected void doSomething(Runnable runnable) { runnable.run(); } +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ReturnTypeAnnotation.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ReturnTypeAnnotation.fir.kt new file mode 100644 index 00000000000..bdf5d30e43e --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/ReturnTypeAnnotation.fir.kt @@ -0,0 +1,18 @@ +// FILE: KotlinFile.kt +fun foo(javaInterface: JavaInterface) { + val value = javaInterface.compute { "" } + value.length +} + +// FILE: JavaInterface.java +import org.jetbrains.annotations.*; + +public interface JavaInterface { + @Nullable + String compute(@NotNull Provider provider); +} + +// FILE: Provider.java +public interface Provider { + public T compute(); +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Simple.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Simple.fir.kt new file mode 100644 index 00000000000..33efc0e7495 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Simple.fir.kt @@ -0,0 +1,30 @@ +// FILE: KotlinFile.kt +class KotlinClass { + public fun doSomething(runnable: Runnable) { runnable.run() } +} + +public interface I { + public fun doIt() +} + +fun foo(javaClass: JavaClass, kotlinClass: KotlinClass) { + javaClass.doSomething { + bar() + } + + kotlinClass.doSomething { + bar() + } + + javaClass.doSomething2 { + bar() + } +} + +fun bar(){} + +// FILE: JavaClass.java +public class JavaClass { + public void doSomething(Runnable runnable) { runnable.run(); } + public void doSomething2(I i) { i.doIt(); } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolution.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolution.fir.kt new file mode 100644 index 00000000000..26b40b35e3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolution.fir.kt @@ -0,0 +1,36 @@ +// !CHECK_TYPE +// FILE: A.java +public class A { + public int foo(Runnable r) { return 0; } + public String foo(Object r) { return null;} + + public int bar(Runnable r) { return 1; } + public String bar(CharSequence r) { return null; } +} + +// FILE: 1.kt +fun fn() {} +fun x(a: A, r: Runnable) { + a.foo(::fn) checkType { _() } + a.foo {} checkType { _() } + + a.foo(null) checkType { _() } + a.foo(Runnable { }) checkType { _() } + a.foo(r) checkType { _() } + + a.foo(123) checkType { _() } + a.foo("") checkType { _() } + + a.bar(::fn) checkType { _() } + a.bar {} checkType { _() } + + a.bar(r) checkType { _() } + + a.bar(null) + + a.bar(null as Runnable?) checkType { _() } + a.bar(null as CharSequence?) checkType { _() } + + a.bar("") checkType { _() } + a.bar(123) +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStatic.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStatic.fir.kt new file mode 100644 index 00000000000..8010a01b4a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStatic.fir.kt @@ -0,0 +1,36 @@ +// !CHECK_TYPE +// FILE: A.java +public class A { + public static int foo(Runnable r) { return 0; } + public static String foo(Object r) { return null;} + + public static int bar(Runnable r) { return 1; } + public static String bar(CharSequence r) { return null; } +} + +// FILE: 1.kt +fun fn() {} +fun x(r: Runnable) { + A.foo(::fn) checkType { _() } + A.foo {} checkType { _() } + + A.foo(null) checkType { _() } + A.foo(Runnable { }) checkType { _() } + A.foo(r) checkType { _() } + + A.foo(123) checkType { _() } + A.foo("") checkType { _() } + + A.bar(::fn) checkType { _() } + A.bar {} checkType { _() } + + A.bar(r) checkType { _() } + + A.bar(null) + + A.bar(null as Runnable?) checkType { _() } + A.bar(null as CharSequence?) checkType { _() } + + A.bar("") checkType { _() } + A.bar(123) +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStaticWithoutRefinedSams.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStaticWithoutRefinedSams.fir.kt new file mode 100644 index 00000000000..5861cef2797 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionStaticWithoutRefinedSams.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: -RefinedSamAdaptersPriority -NewInference +// !CHECK_TYPE +// FILE: A.java +public class A { + public static int foo(Runnable r) { return 0; } + public static String foo(Object r) { return null;} + + public static int bar(Runnable r) { return 1; } + public static String bar(CharSequence r) { return null; } +} + +// FILE: 1.kt +fun fn() {} +fun x(r: Runnable) { + A.foo(::fn) checkType { _() } + A.foo {} checkType { _() } + + A.foo(null) checkType { _() } + A.foo(Runnable { }) checkType { _() } + A.foo(r) checkType { _() } + + A.foo(123) checkType { _() } + A.foo("") checkType { _() } + + A.bar(::fn) checkType { _() } + A.bar {} checkType { _() } + + A.bar(r) checkType { _() } + + A.bar(null) + + A.bar(null as Runnable?) checkType { _() } + A.bar(null as CharSequence?) checkType { _() } + + A.bar("") checkType { _() } + A.bar(123) +} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionWithoutRefinedSams.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionWithoutRefinedSams.fir.kt new file mode 100644 index 00000000000..4f02afb50ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/overloadResolutionWithoutRefinedSams.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: -RefinedSamAdaptersPriority -NewInference +// !CHECK_TYPE +// FILE: A.java +public class A { + public int foo(Runnable r) { return 0; } + public String foo(Object r) { return null;} + + public int bar(Runnable r) { return 1; } + public String bar(CharSequence r) { return null; } +} + +// FILE: 1.kt +fun fn() {} +fun x(a: A, r: Runnable) { + a.foo(::fn) checkType { _() } + a.foo {} checkType { _() } + + a.foo(null) checkType { _() } + a.foo(Runnable { }) checkType { _() } + a.foo(r) checkType { _() } + + a.foo(123) checkType { _() } + a.foo("") checkType { _() } + + a.bar(::fn) checkType { _() } + a.bar {} checkType { _() } + + a.bar(r) checkType { _() } + + a.bar(null) + + a.bar(null as Runnable?) checkType { _() } + a.bar(null as CharSequence?) checkType { _() } + + a.bar("") checkType { _() } + a.bar(123) +} diff --git a/compiler/testData/diagnostics/tests/tailRecOnVirtualMember.fir.kt b/compiler/testData/diagnostics/tests/tailRecOnVirtualMember.fir.kt new file mode 100644 index 00000000000..12e7f3eb990 --- /dev/null +++ b/compiler/testData/diagnostics/tests/tailRecOnVirtualMember.fir.kt @@ -0,0 +1,171 @@ +//!LANGUAGE: -ProhibitTailrecOnVirtualMember + +open class A { + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + +open class B : A() { + final tailrec override fun foo(x: Int) { + foo(x) + } + + final tailrec override fun bar(y: Int) { + bar(y) + } + + final tailrec override fun baz(y: Int) { + baz(y) + } +} + + +open class C : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} + +object D : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y - 1) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} + +sealed class E : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + + class E1 : E() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + } +} + +enum class F { + F0, + F1() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + }; + + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + +enum class G { + + G1; + + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + + +val z = object : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/tailRecOnVirtualMemberError.fir.kt b/compiler/testData/diagnostics/tests/tailRecOnVirtualMemberError.fir.kt new file mode 100644 index 00000000000..c11063ead15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/tailRecOnVirtualMemberError.fir.kt @@ -0,0 +1,170 @@ +//!LANGUAGE: +ProhibitTailrecOnVirtualMember + +open class A { + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + +open class B : A() { + final tailrec override fun foo(x: Int) { + foo(x) + } + + final tailrec override fun bar(y: Int) { + bar(y) + } + + final tailrec override fun baz(y: Int) { + baz(y) + } +} + + +open class C : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} + +object D : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y - 1) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} + +sealed class E : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + + class E1 : E() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + } +} + +enum class F { + F0, + F1() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } + }; + + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + +enum class G { + + G1; + + tailrec open fun foo(x: Int) { + foo(x) + } + + internal tailrec open fun bar(y: Int) { + bar(y) + } + + protected tailrec open fun baz(y: Int) { + baz(y) + } + + private tailrec fun boo(y: Int) { + boo(y) + } + + internal tailrec fun baa(y: Int) { + baa(y) + } +} + +val z = object : A() { + tailrec override fun foo(x: Int) { + foo(x) + } + + tailrec override fun bar(y: Int) { + bar(y) + } + + tailrec override fun baz(y: Int) { + baz(y) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/tailRecOverridden.fir.kt b/compiler/testData/diagnostics/tests/tailRecOverridden.fir.kt new file mode 100644 index 00000000000..67f32ce524f --- /dev/null +++ b/compiler/testData/diagnostics/tests/tailRecOverridden.fir.kt @@ -0,0 +1,32 @@ +// See also KT-4285 +open class A { + open fun foo(x: Int = 0) {} + + open fun gav(y: Int = 1, z: Int = 2) {} +} + +class B: A() { + tailrec override fun foo(x: Int) { + foo() + } + + tailrec override fun gav(y: Int, z: Int) { + gav(y) + } + + tailrec fun bar(y: Double): Double = bar(y * 2.0) +} + +class C: A() { + tailrec override fun foo(x: Int) { + foo(0) + } + + tailrec override fun gav(y: Int, z: Int) { + gav(y - 1, z - 1) + } + + tailrec fun bar(y: Int = 1, z: Int = 2) { + bar(z) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/tailRecursionComplex.fir.kt b/compiler/testData/diagnostics/tests/tailRecursionComplex.fir.kt new file mode 100644 index 00000000000..7fc93d8ff12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/tailRecursionComplex.fir.kt @@ -0,0 +1,16 @@ +object O { + // This is correct, foo is the same + tailrec fun foo(i: Int): Int = if (i < 0) 0 else O.foo(i - 1) +} + +class A { + tailrec fun foo(i: Int) = if (i < 0) 0 else A.foo(i - 1) + + companion object { + fun foo(i: Int) = 42 + i + } +} + +class B { + tailrec fun foo(i: Int) = if (i < 0) 0 else O.foo(i - 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/basic.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/basic.fir.kt new file mode 100644 index 00000000000..b20feb73784 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/basic.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +abstract class Test1 : Map { + fun containsKey(key: String): Boolean = TODO() + + fun getOrDefault(key: String, defaultValue: String): String = TODO() +} + +abstract class Test2 : MutableMap { + fun replace(key: String, value: String): String? = TODO() +} + +abstract class Test3 : java.util.AbstractMap() { + fun containsKey(key: String): Boolean = TODO() + + fun replace(key: String, value: String): String? = TODO() +} + diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/delegation.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/delegation.fir.kt new file mode 100644 index 00000000000..affebd4e03f --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/delegation.fir.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + + +// Default methods from Java interfaces are NOT overridden by delegation. +// So, in the example below 'TestNoDelegationToDefaultMethods#replace' implicitly overrides a method from 'java.util.Map' (which is ok), +// but not a method from 'WithDelegation' (would be an error). +open class WithDelegation(val m: Map) : Map by m + +class TestNoDelegationToDefaultMethods(m: Map): WithDelegation(m) { + fun containsKey(key: String): Boolean = TODO() + + fun getOrDefault(key: String, defaultValue: String): String = TODO() + + fun replace(key: String, value: String): String? = TODO() +} + + + +interface IBaseWithKotlinDeclaration : Map { + fun replace(key: String, value: String): String? +} + +abstract class WithDelegation2(val m: Map) : Map by m, IBaseWithKotlinDeclaration + +abstract class TestNoDelegationToDefaultMethods2(m: Map): WithDelegation2(m) { + fun containsKey(key: String): Boolean = TODO() + + fun getOrDefault(key: String, defaultValue: String): String = TODO() + + // VIRTUAL_MEMBER_HIDDEN: hides member declaration inherited from a Kotlin interface + fun replace(key: String, value: String): String? = TODO() +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfaces.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfaces.fir.kt new file mode 100644 index 00000000000..fbff5e5273d --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfaces.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +interface IBase : Map + +interface TestDerivedInterfaceHiding : IBase { + fun replace(key: String, value: String): String? +} + +interface TestDerivedInterfaceDefault : IBase { + fun replace(key: String, value: String): String? = TODO() +} + + diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfacesWithKotlinFun.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfacesWithKotlinFun.fir.kt new file mode 100644 index 00000000000..bc6ac7dde3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/derivedInterfacesWithKotlinFun.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +interface IBaseWithKotlinDeclaration : Map { + fun replace(key: String, value: String): String? +} + +interface TestDerivedInterfaceHidingWithKotlinDeclaration : IBaseWithKotlinDeclaration { + // VIRTUAL_MEMBER_HIDDEN: hides member declaration inherited from a Kotlin interface + fun replace(key: String, value: String): String? +} + +interface TestDerivedInterfaceDefaultWithKotlinDeclaration : IBaseWithKotlinDeclaration { + // VIRTUAL_MEMBER_HIDDEN: hides member declaration inherited from a Kotlin interface + fun replace(key: String, value: String): String? = TODO() +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/fillInStackTrace.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/fillInStackTrace.fir.kt new file mode 100644 index 00000000000..a9199de4138 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/fillInStackTrace.fir.kt @@ -0,0 +1,4 @@ +// JAVAC_EXPECTED_FILE +class ControlFlowException : Exception("") { + fun fillInStackTrace() = this +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/finalize.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/finalize.fir.kt new file mode 100644 index 00000000000..914bf45c411 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/finalize.fir.kt @@ -0,0 +1,10 @@ +enum class TestEnum { + ENTRY; + + fun getDeclaringClass() {} + fun finalize() {} +} + +class TestFinalize { + fun finalize() {} +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/hashMapGetOrDefault.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/hashMapGetOrDefault.fir.kt new file mode 100644 index 00000000000..a06d4279cce --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/backwardCompatibility/hashMapGetOrDefault.fir.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PLATFORM_CLASS_MAPPED_TO_KOTLIN +// JAVAC_EXPECTED_FILE + +class MyHashMap : java.util.HashMap() { + fun getOrDefault(key: String, defaultValue: String): String = TODO() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/concurrentMapRemove.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/concurrentMapRemove.fir.kt new file mode 100644 index 00000000000..047e151651d --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/concurrentMapRemove.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.concurrent.* + +val concurrent: ConcurrentMap = null!! +val concurrentHash: ConcurrentHashMap = null!! + +fun foo() { + concurrent.remove("", 1) + concurrent.remove("", "") + concurrentHash.remove("", 1) + concurrentHash.remove("", "") + + // Flexible types + concurrent.remove(null, 1) + concurrent.remove(null, null) + + // @PurelyImplements + concurrentHash.remove(null, 1) + concurrentHash.remove(null, null) +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt new file mode 100644 index 00000000000..fb54c047784 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt @@ -0,0 +1,41 @@ +// FULL_JDK + +import java.util.function.Consumer + +abstract class MyIt1 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + +abstract class MyIt2 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + +abstract class MyIt3 : Iterator { + override fun forEachRemaining(x: Consumer?) {} +} + +abstract class MyIt4 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + +abstract class MyIt5 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + +abstract class MyIt6 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + +abstract class MyIt7 : Iterator { + override fun forEachRemaining(x: Consumer) {} +} + + +fun foo(x: Iterator, y: Iterator) { + x.forEachRemaining(null) + + x.forEachRemaining { it -> it.length } + x.forEachRemaining { it -> it?.length } + y.forEachRemaining { it -> it.length } + y.forEachRemaining { it -> it?.length } +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/getOrDefault.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/getOrDefault.fir.kt new file mode 100644 index 00000000000..bdc7e807df9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/getOrDefault.fir.kt @@ -0,0 +1,20 @@ +// FULL_JDK + +abstract class A : Map + +fun foo(x: Map, a: A, b: java.util.HashMap) { + x.getOrDefault(1, "") + x.getOrDefault("", "") + x.getOrDefault(1, 2) + x.getOrDefault("", 2) + + a.getOrDefault(1, "") + a.getOrDefault("", "") + a.getOrDefault(1, 2) + a.getOrDefault("", 2) + + b.getOrDefault(1, "") + b.getOrDefault("", "") + b.getOrDefault(1, 2) + b.getOrDefault("", 2) +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt new file mode 100644 index 00000000000..3f37343499b --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/mutableMapRemove.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -PARAMETER_NAME_CHANGED_ON_OVERRIDE +// !WITH_NEW_INFERENCE +// FULL_JDK + +class KotlinMap1 : java.util.AbstractMap() { + override val entries: MutableSet> + get() = throw UnsupportedOperationException() + + override fun remove(x: K, y: V) = true +} + +class KotlinMap2 : java.util.AbstractMap() { + override val entries: MutableSet> + get() = throw UnsupportedOperationException() + + override fun remove(x: String, y: Int) = true +} + +fun foo(x: MutableMap, y: java.util.HashMap, z: java.util.AbstractMap) { + x.remove("", 1) + x.remove("", "") + x.remove("", null) + + y.remove("", 1) + y.remove("", "") + y.remove("", null) + + z.remove("", 1) + z.remove("", "") + z.remove("", null) +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/removeIf.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/removeIf.fir.kt new file mode 100644 index 00000000000..3ecc5f3048e --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/removeIf.fir.kt @@ -0,0 +1,12 @@ +// FULL_JDK + +import java.util.stream.* + +interface A : MutableCollection { + override fun removeIf(x: java.util.function.Predicate) = false +} + +fun foo(x: MutableList, y: A) { + x.removeIf { it.length > 0 } + y.removeIf { it.length > 0 } +} diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/stream.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/stream.fir.kt new file mode 100644 index 00000000000..ba756b281d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/stream.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.stream.* + +interface A : Collection { + override fun stream(): Stream = Stream.of() +} + +fun foo(x: List, y: A) { + x.stream().filter { it.length > 0 }.collect(Collectors.toList()) + y.stream().filter { it.length > 0 } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt new file mode 100644 index 00000000000..f6a01a8db89 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt @@ -0,0 +1,12 @@ +// FILE: f.kt +class A() { + fun foo() : Unit { + this@A + this@a + this + } + + val x = this@A.foo() + val y = this.foo() + val z = foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/Super.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/Super.fir.kt new file mode 100644 index 00000000000..0f998cc8c11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/Super.fir.kt @@ -0,0 +1,64 @@ +package example + +interface T { + fun foo() {} +} +open class C() { + fun bar() {} +} + +class A() : C(), T { + + fun test() { + super + super + super.foo() + super.foo() + super.bar() + super@A.foo() + super@A.bar() + super.bar() + super@A.bar() + super.foo() + super<>.foo() + super<() -> Unit>.foo() + super.foo() + super@B.foo() + super@B.bar() + } + + inner class B : T { + fun test() { + super.foo(); + super.bar() + super@A.bar() + super@A.foo() + super@B.foo() + super@B.foo() + super.foo() + super + super + } + } +} + +interface G { + fun foo() {} +} + +class CG : G { + fun test() { + super.foo() // OK + super>.foo() // Warning + super>.foo() // Error + super>.foo() // Error + } +} + +// The case when no supertype is resolved +class ERROR() : UR { + + fun test() { + super.foo() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.fir.kt new file mode 100644 index 00000000000..8fb5ae1f5d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.fir.kt @@ -0,0 +1,5 @@ +class Dup { + fun Dup() : Unit { + this@Dup + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.fir.kt new file mode 100644 index 00000000000..a49b33534be --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.fir.kt @@ -0,0 +1,19 @@ +interface IBase { + fun foo() {} + fun bar() {} +} + +interface IDerived : IBase { + override fun foo() {} + fun qux() {} +} + +class Test : IDerived, IBase { + fun test() { + super.foo() + super.bar() + super.foo() + super.bar() + super.qux() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.fir.kt new file mode 100644 index 00000000000..87fa9a1ce94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A { + operator fun invoke() {} + operator fun invoke(f: () -> Unit) {} +} + +class B : A() { + fun bar() { + super() + (super)() + super {} + (super) {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.fir.kt new file mode 100644 index 00000000000..4d8bd0dc92f --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.fir.kt @@ -0,0 +1,10 @@ +open class A { + open fun foo() {} +} + +interface ATrait : A { + + override fun foo() { + super.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.fir.kt new file mode 100644 index 00000000000..7965bd13a7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.fir.kt @@ -0,0 +1,29 @@ +interface IBase { + fun foo() {} + fun bar() {} +} + +interface IDerived1 : IBase { + override fun foo() {} + fun qux() {} +} + +interface IDerived2 : IBase { + override fun foo() {} +} + +class Test : IDerived1, IBase, IDerived2 { + override fun foo() {} + + fun test() { + super.foo() + super.bar() + + super.foo() + super.bar() + super.qux() + + super.foo() + super.bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunction.fir.kt new file mode 100644 index 00000000000..6bb82a500f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunction.fir.kt @@ -0,0 +1,4 @@ +fun String.f() { + super@f.compareTo("") + super.compareTo("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.fir.kt new file mode 100644 index 00000000000..3e04469afb2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.fir.kt @@ -0,0 +1,9 @@ +// No supertype at all + +fun Any.extension(arg: Any?) {} + +class A1 { + fun test() { + super.extension(null) // Call to an extension function + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.fir.kt new file mode 100644 index 00000000000..7ff075f2363 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.fir.kt @@ -0,0 +1,5 @@ +fun foo() { + super + super.foo() + super.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.fir.kt new file mode 100644 index 00000000000..4a2dac7c651 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.fir.kt @@ -0,0 +1,12 @@ +fun any(a : Any) {} + +fun notAnExpression() { + any(super) // not an expression + if (super) {} else {} // not an expression + val x = super // not an expression + when (1) { + super -> 1 // not an expression + else -> {} + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt new file mode 100644 index 00000000000..c4d4e6382a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt @@ -0,0 +1,18 @@ +// !CHECK_TYPE + +class A(val a:Int) { + inner class B() { + fun Byte.xx() : Double.() -> Any { + checkSubtype(this) + val a: Double.() -> Unit = { + checkSubtype(this) + checkSubtype(this@xx) + checkSubtype(this@B) + checkSubtype(this@A) + } + val b: Double.() -> Unit = a@{ checkSubtype(this@a) + checkSubtype(this@xx) } + val c = a@{ -> this@a + checkSubtype(this@xx) } + return (a@{checkSubtype(this@a) + checkSubtype(this@xx)}) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInInnerClasses.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInInnerClasses.fir.kt new file mode 100644 index 00000000000..37894b81581 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInInnerClasses.fir.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +class A(val a:Int) { + + inner class B() { + val x = checkSubtype(this@B) + val y = checkSubtype(this@A) + val z = checkSubtype(this) + val Int.xx : Int get() = checkSubtype(this) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt new file mode 100644 index 00000000000..007d6e065bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt @@ -0,0 +1,8 @@ +interface Base { + fun foo() +} +val String.test: Base = object: Base { + override fun foo() { + this@test + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt new file mode 100644 index 00000000000..34e17b1c77e --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt @@ -0,0 +1,4 @@ +fun foo1() : Unit { + this + this@a +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.fir.kt new file mode 100644 index 00000000000..11485e6d46e --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.fir.kt @@ -0,0 +1,24 @@ +// FILE: test.kt + +public interface Test { + fun test(): String { + return "123"; + } +} + +interface KTrait : Test { + fun ktest() { + super.test() + + test() + } +} + +class A : KTrait { + fun b() { + super.test() + + test() + } +} + diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.fir.kt new file mode 100644 index 00000000000..23d89c88fac --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.fir.kt @@ -0,0 +1,38 @@ +// !WITH_NEW_INFERENCE +open class GenericBaseClass { + open fun foo(x: T): T = x + open fun ambiguous(x: T): T = x +} + +interface GenericBaseInterface { + fun bar(x: T): T = x + fun ambiguous(x: T): T = x +} + +class GenericDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: T): T = super.foo(x) + override fun bar(x: T): T = super.bar(x) + + override fun ambiguous(x: T): T = + super.ambiguous(x) +} + +class SpecializedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: String): String = super.bar(x) + + override fun ambiguous(x: String): String = + super.ambiguous(x) + override fun ambiguous(x: Int): Int = + super.ambiguous(x) +} + +class MixedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: T): T = super.bar(x) + + override fun ambiguous(x: Int): Int = + super.ambiguous(x) + override fun ambiguous(x: T): T = + super.ambiguous(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.fir.kt new file mode 100644 index 00000000000..74ce71eb7a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.fir.kt @@ -0,0 +1,57 @@ +// Base Interface +// \ / +// \/ +// Derived +// + +open class Base() { + open fun foo() {} + + open fun ambiguous() {} + + open val prop: Int + get() = 1234 + + open val ambiguousProp: Int + get() = 111 +} + +interface Interface { + fun bar() {} + + fun ambiguous() {} + + val ambiguousProp: Int + get() = 222 +} + +class Derived : Base(), Interface { + override fun foo() {} + override fun bar() {} + + override fun ambiguous() {} + + override val ambiguousProp: Int + get() = 333 + + override val prop: Int + get() = 4321 + + fun callsFunFromSuperClass() { + super.foo() + } + + fun getSuperProp(): Int = + super.prop + + fun getAmbiguousSuperProp(): Int = + super.ambiguousProp + + fun callsFunFromSuperInterface() { + super.bar() + } + + fun callsAmbiguousSuperFun() { + super.ambiguous() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.fir.kt new file mode 100644 index 00000000000..8908eb77be2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.fir.kt @@ -0,0 +1,39 @@ +// fun foo: abstract in A, unresolved in I +// fun bar: implemented in A, abstract in I +// fun qux: abstract in A, abstract in I +// val x: unresolved in A, abstract in I +// val y: abstract in A, implemented in I + +abstract class A { + abstract fun foo(): Int + open fun bar() {} + abstract fun qux() + + abstract val y: Int +} + +interface I { + fun bar() + fun qux() + + val x: Int + val y: Int get() = 111 +} + +class B : A(), I { + override val x: Int = 12345 + override val y: Int = super.y + + override fun foo(): Int { + super.foo() + return super.x + } + + override fun bar() { + super.bar() + } + + override fun qux() { + super.qux() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.fir.kt new file mode 100644 index 00000000000..0fa5ad351c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// Ambiguity between fun and callable property + +open class BaseWithCallableProp { + val fn = { "fn.invoke()" } + + val bar = { "bar.invoke()"} + open fun bar(): String = "bar()" +} + +interface InterfaceWithFun { + fun fn(): String = "fn()" +} + +class DerivedUsingFun : BaseWithCallableProp(), InterfaceWithFun { + fun foo(): String = + super.fn() + + override fun bar(): String = + super.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.fir.kt new file mode 100644 index 00000000000..a6f0af2a1b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.fir.kt @@ -0,0 +1,51 @@ +// Check that it works with inherited members +// +// DeeperBase DeeperInterface +// | | +// DeepBase DeepInterface +// \ / +// \/ +// DeepDerived +// + +open class DeeperBase { + open fun deeperBaseFun() {} + + open val deeperBaseProp: Int + get() = 333 +} + +open class DeepBase : DeeperBase() { +} + +interface DeeperInterface { + fun deeperInterfaceFun() {} +} + +interface DeepInterface : DeeperInterface { + fun deepInterfaceFun() {} +} + +class DeepDerived : DeepBase(), DeepInterface { + override fun deeperBaseFun() {} + + override val deeperBaseProp: Int + get() = 444 + + override fun deeperInterfaceFun() {} + override fun deepInterfaceFun() {} + + fun callsSuperDeeperBaseFun() { + super.deeperBaseFun() + } + + fun getsSuperDeeperBaseProp(): Int = + super.deeperBaseProp + + fun callsSuperInterfaceFuns() { + super.deeperInterfaceFun() + super.deepInterfaceFun() + super.deeperInterfaceFun() + super.deepInterfaceFun() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.fir.kt new file mode 100644 index 00000000000..0f9df74211a --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.fir.kt @@ -0,0 +1,22 @@ +open class GenericBaseClass { + open fun foo(x: T): T = x +} + +interface GenericBaseInterface { + fun bar(x: T): T = x +} + +class GenericDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: T): T = super.foo(x) + override fun bar(x: T): T = super.bar(x) +} + +class SpecializedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: String): String = super.bar(x) +} + +class MixedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: T): T = super.bar(x) +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.fir.kt new file mode 100644 index 00000000000..414b53a7d0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.fir.kt @@ -0,0 +1,33 @@ +open class A { + open fun foo() {} +} + +interface B { + fun bar() {} +} + +interface Q { + fun qux() {} +} + +class C : A(), B { + override fun foo() { + super@C.foo() + } + + override fun bar() { + super@C.bar() + } + + inner class D : A(), Q { + override fun foo() { + super@C.foo() + super@D.foo() + } + + override fun qux() { + super@C.qux() + super@D.qux() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.fir.kt new file mode 100644 index 00000000000..749014aee50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.fir.kt @@ -0,0 +1,28 @@ +// Interface AnotherInterface +// \ / +// \/ +// DerivedInterface +// + +interface Interface { + fun foo() {} + fun ambiguous() {} + val ambiguousProp: Int + get() = 222 +} + +interface AnotherInterface { + fun ambiguous() {} + val ambiguousProp: Int + get() = 333 +} + +interface DerivedInterface: Interface, AnotherInterface { + override fun foo() { super.foo() } + override fun ambiguous() { + super.ambiguous() + } + override val ambiguousProp: Int + get() = super.ambiguousProp +} + diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.fir.kt new file mode 100644 index 00000000000..51bb88b6904 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.fir.kt @@ -0,0 +1,21 @@ +interface Interface { + fun foo(x: Int): Int +} + +fun withLocalClasses(param: Int): Interface { + open class LocalBase { + open val param: Int + get() = 100 + } + + interface LocalInterface : Interface { + override fun foo(x: Int): Int = + x + param + } + + return object : LocalBase(), LocalInterface { + override fun foo(x: Int): Int = + x + super.param + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.fir.kt new file mode 100644 index 00000000000..433959a2176 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.fir.kt @@ -0,0 +1,53 @@ +// Check that unresolved super type doesn't interfere with unqualified super resolution. + +open class Base() { + open fun foo() {} + + open fun ambiguous() {} + + open val prop: Int + get() = 1234 + + open val ambiguousProp: Int + get() = 111 +} + +interface Interface { + fun bar() {} + + fun ambiguous() {} + + val ambiguousProp: Int + get() = 222 +} + +class ClassDerivedFromUnresolved : Base(), Interface, Unresolved { + override fun foo() {} + override fun bar() {} + + override fun ambiguous() {} + + override val ambiguousProp: Int + get() = 333 + + override val prop: Int + get() = 4321 + + fun callsFunFromSuperClass() { + super.foo() + } + + fun getSuperProp(): Int = + super.prop + + fun getAmbiguousSuperProp(): Int = + super.ambiguousProp + + fun callsFunFromSuperInterface() { + super.bar() + } + + fun callsAmbiguousSuperFun() { + super.ambiguous() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOfAnyOverridenInInterface.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOfAnyOverridenInInterface.fir.kt new file mode 100644 index 00000000000..ba5f4f70298 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOfAnyOverridenInInterface.fir.kt @@ -0,0 +1,8 @@ +interface IWithToString { + override fun toString(): String +} + +class A : IWithToString { + // Should be Any#toString(), even though IWithToString defines an abstract toString. + override fun toString(): String = super.toString() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOverriddenInAnotherSupertype.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOverriddenInAnotherSupertype.fir.kt new file mode 100644 index 00000000000..2f18bb69586 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodOverriddenInAnotherSupertype.fir.kt @@ -0,0 +1,29 @@ +interface A { + fun foo() {} +} + +abstract class C : A { + override abstract fun foo() +} + +interface Unrelated { + fun foo() {} +} + +class Test1 : C(), A { + override fun foo() { + // Abstract 'foo' defined in 'C' wins against non-abstract 'foo' defined in 'A', + // because 'C' is a subclass of 'A' (and 'C::foo' overrides 'A::foo'), + // even though 'A' is explicitly listed in supertypes list for 'D'. + super.foo() + } +} + +class Test2 : C(), A, Unrelated { + override fun foo() { + // This is ok, because there's a non-abstract 'foo' in 'Unrelated', + // which is not overridden by abstract 'foo' in 'C'. + super.foo() + super.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodsOfAny.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodsOfAny.fir.kt new file mode 100644 index 00000000000..e61f5a4f19a --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/withMethodsOfAny.fir.kt @@ -0,0 +1,10 @@ +interface IFoo + +interface IBar + +class A : IFoo, IBar { + // Unqualified 'super' should be resolved to 'Any'. + override fun equals(other: Any?): Boolean = super.equals(other) + override fun hashCode(): Int = super.hashCode() + override fun toString(): String = super.toString() +} diff --git a/compiler/testData/diagnostics/tests/traitWithRequired/traitRequiresAny.fir.kt b/compiler/testData/diagnostics/tests/traitWithRequired/traitRequiresAny.fir.kt new file mode 100644 index 00000000000..a0f84fee62f --- /dev/null +++ b/compiler/testData/diagnostics/tests/traitWithRequired/traitRequiresAny.fir.kt @@ -0,0 +1,5 @@ +interface AnyTrait : Any + +class Foo : AnyTrait + +class Bar : AnyTrait, Any() diff --git a/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt b/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt new file mode 100644 index 00000000000..8ecc765977f --- /dev/null +++ b/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt @@ -0,0 +1,10 @@ +open class bar() + +interface Foo() : bar(), bar, bar { +} + +interface Foo2 : bar, Foo { +} + +open class Foo1() : bar(), bar, Foo, Foo() {} +open class Foo12 : bar(), bar {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/cannotHaveManyClassUpperBounds.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/cannotHaveManyClassUpperBounds.fir.kt new file mode 100644 index 00000000000..106db4f7c00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/cannotHaveManyClassUpperBounds.fir.kt @@ -0,0 +1,18 @@ +open class C1 +open class C2 +open class C3 : C2() + +class A1 where T : C1, T : C2 +class A2 where T : C1, T : C2, T : C3 +class A3 where T : C2, T : C3 +class A4 where T : C3, T : C2 + +fun f1() where T : C1, T : C2, T : C3 {} +fun f2() where T : C2, T : C3 {} +fun f3() where T : C3, T : C2 {} + +enum class E1 +class A5 where T : C1, T : E1 + +object O1 +class A6 where T : O1, T : C2 diff --git a/compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.fir.kt new file mode 100644 index 00000000000..25cf191662a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/deprecatedSyntax.fir.kt @@ -0,0 +1,3 @@ +fun foo() { + fun bar() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.fir.kt new file mode 100644 index 00000000000..e0683acd1be --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/extFunctionTypeAsUpperBound.fir.kt @@ -0,0 +1,7 @@ +fun String> foo() {} + +val String> bar = fun (x: Int): String { return x.toString() } + +class A where T : Double.(Int) -> Unit + +interface B Unit> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.fir.kt new file mode 100644 index 00000000000..edd3dccff91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/functionTypeAsUpperBound.fir.kt @@ -0,0 +1,7 @@ +fun String> foo() {} + +val kotlin.String> bar = fun (x: Int): String { return x.toString() } + +class A where T : () -> Unit, U : (Int) -> Double, V : (T, U) -> U + +interface B Unit> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt new file mode 100644 index 00000000000..4c3a94be300 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt @@ -0,0 +1,103 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST +// !WITH_NEW_INFERENCE +// SKIP_TXT +// Issue: KT-20849 + +fun test_1(x: T): T = null as T +fun test_2(x: () -> T): T = null as T + +fun case_1() { + null?.run { return } + null!!.run { throw Exception() } +} + +fun case_2() { + test_1 { null!! } + test_2 { null!! } +} + +fun case_3() { + test_1 { throw Exception() } + test_2 { throw Exception() } +} + +fun case_6() { + null!! +} + +fun case_7(x: Boolean?) { + when (x) { + true -> throw Exception() + false -> throw Exception() + null -> throw Exception() + } +} + +fun something(): T = Any() as T + +class Context + +fun Any.decodeIn(typeFrom: Context): T = something() + +fun Any?.decodeOut1(typeFrom: Context): T { + return this?.decodeIn(typeFrom) ?: kotlin.Unit +} + +fun Any.decodeOut2(typeFrom: Context): T { + val x: Nothing = this.decodeIn(typeFrom) +} + +fun Any.decodeOut3(typeFrom: Context): T { + val x = this.decodeIn(typeFrom) +} + +fun Any.decodeOut4(typeFrom: Context): T { + val x: Any = this.decodeIn(typeFrom) +} + +class TrieNode { + companion object { + internal val EMPTY = TrieNode() + } +} +class PersistentHashSet(root: TrieNode) { + companion object { + internal val EMPTY = PersistentHashSet(TrieNode.EMPTY) + } +} + +interface F +fun F.join() = {} + +fun main() { + val f: Any = Any() + (f as F<*>).join() +} + +fun bug(worker: Worker) { + stateless { + onWorkerOutput(worker) + } +} + +fun RenderContext.onWorkerOutput(worker: Worker): Unit = Unit + +fun stateless( + render: RenderContext.(input: InputT) -> RenderingT +) { } + +interface Worker + +interface RenderContext + +val emptyOrNull: List? = null +val x = emptyOrNull?.get(0) + +val errorCompletion = { e: Throwable -> throw Exception() } + +fun test1() { + errorCompletion(Exception("fail")) +} +fun test2() { + errorCompletion.invoke(Exception("fail")) +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.fir.kt new file mode 100644 index 00000000000..836fdbb4e77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNCHECKED_CAST +// !WITH_NEW_INFERENCE +// WITH_RUNTIME +// WITH_REFLECT +// SKIP_TXT + +import kotlin.reflect.* + +private object Scope { + class Inv + + class Delegate(private val p: Inv) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T { + return materialize() + } + } + + fun materialize(): T = Any() as T + + fun test(i: Inv) { + val p: Int by Scope.Delegate(i) + } +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.fir.kt new file mode 100644 index 00000000000..8e88088a0cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/misplacedConstraints.fir.kt @@ -0,0 +1,13 @@ +class Foo where T : Comparable { + fun foo(u: U): U where U: Comparable { + fun bar() where T: U {} + return u + } + + val U.foo: U? where U: Comparable + get() { return null } +} + +class Bar where U: Comparable { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParameters.fir.kt new file mode 100644 index 00000000000..93872b99e62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParameters.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -REDUNDANT_PROJECTION -CONFLICTING_PROJECTION + +interface G + +val T.a: Int + get() = 3 + +val Map.b: String + get() = "asds" + +val G.c: Int get() = 5 + +val List>.d: Int get() = 6 + +val G.e: T? + get() = null + +val List>>.f: Int get() = 7 + +val List>>.g: Int get() = 7 +val List>>.h: Int get() = 7 + +val List>>.i: Int get() = 7 + +var p = 1 + +class C { + val T1.a: Int get() = 3 + val T2.b: Int get() = 3 + val E.c: Int get() = 3 + val Map.d: Int get() = 3 + val Map.e: Int get() = 3 +} + +val > T.z1: Int + get() = 4 + +interface D> + +val > X.z2: Int + get() = 4 + +val D<*>.z3: Int + get() = 4 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParametersWithUpperBounds.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParametersWithUpperBounds.fir.kt new file mode 100644 index 00000000000..4f3ea1b2bca --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/propertyTypeParametersWithUpperBounds.fir.kt @@ -0,0 +1,28 @@ + +val K.a: Int get() = 4 + +val K.b: Int where T : K + get() = 4 + +val K.c: Int where T : List + get() = 4 + +val K.d: Int where K : T + get() = 4 + +val K.e: Int where K : List + get() = 4 + +interface G +val G.x1: Int where T : G + get() = 4 + + +val Z.x2: Int where X : Y, Z : Y + get() = 4 + +val , Z: List>> Z.x3: Int + get() = 5 + +val >, Z> Map>.x4: Int + get() = 5 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typeParameters/repeatedBound.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/repeatedBound.fir.kt new file mode 100644 index 00000000000..9364f6ab3c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/repeatedBound.fir.kt @@ -0,0 +1,7 @@ +interface I1 + +class A1 where T : I1, T : I1 +class A2 where T : I1, T : I1? +class A3 where K : V, K : V + +fun f1() where T : I1, T : I1 {} diff --git a/compiler/testData/diagnostics/tests/typeParameters/upperBoundCannotBeArray.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/upperBoundCannotBeArray.fir.kt new file mode 100644 index 00000000000..1edf45e1e0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/upperBoundCannotBeArray.fir.kt @@ -0,0 +1,18 @@ +fun > f1() {} +fun > f2() {} +fun f3() where A : Array, A : Array {} + +fun f4() {} + +fun f5() where T : Array {} + +val > T.v: String get() = "" + +class C2> +interface C3 where A : Array, A : Array + +fun foo() { + class C1> { + fun , B : Array, C : A> f() {} + } +} diff --git a/compiler/testData/diagnostics/tests/typealias/aliasesOnly.fir.kt b/compiler/testData/diagnostics/tests/typealias/aliasesOnly.fir.kt new file mode 100644 index 00000000000..6d283e0cf15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/aliasesOnly.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +typealias S = String + +class C { + typealias SS = String + typealias SF = (T) -> String +} diff --git a/compiler/testData/diagnostics/tests/typealias/annotationsOnTypeAliases.fir.kt b/compiler/testData/diagnostics/tests/typealias/annotationsOnTypeAliases.fir.kt new file mode 100644 index 00000000000..c31ba56353d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/annotationsOnTypeAliases.fir.kt @@ -0,0 +1,15 @@ +// WITH_RUNTIME +import kotlin.annotation.AnnotationTarget.* + +annotation class NoTarget + +@Target(CLASS) +annotation class IrrelevantTarget + +@Target(TYPEALIAS) +annotation class TypealiasTarget + +@NoTarget +@IrrelevantTarget +@TypealiasTarget +typealias Test = String \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/boundViolationInTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/boundViolationInTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..8b7607144f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/boundViolationInTypeAliasConstructor.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +class Num(val x: T) + +typealias N = Num +typealias N2 = N + +val x1 = Num("") +val x2 = N("") +val x3 = N2("") + +class TColl> + +typealias TC = TColl +typealias TC2 = TC + +val y1 = TColl() +val y2 = TC() +val y3 = TC2() diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.fir.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.fir.kt new file mode 100644 index 00000000000..c868b92be74 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class TColl> + +typealias TC = TColl +typealias TC2 = TC + +fun test1(x: TC2>) {} +fun test2(x: TC2>) {} +fun test3(x: TC2>) {} +fun test4(x: TC2>) {} + +val test5 = TC2>() +val test6 = TC2>() +val test7 = TC2>() +val test8 = TC2>() diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.fir.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.fir.kt new file mode 100644 index 00000000000..dd2a35d6211 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class Num +class NumColl> +class TColl> + +typealias NA = Num +typealias NL = NumColl> +typealias TC = TColl + +fun test1(x: NA) {} +fun test2(x: NA) {} +fun test3(x: NL) {} +fun test4(x: NL) {} + +val test5 = NA() +val test6 = NA() +val test7 = NL() +val test8 = NL() + +fun test9(x: TC>) {} +fun test10(x: TC>) {} +fun test11(x: TC>) {} +fun test12(x: TC>) {} + +val test13 = TC>() +val test14 = TC>() +val test15 = TC>() +val test16 = TC>() diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.fir.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.fir.kt new file mode 100644 index 00000000000..7d71da84dce --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +class TC> + +typealias TCAlias = TC +typealias TCAliasT = TC +typealias TCAliasC = TC +typealias TCAliasT1 = TCAlias +typealias TCAliasC1 = TCAlias + +typealias Test1 = TC +typealias Test2 = TC> +typealias Test3 = TCAlias +typealias Test4 = TCAlias> +typealias Test5 = TCAliasT +typealias Test6 = TCAliasC +typealias Test7 = TCAliasC> +typealias Test8 = TCAliasT1 +typealias Test9 = TCAliasC1 +typealias Test10 = TCAliasC1> diff --git a/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.fir.kt new file mode 100644 index 00000000000..377d2af6c7d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Outer { + typealias LTO = List + + class Nested { + typealias LTO = List + typealias LTN = List + + inner class Inner { + typealias LTO = List + typealias LTN = List + typealias LTI = List + } + } +} + +fun foo() { + class Local { + typealias LTF = List + typealias LTL = List + } + + fun localfun() = + object { + typealias LTF = List + typealias LTLF = List + } +} diff --git a/compiler/testData/diagnostics/tests/typealias/classReference.fir.kt b/compiler/testData/diagnostics/tests/typealias/classReference.fir.kt new file mode 100644 index 00000000000..33c74a0eb4a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/classReference.fir.kt @@ -0,0 +1,3 @@ +typealias S = String + +val s = S::class diff --git a/compiler/testData/diagnostics/tests/typealias/conflictingProjections.fir.kt b/compiler/testData/diagnostics/tests/typealias/conflictingProjections.fir.kt new file mode 100644 index 00000000000..eb078eb386a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/conflictingProjections.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +interface In +interface Out + +typealias InAlias = In +typealias OutAlias = Out + +typealias TestOutForIn = In +typealias TestInForOut = Out + +typealias TestOutForInWithinAlias = InAlias +typealias TestInForOutWithinAlias = OutAlias + +fun testOutForInWithinResolvedType(x: InAlias) {} +fun testInForOutWithinResolvedType(x: OutAlias) {} diff --git a/compiler/testData/diagnostics/tests/typealias/constructorCallThroughPrivateAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/constructorCallThroughPrivateAlias.fir.kt new file mode 100644 index 00000000000..777b7a75749 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/constructorCallThroughPrivateAlias.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !CHECK_TYPE +// FILE: a.kt +package a + +class B(x: String) +typealias A1 = B +private typealias A2 = B +private typealias A3 = B + +fun A3(x: Any) = "OK" + +fun bar() { + A3("") checkType { _() } +} + +// FILE: main.kt +package usage + +import a.B + +fun baz() { + a.A1("") // resolved to B constructor, OK + a.A2("") // resolved to B constructor, INVISIBLE_MEMBER because type alias is private, OK + + a.A3("") checkType { _() } + + val x: a.A2 = B("") // A2 is unresolved because it's private in file, OK +} diff --git a/compiler/testData/diagnostics/tests/typealias/cyclicInheritanceViaTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/cyclicInheritanceViaTypeAlias.fir.kt new file mode 100644 index 00000000000..2943e8b4c4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/cyclicInheritanceViaTypeAlias.fir.kt @@ -0,0 +1,7 @@ +class A : B() { + open class Nested +} + +typealias ANested = A.Nested + +open class B : ANested() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/enumEntryQualifier.fir.kt b/compiler/testData/diagnostics/tests/typealias/enumEntryQualifier.fir.kt new file mode 100644 index 00000000000..95a0fd48338 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/enumEntryQualifier.fir.kt @@ -0,0 +1,6 @@ +enum class MyEnum { A } + +typealias TestAlias = MyEnum + +val test1 = MyEnum.A +val test2 = TestAlias.A \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.fir.kt b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.fir.kt new file mode 100644 index 00000000000..2b9ab13235f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +typealias L = List + +class Outer { + private class Private + protected class Protected + internal class Internal + + typealias TestPrivate1 = Private + protected typealias TestPrivate2 = Private + internal typealias TestPrivate3 = Private + private typealias TestPrivate4 = Private + typealias TestPrivate5 = L + typealias TestPrivate6 = L + + typealias TestProtected1 = Protected + protected typealias TestProtected2 = Protected + internal typealias TestProtected3 = Protected + private typealias TestProtected4 = Protected + typealias TestProtected5 = L + typealias TestProtected6 = L + + typealias TestInternal1 = Internal + protected typealias TestInternal2 = Internal + internal typealias TestInternal3 = Internal + private typealias TestInternal4 = Internal + typealias TestInternal5 = L + typealias TestInternal6 = L +} + +private class Private +internal class Internal + +typealias TestPrivate1 = Private +internal typealias TestPrivate2 = Private +private typealias TestPrivate3 = Private +typealias TestPrivate4 = L +typealias TestPrivate5 = L + +typealias TestInternal1 = Internal +internal typealias TestInternal2 = Internal +private typealias TestInternal3 = Internal +typealias TestInternal4 = L +typealias TestInternal5 = L diff --git a/compiler/testData/diagnostics/tests/typealias/functionTypeInTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/functionTypeInTypeAlias.fir.kt new file mode 100644 index 00000000000..d1b1e45332e --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/functionTypeInTypeAlias.fir.kt @@ -0,0 +1,3 @@ +val f: () -> Unit = {} + +typealias F = () -> Unit diff --git a/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..fd683ffa156 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.fir.kt @@ -0,0 +1,10 @@ +class C(val x: T, val y: String) { + constructor(x: T): this(x, "") +} + +typealias GTC = C + +val test1 = GTC("", "") +val test2 = GTC("", "") +val test3 = GTC("") +val test4 = GTC("") diff --git a/compiler/testData/diagnostics/tests/typealias/genericTypeAliasObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasObject.fir.kt new file mode 100644 index 00000000000..d301b19d0cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasObject.fir.kt @@ -0,0 +1,25 @@ +object AnObject { + val ok = "OK" + fun foo() = "OK" +} + +typealias GenericTestObject = AnObject + +val test11: AnObject = GenericTestObject +val test12: GenericTestObject<*> = GenericTestObject +val test13: String = GenericTestObject.ok +val test14: String = GenericTestObject.foo() + +class GenericClassWithCompanion { + companion object { + val ok = "OK" + fun foo() = "OK" + } +} + +typealias TestGCWC = GenericClassWithCompanion + +val test25: GenericClassWithCompanion.Companion = TestGCWC +val test26 = TestGCWC +val test27: String = TestGCWC.ok +val test28: String = TestGCWC.foo() diff --git a/compiler/testData/diagnostics/tests/typealias/illegalTypeInTypeAliasExpansion.fir.kt b/compiler/testData/diagnostics/tests/typealias/illegalTypeInTypeAliasExpansion.fir.kt new file mode 100644 index 00000000000..1602af910b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/illegalTypeInTypeAliasExpansion.fir.kt @@ -0,0 +1,12 @@ +typealias A = Array +typealias AA = A> + +typealias AN = A + +typealias AAN = AA + +typealias AAN2 = A> + +typealias First = List +typealias UnusedAN1 = First> +typealias UnusedAN2 = First> // TODO diff --git a/compiler/testData/diagnostics/tests/typealias/import.fir.kt b/compiler/testData/diagnostics/tests/typealias/import.fir.kt new file mode 100644 index 00000000000..d370c3d0978 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/import.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// FILE: file1.kt +package package1 + +typealias S = String + +// FILE: file2.kt +package package2 + +typealias I = Int + +class Outer { + typealias A = Any +} + +// FILE: test.kt +package package3 + +import package1.* +import package2.I +import package2.Outer.A + +val testS: S = "" +val testI: I = 42 +val testA: A = Any() diff --git a/compiler/testData/diagnostics/tests/typealias/importForTypealiasObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/importForTypealiasObject.fir.kt new file mode 100644 index 00000000000..a02955adc61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/importForTypealiasObject.fir.kt @@ -0,0 +1,18 @@ +// FILE: 1.kt +package something + +object N + +class WC { + companion object +} + +typealias T = N +typealias TWC = WC + +// FILE: 2.kt +import something.T +import something.TWC + +val test1 = T.hashCode() +val test2 = TWC.hashCode() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.fir.kt new file mode 100644 index 00000000000..9486785b750 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.fir.kt @@ -0,0 +1,15 @@ +// FILE: 1.kt +package bar + +typealias HostAlias = Host + +object Host { + fun foo() {} +} + +// FILE: 2.kt +import bar.HostAlias.foo + +fun test() { + foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.fir.kt new file mode 100644 index 00000000000..c07a996b728 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_JAVAC + +// FILE: test/jv/JavaSample.java + +package test.jv; + +public class JavaSample { + public static void member() {} +} + +// FILE: foo.kt + +package test.kot + +typealias JavaAlias = test.jv.JavaSample + +// FILE: test.kt + +import test.kot.JavaAlias +import test.kot.JavaAlias.member + +fun foo( + sample: JavaSample, + alias: JavaAlias +) { + member() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/inGenerics.fir.kt b/compiler/testData/diagnostics/tests/typealias/inGenerics.fir.kt new file mode 100644 index 00000000000..567455e61df --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/inGenerics.fir.kt @@ -0,0 +1,12 @@ +typealias MyString = String + +class Container(val x: T) + +typealias MyStringContainer = Container + +val ms: MyString = "MyString" + +val msn: MyString? = null + +val msc: MyStringContainer = Container(ms) +val msc1 = MyStringContainer(null) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt b/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt new file mode 100644 index 00000000000..728ecb7ff5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt @@ -0,0 +1,6 @@ +interface IBase + +typealias B = IBase + +class Test1 : B +class Test2 : IBase, B diff --git a/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.fir.kt new file mode 100644 index 00000000000..d0e84053c88 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +interface ICell { + val x: T +} + +class Cell(override val x: T): ICell + +open class Base { + typealias CT = Cell + inner class InnerCell(override val x: T): ICell +} + +class Derived : Base() { + val x1: InnerCell = InnerCell(42) + val x2: Base.InnerCell = InnerCell(42) + + val test1: CT = Cell(42) + val test2: Base.CT = Cell(42) +} diff --git a/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt new file mode 100644 index 00000000000..3007b87c660 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +open class Base { + typealias Nested = String +} + +class Derived : Base() + +fun test(x: Derived.Nested) = x + +fun Base.testWithImplicitReceiver(x: Nested) { + val y: Nested = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..3f044a11226 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructor.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Outer { + inner class Inner +} + +typealias OI = Outer.Inner + +fun test1(x: Outer) = x.OI() + + +class Generic { + inner class Inner +} + +typealias GI = Generic.Inner +typealias GIntI = Generic.Inner + +fun test2(x: Generic) = x.GI() +fun test3(x: Generic) = x.GI() +fun test4(x: Generic>) = x.GI() +fun test5(x: Generic) = x.GIntI() +fun Generic.test6() = GIntI() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructorInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructorInSupertypes.fir.kt new file mode 100644 index 00000000000..22e8b76378c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructorInSupertypes.fir.kt @@ -0,0 +1,40 @@ +// !WITH_NEW_INFERENCE +package test + +typealias OI = Outer.Inner + +class Outer { + open inner class Inner + + inner class Test : OI() +} + + +typealias GI = Generic.Inner +typealias GIInt = Generic.Inner +typealias GIStar = Generic<*>.Inner +typealias GG = Generic.Generic +typealias GIntG = Generic.Generic +typealias GGInt = Generic.Generic + +class Generic { + open inner class Inner + open inner class Generic + + inner class Test1 : GI() + inner class Test2 : GIInt() + inner class Test3 : GIStar() + inner class Test3a : test.Generic<*>.Inner() + + inner class Test4 : GG() + inner class Test5 : GG() + inner class Test6 : GG() + inner class Test7 : GG() + inner class Test8 : GIntG() + inner class Test9 : GGInt() + inner class Test10 : GGInt() + + inner class Test11 : GG { + constructor() : super() + } +} diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt new file mode 100644 index 00000000000..38b340f6a24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Outer { + class Nested + class GenericNested + inner class Inner + inner class GenericInner + + typealias NestedAlias = Nested + typealias GenericNestedAlias = GenericNested + typealias InnerAlias = Inner + typealias GenericInnerAlias = GenericInner + + fun test1(x: NestedAlias) = x + fun test2(x: GenericNestedAlias) = x + fun test3(x: GenericNestedAlias) = x + fun test4(x: InnerAlias) = x + fun test5(x: GenericInnerAlias) = x + fun test6(x: GenericInnerAlias) = x +} +fun test1(x: Outer.NestedAlias) = x +fun test2(x: Outer.NestedAlias) = x +fun test3(x: Outer.NestedAlias) = x +fun test4(x: Outer.GenericNestedAlias) = x +fun test5(x: Outer.GenericNestedAlias) = x +fun test6(x: Outer.GenericNestedAlias) = x +fun test7(x: Outer.GenericNestedAlias) = x +fun test8(x: Outer.GenericNestedAlias) = x +fun test9(x: Outer.InnerAlias) = x +fun test10(x: Outer.InnerAlias) = x +fun test11(x: Outer.InnerAlias) = x +fun test12(x: Outer.GenericInnerAlias) = x +fun test13(x: Outer.GenericInnerAlias) = x +fun test14(x: Outer.GenericInnerAlias) = x diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.fir.kt new file mode 100644 index 00000000000..f1a2018e98d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class C { + inner class D + + typealias DA = D + typealias SDA = C.D + typealias TSDA = C.D + typealias TC = C + typealias SSDA = C<*>.D + typealias SSC = C<*> +} + +fun test1(x: C.DA) = x +fun test2(x: C.SDA) = x +fun test3(x: C.TSDA) = x +fun test4(x: C.TC) = x + +fun test5(x: C<*>.DA) = x +fun test6(x: C<*>.TSDA) = x +fun test7(x: C<*>.TC) = x + +fun test8(x: C.SSDA) = x +fun test9(x: C.SSC) = x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..f2e054d434f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Pair(val x: X, val y: Y) + +class C { + typealias P = Pair + typealias P1 = Pair + typealias P2 = Pair +} + +// C<...>.P[<...>]() syntax doesn't work due to the way qualified expressions are resolved now. +// This restriction can be removed later. +val test0 = C.P(1, 1) +val test1 = C.P1("", 1) +val test2 = C.P2(1, "") +val test3 = C.P1("", 1) +val test4 = C.P2(1, "") + +// C.P() syntax could work if we add captured type parameters as type variables in a constraint system for corresponding call. +// However, this should be consistent with inner classes capturing type parameters. +val test5 = C.P(1, 1) +val test6 = C.P1("", 1) +val test7 = C.P2(1, "") diff --git a/compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.fir.kt new file mode 100644 index 00000000000..bf998f4817c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.fir.kt @@ -0,0 +1,5 @@ +typealias S = String + +fun test1(x: Any) = x is S +fun test2(x: Any) = x as S +fun test3(x: Any) = x as? S diff --git a/compiler/testData/diagnostics/tests/typealias/javaStaticMembersViaTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/javaStaticMembersViaTypeAlias.fir.kt new file mode 100644 index 00000000000..df25925e618 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/javaStaticMembersViaTypeAlias.fir.kt @@ -0,0 +1,46 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: JTest.java +public class JTest { + public static String foo() { return ""; } + public static class Nested {} +} + +// FILE: JDerived.java +public class JDerived extends JTest { +} + +// FILE: test.kt +class KTest { + class Nested + inner class Inner +} + +interface ITest { + class Nested +} + +typealias JT = JTest +typealias JD = JDerived +typealias KT = KTest +typealias IT = ITest + +// Referencing Java class static members via type alias should be ok +val testFoo: String = JT.foo() +val seeAlsoFoo: String = JTest.foo() +// Referencing base Java class static members via type alias for derived Java class should be ok +val testDerivedFoo: String = JD.foo() +val seeAlsoDerivedFoo: String = JDerived.foo() + +// Referencing nested classes via type alias should be prohibited +// (in type position and in expression position) +val testNested1: JT.Nested = JT.Nested() +val testNested2: KT.Nested = KT.Nested() +val testNested3: IT.Nested = IT.Nested() +val testInner1: JT.Inner = JT.Inner() +val testInner2: KT.Inner = KT.Inner() +fun testNestedAsTypeArgument1(x: List) {} +fun testNestedAsTypeArgument2(x: List) {} +fun testNestedAsTypeArgument3(x: List) {} +fun testInnerAsTypeArgument1(x: List) {} +fun testInnerAsTypeArgument2(x: List) {} + diff --git a/compiler/testData/diagnostics/tests/typealias/kt14498.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt14498.fir.kt new file mode 100644 index 00000000000..37df74eb372 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt14498.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_TYPEALIAS_PARAMETER + +interface I1 +interface Out +interface InvOut + +typealias A1 = I1 +typealias A2 = I1 +typealias AOut = Out +typealias AInvOut = InvOut +typealias AInvOutTT = AInvOut + +class Test1 : A1 +class Test2 : A2 +class Test3 : AOut +class Test4 : AInvOut +class Test5 : AInvOutTT \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/kt14498a.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt14498a.fir.kt new file mode 100644 index 00000000000..9525f219a2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt14498a.fir.kt @@ -0,0 +1,11 @@ +interface Out +interface Inv +typealias A1 = Out> +typealias A2 = Out> +typealias A3 = Inv> +typealias A4 = Out> + +interface Q1 : Out> +interface Q2 : Out> +interface Q3 : Out> +interface Q4 : Out> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/kt14518.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt14518.fir.kt new file mode 100644 index 00000000000..8af18fe0e40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt14518.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class OuterClass { + class NestedClass + typealias NestedType = NestedClass +} + +typealias ON1 = OuterClass.NestedClass +typealias ON2 = OuterClass.NestedType +typealias ON3 = OuterClass.NestedType \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/kt14641.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt14641.fir.kt new file mode 100644 index 00000000000..d4014f9c2fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt14641.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class A { + public inner class B { } + public typealias BAlias = B +} + +fun f() { + val a = A() + a.BAlias +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/kt15734.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt15734.fir.kt new file mode 100644 index 00000000000..f35a9e1befc --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt15734.fir.kt @@ -0,0 +1,19 @@ +@Target(AnnotationTarget.TYPE) +annotation class Ann + +typealias TString = String + +typealias TNString = TString? + +typealias TNAString = @Ann TString? + +val test1: TNString = TODO() +val test2: TNAString = TODO() +val test3: List = TODO() +val test4: List = TODO() +val test5: List = TODO() +val test6: () -> List = TODO() + +fun test(x: TNString) { + x.hashCode() +} diff --git a/compiler/testData/diagnostics/tests/typealias/kt19601.fir.kt b/compiler/testData/diagnostics/tests/typealias/kt19601.fir.kt new file mode 100644 index 00000000000..324ac3752e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/kt19601.fir.kt @@ -0,0 +1,11 @@ +interface Order + +typealias Ord = Order + +class Test1> + +interface Num + +typealias N = Num + +class Test2> \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt new file mode 100644 index 00000000000..a7c55d93331 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +fun emptyList(): List = null!! + +fun foo() { + typealias LT = List + + val a: LT = emptyList() + + fun localFun(): LT { + typealias LLT = List + + val b: LLT = a + + return b + } + + localFun() +} diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..9ef9044cf81 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Cell(val x: TC) + +fun id(x: T): T { + typealias C = Cell + class Local(val cell: C) + val cx = C(x) + val c: C = Local(cx).cell + return c.x +} diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.fir.kt new file mode 100644 index 00000000000..c6bc19100cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.fir.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +fun outer() { + companion typealias TestLocal = Any +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.fir.kt new file mode 100644 index 00000000000..571a38bf315 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +fun outer() { + typealias Test1 = Test1 + typealias Test2 = List + typealias Test3 = List> +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/methodReference.fir.kt b/compiler/testData/diagnostics/tests/typealias/methodReference.fir.kt new file mode 100644 index 00000000000..c0914863e45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/methodReference.fir.kt @@ -0,0 +1,7 @@ +class C { + fun foo() {} +} + +typealias CA = C + +val cf = CA::foo diff --git a/compiler/testData/diagnostics/tests/typealias/nested.fir.kt b/compiler/testData/diagnostics/tests/typealias/nested.fir.kt new file mode 100644 index 00000000000..77a8316109e --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/nested.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Pair(val x1: T1, val x2: T2) + +class C { + typealias P2 = Pair + + fun p() = P2(1, 1) + fun first(p: P2) = p.x1 + fun second(p: P2) = p.x2 +} + +val p1 = Pair(1, 1) + +val test1: Int = C().first(p1) +val test2: Int = C().second(p1) + +fun C.testExtFun1(x: C.P2) = x + +fun C.testExtFun2(): C.P2 { + val x: C.P2 = p() + val y = C.P2(1, 1) + return x +} diff --git a/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt new file mode 100644 index 00000000000..08e34472f34 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Pair(val x1: T1, val x2: T2) + +class C { + typealias P2 = Pair + typealias PT2 = Pair + + fun first(p: P2) = p.x1 + fun second(p: P2) = p.x2 + + fun first2(p: PT2) = p.x1 + fun second2(p: PT2) = p.x2 +} + +val p1 = Pair(1, 1) +val p2 = Pair(1, "") + +val test1: Int = C().first(p1) +val test2: Int = C().second(p1) + +val test3: Int = C().first2(p2) +val test4: String = C().second2(p2) diff --git a/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.fir.kt b/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.fir.kt new file mode 100644 index 00000000000..e5ec2fb2f50 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +class Pair(val x1: T1, val x2: T2) + +class C { + typealias P2 = Pair +} + +val p1: C.P2 = Pair("", 1) diff --git a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt new file mode 100644 index 00000000000..6e62fc11653 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +typealias Array2D = Array> + +fun foo1(a: Array2D) = a + +fun bar1(a: Array2D) = + foo1(a) + + +typealias TMap = Map + +fun foo2(m: TMap) = m + +fun bar2(m: TMap<*>) = + foo2(m) diff --git a/compiler/testData/diagnostics/tests/typealias/noRHS.fir.kt b/compiler/testData/diagnostics/tests/typealias/noRHS.fir.kt new file mode 100644 index 00000000000..f2598266905 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/noRHS.fir.kt @@ -0,0 +1,6 @@ +typealias + +typealias A1 + +typealias A2 = + \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/parameterRestrictions.fir.kt b/compiler/testData/diagnostics/tests/typealias/parameterRestrictions.fir.kt new file mode 100644 index 00000000000..8515a4b3cf4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/parameterRestrictions.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_TYPEALIAS_PARAMETER + +typealias WithVariance = Int +typealias WithBounds1 = Int +typealias WithBounds2 = Int + +typealias WithBounds3 where X : Any = Int + +val x: WithVariance = 0 diff --git a/compiler/testData/diagnostics/tests/typealias/parameterSubstitution.fir.kt b/compiler/testData/diagnostics/tests/typealias/parameterSubstitution.fir.kt new file mode 100644 index 00000000000..35fd6a5dd58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/parameterSubstitution.fir.kt @@ -0,0 +1,8 @@ +class C + +typealias CA = C + +val ca1: CA = C() +val ca2: CA> = C>() +val ca3: CA> = C>() +val ca4: CA = C() diff --git a/compiler/testData/diagnostics/tests/typealias/privateInFile.fir.kt b/compiler/testData/diagnostics/tests/typealias/privateInFile.fir.kt new file mode 100644 index 00000000000..c76aa214c7e --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/privateInFile.fir.kt @@ -0,0 +1,22 @@ +// FILE: file1.kt +private class C { + companion object +} + +private typealias TA = C + +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +// FILE: file2.kt +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +private class C +private typealias TA = Int \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/projectionsInTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/projectionsInTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..3be68c3e5dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/projectionsInTypeAliasConstructor.fir.kt @@ -0,0 +1,6 @@ +class In(val x: Any) + +typealias InAlias = In + +val test1 = In("") +val test2 = InAlias("") diff --git a/compiler/testData/diagnostics/tests/typealias/recursive.fir.kt b/compiler/testData/diagnostics/tests/typealias/recursive.fir.kt new file mode 100644 index 00000000000..ffa482edf53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/recursive.fir.kt @@ -0,0 +1,11 @@ +typealias R = R + +typealias L = List + +typealias A = B +typealias B = A + +typealias F1 = (Int) -> F2 +typealias F2 = (F1) -> Int + +val x: A = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/returnTypeNothingShouldBeSpecifiedExplicitly.fir.kt b/compiler/testData/diagnostics/tests/typealias/returnTypeNothingShouldBeSpecifiedExplicitly.fir.kt new file mode 100644 index 00000000000..d5da819532c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/returnTypeNothingShouldBeSpecifiedExplicitly.fir.kt @@ -0,0 +1,5 @@ +typealias N = Nothing + +fun testFun(): N = null!! +val testVal: N = null!! +val testValWithGetter: N get() = null!! diff --git a/compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.fir.kt new file mode 100644 index 00000000000..65b7bc9ff00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.fir.kt @@ -0,0 +1,8 @@ +typealias S = String +typealias SS = S +typealias SSS = SS + +val s1: SSS = "" +val s2: SSS? = null +val s3: List? = null +val s4: List?>? = null diff --git a/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.fir.kt new file mode 100644 index 00000000000..6634ae21081 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.fir.kt @@ -0,0 +1,30 @@ +// FILE: foo.kt + +// FILE: foo.kt + +package test + +typealias ClassAlias = ClassSample +typealias ObjectAlias = ObjectSample +typealias EnumAlias = EnumSample + +class ClassSample + +object ObjectSample + +enum class EnumSample { + Entry; +} + +// FILE: bar.kt + +import test.ClassAlias.* +import test.ObjectAlias.* +import test.EnumAlias.* +import test.EnumAlias + + +fun bar() { + Entry + EnumAlias.Entry +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/starProjection.fir.kt b/compiler/testData/diagnostics/tests/typealias/starProjection.fir.kt new file mode 100644 index 00000000000..2b0c3acbeed --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/starProjection.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +typealias A = Map +typealias B = A<*> + +fun check(x: B) = x + +fun test1(x: Map) = check(x) + +fun test2(x: Map) = check(x) + +fun test3(x: Map) = check(x).size + +fun test4(x: Map) = check(x)["42"] + +fun test5(x: Map) = check(x)[42] \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/starProjectionInTypeAliasArgument.fir.kt b/compiler/testData/diagnostics/tests/typealias/starProjectionInTypeAliasArgument.fir.kt new file mode 100644 index 00000000000..4f98fe9a121 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/starProjectionInTypeAliasArgument.fir.kt @@ -0,0 +1,6 @@ +class NumCharSeq(val n: N, val m: M) + +typealias Test = NumCharSeq + +fun getN(t: Test<*, *>) = t.n +fun getM(t: Test<*, *>) = t.m diff --git a/compiler/testData/diagnostics/tests/typealias/substitutionVariance.fir.kt b/compiler/testData/diagnostics/tests/typealias/substitutionVariance.fir.kt new file mode 100644 index 00000000000..bb31c55e0fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/substitutionVariance.fir.kt @@ -0,0 +1,67 @@ +// NI_EXPECTED_FILE + +class In +class Out +class Inv + +typealias In1 = In +typealias In2 = In +typealias In3 = In +typealias In4 = In<*> + +typealias Out1 = Out +typealias Out2 = Out +typealias Out3 = Out +typealias Out4 = Out<*> + +typealias Inv1 = Inv +typealias Inv2 = Inv +typealias Inv3 = Inv +typealias Inv4 = Inv<*> + +val inv1: Inv1 = Inv() + +fun inInv_Inv(x: In1) = x +fun inInv_In(x: In1) = x +fun inInv_Out(x: In1) = x +fun inInv_Star(x: In1<*>) = x + +fun inIn_Inv(x: In2) = x +fun inIn_In(x: In2) = x +fun inIn_Out(x: In2) = x +fun inIn_Star(x: In2<*>) = x + +fun inOut_Inv(x: In3) = x +fun inOut_In(x: In3) = x +fun inOut_Out(x: In3) = x +fun inOut_Star(x: In3<*>) = x + +fun outInv_Inv(x: Out1) = x +fun outInv_In(x: Out1) = x +fun outInv_Out(x: Out1) = x +fun outInv_Star(x: Out1<*>) = x + +fun outIn_Inv(x: Out2) = x +fun outIn_In(x: Out2) = x +fun outIn_Out(x: Out2) = x +fun outIn_Star(x: Out2<*>) = x + +fun outOut_Inv(x: Out3) = x +fun outOut_In(x: Out3) = x +fun outOut_Out(x: Out3) = x +fun outOut_Star(x: Out3<*>) = x + +fun invInv_Inv(x: Inv1) = x +fun invInv_In(x: Inv1) = x +fun invInv_Out(x: Inv1) = x +fun invInv_Star(x: Inv1<*>) = x + +fun invIn_Inv(x: Inv2) = x +fun invIn_In(x: Inv2) = x +fun invIn_Out(x: Inv2) = x +fun invIn_Star(x: Inv2<*>) = x + +fun invOut_Inv(x: Inv3) = x +fun invOut_In(x: Inv3) = x +fun invOut_Out(x: Inv3) = x +fun invOut_Star(x: Inv3<*>) = x diff --git a/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt b/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt new file mode 100644 index 00000000000..ad99d935b42 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/throwJLException.fir.kt @@ -0,0 +1,7 @@ +// +JDK + +typealias Exn = java.lang.Exception + +fun test() { + throw Exn +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.fir.kt b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.fir.kt new file mode 100644 index 00000000000..8c79e33dda3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.fir.kt @@ -0,0 +1,19 @@ +typealias TopLevel = Any + +interface A { + typealias Nested = Any +} + +class C { + typealias Nested = Any + class D { + typealias Nested = Any + fun foo() { + typealias LocalInMember = Any + } + } +} + +fun foo() { + typealias Local = Any +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.fir.kt new file mode 100644 index 00000000000..2e44c513075 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.fir.kt @@ -0,0 +1,10 @@ +class C { + companion object { + val OK = "OK" + } +} + +typealias C2 = C + +val test1: String = C2.OK +val test2: String = C2.OK diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInConstructor.fir.kt new file mode 100644 index 00000000000..8945b180940 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInConstructor.fir.kt @@ -0,0 +1,11 @@ +class Pair(val x1: T1, val x2: T2) + +typealias P2 = Pair + +val test1: Pair = P2("", "") +val test1x1: String = test1.x1 +val test1x2: String = test1.x2 + +val test2: P2 = P2("", "") +val test2x1: String = test2.x1 +val test2x2: String = test2.x2 diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.fir.kt new file mode 100644 index 00000000000..58a8a49211c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +typealias L = List +typealias NL = List? +typealias LStar = List<*> +typealias MyList = List + +fun testL1(x: Collection) = x is L +fun testL2(x: Collection): List = x as L +fun testL3(x: Collection?): List? = x as L? +fun testL4(x: Collection?): List? = x as? L + +fun testNL1(x: Collection?): Boolean = x is NL +fun testNL2(x: Collection?): List? = x as NL +fun testNL3(x: Collection?): List? = x as NL? + +fun testLStar(x: Collection): List = x as LStar +fun testMyList(x: Collection): List = x as MyList + +typealias MMTT = MutableMap +typealias Dictionary = MutableMap +typealias WriteableMap = MutableMap +typealias ReadableList = MutableList + +fun testWrong1(x: Map) = x is MMTT +fun testWrong2(x: Map) = x is Dictionary +fun testWrong3(x: Map) = x is WriteableMap +fun testWrong4(x: List) = x is ReadableList + +fun testLocal(x: Any) { + class C + typealias CA = C + if (x is C) {} + if (x is CA) {} +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.fir.kt new file mode 100644 index 00000000000..1894f09620f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY +// NI_EXPECTED_FILE + +class C { + typealias Self = C + class Nested { + class N2 + typealias Root = C + } + companion object X { + val ok = "OK" + class InCompanion + } +} + +val c = C.Self.Self() +val n = C.Self.Nested() +val x = C.Self.X +val n2 = C.Nested.Root.Nested.N2() +val ic = C.Self.InCompanion() +val ok = C.Self.ok diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.fir.kt new file mode 100644 index 00000000000..39534bbba1b --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +open class Base { + open fun foo() {} +} + +open class GenericBase { + open fun foo() {} +} + +class Unrelated { + fun foo() {} +} + +typealias B = Base +typealias U = Unrelated +typealias GB = GenericBase + +class TestSuperForBase : B() { + typealias MyBase = B + + override fun foo() { + super.foo() + super.foo() + super.foo() + super.foo() + } +} + +class TestSuperForGenericBase : GB() { + typealias MyBase = GB + typealias MyBaseInt = GB + + override fun foo() { + super.foo() + super.foo() + super.foo() + super.foo() // Type arguments don't matter here + super.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt new file mode 100644 index 00000000000..098cb31bb3b --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt @@ -0,0 +1,24 @@ +class C(val x: String) { + constructor(): this("") +} + +typealias TC = C + +val test1: C = TC("") +val test2: TC = TC("") +val test3: C = TC() +val test4: TC = TC() + +val test5 = TC("", "") + +interface Interface +typealias TI = Interface + +object AnObject +typealias TO = AnObject + +val test6 = TI() +val test6a = Interface() + +val test7 = TO() +val test7a = AnObject() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt new file mode 100644 index 00000000000..ef5ecb51b5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Bound(val x: X, val y: Y) +typealias B = Bound +typealias BOutIn = Bound, in T> +typealias BInIn = Bound, in T> + +fun listOf(): List = null!! + +// Unresolved reference is ok here: +// we can't create a substituted signature for type alias constructor +// since it has 'out' type projection in 'in' position. +val test1 = BOutIn(listOf(), null!!) + +val test2 = BInIn(listOf(), null!!) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt new file mode 100644 index 00000000000..7696ae222a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt @@ -0,0 +1,6 @@ +interface IFoo + +typealias Test = IFoo + +val testAsFunction = Test() +val testAsValue = Test \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjection.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjection.fir.kt new file mode 100644 index 00000000000..b708007b8f7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjection.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class C + +typealias CStar = C<*> +typealias CIn = C +typealias COut = C +typealias CT = C + +val test1 = CStar() +val test2 = CIn() +val test3 = COut() +val test4 = CT<*>() +val test5 = CT>() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjectionInSupertypes.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjectionInSupertypes.fir.kt new file mode 100644 index 00000000000..4db0b2a98f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForProjectionInSupertypes.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +open class C + +typealias CStar = C<*> +typealias CIn = C +typealias COut = C +typealias CT = C + +class Test1 : CStar() +class Test2 : CIn() +class Test3 : COut() + +class Test4 : CStar { + constructor() : super() +} + +class Test5 : CT<*>() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInSuperCall.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInSuperCall.fir.kt new file mode 100644 index 00000000000..71c53d03a77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInSuperCall.fir.kt @@ -0,0 +1,14 @@ +open class MyBase protected constructor() { + protected constructor(x: Nothing?): this() +} +typealias MyAlias = MyBase + +class MyDerived1 : MyAlias() +class MyDerived1a : MyBase() + +class MyDerived2 : MyAlias(null) +class MyDerived2a : MyBase(null) + +class MyDerived3 : MyAlias { + constructor(x: Nothing?) : super(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInferenceInSupertypesList.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInferenceInSupertypesList.fir.kt new file mode 100644 index 00000000000..a2653eecef4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorInferenceInSupertypesList.fir.kt @@ -0,0 +1,7 @@ +open class Ref(var x: T) + +typealias R = Ref + +// Type inference SHOULD NOT work for type alias constructor in supertypes list +class Test1 : R(0) +class Test2 : R(0) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorReturnType.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorReturnType.fir.kt new file mode 100644 index 00000000000..e6a4d0eae5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorReturnType.fir.kt @@ -0,0 +1,18 @@ +class Cell(val x : T) +class Pair(val x1: T1, val x2: T2) + +typealias CIntA = Cell +typealias CA = Cell +typealias PIntIntA = Pair +typealias PA = Pair +typealias P2A = Pair + +val test1 = CIntA(10) +val test2 = CA(10) +val test3 = CA(10) +val test4 = PIntIntA(10, 20) +val test5 = PA(10, 20) +val test6 = PA(10, 20) +val test7 = P2A(10, 20) +val test8 = P2A(10, 20) + diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt new file mode 100644 index 00000000000..ce8525c055c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.fir.kt @@ -0,0 +1,33 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Num(val x: Tn) +typealias N = Num + +val test0 = N(1) +val test1 = N("1") + + +class Cons(val head: T, val tail: Cons?) +typealias C = Cons +typealias CC = C> + +val test2 = C(1, 2) +val test3 = CC(1, 2) +val test4 = CC(C(1, null), null) + + +class Pair(val x: X, val y: Y) +typealias PL = Pair> +typealias PN = Pair> + +val test5 = PL(1, null) + + +class Foo(val p: Pair) +typealias F = Foo + +fun testProjections1(x: Pair) = F(x) +fun testProjections2(x: Pair) = F(x) +fun testProjections3(x: Pair) = F(x) +fun testProjections4(x: Pair) = F(x) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.fir.kt new file mode 100644 index 00000000000..7f8a87e86f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Cons(val head: T, val tail: Cons?) +typealias C = Cons + +val test1 = C(1, C(2, null)) +val test2 = C(1, C("", null)) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls2.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls2.fir.kt new file mode 100644 index 00000000000..52045873554 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls2.fir.kt @@ -0,0 +1,41 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +interface Ref { + var x: T +} + +class LateInitNumRef() : Ref { + constructor(x: NN) : this() { this.x = x } + + private var xx: NN? = null + + override var x: NN + get() = xx!! + set(value) { + xx = value + } +} + +typealias LateNR = LateInitNumRef + +fun > update(r: R, v: V): R { + r.x = v + return r +} + +val r1 = update(LateInitNumRef(), 1) +val r1a = update(LateNR(), 1) +val r2 = update(LateInitNumRef(1), 1) +val r2a = update(LateNR(1), 1) +val r3 = LateInitNumRef(1) +val r3a = LateNR(1) + +fun test() { + r1.x = r1.x + r1a.x = r1a.x + r2.x = r2.x + r2a.x = r2a.x + r3.x = r3.x + r3a.x = r3a.x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithPhantomTypes.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithPhantomTypes.fir.kt new file mode 100644 index 00000000000..b49ee36fb07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithPhantomTypes.fir.kt @@ -0,0 +1,17 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Foo +class Bar + +class Hr(val a: A, val b: B) + +typealias Test = Hr, Bar> + +val test1 = Test(1, "") +val test2 = Test(1, 2) + + +typealias Bas = Hr, Bar> + +val test3 = Bas(1, 1) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorVsFunction.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorVsFunction.fir.kt new file mode 100644 index 00000000000..f4b3547a87d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorVsFunction.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !CHECK_TYPE +// FILE: a.kt +class B(x: String) + +typealias A1 = B +private typealias A2 = B +private typealias A3 = B + +fun A3(x: Any) = "OK" + +fun bar() { + A3("") checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt new file mode 100644 index 00000000000..554340134b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +abstract class AbstractClass +typealias Test1 = AbstractClass +val test1 = Test1() +val test1a = AbstractClass() + +annotation class AnnotationClass +typealias Test2 = AnnotationClass +val test2 = Test2() +val test2a = AnnotationClass() + +enum class EnumClass { VALUE1, VALUE2 } +typealias Test3 = EnumClass +val test3 = Test3() +val test3a = EnumClass() + +sealed class SealedClass +typealias Test4 = SealedClass +val test4 = Test4() +val test4a = SealedClass() + +class Outer { + inner class Inner + typealias TestInner = Inner +} +typealias Test5 = Outer.Inner + +val test5 = Test5() +val test5a = Outer.Inner() +val test5b = Outer.TestInner() +val test5c = Outer().TestInner() +val test5d = Outer().Inner() +val test5e = Outer().Test5() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongVisibility.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongVisibility.fir.kt new file mode 100644 index 00000000000..0fdf9492549 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongVisibility.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +open class MyClass private constructor(val x: Int) { + + protected constructor(x: String) : this(x.length) + + constructor(x: Double) : this(x.toInt()) +} + +typealias MyAlias = MyClass + +val test1 = MyAlias(1) +val test1a = MyClass(1) + +val test2 = MyAlias("") +val test2a = MyClass("") + +val test3 = MyAlias(1.0) +val test3a = MyClass(1.0) + +class MyDerived : MyClass(1.0) { + val test4 = MyAlias(1) + val test4a = MyClass(1) + val test5 = MyAlias("") + val test5a = MyClass("") + val test6 = MyAlias(1.0) + val test6a = MyClass(1.0) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasExpansionRepeatedAnnotations.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasExpansionRepeatedAnnotations.fir.kt new file mode 100644 index 00000000000..faeac4d3906 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasExpansionRepeatedAnnotations.fir.kt @@ -0,0 +1,16 @@ +@Target(AnnotationTarget.TYPE) +annotation class A + +typealias AInt = @A Int +typealias AI = AInt + +typealias Test1 = @A AInt +typealias Test2 = @A AI +typealias Test3 = List<@A AInt> +typealias Test4 = List<@A AI> + +val testProperty1: @A AInt = 0 +val testProperty2: @A AI = 0 + +fun testFunction1(x: @A AInt): @A AInt = x +fun testFunction2(x: @A AI): @A AI = x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasForProjectionInSuperInterfaces.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasForProjectionInSuperInterfaces.fir.kt new file mode 100644 index 00000000000..34d52277449 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasForProjectionInSuperInterfaces.fir.kt @@ -0,0 +1,32 @@ +interface Inv +interface Out +interface In + +typealias InvStar = Inv<*> +typealias InvIn = Inv +typealias InvOut = Inv +typealias InvT = Inv + +typealias OutStar = Out<*> +typealias OutOut = Out +typealias OutT = Out + +typealias InStar = In<*> +typealias InIn = In +typealias InT = In + +class Test1 : InvStar +class Test2 : InvIn +class Test3 : InvOut +class Test4 : InvT<*> +class Test5 : InvT> + +class Test6 : OutStar +class Test7 : OutOut +class Test8 : OutT +class Test9 : OutT + +class Test10 : InStar +class Test11 : InIn +class Test12 : InT +class Test13 : InT \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasInAnonymousObjectType.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasInAnonymousObjectType.fir.kt new file mode 100644 index 00000000000..7567522a5b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasInAnonymousObjectType.fir.kt @@ -0,0 +1,5 @@ +open class Foo + +typealias FooStr = Foo + +val test = object : FooStr() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.fir.kt new file mode 100644 index 00000000000..d11df54d662 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.fir.kt @@ -0,0 +1,8 @@ +class C { + private companion object +} + +typealias CAlias = C + +val test1 = CAlias +val test1a = C \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.fir.kt new file mode 100644 index 00000000000..285064d139a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.fir.kt @@ -0,0 +1,6 @@ +typealias Processor = (number: Int) -> Unit +typealias Handler = (String) -> Processor? + +fun x(handler: Handler) { + return handler("a")!!(1) +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObject.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasObject.fir.kt new file mode 100644 index 00000000000..72e1b26402f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasObject.fir.kt @@ -0,0 +1,32 @@ +object AnObject { + val ok = "OK" + fun foo() = "OK" +} + +typealias TestObject = AnObject + +val test11: AnObject = TestObject +val test12: TestObject = TestObject +val test13: String = TestObject.ok +val test14: String = TestObject.foo() + +typealias TestObject2 = TestObject + +val test21: AnObject = TestObject2 +val test22: TestObject2 = TestObject2 +val test23: String = TestObject2.ok +val test24: String = TestObject2.foo() + +class ClassWithCompanion { + companion object { + val ok = "OK" + fun foo() = "OK" + } +} + +typealias TestCWC = ClassWithCompanion + +val test35: ClassWithCompanion.Companion = TestCWC +val test36 = TestCWC +val test37: String = TestCWC.ok +val test38: String = TestCWC.foo() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt new file mode 100644 index 00000000000..958b5f28c16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.fir.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +object ObjectWithInvoke { + operator fun invoke() = this +} + +class ClassWithCompanionObjectWithInvoke { + companion object { + operator fun invoke(x: Any) = x + } +} + +typealias WI = ObjectWithInvoke + +typealias CWI = ClassWithCompanionObjectWithInvoke + +val test1 = WI() +val test2 = WI(null) + +val test3 = CWI() +val test4 = CWI("") +val test5 = CWI(null) +val test5a = ClassWithCompanionObjectWithInvoke(null) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.fir.kt new file mode 100644 index 00000000000..ba72e03fbe7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + +typealias ToTypeParam1 = T +typealias ToTypeParam2 = ToTypeParam1 +typealias ToTypeParam3 = ToTypeParam2 +typealias ToTypeParam4 = ToTypeParam1 + +typealias ToFun1 = () -> Unit +typealias ToFun2 = (T) -> Unit + +class Outer { + typealias ToTypeParam1 = T + typealias ToTypeParam2 = ToTypeParam1 + typealias ToTypeParam3 = ToTypeParam2 + typealias ToTypeParam4 = ToTypeParam1 +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasesInImportDirectives.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasesInImportDirectives.fir.kt new file mode 100644 index 00000000000..d2d21ee4dda --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasesInImportDirectives.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: foo.kt + +package test + +typealias ClassAlias = ClassSample +typealias ObjectAlias = ObjectSample +typealias EnumAlias = EnumSample + +class ClassSample { + class Nested1 +} + +object ObjectSample { + class Nested2 +} + +enum class EnumSample { + Entry; + + class Nested3 +} + +// FILE: test.kt + +import test.ClassAlias +import test.ClassAlias.Nested1 + +import test.ClassSample.Nested1.* +import test.ClassAlias.Nested1.* + +import test.ObjectAlias +import test.ObjectAlias.Nested2 + +import test.ObjectSample.Nested2.* +import test.ObjectAlias.Nested2.* + +import test.EnumAlias +import test.EnumAlias.Nested3 + +import test.EnumSample.Nested3.* +import test.EnumAlias.Nested3.* + +import test.EnumAlias.Entry + +fun f() {} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasesInQualifiers.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasesInQualifiers.fir.kt new file mode 100644 index 00000000000..5132f4a66f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasesInQualifiers.fir.kt @@ -0,0 +1,75 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +// FILE: foo.kt + +package test + +typealias ClassAlias = ClassSample +typealias ObjectAlias = ObjectSample +typealias EnumAlias = EnumSample + +class ClassSample { + class Nested { + fun func() {} + } + + fun func() {} +} + +object ObjectSample { + class Nested { + fun func() {} + } + + fun func() {} +} + +enum class EnumSample { + Entry; + + class Nested { + fun func() {} + } + + fun func() {} +} + +// FILE: test.kt + +fun foo( + a0: test.ClassSample.Nested, + a1: test.ClassAlias.Nested, + + b0: test.ObjectSample.Nested, + b1: test.ObjectAlias.Nested, + + c0: test.EnumSample.Nested, + c1: test.EnumAlias.Nested +) { + test.ClassSample::Nested + test.ClassAlias::Nested + + test.ClassSample::func + test.ClassAlias::func + + test.ClassSample.Nested::func + test.ClassAlias.Nested::func + + test.ObjectSample::Nested + test.ObjectAlias::Nested + + test.ObjectSample::func + test.ObjectAlias::func + + test.ObjectSample.Nested::func + test.ObjectAlias.Nested::func + + test.EnumSample::Nested + test.EnumAlias::Nested + + test.EnumSample::func + test.EnumAlias::func + + test.EnumSample.Nested::func + test.EnumAlias.Nested::func +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotations.fir.kt b/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotations.fir.kt new file mode 100644 index 00000000000..5d30894a70d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotations.fir.kt @@ -0,0 +1,16 @@ +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +typealias Alias1 = @Ann1 String +typealias Alias2 = @Ann2 Alias1 +fun test1(a: Alias2) = a + +// NB @ExtensionFunctionType on non-functional type is not an error +typealias Alias3 = @ExtensionFunctionType Alias1 +fun test2(a: Alias3) = a + +typealias LA1 = List<@Ann2 Alias1> +fun test3(la1: LA1) = la1 diff --git a/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotationsInArguments.fir.kt b/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotationsInArguments.fir.kt new file mode 100644 index 00000000000..1f635bb621a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typealiasRhsAnnotationsInArguments.fir.kt @@ -0,0 +1,11 @@ +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +class C + +typealias CA = C<@Ann1 T> + +fun test(x: CA<@Ann2 Int>) = x \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotationInArguments.fir.kt b/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotationInArguments.fir.kt new file mode 100644 index 00000000000..5936c10fb09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotationInArguments.fir.kt @@ -0,0 +1,6 @@ +@Target(AnnotationTarget.TYPE) +annotation class A + +typealias Gen = List<@A T> + +typealias Test1 = Gen<@A Int> diff --git a/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotations.fir.kt b/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotations.fir.kt new file mode 100644 index 00000000000..0d7b4dc99b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typealiasRhsRepeatedAnnotations.fir.kt @@ -0,0 +1,4 @@ +@Target(AnnotationTarget.TYPE) +annotation class A + +typealias Test1 = @A @A Int diff --git a/compiler/testData/diagnostics/tests/typealias/unsupportedTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/unsupportedTypeAlias.fir.kt new file mode 100644 index 00000000000..c5f2135351d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/unsupportedTypeAlias.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: -TypeAliases + +class C + +typealias S = String +typealias L = List +typealias CA = C +typealias Unused = Any + +val test1: S = "" + +fun test2(x: L) = x + +class Test3 : CA() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/unusedTypeAliasParameter.fir.kt b/compiler/testData/diagnostics/tests/typealias/unusedTypeAliasParameter.fir.kt new file mode 100644 index 00000000000..ae5caa6933a --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/unusedTypeAliasParameter.fir.kt @@ -0,0 +1,2 @@ +typealias Test = List +typealias Test2 = Test diff --git a/compiler/testData/diagnostics/tests/typealias/wrongNumberOfArgumentsInTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/wrongNumberOfArgumentsInTypeAliasConstructor.fir.kt new file mode 100644 index 00000000000..4a15293d85c --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/wrongNumberOfArgumentsInTypeAliasConstructor.fir.kt @@ -0,0 +1,42 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +class Pair(val x1: T1, val x2: T2) + +typealias P = Pair + +typealias P2 = Pair + +typealias PR = Pair + +val test0 = P(1, 2) +val test1 = P(1, 2) +val test2 = P(1, 2) +val test3 = P(1, 2) + +val test0p2 = P2(1, 1) +val test0p2a = P2(1, "") +val test1p2 = P2(1, 1) +val test2p2 = P2(1, 1) +val test3p2 = P2(1, 1) + +val test0pr = PR(1, "") +val test1pr = PR(1, "") +val test2pr = PR(1, "") +val test2pra = PR(1, "") +val test3pr = P2(1, "") + +class Num(val x: T) +typealias N = Num + +val testN0 = N("") +val testN1 = N(1) +val testN1a = N("") +val testN2 = N(1) + +class MyPair(val string: T1, val number: T2) +typealias MP = MyPair + +val testMP0 = MP("", 1) +val testMP1 = MP(1, "") +val testMP2 = MP("", "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/illegalUnderscores.fir.kt b/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/illegalUnderscores.fir.kt new file mode 100644 index 00000000000..1833301d78a --- /dev/null +++ b/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/illegalUnderscores.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun foo() { + 1_ + 0x_f + 0X_f + 0b_1 + 0B_1 + 1.0_ + 1_.1 + 1.0_e1 + 1.0E_1 + 0Xe_ + 1.1_e-1_23 + 1.0e+_0 + 1.0e-_0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/noUnderscores.fir.kt b/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/noUnderscores.fir.kt new file mode 100644 index 00000000000..2de40181060 --- /dev/null +++ b/compiler/testData/diagnostics/tests/underscoresInNumericLiterals/noUnderscores.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -UnderscoresInNumericLiterals +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +fun foo() { + 100_1 + 3_.1 + 2___4 + 123_ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/unit/nullableUnit.fir.kt b/compiler/testData/diagnostics/tests/unit/nullableUnit.fir.kt new file mode 100644 index 00000000000..42d2f77036a --- /dev/null +++ b/compiler/testData/diagnostics/tests/unit/nullableUnit.fir.kt @@ -0,0 +1,5 @@ +fun foo() {} + +val x: Unit? = when ("A") { + "B" -> foo() +} diff --git a/compiler/testData/diagnostics/tests/unproperDefaultInitializationInTailrec.fir.kt b/compiler/testData/diagnostics/tests/unproperDefaultInitializationInTailrec.fir.kt new file mode 100644 index 00000000000..19d2b6eeffa --- /dev/null +++ b/compiler/testData/diagnostics/tests/unproperDefaultInitializationInTailrec.fir.kt @@ -0,0 +1,39 @@ +//!LANGUAGE: -ProperComputationOrderOfTailrecDefaultParameters + +import kotlin.reflect.KClass + +fun withEffects(): String = "OK" + +const val Z = "123" + +enum class EnumA { + A +} + +tailrec fun foo(i: Int = 1, c: Char = '2', s: String = "1234", b: Boolean = true, d: Double = 1.0, l: Long = 1L, y: String = withEffects()) { + foo(i, c, s, b, d, l, y) +} + +tailrec fun foo2(x: Int = 1, y: String = withEffects(), z: String = Z) { + foo2(x, y, z) +} + +tailrec fun foo3(y: String = withEffects()) { + foo3(y) +} + +tailrec fun foo4(x: String = withEffects(), y: String = withEffects()) { + foo4(x, y) +} + +tailrec fun foo5(x: String = withEffects(), y: String = withEffects(), z: String = withEffects()) { + foo5(x, y, z) +} + +tailrec fun foo6(x: String = withEffects(), y: EnumA = EnumA.A) { + foo6(x, y) +} + +tailrec fun foo7(x: String = withEffects(), y: KClass = EnumA.A::class) { + foo7(x, y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/AmbiguousVararg.fir.kt b/compiler/testData/diagnostics/tests/varargs/AmbiguousVararg.fir.kt new file mode 100644 index 00000000000..9bd9ae98207 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/AmbiguousVararg.fir.kt @@ -0,0 +1,6 @@ +fun foo(vararg t : String) = "" +fun foo(vararg t : Int) = "" + +fun test() { + foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/MoreSpecificVarargsOfEqualLength.fir.kt b/compiler/testData/diagnostics/tests/varargs/MoreSpecificVarargsOfEqualLength.fir.kt new file mode 100644 index 00000000000..d820de2c83f --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/MoreSpecificVarargsOfEqualLength.fir.kt @@ -0,0 +1,9 @@ +fun main(d : D) { + d.from("") + d.from(1) +} + +class D { + fun from(vararg a : Any){} + fun from(vararg a : String){} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/MostSepcificVarargsWithJava.fir.kt b/compiler/testData/diagnostics/tests/varargs/MostSepcificVarargsWithJava.fir.kt new file mode 100644 index 00000000000..dfb55e3a99f --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/MostSepcificVarargsWithJava.fir.kt @@ -0,0 +1,19 @@ +// FILE: kotlin.kt +fun main(j : C, s : Array) { + j.from() + j.from("") + j.from("", "") + j.from("", "", "") + + j.from("", *s) // This should not be an ambiguity, see KT-1842 + j.from(*s) +} + +// FILE: C.java +public class C { + void from() {} + void from(String s) {} + void from(String s, String s1) {} + void from(String... s) {} + void from(String s1, String... s) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/NilaryVsVararg.fir.kt b/compiler/testData/diagnostics/tests/varargs/NilaryVsVararg.fir.kt new file mode 100644 index 00000000000..15e7efdc923 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/NilaryVsVararg.fir.kt @@ -0,0 +1,10 @@ +fun foo0() : String = "noarg" + +fun foo0(vararg t : Int) : String = "vararg" + +fun test0() { + foo0() + foo0(1) + val a = IntArray(0) + foo0(*a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.fir.kt b/compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.fir.kt new file mode 100644 index 00000000000..458239df8a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.fir.kt @@ -0,0 +1,66 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS:-UNUSED_PARAMETER + +// KT-9883 prohibit using spread operator for nullable value + +// FILE: A.java + +public class A { + public void foo(int x, String ... args) {} + public static String[] ar; +} + +// FILE: J.java + +public class J { + public interface Invoke { + void invoke(String ...args); + } + + public static Invoke staticFun; +} + +// FILE: 1.kt +val args: Array? = null + +fun bar(x: Int, vararg s: String) {} + +fun baz(s: String) {} + +fun getArr(): Array? = null + +fun f() { + A().foo(1, *args) + bar(2, *args) + baz(*args) +} + +fun g(args: Array?) { + + if (args != null) { + A().foo(1, *args) + } + A().foo(1, *A.ar) +} + +class B { + var args: Array? = null +} + +fun h(b: B) { + if (b.args != null) { + A().foo(1, *b.args) + } +} + +fun k() { + A().foo(1, *getArr()) + bar(2, *getArr()) + baz(*getArr()) +} + +fun invokeTest(goodArgs: Array) { + J.staticFun(*goodArgs) + J.staticFun(*args) + J.staticFun(*args ?: null) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/UnaryVsVararg.fir.kt b/compiler/testData/diagnostics/tests/varargs/UnaryVsVararg.fir.kt new file mode 100644 index 00000000000..015513edea1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/UnaryVsVararg.fir.kt @@ -0,0 +1,9 @@ +fun foo1(a : Int) : String = "noarg" + +fun foo1(a : Int, vararg t : Int) : String = "vararg" + +fun test1() { + foo1(1) + val a = IntArray(0) + foo1(1, *a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotation.fir.kt new file mode 100644 index 00000000000..fe68f83f245 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotation.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: -ProhibitNonConstValuesAsVarargsInAnnotations, -ProhibitAssigningSingleElementsToVarargsInNamedForm + +val nonConstArray = longArrayOf(0) +fun nonConstFun(): LongArray = TODO() + +fun nonConstLong(): Long = TODO() + +annotation class Anno(vararg val value: Long) + +@Anno(value = nonConstArray) +fun foo1() {} + +@Anno(value = nonConstFun()) +fun foo2() {} + +@Anno(value = longArrayOf(nonConstLong())) +fun foo3() {} + +@Anno(value = [nonConstLong()]) +fun foo4() {} + +@Anno(value = *nonConstArray) +fun bar1() {} + +@Anno(*nonConstArray) +fun bar2() {} diff --git a/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotationError.fir.kt b/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotationError.fir.kt new file mode 100644 index 00000000000..0fde992f5d8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assignNonConstSingleArrayElementAsVarargInAnnotationError.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +ProhibitNonConstValuesAsVarargsInAnnotations, +ProhibitAssigningSingleElementsToVarargsInNamedForm + +val nonConstArray = longArrayOf(0) +fun nonConstFun(): LongArray = TODO() + +fun nonConstLong(): Long = TODO() + +annotation class Anno(vararg val value: Long) + +@Anno(value = nonConstArray) +fun foo1() {} + +@Anno(value = nonConstFun()) +fun foo2() {} + +@Anno(value = longArrayOf(nonConstLong())) +fun foo3() {} + +@Anno(value = [nonConstLong()]) +fun foo4() {} + +@Anno(value = *nonConstArray) +fun bar1() {} + +@Anno(*nonConstArray) +fun bar2() {} diff --git a/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.fir.kt b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.fir.kt new file mode 100644 index 00000000000..115ec1bc83e --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.fir.kt @@ -0,0 +1,46 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations, +AssigningArraysToVarargsInNamedFormInAnnotations + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = arrayOf()) +fun test1() {} + +@Ann(s = intArrayOf()) +fun test2() {} + +@Ann(s = arrayOf(1)) +fun test3() {} + +@Ann("value1", "value2") +fun test4() {} + +@Ann(s = ["value"]) +fun test5() {} + +@JavaAnn(value = arrayOf("value")) +fun jTest1() {} + +@JavaAnn(value = ["value"]) +fun jTest2() {} + +@JavaAnn(value = ["value"], path = ["path"]) +fun jTest3() {} + + +annotation class IntAnn(vararg val i: Int) + +@IntAnn(i = [1, 2]) +fun foo1() {} + +@IntAnn(i = intArrayOf(0)) +fun foo2() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_after.fir.kt b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_after.fir.kt new file mode 100644 index 00000000000..80eef870bb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_after.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations, +AssigningArraysToVarargsInNamedFormInAnnotations, +ProhibitAssigningSingleElementsToVarargsInNamedForm + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = "value") +fun test1() {} + +@Ann(s = *arrayOf("value")) +fun test2() {} + +@Ann(s = *["value"]) +fun test3() {} + +@JavaAnn(value = "value") +fun test4() {} + +@JavaAnn("value", path = arrayOf("path")) +fun test5() {} + +@JavaAnn("value", path = ["path"]) +fun test6() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_before.fir.kt b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_before.fir.kt new file mode 100644 index 00000000000..b08c422c1cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation_before.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations, +AssigningArraysToVarargsInNamedFormInAnnotations, -ProhibitAssigningSingleElementsToVarargsInNamedForm + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = "value") +fun test1() {} + +@Ann(s = *arrayOf("value")) +fun test2() {} + +@Ann(s = *["value"]) +fun test3() {} + +@JavaAnn(value = "value") +fun test4() {} + +@JavaAnn("value", path = arrayOf("path")) +fun test5() {} + +@JavaAnn("value", path = ["path"]) +fun test6() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_after.fir.kt b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_after.fir.kt new file mode 100644 index 00000000000..d81b18def58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_after.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AssigningArraysToVarargsInNamedFormInAnnotations, +ProhibitAssigningSingleElementsToVarargsInNamedForm +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +fun foo(vararg s: Int) {} + +open class Cls(vararg p: Long) + +fun test(i: IntArray) { + foo(s = 1) + foo(s = i) + foo(s = *i) + foo(s = intArrayOf(1)) + foo(s = *intArrayOf(1)) + foo(1) + + Cls(p = 1) + + class Sub : Cls(p = 1) + + val c = object : Cls(p = 1) {} + + foo(s = *intArrayOf(elements = 1)) +} + + +fun anyFoo(vararg a: Any) {} + +fun testAny() { + anyFoo(a = "") + anyFoo(a = arrayOf("")) + anyFoo(a = *arrayOf("")) +} + +fun genFoo(vararg t: T) {} + +fun testGen() { + genFoo(t = 1) + genFoo(t = null) + genFoo>(t = arrayOf()) + genFoo>(t = *arrayOf(arrayOf())) + + genFoo(t = "") + genFoo(t = arrayOf("")) + genFoo(t = *arrayOf("")) +} + +fun manyFoo(vararg v: Int) {} +fun manyFoo(vararg s: String) {} + +fun testMany(a: Any) { + manyFoo(v = 1) + manyFoo(s = "") + + manyFoo(a) + manyFoo(v = a) + manyFoo(s = a) + manyFoo(v = a as Int) + manyFoo(s = a as String) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_before.fir.kt b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_before.fir.kt new file mode 100644 index 00000000000..0ece7246cc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation_before.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AssigningArraysToVarargsInNamedFormInAnnotations, -ProhibitAssigningSingleElementsToVarargsInNamedForm +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +fun foo(vararg s: Int) {} + +open class Cls(vararg p: Long) + +fun test(i: IntArray) { + foo(s = 1) + foo(s = i) + foo(s = *i) + foo(s = intArrayOf(1)) + foo(s = *intArrayOf(1)) + foo(1) + + Cls(p = 1) + + class Sub : Cls(p = 1) + + val c = object : Cls(p = 1) {} + + foo(s = *intArrayOf(elements = 1)) +} + + +fun anyFoo(vararg a: Any) {} + +fun testAny() { + anyFoo(a = "") + anyFoo(a = arrayOf("")) + anyFoo(a = *arrayOf("")) +} + +fun genFoo(vararg t: T) {} + +fun testGen() { + genFoo(t = 1) + genFoo(t = null) + genFoo>(t = arrayOf()) + genFoo>(t = *arrayOf(arrayOf())) + + genFoo(t = "") + genFoo(t = arrayOf("")) + genFoo(t = *arrayOf("")) +} + +fun manyFoo(vararg v: Int) {} +fun manyFoo(vararg s: String) {} + +fun testMany(a: Any) { + manyFoo(v = 1) + manyFoo(s = "") + + manyFoo(a) + manyFoo(v = a) + manyFoo(s = a) + manyFoo(v = a as Int) + manyFoo(s = a as String) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/kt1781.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt1781.fir.kt new file mode 100644 index 00000000000..f34215e5342 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt1781.fir.kt @@ -0,0 +1,13 @@ +// FILE: kotlin.kt +fun foo() { + JavaClass() + JavaClass("") +} + +// FILE: JavaClass.java + +public class JavaClass { + public JavaClass() { } + + public JavaClass(String... ss) { } +} diff --git a/compiler/testData/diagnostics/tests/varargs/kt1835.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt1835.fir.kt new file mode 100644 index 00000000000..f55f90935aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt1835.fir.kt @@ -0,0 +1,12 @@ +// FILE: JavaClass.java +public class JavaClass { + void from(String s) {} + void from(String... s) {} +} + +// FILE: kotlin.kt +fun main() { + JavaClass().from() + JavaClass().from("") + JavaClass().from("", "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/kt1838-param.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt1838-param.fir.kt new file mode 100644 index 00000000000..a6ab5e1ea02 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt1838-param.fir.kt @@ -0,0 +1,5 @@ +class A(vararg t : Int) { + init { + val t1 : IntArray = t + } +} diff --git a/compiler/testData/diagnostics/tests/varargs/kt1838-val.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt1838-val.fir.kt new file mode 100644 index 00000000000..c63bf7396d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt1838-val.fir.kt @@ -0,0 +1,5 @@ +class A(vararg val t : Int) { + init { + val t1 : IntArray = t + } +} diff --git a/compiler/testData/diagnostics/tests/varargs/kt2163.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt2163.fir.kt new file mode 100644 index 00000000000..79ea4dc8fb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt2163.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun printAll(vararg a : Any) {} + +fun main(args: Array) { + printAll(*args) // Shouldn't be an error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/kt422.fir.kt b/compiler/testData/diagnostics/tests/varargs/kt422.fir.kt new file mode 100644 index 00000000000..fa5791cae47 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/kt422.fir.kt @@ -0,0 +1,17 @@ +// KT-422 Tune literal typing rules so that varargs overloaded by primitive types work + +fun foo(vararg t : T) = t +fun foo(vararg a: Int) = a +fun foo(vararg a: Long) = a + +fun test() { + foo(1, 2, 3) // Error, but should be foo of ints +} + +fun array(vararg elements : T) = elements +fun array(vararg elements : Int) = elements + +fun test1() { + array("A", "A") + array(1, 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.fir.kt b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.fir.kt new file mode 100644 index 00000000000..966f4dde6ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.fir.kt @@ -0,0 +1,49 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +ArrayLiteralsInAnnotations, -AssigningArraysToVarargsInNamedFormInAnnotations + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = arrayOf()) +fun test1() {} + +@Ann(s = intArrayOf()) +fun test2() {} + +@Ann(s = arrayOf(1)) +fun test3() {} + +@Ann(s = ["value"]) +fun test5() {} + +@JavaAnn(value = arrayOf("value")) +fun jTest1() {} + +@JavaAnn(value = ["value"]) +fun jTest2() {} + +@JavaAnn(value = ["value"], path = ["path"]) +fun jTest3() {} + +annotation class IntAnn(vararg val i: Int) + +@IntAnn(i = [1, 2]) +fun foo1() {} + +@IntAnn(i = intArrayOf(0)) +fun foo2() {} + +fun foo(vararg i: Int) {} + +@Ann(s = "value") +fun dep1() { + foo(i = 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/prohibitAssigningSingleElementsInNamedForm.fir.kt b/compiler/testData/diagnostics/tests/varargs/prohibitAssigningSingleElementsInNamedForm.fir.kt new file mode 100644 index 00000000000..d186912901c --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/prohibitAssigningSingleElementsInNamedForm.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ProhibitAssigningSingleElementsToVarargsInNamedForm +// !DIAGNOSTICS: -UNUSED_PARAMETER + +annotation class Anno1(vararg val s: String) +annotation class Anno2(vararg val i: Int) + +@Anno1(s = "foo") +@Anno2(i = *intArrayOf(1)) +fun f1() {} + +@Anno1(s = ["foo"]) +@Anno2(i = intArrayOf(1)) +fun f2() {} + +fun foo(vararg ints: Int) {} + +fun test() { + foo(ints = 1) + foo(ints = *intArrayOf(1)) +} diff --git a/compiler/testData/diagnostics/tests/varargs/varargInSetter.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargInSetter.fir.kt new file mode 100644 index 00000000000..2a9b2059798 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargInSetter.fir.kt @@ -0,0 +1,6 @@ +class My { + var x: String = "" + set(vararg value) { + x = value + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/varargIterator.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargIterator.fir.kt new file mode 100644 index 00000000000..b1f1dbcc919 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargIterator.fir.kt @@ -0,0 +1,5 @@ +package test + +class CompositeIterator(vararg iterators: java.util.Iterator){ + val iteratorsIter = iterators.iterator() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/varargOfNothing.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargOfNothing.fir.kt new file mode 100644 index 00000000000..36da02c3fb3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargOfNothing.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun testVarargOfNothing(vararg v: Nothing) {} + +fun testVarargOfNNothing(vararg v: Nothing?) {} + +fun testVarargOfT(vararg v: T) {} + +fun outer() { + fun testVarargOfNothing(vararg v: Nothing) {} + + fun testVarargOfNNothing(vararg v: Nothing?) {} + + fun testVarargOfT(vararg v: T) {} +} diff --git a/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt new file mode 100644 index 00000000000..56f505de853 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun stringVararg(vararg args: String) {} +fun intVararg(vararg args: Int) {} +fun numberVararg(vararg args: Number) {} + +fun useStrings(fn: (String, String, String) -> Unit) = fn("foo", "bar", "boo") +fun useStringArray(fn: (Array) -> Unit) = fn(arrayOf("foo", "bar", "boo")) + +fun useIntArray(fn: (Array) -> Unit) = fn(arrayOf(1, 2, 3)) +fun usePrimitiveIntArray(fn: (IntArray) -> Unit) = fn(intArrayOf(4, 5, 6)) + +fun useMixedStringArgs1(fn: (String, Array) -> Unit) = fn("foo", arrayOf("bar", "baz")) +fun useMixedStringArgs2(fn: (Array, String) -> Unit) = fn(arrayOf("foo", "bar"), "baz") +fun useMixedStringArgs3(fn: (String, Array, String) -> Unit) = fn("foo", arrayOf("bar", "baz"), "boo") +fun useTwoStringArrays(fn: (Array, Array) -> Unit) = fn(arrayOf("foo", "bar"), arrayOf("baz", "boo")) + +fun test() { + useStrings(::stringVararg) + useStringArray(::stringVararg) + useIntArray(::numberVararg) + usePrimitiveIntArray(::intVararg) + useIntArray(::intVararg) + useMixedStringArgs1(::stringVararg) + useMixedStringArgs2(::stringVararg) + useMixedStringArgs3(::stringVararg) + useTwoStringArrays(::stringVararg) +} diff --git a/compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.fir.kt new file mode 100644 index 00000000000..7771bfe988e --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.fir.kt @@ -0,0 +1,13 @@ +fun f(vararg t : Int, f : ()->Unit) { +} + +fun test() { + f {} + f() {} + f(1) { + + } + f(1, 2) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/varargsAndOut1.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargsAndOut1.fir.kt new file mode 100644 index 00000000000..04f8ff3f045 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargsAndOut1.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +fun test(vararg a: String) { + a checkType { _>() } + + foo(a) checkType { _>() } +} + +fun test1(vararg t: T) { + t checkType { _>() } +} + +fun foo(a: Array): Array = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/varargsAndOut2.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargsAndOut2.fir.kt new file mode 100644 index 00000000000..ed2a429bbf9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargsAndOut2.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun bar(vararg a: String) {} + +fun test2(a: Array, b: Array) { + bar(*a) + bar(*b) + bar("", *a, *b, "") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/varargsAndPair.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargsAndPair.fir.kt new file mode 100644 index 00000000000..cc2a581ceb8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/varargsAndPair.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +fun foo(vararg ts: T): T? = null + +class Pair(a: A) + +fun test() { + val v = foo(Pair(1)) + checkSubtype(v) // check that it is not error type +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/Class.fir.kt b/compiler/testData/diagnostics/tests/variance/Class.fir.kt new file mode 100644 index 00000000000..3993b556f6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/Class.fir.kt @@ -0,0 +1,23 @@ +interface In +interface Out +interface Inv + +interface TypeBounds1 +interface TypeBounds2 +interface TypeBounds3 +interface TypeBounds4> +interface TypeBounds5> + +interface WhereTypeBounds1 where X : I +interface WhereTypeBounds2 where X : O +interface WhereTypeBounds3 where X : P +interface WhereTypeBounds4 where X : In +interface WhereTypeBounds5 where X : In + +class SubClass1 : Out +class SubClass2 : Out +class SubClass3 : Out

+class SubClass4 : In +class SubClass5 : In +class SubClass6 : Inv +class SubClass7 : Inv \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/Function.fir.kt b/compiler/testData/diagnostics/tests/variance/Function.fir.kt new file mode 100644 index 00000000000..f405959daeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/Function.fir.kt @@ -0,0 +1,34 @@ +interface In +interface Out +interface Inv +fun getT(): T = null!! + +interface Test { + fun parameters1(i: I, o: O, p: P) + fun parameters2(i: In) + fun parameters3(i: In) + + fun explicitReturnType1() : I + fun explicitReturnType2() : O + fun explicitReturnType3() : P + fun explicitReturnType4() : In + fun explicitReturnType5() : In + + fun imlicitReturnType1() = getT() + fun imlicitReturnType2() = getT() + fun imlicitReturnType3() = getT

() + fun imlicitReturnType4() = getT>() + fun imlicitReturnType5() = getT>() + + fun I.receiver1() + fun O.receiver2() + fun P.receiver3() + fun In.receiver4() + fun In.receiver5() + + fun typeParameter1() + fun typeParameter2() + fun typeParameter3() + fun > typeParameter4() + fun > typeParameter5() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/FunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/variance/FunctionTypes.fir.kt new file mode 100644 index 00000000000..edb90a7f81a --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/FunctionTypes.fir.kt @@ -0,0 +1,12 @@ +interface In +fun getT(): T = null!! + +interface Test { + fun ok1(i: (O) -> I) : (I) -> O + fun ok2(i: (P) -> P) : (P) -> P + fun ok3(i: (In) -> In) = getT<(In) -> In>() + + fun neOk1(i: (I) -> O): (O) -> I + fun neOk2(i: (In) -> In) + fun neOk3() = getT<(In) -> In>() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/InPosition.fir.kt b/compiler/testData/diagnostics/tests/variance/InPosition.fir.kt new file mode 100644 index 00000000000..f1c532ff27c --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/InPosition.fir.kt @@ -0,0 +1,48 @@ +interface In +interface Out +interface Inv +interface Pair + +interface Test { + fun ok1(i: I) + fun ok2(i: In) + fun ok3(i: In>) + fun ok4(i: Inv

) + fun ok5(i: P) + fun ok6(i: Out) + fun ok7(i: Out>) + fun ok8(i: Out>) + fun ok9(i: Out>) + fun Ok10(i: I) + fun Ok11(i: In) + fun Ok12(i: In>) + fun Ok13(i: Out) + fun Ok14(i: Pair, I>) + fun Ok15(i: Inv) + + fun Ok20(i: Inv) + fun Ok21(i: Inv) + fun Ok22(i: Inv) + fun Ok23(i: Inv) + + fun neOk1(i: O) + fun neOk2(i: In) + fun neOk3(i: In>) + fun neOk4(i: Inv) + fun neOk5(i: Inv) + fun neOk6(i: In>) + fun neOk7(i: Pair, O>) + fun neOk8(i: Inv) + fun neOk9(i: In) + fun neOk10(i: Out) + + fun neOk11(i: Inv) + fun neOk12(i: Inv) + + fun neOk30(i: Pair) + fun neOk31(i: Pair) + fun neOk32(i: Inv) + fun neOk33(i: Inv<>) + fun neOk34(i: Inv) + fun neOk35(i: Inv) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/InvariantPosition.fir.kt b/compiler/testData/diagnostics/tests/variance/InvariantPosition.fir.kt new file mode 100644 index 00000000000..324b1c9f631 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/InvariantPosition.fir.kt @@ -0,0 +1,45 @@ +interface In +interface Out +interface Inv +interface Pair + +interface Test { + var ok1: Inv

+ var ok2: P + var ok3: Out> + var ok4: Pair, Out

> + var ok5: Inv + var ok6: Inv + var ok7: Inv + + var neOk1: O + var neOk2: In + var neOk3: In> + var neOk4: Inv + var neOk5: Inv + var neOk6: In> + var neOk7: Pair, O> + var neOk8: Inv + var neOk9: Inv + var neOk10: In + + var neOk11: I + var neOk12: In + var neOk13: In> + var neOk14: Out + var neOk15: Out> + var neOk16: Out> + var neOk17: Pair, I> + + var neOk20: Inv + var neOk21: Inv + var neOk22: Inv + var neOk23: Inv + + var neOk30: Pair + var neOk31: Pair + var neOk32: Inv + var neOk33: Inv<> + var neOk34: Inv + var neOk35: Inv +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/NullableTypes.fir.kt b/compiler/testData/diagnostics/tests/variance/NullableTypes.fir.kt new file mode 100644 index 00000000000..66626173ee0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/NullableTypes.fir.kt @@ -0,0 +1,16 @@ +interface In +interface Out +interface Inv

+fun getT(): T = null!! + + +interface Test { + fun ok1(i: I?) : O? + fun ok2(i: In?) : Out? + fun ok3(i: Inv) = getT>() + + fun neOk1(i: O?) : I? + fun neOk(i: Out?) : In? + fun neOk3(i: Inv) + fun neOk4() = getT?>() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/OutPosition.fir.kt b/compiler/testData/diagnostics/tests/variance/OutPosition.fir.kt new file mode 100644 index 00000000000..287332912c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/OutPosition.fir.kt @@ -0,0 +1,40 @@ +interface In +interface Out +interface Inv +interface Pair + +interface Test { + fun ok1(): O + fun ok2(): In + fun ok3(): In> + fun ok4(): Inv

+ fun ok5(): P + fun ok6(): Out + fun ok7(): Out

+ fun ok8(): Out> + fun ok9(): Pair, O> + + fun ok10(): Inv + fun ok11(): Inv + fun ok12(): Inv + fun ok13(): Inv + + fun neOk1(): I + fun neOk2(): In + fun neOk3(): In> + fun neOk4(): Inv + fun neOk5(): Inv + fun neOk6(): Pair, I> + fun neOk7(): Inv + fun neOk8(): Out + + fun neOk10(): Inv + fun neOk11(): Inv + + fun neOk30(): Pair + fun neOk31(): Pair + fun neOk32(): Inv + fun neOk33(): Inv<> + fun neOk34(): Inv + fun neOk35(): Inv +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/PrimaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/variance/PrimaryConstructor.fir.kt new file mode 100644 index 00000000000..c97cf42397c --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/PrimaryConstructor.fir.kt @@ -0,0 +1,25 @@ +interface In +interface Out +interface Inv + +fun getT(): T = null!! + +class Test( + val type1: I, + val type2: O, + val type3: P, + val type4: In, + val type5: In, + + var type6: I, + var type7: O, + var type8: P, + var type9: In, + var type0: In, + + type11: I, + type12: O, + type13: P, + type14: In, + type15: In +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/ValProperty.fir.kt b/compiler/testData/diagnostics/tests/variance/ValProperty.fir.kt new file mode 100644 index 00000000000..277e2c628ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/ValProperty.fir.kt @@ -0,0 +1,50 @@ +import kotlin.reflect.KProperty + +interface In +interface Out +interface Inv + +class Delegate { + operator fun getValue(t: Any, p: KProperty<*>): T = null!! + operator fun setValue(t: Any, p: KProperty<*>, value: T) {} +} + +fun getT(): T = null!! + +abstract class Test { + abstract val type1: I + abstract val type2: O + abstract val type3: P + abstract val type4: In + abstract val type5: In + + val implicitType1 = getT() + val implicitType2 = getT() + val implicitType3 = getT

() + val implicitType4 = getT>() + val implicitType5 = getT>() + + val delegateType1 by Delegate() + val delegateType2 by Delegate() + val delegateType3 by Delegate

() + val delegateType4 by Delegate>() + val delegateType5 by Delegate>() + + abstract val I.receiver1: Int + abstract val O.receiver2: Int + abstract val P.receiver3: Int + abstract val In.receiver4: Int + abstract val In.receiver5: Int + + val X.typeParameter1: Int get() = 0 + val X.typeParameter2: Int get() = 0 + val X.typeParameter3: Int get() = 0 + val > X.typeParameter4: Int get() = 0 + val > X.typeParameter5: Int get() = 0 + + val X.typeParameter6: Int where X : I get() = 0 + val X.typeParameter7: Int where X : O get() = 0 + val X.typeParameter8: Int where X : P get() = 0 + val X.typeParameter9: Int where X : In get() = 0 + val X.typeParameter0: Int where X : In get() = 0 +} diff --git a/compiler/testData/diagnostics/tests/variance/VarProperty.fir.kt b/compiler/testData/diagnostics/tests/variance/VarProperty.fir.kt new file mode 100644 index 00000000000..a8cb2614b8b --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/VarProperty.fir.kt @@ -0,0 +1,50 @@ +import kotlin.reflect.KProperty + +interface In +interface Out +interface Inv + +class Delegate { + operator fun getValue(t: Any, p: KProperty<*>): T = null!! + operator fun setValue(t: Any, p: KProperty<*>, varue: T) {} +} + +fun getT(): T = null!! + +abstract class Test { + abstract var type1: I + abstract var type2: O + abstract var type3: P + abstract var type4: In + abstract var type5: In + + var implicitType1 = getT() + var implicitType2 = getT() + var implicitType3 = getT

() + var implicitType4 = getT>() + var implicitType5 = getT>() + + var delegateType1 by Delegate() + var delegateType2 by Delegate() + var delegateType3 by Delegate

() + var delegateType4 by Delegate>() + var delegateType5 by Delegate>() + + abstract var I.receiver1: Int + abstract var O.receiver2: Int + abstract var P.receiver3: Int + abstract var In.receiver4: Int + abstract var In.receiver5: Int + + var X.typeParameter1: Int get() = 0; set(i) {} + var X.typeParameter2: Int get() = 0; set(i) {} + var X.typeParameter3: Int get() = 0; set(i) {} + var > X.typeParameter4: Int get() = 0; set(i) {} + var > X.typeParameter5: Int get() = 0; set(i) {} + + var X.typeParameter6: Int where X : I get() = 0; set(i) {} + var X.typeParameter7: Int where X : O get() = 0; set(i) {} + var X.typeParameter8: Int where X : P get() = 0; set(i) {} + var X.typeParameter9: Int where X : In get() = 0; set(i) {} + var X.typeParameter0: Int where X : In get() = 0; set(i) {} +} diff --git a/compiler/testData/diagnostics/tests/variance/Visibility.fir.kt b/compiler/testData/diagnostics/tests/variance/Visibility.fir.kt new file mode 100644 index 00000000000..9cdd40a0c09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/Visibility.fir.kt @@ -0,0 +1,20 @@ +interface Test { + val internal_val: I + public val public_val: I + protected val protected_val: I + private val private_val: I + + var interlan_private_set: O + private set + public var public_private_set: O + private set + protected var protected_private_set: O + private set + private var private_private_set: O + private set + + fun internal_fun(i: O) : I + public fun public_fun(i: O) : I + protected fun protected_fun(i: O) : I + private fun private_fun(i: O) : I +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/ea1337846.fir.kt b/compiler/testData/diagnostics/tests/variance/ea1337846.fir.kt new file mode 100644 index 00000000000..bfac78ff16e --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/ea1337846.fir.kt @@ -0,0 +1,21 @@ +// https://ea.jetbrains.com/browser/ea_reports/1337846 + +//interface ComputablePoint +// +//interface ComputableSegment +// +//interface ComputableLineSegment : ComputableSegment + +//interface Path + +typealias EachSegmentComparator = (currentSegment: SegmentType, otherSegment: SegmentType, relationship: Int) -> Boolean + +interface ComputablePath + : Path +where + NumberType: Number, + PointType: ComputablePoint, + SegmentType: ComputableLineSegment +{ + fun anyTwoSegments(comparator: EachSegmentComparator>): Boolean +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/Abstract.fir.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/Abstract.fir.kt new file mode 100644 index 00000000000..d46d0e62dc8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/Abstract.fir.kt @@ -0,0 +1,7 @@ +internal abstract class Test { + private/*private to this*/ final fun foo(): I { + throw Exception() + } + + private/*private to this*/ final val i: I get() = foo() +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.fir.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.fir.kt new file mode 100644 index 00000000000..66745afaede --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.fir.kt @@ -0,0 +1,37 @@ +fun getT(): T = null!! + +class Test { + private fun foo() : I = getT() + + fun apply(i: I) {} + + init { + foo() + this.foo() + } + + fun test() { + apply(foo()) + apply(this.foo()) + with(Test()) { + apply(foo()) // resolved to this@Test.foo + apply(this.foo()) + apply(this@with.foo()) + apply(this@Test.foo()) + } + } + + fun test(t: Test) { + t.apply(t.foo()) + } + + companion object { + fun test(t: Test) { + t.apply(t.foo()) + } + } +} + +fun test(t: Test) { + t.apply(t.foo()) +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.fir.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.fir.kt new file mode 100644 index 00000000000..e5b46746182 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.fir.kt @@ -0,0 +1,37 @@ +fun getT(): T = null!! + +class Test { + private val i: I = getT() + + init { + apply(i) + apply(this.i) + } + + fun apply(i: I) {} + + fun test() { + apply(i) + apply(this.i) + with(Test()) { + apply(i) // resolved to this@Test.i + apply(this.i) + apply(this@with.i) + apply(this@Test.i) + } + } + + fun test(t: Test) { + t.apply(t.i) + } + + companion object { + fun test(t: Test) { + t.apply(t.i) + } + } +} + +fun test(t: Test) { + t.apply(t.i) +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.fir.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.fir.kt new file mode 100644 index 00000000000..e662794145d --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.fir.kt @@ -0,0 +1,37 @@ +fun getT(): T = null!! + +class Test { + private var i: I = getT() + private val j: I + + init { + j = getT() + i = getT() + this.i = getT() + } + + fun test() { + i = getT() + this.i = getT() + with(Test()) { + i = getT() // resolved to this@Test.i + this.i = getT() + this@with.i = getT() + this@Test.i = getT() + } + } + + fun test(t: Test) { + t.i = getT() + } + + companion object { + fun test(t: Test) { + t.i = getT() + } + } +} + +fun test(t: Test) { + t.i = getT() +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.fir.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.fir.kt new file mode 100644 index 00000000000..486f11c43f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.fir.kt @@ -0,0 +1,20 @@ +fun getT(): T = null!! + +class A(init: I) { + private val i: I + + init { + i = getT() + } + + private var i2 = i + private val i3: I + + private var i4 = getT() + + init { + i2 = getT() + i3 = init + i4 = i3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromJava.fir.kt b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromJava.fir.kt new file mode 100644 index 00000000000..3185bec9eaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromJava.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +ProhibitInvisibleAbstractMethodsInSuperclasses +// FILE: base/Base.java +package base; + +public abstract class Base { + public void foo() { + packagePrivateFoo(); + } + + /* package-private */ abstract void packagePrivateFoo(); +} + +// FILE: Impl.kt +package impl +import base.* + +class Impl : Base() + +fun foo() { + Impl().foo() +} diff --git a/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlin.fir.kt b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlin.fir.kt new file mode 100644 index 00000000000..2c7d6dd65db --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlin.fir.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: +ProhibitInvisibleAbstractMethodsInSuperclasses +// MODULE: base +// FILE: Base.kt +package base + +abstract class Base { + fun foo(): String { + return internalFoo() + } + internal abstract fun internalFoo(): String +} + +open class BaseWithOverride : Base() { + override fun internalFoo(): String = "" +} + +// MODULE: intermediate(base) +// FILE: Intermediate.kt +package intermediate +import base.* + +abstract class Intermediate : Base() + +// MODULE: impl(base, intermediate) +// FILE: Impl.kt +package impl +import base.* +import intermediate.* + +class ImplDirectFromBase : Base() + +object ImplObjDirectFromBase : Base() + +class ImplDirectFromBaseWithOverride : BaseWithOverride() + +class ImplDirectFromBaseWithOverrid : Base() { + override fun internalFoo(): String = "" +} + +class ImplViaIntermediate : Intermediate() + +fun foo() { + ImplDirectFromBase().foo() + ImplObjDirectFromBase.foo() + ImplDirectFromBaseWithOverride().foo() + ImplViaIntermediate().foo() +} diff --git a/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlinWarning.fir.kt b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlinWarning.fir.kt new file mode 100644 index 00000000000..8a09feb8a6f --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/abstractInvisibleMemberFromKotlinWarning.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -ProhibitInvisibleAbstractMethodsInSuperclasses +// MODULE: base +// FILE: Base.kt +package base + +abstract class Base { + fun foo(): String { + return internalFoo() + } + internal abstract fun internalFoo(): String +} + +// MODULE: impl(base) +// FILE: Impl.kt +package impl +import base.* + +class Impl : Base() + +fun foo() { + Impl().foo() +} diff --git a/compiler/testData/diagnostics/tests/when/AnnotatedWhenStatement.fir.kt b/compiler/testData/diagnostics/tests/when/AnnotatedWhenStatement.fir.kt new file mode 100644 index 00000000000..cc1c5c9db55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/AnnotatedWhenStatement.fir.kt @@ -0,0 +1,8 @@ +fun foo(a: Int) { + @ann + when (a) { + 1 -> {} + } +} + +annotation class ann diff --git a/compiler/testData/diagnostics/tests/when/BranchBypassVal.fir.kt b/compiler/testData/diagnostics/tests/when/BranchBypassVal.fir.kt new file mode 100644 index 00000000000..1fc11675ec2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/BranchBypassVal.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +class A + +fun test(a: Any): String { + val q: String? = null + + when (a) { + is A -> q!! + } + // When is not exhaustive + return q +} diff --git a/compiler/testData/diagnostics/tests/when/BranchBypassVar.fir.kt b/compiler/testData/diagnostics/tests/when/BranchBypassVar.fir.kt new file mode 100644 index 00000000000..7a8e4484cca --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/BranchBypassVar.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +class A + +fun test(a: Any) { + var q: String? = null + + when (a) { + is A -> q = "1" + } + // When is not exhaustive + return q +} diff --git a/compiler/testData/diagnostics/tests/when/BranchFalseBypass.fir.kt b/compiler/testData/diagnostics/tests/when/BranchFalseBypass.fir.kt new file mode 100644 index 00000000000..1b406849f6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/BranchFalseBypass.fir.kt @@ -0,0 +1,12 @@ +enum class My { A, B } + +fun test(a: My): String { + val q: String? + + when (a) { + My.A -> q = "1" + My.B -> q = "2" + } + // When is exhaustive + return q +} diff --git a/compiler/testData/diagnostics/tests/when/BranchFalseBypassElse.fir.kt b/compiler/testData/diagnostics/tests/when/BranchFalseBypassElse.fir.kt new file mode 100644 index 00000000000..c66f5e955aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/BranchFalseBypassElse.fir.kt @@ -0,0 +1,12 @@ +class A + +fun test(a: Any): String { + var q: String? + + when (a) { + is A -> q = "1" + else -> q = "2" + } + // When is not exhaustive + return q +} diff --git a/compiler/testData/diagnostics/tests/when/CommaInWhenConditionWithoutArgument.fir.kt b/compiler/testData/diagnostics/tests/when/CommaInWhenConditionWithoutArgument.fir.kt new file mode 100644 index 00000000000..da4a6d4c2a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/CommaInWhenConditionWithoutArgument.fir.kt @@ -0,0 +1,11 @@ +fun foo(x: Int, y: Int): Int = + when { + x > 0, y > 0,, x < 0 -> 1 + else -> 0 + } + +fun bar(x: Int): Int = + when (x) { + 0 -> 0 + else -> 1 + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/DuplicatedLabels.fir.kt b/compiler/testData/diagnostics/tests/when/DuplicatedLabels.fir.kt new file mode 100644 index 00000000000..72d12360fa9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/DuplicatedLabels.fir.kt @@ -0,0 +1,51 @@ +package test + +const val four = 4 + +fun first(arg: Int) = when (arg) { + 1 -> 2 + 2 -> 3 + 1 -> 4 + 4 -> 5 + 1 -> 6 + 2 -> 7 + // Error should be here: see KT-11971 + four -> 8 + else -> 0 +} + +fun second(arg: String): Int { + when (arg) { + "ABC" -> return 0 + "DEF" -> return 1 + "ABC" -> return -1 + "DEF" -> return -2 + } + return 42 +} + +fun third(arg: Any?): Int { + when (arg) { + null -> return -1 + is String -> return 0 + is Double -> return 1 + is Double -> return 2 + null -> return 3 + else -> return 5 + } +} + +enum class Color { RED, GREEN, BLUE } + +fun fourth(arg: Color) = when (arg) { + Color.RED -> "RED" + Color.GREEN -> "GREEN" + Color.RED -> "BLUE" + Color.BLUE -> "BLUE" +} + +fun fifth(arg: Any?) = when (arg) { + is Any -> "Any" + else -> "" + else -> null +} diff --git a/compiler/testData/diagnostics/tests/when/ElseOnNullableEnum.fir.kt b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnum.fir.kt new file mode 100644 index 00000000000..049871ff6bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnum.fir.kt @@ -0,0 +1,46 @@ +// KT-2902 Check for null should be required when match nullable enum element + +// FILE: 1.kt + +enum class E { A, B } + +fun test(e: E?) = when (e) { + E.A -> 1 + E.B -> 2 +} + +fun withNull(e: E?) = when (e) { + E.A -> 3 + E.B -> 4 + null -> null +} + +fun nullableNothing(): Nothing? = null +fun withNullableNothing(e: E?) = when (e) { + E.A -> 5 + E.B -> 6 + nullableNothing() -> null +} + +fun platformType() = when (J.foo()) { + E.A -> 7 + E.B -> 8 +} + +fun platformTypeSmartCast(): Int { + val e = J.foo() + if (e == null) return -1 + return when (e) { + E.A -> 1 + E.B -> 2 + } +} + + +// FILE: J.java + +class J { + static E foo() { + return E.A; + } +} diff --git a/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.fir.kt b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.fir.kt new file mode 100644 index 00000000000..f0f8219837f --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ElseOnNullableEnumWithSmartCast.fir.kt @@ -0,0 +1,11 @@ +enum class E { A, B } + +fun foo(e: E, something: Any?): Int { + if (something != null) return 0 + + return when (e) { + E.A -> 1 + E.B -> 2 + something -> 3 + } +} diff --git a/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpression.fir.kt b/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpression.fir.kt new file mode 100644 index 00000000000..4683fbbb7b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpression.fir.kt @@ -0,0 +1,8 @@ +// EA-68871: empty when condition +fun foo(arg: Int): Int { + when (arg) { + 0 -> return 0 + -> return 4 + else -> return -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpressionEnum.fir.kt b/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpressionEnum.fir.kt new file mode 100644 index 00000000000..9746ea53b58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/EmptyConditionWithExpressionEnum.fir.kt @@ -0,0 +1,9 @@ +// EA-68871: empty when condition +enum class My { FIRST, SECOND } +fun foo(arg: My): Int { + when (arg) { + My.FIRST -> return 0 + -> return 4 + else -> return -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.fir.kt new file mode 100644 index 00000000000..fc65d061fce --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.fir.kt @@ -0,0 +1,8 @@ +// See also: KT-3743 +fun foo(arg: Boolean): String { + // Must be exhaustive + return when(arg) { + true -> "truth" + false -> "falsehood" + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanBrackets.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanBrackets.fir.kt new file mode 100644 index 00000000000..3ac5e9812b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanBrackets.fir.kt @@ -0,0 +1,7 @@ +fun foo(arg: Boolean): String { + // Must be exhaustive + return when(arg) { + (true) -> "truth" + ((false)) -> "falsehood" + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanComplex.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanComplex.fir.kt new file mode 100644 index 00000000000..43d4890652b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanComplex.fir.kt @@ -0,0 +1,8 @@ +// See also: KT-3743 +fun foo(arg: Boolean): String { + // Must be exhaustive + return when(arg) { + 2 == 2 -> "truth" + 2 == 1 -> "falsehood" + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanNullable.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanNullable.fir.kt new file mode 100644 index 00000000000..dfb530e9641 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveBooleanNullable.fir.kt @@ -0,0 +1,9 @@ +// See also: KT-3743 +fun foo(arg: Boolean?): String { + // Must be exhaustive + return when(arg) { + true -> "truth" + false -> "falsehood" + null -> "unknown" + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveBreakContinue.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveBreakContinue.fir.kt new file mode 100644 index 00000000000..8a4910d7564 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveBreakContinue.fir.kt @@ -0,0 +1,14 @@ +enum class Color { RED, GREEN, BLUE } + +fun foo(arr: Array): Color { + loop@ for (color in arr) { + when (color) { + Color.RED -> return color + Color.GREEN -> break@loop + Color.BLUE -> if (arr.size == 1) return color else continue@loop + } + // Unreachable + return Color.BLUE + } + return Color.GREEN +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveEnumIs.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveEnumIs.fir.kt new file mode 100644 index 00000000000..3c58abd2073 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveEnumIs.fir.kt @@ -0,0 +1,11 @@ +enum class MyEnum { + A, B, C +} + +fun foo(x: MyEnum): Int { + return when (x) { + is MyEnum.A -> 1 + is MyEnum.B -> 2 + is MyEnum.C -> 3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveEnumMixed.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveEnumMixed.fir.kt new file mode 100644 index 00000000000..6ff1b9e4ba9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveEnumMixed.fir.kt @@ -0,0 +1,11 @@ +enum class MyEnum { + A, B, C +} + +fun foo(x: MyEnum): Int { + return when (x) { + MyEnum.A -> 1 + is MyEnum.B -> 2 + is MyEnum.C -> 3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveInitialization.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveInitialization.fir.kt new file mode 100644 index 00000000000..0e15e5efb3d --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveInitialization.fir.kt @@ -0,0 +1,15 @@ +enum class Direction { + NORTH, SOUTH, WEST, EAST +} + +fun foo(dir: Direction): Int { + val res: Int + // See KT-6046: res is always initialized + when (dir) { + Direction.NORTH -> res = 1 + Direction.SOUTH -> res = 2 + Direction.WEST -> res = 3 + Direction.EAST -> res = 4 + } + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveNoInitialization.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveNoInitialization.fir.kt new file mode 100644 index 00000000000..b7f68238504 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveNoInitialization.fir.kt @@ -0,0 +1,11 @@ +fun foo(b: Boolean): Int { + val x: Int + val y: Int + when (b) { + true -> y = 1 + false -> y = 0 + } + // x is initialized here + x = 3 + return x + y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveNullable.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveNullable.fir.kt new file mode 100644 index 00000000000..19edb89d8fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveNullable.fir.kt @@ -0,0 +1,14 @@ +enum class MyEnum { + A, B +} + +fun foo(x: MyEnum?): Int { + val y: Int + // See KT-6046: y is always initialized + when (x) { + MyEnum.A -> y = 1 + MyEnum.B -> y = 2 + null -> y = 0 + } + return y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnum.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnum.fir.kt new file mode 100644 index 00000000000..2a97dd3827c --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnum.fir.kt @@ -0,0 +1,21 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +public enum J { + A, B; + + public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + // When is exhaustive (count a platform enum as a special case) + return when (J.create()) { + J.A -> 1 + J.B -> 2 + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumAnnotated.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumAnnotated.fir.kt new file mode 100644 index 00000000000..6820a883e59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumAnnotated.fir.kt @@ -0,0 +1,23 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +import org.jetbrains.annotations.*; + +public enum J { + A, B; + + @NotNull public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + // When is exhaustive (count a platform enum as a special case) + return when (J.create()) { + J.A -> 1 + J.B -> 2 + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumElse.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumElse.fir.kt new file mode 100644 index 00000000000..bd311096cf2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumElse.fir.kt @@ -0,0 +1,21 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +public enum J { + A, B; + + public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + return when (J.create()) { + J.A -> 1 + J.B -> 2 + else -> 0 + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumNull.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumNull.fir.kt new file mode 100644 index 00000000000..c809bee2c2b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumNull.fir.kt @@ -0,0 +1,22 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +public enum J { + A, B; + + public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + // When is exhaustive including null + return when (J.create()) { + J.A -> 1 + J.B -> 2 + null -> 0 + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumStatement.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumStatement.fir.kt new file mode 100644 index 00000000000..a51fda0cbdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustivePlatformEnumStatement.fir.kt @@ -0,0 +1,20 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +public enum J { + A, B; + + public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + when (J.create()) { + J.A -> return 1 + J.B -> return 2 + } +} diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveReturn.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveReturn.fir.kt new file mode 100644 index 00000000000..11c764c8ccd --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveReturn.fir.kt @@ -0,0 +1,13 @@ +enum class Direction { + NORTH, SOUTH, WEST, EAST +} + +fun foo(dir: Direction): Int { + when (dir) { + Direction.NORTH -> return 1 + Direction.SOUTH -> return 2 + Direction.WEST -> return 3 + Direction.EAST -> return 4 + } + // See KT-1882: no return is needed at the end +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveReturnThrow.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveReturnThrow.fir.kt new file mode 100644 index 00000000000..b6bafbb0de4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveReturnThrow.fir.kt @@ -0,0 +1,14 @@ +enum class Direction { + NORTH, SOUTH, WEST, EAST +} + +fun foo(dir: Direction): Int { + when (dir) { + Direction.NORTH -> return 1 + Direction.SOUTH -> throw AssertionError("!!!") + Direction.WEST -> return 3 + Direction.EAST -> return 4 + } + // Error: Unreachable code. Return is not required. + if (dir == Direction.SOUTH) return 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveValOverConditionalInit.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveValOverConditionalInit.fir.kt new file mode 100644 index 00000000000..a1ec917c645 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveValOverConditionalInit.fir.kt @@ -0,0 +1,22 @@ +fun foo(a: Boolean, b: Boolean): Int { + val x: Int + if (a) { + x = 1 + } + when (b) { + true -> x = 2 + false -> x = 3 + } + return x +} + +fun bar(a: Boolean, b: Boolean): Int { + val x: Int + if (a) { + x = 1 + } + when (b) { + false -> x = 3 + } + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveVarOverConditionalInit.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveVarOverConditionalInit.fir.kt new file mode 100644 index 00000000000..17994c2be70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveVarOverConditionalInit.fir.kt @@ -0,0 +1,22 @@ +fun foo(a: Boolean, b: Boolean): Int { + var x: Int + if (a) { + x = 1 + } + when (b) { + true -> x = 2 + false -> x = 3 + } + return x +} + +fun bar(a: Boolean, b: Boolean): Int { + var x: Int + if (a) { + x = 1 + } + when (b) { + false -> x = 3 + } + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheck.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheck.fir.kt new file mode 100644 index 00000000000..86925b7212a --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheck.fir.kt @@ -0,0 +1,14 @@ +// KT-7857: when exhaustiveness does not take previous nullability checks into account +enum class X { A, B } +fun foo(arg: X?): Int { + if (arg != null) { + return when (arg) { + X.A -> 1 + X.B -> 2 + // else or null branch should not be required here! + } + } + else { + return 0 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBefore.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBefore.fir.kt new file mode 100644 index 00000000000..41d97447c03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBefore.fir.kt @@ -0,0 +1,12 @@ +// KT-7857: when exhaustiveness does not take previous nullability checks into account +enum class X { A, B } +fun foo(arg: X?): Int { + if (arg == null) { + return 0 + } + return when (arg) { + X.A -> 1 + X.B -> 2 + // else or null branch should not be required here! + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBoolean.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBoolean.fir.kt new file mode 100644 index 00000000000..67e7e269297 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckBoolean.fir.kt @@ -0,0 +1,13 @@ +// KT-7857: when exhaustiveness does not take previous nullability checks into account +fun foo(arg: Boolean?): Int { + if (arg != null) { + return when (arg) { + true -> 1 + false -> 0 + // else or null branch should not be required here! + } + } + else { + return -1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckElse.fir.kt b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckElse.fir.kt new file mode 100644 index 00000000000..3b315600ab8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ExhaustiveWithNullabilityCheckElse.fir.kt @@ -0,0 +1,14 @@ +// KT-7857: when exhaustiveness does not take previous nullability checks into account +enum class X { A, B } +fun foo(arg: X?): Int { + if (arg == null) { + return 0 + } + else { + return when (arg) { + X.A -> 1 + X.B -> 2 + // else or null branch should not be required here! + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseExpectedUnit.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseExpectedUnit.fir.kt new file mode 100644 index 00000000000..4b240e601c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseExpectedUnit.fir.kt @@ -0,0 +1,7 @@ +fun foo(x: Int) { + val y: Unit = when (x) { + 2 -> {} + 3 -> {} + } + return y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseNoExpectedType.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseNoExpectedType.fir.kt new file mode 100644 index 00000000000..c625fff796e --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseNoExpectedType.fir.kt @@ -0,0 +1,6 @@ +fun foo(x: Int): Any { + val v = when (x) { + 2 -> 0 + } + return v +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.fir.kt new file mode 100644 index 00000000000..695f64ab91c --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseReturnedCoercionToUnit.fir.kt @@ -0,0 +1,11 @@ +fun foo(x: Int) { + r { + when (x) { + 2 -> 0 + } + } +} + +fun r(f: () -> Unit) { + f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseReturnedFromLambdaExpectedInt.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseReturnedFromLambdaExpectedInt.fir.kt new file mode 100644 index 00000000000..4dfb9c7dbcf --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseReturnedFromLambdaExpectedInt.fir.kt @@ -0,0 +1,11 @@ +fun foo(x: Int) { + r { + when (x) { + 2 -> 0 + } + } +} + +fun r(f: () -> Int) { + f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseReturnedNonUnit.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseReturnedNonUnit.fir.kt new file mode 100644 index 00000000000..1ba2b607982 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseReturnedNonUnit.fir.kt @@ -0,0 +1,5 @@ +fun foo(x: Int): Any { + return when (x) { + 2 -> 0 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseReturnedUnit.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseReturnedUnit.fir.kt new file mode 100644 index 00000000000..606fe43e816 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseReturnedUnit.fir.kt @@ -0,0 +1,6 @@ +fun foo(x: Int) { + return when (x) { + 2 -> {} + 3 -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NoElseWhenStatement.fir.kt b/compiler/testData/diagnostics/tests/when/NoElseWhenStatement.fir.kt new file mode 100644 index 00000000000..000a829fa71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NoElseWhenStatement.fir.kt @@ -0,0 +1,6 @@ +fun foo(x: Int) { + when (x) { + 2 -> {} + 3 -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveBooleanNullable.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveBooleanNullable.fir.kt new file mode 100644 index 00000000000..a1b0cf6478c --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveBooleanNullable.fir.kt @@ -0,0 +1,8 @@ +// See also: KT-3743 +fun foo(arg: Boolean?): String { + // Must be NOT exhaustive + return when(arg) { + true -> "truth" + false -> "falsehood" + } +} diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustivePlatformEnum.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustivePlatformEnum.fir.kt new file mode 100644 index 00000000000..f88086ef62a --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustivePlatformEnum.fir.kt @@ -0,0 +1,20 @@ +// See KT-6399: exhaustive whens on platform enums + +// FILE: J.java + +public enum J { + A, B; + + public static J create() { + return J.A; + } +} + +// FILE: K.kt + +fun foo(): Int { + // When is not-exhaustive + return when (J.create()) { + J.A -> 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWarning.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarning.fir.kt new file mode 100644 index 00000000000..311b12aae32 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarning.fir.kt @@ -0,0 +1,11 @@ +// Base for KT-6227 +enum class X { A, B, C, D } + +fun foo(arg: X): String { + var res = "XXX" + when (arg) { + X.A -> res = "A" + X.B -> res = "B" + } + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningElse.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningElse.fir.kt new file mode 100644 index 00000000000..673943fa385 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningElse.fir.kt @@ -0,0 +1,12 @@ +// Base for KT-6227 +enum class X { A, B, C, D } + +fun foo(arg: X): String { + val res: String + when (arg) { + X.A -> res = "A" + X.B -> res = "B" + else -> res = "CD" + } + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningFalse.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningFalse.fir.kt new file mode 100644 index 00000000000..c78080fd833 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningFalse.fir.kt @@ -0,0 +1,13 @@ +// Base for KT-6227 +enum class X { A, B, C, D } + +fun foo(arg: X): String { + val res: String + when (arg) { + X.A -> res = "A" + X.B -> res = "B" + X.C -> res = "C" + X.D -> res = "D" + } + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningForSealedClass.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningForSealedClass.fir.kt new file mode 100644 index 00000000000..36e760226ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningForSealedClass.fir.kt @@ -0,0 +1,16 @@ +sealed class S + +object First : S() + +class Derived(val s: String) : S() + +object Last : S() + +fun use(s: String) = s + +fun foo(s: S) { + when (s) { + First -> {} + is Derived -> use(s.s) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningNull.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningNull.fir.kt new file mode 100644 index 00000000000..a71a3c99564 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWarningNull.fir.kt @@ -0,0 +1,14 @@ +// Base for KT-6227 +enum class X { A, B, C, D } + +fun foo(arg: X?): String { + var res = "XXX" + // Should we report something here? Probably not, null is not an enum entry + when (arg) { + X.A -> res = "A" + X.B -> res = "B" + X.C -> res = "C" + X.D -> res = "D" + } + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/NonExhaustiveWithNullabilityCheck.fir.kt b/compiler/testData/diagnostics/tests/when/NonExhaustiveWithNullabilityCheck.fir.kt new file mode 100644 index 00000000000..97cb1995804 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/NonExhaustiveWithNullabilityCheck.fir.kt @@ -0,0 +1,12 @@ +// KT-7857: when exhaustiveness does not take previous nullability checks into account +enum class X { A, B } +fun foo(arg: X?): Int { + if (arg != null) { + return when (arg) { + X.B -> 2 + } + } + else { + return 0 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/PropertyNotInitialized.fir.kt b/compiler/testData/diagnostics/tests/when/PropertyNotInitialized.fir.kt new file mode 100644 index 00000000000..c286b1e93c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/PropertyNotInitialized.fir.kt @@ -0,0 +1,16 @@ +// See KT-5113 +enum class E { + A, + B +} + +class Outer(e: E) { + private val prop: Int + init { + when(e ) { + // When is exhaustive, property is always initialized + E.A -> prop = 1 + E.B -> prop = 2 + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/RedundantElse.fir.kt b/compiler/testData/diagnostics/tests/when/RedundantElse.fir.kt new file mode 100644 index 00000000000..88d76554d03 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/RedundantElse.fir.kt @@ -0,0 +1,68 @@ +// FILE: MyEnum.java +public enum MyEnum { + SINGLE; + + public static MyEnum getInstance() { + return SINGLE; + } +} + + +// FILE: test.kt + +sealed class X { + class A : X() + class B : X() +} + +fun foo(x: X) = when (x) { + is X.A -> {} + is X.B -> {} + else -> {} +} + +fun bar(x: X?): String = when (x) { + is X.A -> "A" + is X.B -> "B" + null -> "null" + else -> "Unreachable" +} + +fun justUse(x: X) { + when (x) { + is X.A -> {} + is X.B -> {} + // Redundant even in statement position + else -> {} + } +} + +enum class E { + A, B +} + +fun foo(e: E): String = when (e) { + E.A -> "A" + E.B -> "B" + else -> "" +} + +fun bar(e: E?): String = when (e) { + E.A -> "A" + E.B -> "B" + else -> "" // no warning +} + +fun foo(b: Boolean) = when (b) { + true -> 1 + false -> 0 + else -> -1 +} + +fun useJava(): String { + val me = MyEnum.getInstance() + return when (me) { + MyEnum.SINGLE -> "OK" + else -> "FAIL" // no warning + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/ReservedExhaustiveWhen.fir.kt b/compiler/testData/diagnostics/tests/when/ReservedExhaustiveWhen.fir.kt new file mode 100644 index 00000000000..768ca9e343d --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/ReservedExhaustiveWhen.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +infix fun Any.sealed(a: Any?) {} + +val x = 1 sealed when (1) { + 1 -> 1 + else -> 2 +} + +val x1 = 1 sealed /**/ when (1) { + 1 -> 1 + else -> 2 +} + +fun foo() { + sealed when { + else -> {} + } + + 1 sealed when { + else -> {} + } + + 1 sealed (when { + else -> {} + }) + + 1 + sealed when { + else -> {} + } + + 1 sealed + when { + else -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/TopLevelSealed.fir.kt b/compiler/testData/diagnostics/tests/when/TopLevelSealed.fir.kt new file mode 100644 index 00000000000..51371115be4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TopLevelSealed.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +sealed class A { + class B: A() { + class C: A() + } +} + +class D: A() + +fun test(a: A) { + val nonExhaustive = when (a) { + is A.B -> "B" + is A.B.C -> "C" + } + + val exhaustive = when (a) { + is A.B -> "B" + is A.B.C -> "C" + is D -> "D" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/When.fir.kt b/compiler/testData/diagnostics/tests/when/When.fir.kt new file mode 100644 index 00000000000..287bc1ea340 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/When.fir.kt @@ -0,0 +1,46 @@ +// !WITH_NEW_INFERENCE +fun Int.foo() : Boolean = true + +fun foo() : Int { + val s = "" + val x = 1 + when (x) { + is String -> 1 + !is Int -> 1 + is Any? -> 1 + is Any -> 1 + s -> 1 + 1 -> 1 + 1 + a -> 1 + in 1..a -> 1 + !in 1..a -> 1 + else -> 1 + } + + return 0 +} + +val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() + +fun test() { + val x = 1; + val s = ""; + + when (x) { + s -> 1 + "" -> 1 + x -> 1 + 1 -> 1 + } + + val z = 1 + + when (z) { + else -> 1 + 1 -> 2 + } + + when (z) { + else -> 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/WhenTypeDisjunctions.fir.kt b/compiler/testData/diagnostics/tests/when/WhenTypeDisjunctions.fir.kt new file mode 100644 index 00000000000..61f82a393b6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/WhenTypeDisjunctions.fir.kt @@ -0,0 +1,21 @@ +fun foo(s: Any): String { + val x = when (s) { + is String -> s + is Int -> "$s" + else -> return "" + } + + val y: String = x // should be Ok + return y +} + +fun bar(s: Any): String { + val x = when (s) { + is String -> s as String // meaningless + is Int -> "$s" + else -> return "" + } + + val y: String = x // no error + return y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/kt10439.fir.kt b/compiler/testData/diagnostics/tests/when/kt10439.fir.kt new file mode 100644 index 00000000000..fe6325b748a --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt10439.fir.kt @@ -0,0 +1,13 @@ +// !WITH_NEW_INFERENCE +fun foo(x: Int) = x + +fun test0(flag: Boolean) { + foo(if (flag) true else "") +} + +fun test1(flag: Boolean) { + foo(when (flag) { + true -> true + else -> "" + }) +} diff --git a/compiler/testData/diagnostics/tests/when/kt10809.fir.kt b/compiler/testData/diagnostics/tests/when/kt10809.fir.kt new file mode 100644 index 00000000000..3ccd6260110 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt10809.fir.kt @@ -0,0 +1,52 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -DEBUG_INFO_SMARTCAST +// NI_EXPECTED_FILE + +interface Data +interface Item +class FlagData(val value: Boolean) : Data +class ListData(val list: List) : Data + +fun listOf(vararg items: T): List = null!! + +fun test1(o: Any) = when (o) { + is List<*> -> + ListData(listOf()) + is Int -> when { + o < 0 -> + FlagData(true) + else -> + null + } + else -> + null +} + +fun test1x(o: Any): Data? = when (o) { + is List<*> -> + ListData(listOf()) + is Int -> when { + o < 0 -> + FlagData(true) + else -> + null + } + else -> + null +} + +fun test2() = + if (true) + ListData(listOf()) + else + FlagData(true) + +fun test2x(): Data = + if (true) ListData(listOf()) else FlagData(true) + +fun test2y(): Any = + if (true) ListData(listOf()) else FlagData(true) + +fun test2z(): Any = + run { if (true) ListData(listOf()) else FlagData(true) } + diff --git a/compiler/testData/diagnostics/tests/when/kt10811.fir.kt b/compiler/testData/diagnostics/tests/when/kt10811.fir.kt new file mode 100644 index 00000000000..e99415e09a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt10811.fir.kt @@ -0,0 +1,24 @@ +interface Maybe +class Some(val value: T) : Maybe +class None : Maybe + +fun none() : None = TODO() + +fun test1() : Maybe = if (true) none() else Some("") + +fun test2() : Maybe = when { + true -> none() + else -> Some("") +} + +fun test3() : Maybe = when { + true -> none() + else -> Some("") +} + +fun test4() : Maybe { + when ("") { + "a" -> return none() + else -> return Some("") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/kt4434.fir.kt b/compiler/testData/diagnostics/tests/when/kt4434.fir.kt new file mode 100644 index 00000000000..2d2809f0b0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt4434.fir.kt @@ -0,0 +1,27 @@ +// KT-4434 Missed diagnostic about else branch in when + +package test + +fun foo(): Int { + val a = "a" + return if (a.length > 0) { + when (a) { + "a" -> 1 + } + } + else { + 3 + } +} + +fun bar(): Int { + val a = "a" + if (a.length > 0) { + return when (a) { + "a" -> 1 + } + } + else { + return 3 + } +} diff --git a/compiler/testData/diagnostics/tests/when/kt9929.fir.kt b/compiler/testData/diagnostics/tests/when/kt9929.fir.kt new file mode 100644 index 00000000000..bdcef146df4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt9929.fir.kt @@ -0,0 +1,10 @@ +// !WITH_NEW_INFERENCE +val test: Int = if (true) { + when (2) { + 1 -> 1 + else -> null + } +} +else { + 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/kt9972.fir.kt b/compiler/testData/diagnostics/tests/when/kt9972.fir.kt new file mode 100644 index 00000000000..b5265b36f1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/kt9972.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE +fun test1(): Int { + val x: String = if (true) { + when { + true -> Any() + else -> null + } + } else "" + return x.hashCode() +} + +fun test2(): Int { + val x: String = when { + true -> Any() + else -> null + } ?: return 0 + return x.hashCode() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt new file mode 100644 index 00000000000..e82e0a7bae4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt @@ -0,0 +1,25 @@ +// !WITH_NEW_INFERENCE +val test1: (String) -> Boolean = + when { + true -> {{ true }} + else -> {{ false }} + } + +val test2: (String) -> Boolean = + when { + true -> {{ true }} + else -> null!! + } + +val test3: (String) -> Boolean = + when { + true -> { s -> true } + else -> null!! + } + +val test4: (String) -> Boolean = + when { + true -> { s1, s2 -> true } + else -> null!! + } + diff --git a/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.fir.kt b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.fir.kt new file mode 100644 index 00000000000..ecdc4aeaa90 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/whenWithNothingAndLambdas.fir.kt @@ -0,0 +1,39 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +val test1 = when { + true -> { { true } } + else -> TODO() +} + +val test1a: () -> Boolean = when { + true -> { { true } } + else -> TODO() +} + +val test2 = when { + true -> { { true } } + else -> when { + true -> { { true } } + else -> TODO() + } +} + +val test2a: () -> Boolean = when { + true -> { { true } } + else -> when { + true -> { { true } } // TODO + else -> TODO() + } +} + +val test3 = when { + true -> { { true } } + true -> { { true } } + else -> TODO() +} + +val test3a: () -> Boolean = when { + true -> { { true } } + true -> { { true } } + else -> TODO() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/capturingInInitializer.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/capturingInInitializer.fir.kt new file mode 100644 index 00000000000..ef0abfe66e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/capturingInInitializer.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun getBoolean() = true + +fun testSafeCaptureVarInInitializer() { + var x: Int? = 42 + x!! + x.inc() + + val s = when (val y = run { x = 42; 32 }) { + 0 -> { + x.inc() // TODO fix smart casts for captured variables + "0" + } + else -> "!= 0" + } + + x.inc() // TODO fix smart casts for captured variables +} + + +fun testUnsafeCaptureVarInInitializer() { + var x: Int? = 42 + x!! + x.inc() + + val s = when (val y = run { x = null; 32 }) { + 0 -> { + x.inc() // NB smart cast should be impossible + "0" + } + else -> "!= 0" + } + + x.inc() // NB smart cast should be impossible +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/invisibleOutsideOfWhen.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/invisibleOutsideOfWhen.fir.kt new file mode 100644 index 00000000000..43f33af1a4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/invisibleOutsideOfWhen.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo(): Any = 42 + +fun test(x: Any) { + val z1 = when (val y = foo()) { + 42 -> "Magic: $y, $x" + else -> { + "Not magic: $y, $x" + } + } + val z2 = "Anyway, it was $y" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/jumpoutInInitializer.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/jumpoutInInitializer.fir.kt new file mode 100644 index 00000000000..e6b6b7894f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/jumpoutInInitializer.fir.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + + +fun testJumpOutInElvis(x: Int?) { + loop@ while (true) { + val y = when (val z = x ?: break@loop) { + 0 -> "0" + else -> "not 0" + } + + x.inc() + } + + x.inc() +} + +fun testJumpOutInElvisLikeIf(x: Int?) { + loop@ while (true) { + val y = when (val z = if (x == null) break@loop else x) { + 0 -> "0" + else -> "not 0" + } + x.inc() + } + + x.inc() +} + + +fun getBoolean() = true + +fun testJumpOutInIf(x: Int?) { + loop@ while (true) { + val y = when (val z = if (getBoolean()) { x!!; break@loop } else x) { + 0 -> "0" + else -> "not 0" + } + x.inc() + } + + x.inc() // Actually, safe, but it's OK if it's error +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/nestedWhenWithSubject.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/nestedWhenWithSubject.fir.kt new file mode 100644 index 00000000000..1be42fe50ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/nestedWhenWithSubject.fir.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VALUE + +fun foo() {} +fun bar(x: T, y: T) {} + +fun test1() { + when (1) { + 1 -> + when (val y = 2) { + 2 -> foo() + } + } +} + +fun test2() { + when (val x = 1) { + 1 -> + when (val y = 2) { + 2 -> foo() + } + } +} + +fun test3() { + when (val x = 1) { + 1 -> + when (val x = 2) { + 2 -> foo() + } + } +} + +fun test4() { + when (val x = 1) { + 1 -> + when (val y = 2) { + 2 -> bar(x, y) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/noSubjectVariableName.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/noSubjectVariableName.fir.kt new file mode 100644 index 00000000000..82c12f2fa0d --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/noSubjectVariableName.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + + +fun testNoSubjectVariableName(x: Int?) { + val y = when (val = 42) { + 0 -> "0" + else -> "not 0" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/reassignmentToWhenSubjectVariable.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/reassignmentToWhenSubjectVariable.fir.kt new file mode 100644 index 00000000000..f3aea651833 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/reassignmentToWhenSubjectVariable.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VALUE + +fun foo(): Any = 42 + +fun test1(x: Any) { + when (val y = foo()) { + is String -> y = "" + } +} diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/shadowingOtherVariable.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/shadowingOtherVariable.fir.kt new file mode 100644 index 00000000000..f5da5eda4d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/shadowingOtherVariable.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun foo(): Any = 42 +fun useInt(i: Int) {} + +fun testShadowingParameter(y: Any) { + when (val y = foo()) { + else -> {} + } +} + +fun testShadowedInWhenBody(x: Any) { + when (val y = x) { + is String -> { + val y = y.length + useInt(y) + } + } +} + +fun testShadowinLocalVariable() { + val y = foo() + when (val y = foo()) { + else -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.fir.kt new file mode 100644 index 00000000000..c93e8c1f329 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.fir.kt @@ -0,0 +1,49 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !WITH_NEW_INFERENCE + +fun foo(s1: Int, s2: Int) = s1 + s2 + +fun test1(x: String?) = + when (val y = x?.length) { + null -> 0 + else -> foo(x.length, y) + } + +fun test2(x: String?) { + when (val y = run { x!! }) { + "foo" -> x.length + "bar" -> y.length + } +} + +fun test3(x: String?, y: String?) { + when (val z = x ?: y!!) { + "foo" -> x.length + "bar" -> y.length + "baz" -> z.length + } +} + +fun id(x: T): T = x + +fun test4(x: String?) { + when (val y = id(x!!)) { + "foo" -> x.length + "bar" -> y.length + } +} + +class Inv(val data: T) + +fun test5(x: Inv) { + when (val y = x.data) { + is String -> y.length // should be ok + null -> x.data.length // should be error + } +} + +fun test6(x: Inv) { + when (val y = x.data) { + is String -> x.data.length // should be ok + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.fir.kt new file mode 100644 index 00000000000..36c367905cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastsOnSubjectVariable.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject + +fun test(x: Any?) = + when (val y = x) { + is String -> "String, length = ${y.length}" + null -> "Null" + else -> "Any, hashCode = ${y.hashCode()}" + } diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToEnum.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToEnum.fir.kt new file mode 100644 index 00000000000..882e2c17b76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToEnum.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + +enum class E { FIRST, SECOND } + +fun testSmartcastToEnumInSubjectInitializer1(e: E?) { + val x1 = when (val ne = e!!) { + E.FIRST -> "f" + E.SECOND -> "s" + } +} + +fun testSmartcastToEnumInSubjectInitializer2(e: E?) { + val x2 = when (val ne: Any = e!!) { // NB explicit type annotation + E.FIRST -> "f" + E.SECOND -> "s" + } +} diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToSealed.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToSealed.fir.kt new file mode 100644 index 00000000000..7e66946fe0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartcastToSealed.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + +sealed class Either +class Left : Either() +class Right : Either() + +fun testSmartcastToSealedInSubjectInitializer1(x: Any?) { + val y1 = when (val either = x as Either) { + is Left -> "L" + is Right -> "R" + } +} + +fun testSmartcastToSealedInSubjectInitializer2(x: Any?) { + val y2 = when (val either: Any = x as Either) { // NB explicit type annotation + is Left -> "L" + is Right -> "R" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/softModifierName.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/softModifierName.fir.kt new file mode 100644 index 00000000000..0e554ba12f9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/softModifierName.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject + +fun test(data: String) = + when (data.length) { + 0 -> -1 + else -> 42 + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/subjectVariableInIsPattern.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/subjectVariableInIsPattern.fir.kt new file mode 100644 index 00000000000..ed1765401ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/subjectVariableInIsPattern.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +fun test(x: Any) { + when (val y = x) { + is String -> {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedFeature.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedFeature.fir.kt new file mode 100644 index 00000000000..8790b260a15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedFeature.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo(): Any = 42 + +fun test(x: Any) { + // NB check that we still resolve 'y', even though current language version doesn' support variable declaration in when subject + + val z1 = when (val y = foo()) { + 42 -> "Magic: $y, $x" + else -> { + "Not magic: $y, $x" + } + } + val z2 = "Anyway, it was $y" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt new file mode 100644 index 00000000000..6268016b679 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// WITH_RUNTIME + +fun foo(): Any = 42 +fun String.bar(): Any = 42 + + +fun testSimpleValInWhenSubject() { + when (val y = foo()) { + } +} + +fun testValWithoutInitializerWhenSubject() { + when (val y: Any) { + is String -> y.length + } +} + +fun testVarInWhenSubject() { + when (var y = foo()) { + is String -> y.length + } +} + +fun testDelegatedValInWhenSubject() { + when (val y by lazy { 42 }) { + } +} diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unusedWhenSubjectVariable.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unusedWhenSubjectVariable.fir.kt new file mode 100644 index 00000000000..88cfdd3aa77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unusedWhenSubjectVariable.fir.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +VariableDeclarationInWhenSubject + +fun foo(): Any = 42 + +fun test() { + when (val x = foo()) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.fir.kt new file mode 100644 index 00000000000..5965caa70c1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.fir.kt @@ -0,0 +1,55 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST -USELESS_CAST +// !LANGUAGE: +ProhibitNonReifiedArraysAsReifiedTypeArguments +class A + +fun test1( + a: Array, + b: Array, + c: Array, + d: Array, + e: Array, + f: Array +) {} + +fun test2( + a: Array?, + b: Array?, + c: Array?, + d: Array?, + e: Array?, + f: Array? +) {} + +fun test3( + a: A>, + b: A>, + c: A>, + d: A>, + e: A>, + f: A> +) {} + +fun test4( + a: Array>, + b: Array>, + c: Array>, + d: Array>, + e: Array>, + f: Array> +) {} + +fun test5() { + arrayOf() + Array(10) { throw Exception() } +} + +fun foo(): Array = (object {} as Any) as Array + +fun test6() = foo() + + +class B(val array: Array) + +fun bar() = B>(arrayOf()) + +fun test7() = bar() diff --git a/compiler/testData/diagnostics/testsWithStdLib/CallCompanionProtectedNonStatic.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/CallCompanionProtectedNonStatic.fir.kt new file mode 100644 index 00000000000..a59b160ba0e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/CallCompanionProtectedNonStatic.fir.kt @@ -0,0 +1,93 @@ +open class VeryBase { + protected fun baz() {} +} + +open class Base { + protected fun foo() { + bar() // Ok + baz() // Ok + } + + inner class Inner { + fun fromInner() { + foo() // Ok + bar() // Ok + gav() // Ok + baz() // Ok + } + } + + class NestedDerived : Base() { + fun fromNestedDerived() { + foo() // Ok + bar() // Ok + gav() // Ok + baz() // Ok + } + } + + companion object : VeryBase() { + var prop = 42 + protected set + + protected fun bar() {} + + @JvmStatic protected fun gav() {} + + class Nested { + fun fromNested() { + bar() // Ok + gav() // Ok + } + } + } +} + +class Derived : Base() { + fun test() { + foo() // Ok + gav() // Ok + bar() + baz() + prop = 0 + } + + inner class DerivedInner { + fun fromDerivedInner() { + foo() // Ok + gav() // Ok + bar() + baz() + prop = 0 + } + } + + companion object { + fun test2() { + gav() // Ok + bar() + baz() + prop = 0 + } + } +} + +class Other { + fun test(base: Base, derived: Derived) { + base.foo() + base.gav() + base.bar() + derived.foo() + derived.gav() + derived.bar() + } +} + +fun top(base: Base, derived: Derived) { + base.foo() + base.bar() + base.gav() + derived.foo() + derived.bar() + derived.gav() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/CallToMainRedeclaredInMultiFile.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/CallToMainRedeclaredInMultiFile.fir.kt new file mode 100644 index 00000000000..93682b82053 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/CallToMainRedeclaredInMultiFile.fir.kt @@ -0,0 +1,8 @@ +// FILE: a.kt +fun main(args: Array) {} + +// FILE: b.kt +fun main(args: Array) {} + +// FILE: c.kt +fun foo() { main(arrayOf("a", "b")) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/InaccessibleInternalClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/InaccessibleInternalClass.fir.kt new file mode 100644 index 00000000000..66c2c487bc3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/InaccessibleInternalClass.fir.kt @@ -0,0 +1,15 @@ +// FILE: a.kt +package p + +class FilteringSequence + +// FILE: b.kt +// SKIP_TXT +package kotlin.sequences + +import p.* + +interface I { + val v1: FilteringSequence + val v2: IndexingSequence +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt new file mode 100644 index 00000000000..9c108459050 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt @@ -0,0 +1,12 @@ +// See KT-10107: 'Variable must be initialized' for delegate with private set + +class My { + var delegate: String by kotlin.properties.Delegates.notNull() + private set + + // Error: Variable 'delegate' must be initialized + val another: String = delegate + + var delegateWithBackingField: String by kotlin.properties.Delegates.notNull() + private set(arg) { field = arg } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/RedeclarationMainInMultiFileClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/RedeclarationMainInMultiFileClass.fir.kt new file mode 100644 index 00000000000..d05cddfe00b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/RedeclarationMainInMultiFileClass.fir.kt @@ -0,0 +1,11 @@ +// FILE: a.kt +@file:JvmName("Util") +@file:JvmMultifileClass + +fun main() {} + +// FILE: b.kt +@file:JvmName("Util") +@file:JvmMultifileClass + +fun main() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/RenameOnImportHidesDefaultImport.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/RenameOnImportHidesDefaultImport.fir.kt new file mode 100644 index 00000000000..fa01f93f89c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/RenameOnImportHidesDefaultImport.fir.kt @@ -0,0 +1,9 @@ +import kotlin.collections.map as map1 +import kotlin.Array as KotlinArray + +fun f() { + listOf(1).map1 { it.hashCode() } + listOf(1).map { it.hashCode() } +} + +fun g(a1: KotlinArray, a2: Array){} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.fir.kt new file mode 100644 index 00000000000..1e5d8fbe0f5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/addAllProjection.fir.kt @@ -0,0 +1,15 @@ +// !WITH_NEW_INFERENCE + +fun test(mc: MutableCollection) { + mc.addAll(mc) + + mc.addAll(arrayListOf()) + mc.addAll(arrayListOf()) + + mc.addAll(listOf("")) + mc.addAll(listOf("")) + mc.addAll(listOf("")) + + mc.addAll(emptyList()) + mc.addAll(emptyList()) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/ClassObjectAnnotatedWithItsKClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/ClassObjectAnnotatedWithItsKClass.fir.kt new file mode 100644 index 00000000000..013dac39c06 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/ClassObjectAnnotatedWithItsKClass.fir.kt @@ -0,0 +1,12 @@ +package test +import kotlin.reflect.KClass + +annotation class AnnClass(val a: KClass<*>) + +class MyClass { + + @AnnClass(MyClass::class) + companion object { + } + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.fir.kt new file mode 100644 index 00000000000..d5260c2165e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER +import kotlin.properties.Delegates + +class My { + @delegate:JvmSynthetic val s: String by lazy { "s" } + + // Both Ok + @get:JvmSynthetic val t: String by lazy { "t" } + @set:JvmSynthetic var z: String by Delegates.observable("?") { prop, old, new -> old.hashCode() } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/Synchronized.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/Synchronized.fir.kt new file mode 100644 index 00000000000..cf98d083a93 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/Synchronized.fir.kt @@ -0,0 +1,31 @@ +import kotlin.jvm.Synchronized + +interface My { + @Synchronized fun foo() + + @Synchronized fun bar() = 1 + + @Synchronized fun baz(): String { + return "abc" + } + + var v: String + @Synchronized get() = "" + @Synchronized set(value) {} +} + +abstract class Your { + @Synchronized abstract fun foo() + + @Synchronized fun bar() = 1 + + @Synchronized open fun baz(): String { + return "xyz" + } + + var v: String + @Synchronized get() = "" + @Synchronized set(value) {} +} + +@Synchronized fun gav() = 1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/SynchronizedOnInterfaceCompanionMember.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/SynchronizedOnInterfaceCompanionMember.fir.kt new file mode 100644 index 00000000000..e2daa315cee --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/SynchronizedOnInterfaceCompanionMember.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +JvmStaticInInterface +// !JVM_TARGET: 1.8 + +interface I { + companion object { + @Synchronized fun syncFun() {} + + @Synchronized @JvmStatic fun syncFunJvmStatic() {} + + var syncProp: String + @Synchronized get() = "" + @Synchronized set(value) {} + + @JvmStatic var syncPropJvmStatic: String + @Synchronized get() = "" + @Synchronized set(value) {} + + var syncPropJvmStaticAccessors: String + @Synchronized @JvmStatic get() = "" + @Synchronized @JvmStatic set(value) {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/TransientOnDelegate.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/TransientOnDelegate.fir.kt new file mode 100644 index 00000000000..30742ed854c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/TransientOnDelegate.fir.kt @@ -0,0 +1,5 @@ +class C { + val plainField: Int = 1 + @delegate:Transient + val lazy by lazy { 1 } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.fir.kt new file mode 100644 index 00000000000..2d571e84c78 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER +import kotlin.jvm.Volatile +import kotlin.properties.Delegates + +class My { + @Volatile val x = 0 + // ok + @Volatile var y = 1 + + @delegate:Volatile var z: String by Delegates.observable("?") { prop, old, new -> old.hashCode() } + + @field:Volatile val w = 2 +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/annotationsOnUseSiteTargets.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/annotationsOnUseSiteTargets.fir.kt new file mode 100644 index 00000000000..5605a746d7e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/annotationsOnUseSiteTargets.fir.kt @@ -0,0 +1,13 @@ +interface Test { + @get:JvmStatic + val a: Int + + @get:JvmName("1") + val b: Int + + @get:Synchronized + val c: Int + + @get:JvmOverloads + val d: Int +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/illegalPlatformName.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/illegalPlatformName.fir.kt new file mode 100644 index 00000000000..72762f42829 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/illegalPlatformName.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@JvmName("") +fun foo(a: Any) {} + +@JvmName(".") +fun foo() {} + +@JvmName("/") +fun fooSlash() {} + +@JvmName("<") +fun fooLT() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmName.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmName.fir.kt new file mode 100644 index 00000000000..2549e6fa027 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmName.fir.kt @@ -0,0 +1,95 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER + +@JvmName("a") +fun foo() {} + +@JvmName("b") +fun Any.foo() {} + +@JvmName("c") +val px = 1 + +@JvmName("d") +val Any.px : Int + get() = 1 + +val valx: Int + @JvmName("e") + get() = 1 + +var varx: Int + @JvmName("f") + get() = 1 + @JvmName("g") + set(v) {} + +var vardef: Int = 1 + @JvmName("h") + get + @JvmName("i") + set + +@JvmName("C") +class C @JvmName("primary") constructor() { + @JvmName("ctr") constructor(x: Int): this() {} + + @JvmName("a") + fun foo() {} + + @JvmName("b") + fun Any.foo() {} + + @JvmName("c") + val px = 1 + + @JvmName("d") + val Any.px : Int + get() = 1 + + val valx: Int + @JvmName("e") + get() = 1 + + var varx: Int + @JvmName("f") + get() = 1 + @JvmName("g") + set(v) {} +} + +fun foo1() { + @JvmName("a") + fun foo() {} + + @JvmName("a") + val x = 1 +} + +abstract class AB { + @JvmName("AB_absFun1") + abstract fun absFun1() + + abstract fun absFun2() + + @JvmName("AB_openFun") + open fun openFun() {} +} + +class D: AB() { + override fun absFun1() {} + + @JvmName("D_absFun2") + override fun absFun2() {} + + @JvmName("D_openFun") + final override fun openFun() {} + + @JvmName("D_finalFun") + fun finalFun() {} +} + +interface Intf { + @get:JvmName("getBar") // no error in IDE + @set:JvmName("setBar") // no error in IDE + var foo: Int +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmNameOnMangledNames.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmNameOnMangledNames.fir.kt new file mode 100644 index 00000000000..1a4c64ebb53 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/jvmNameOnMangledNames.fir.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline class Foo(val x: Int) { + @JvmName("other") + fun simple() {} +} + +@JvmName("bad") +fun bar(f: Foo) {} + +@JvmName("good") +fun baz(r: Result) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPart.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPart.fir.kt new file mode 100644 index 00000000000..14886ffb509 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPart.fir.kt @@ -0,0 +1,19 @@ +@file:JvmName("MultifileClass") +@file:JvmMultifileClass +@file:FileAnn +@file:FileBinaryAnn +@file:FileSourceAnn + +@Target(AnnotationTarget.FILE) +@Retention(AnnotationRetention.RUNTIME) +public annotation class FileAnn + +@Target(AnnotationTarget.FILE) +@Retention(AnnotationRetention.BINARY) +public annotation class FileBinaryAnn + +@Target(AnnotationTarget.FILE) +@Retention(AnnotationRetention.SOURCE) +public annotation class FileSourceAnn + + diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPartWithJavaAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPartWithJavaAnnotation.fir.kt new file mode 100644 index 00000000000..582be7c2473 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/multifileClassPartWithJavaAnnotation.fir.kt @@ -0,0 +1,40 @@ +// FILE: test.kt +@file:JvmName("MultifileClass") +@file:JvmMultifileClass +@file:JavaAnn +@file:JavaClassAnn +@file:JavaSourceAnn + +// FILE: JavaAnn.java +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface JavaAnn { +} + +// FILE: JavaClassAnn.java +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.CLASS) +public @interface JavaClassAnn { +} + +// FILE: JavaSourceAnn.java +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface JavaSourceAnn { +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/suppressOnFunctionReference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/suppressOnFunctionReference.fir.kt new file mode 100644 index 00000000000..eebe8baba18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/suppressOnFunctionReference.fir.kt @@ -0,0 +1,4 @@ +// !WITH_NEW_INFERENCE +// See KT-15839 + +val x = "1".let(@Suppress("DEPRECATION") Integer::parseInt) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt new file mode 100644 index 00000000000..37d863e9cb7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt @@ -0,0 +1,24 @@ +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann(val i: IntArray) + +@Ann(intArrayOf(i)) +@Ann(intArrayOf(i2)) +@Ann(intArrayOf(i3)) +@Ann(intArrayOf(i, i2, i3)) +@Ann(intArrayOf(intArrayOf(i, i2, i3))) +class Test + +var i = 1 +const val i2 = 1 +val i3 = foo() + +fun foo(): Int = 1 + +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class AnnAnn(val i: Array) +@AnnAnn(arrayOf(Ann(intArrayOf(1)))) +@AnnAnn(arrayOf(iAnn)) +class TestAnn +val iAnn = Ann(intArrayOf(1)) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/simple.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/simple.fir.kt new file mode 100644 index 00000000000..d380508fa01 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/simple.fir.kt @@ -0,0 +1,30 @@ +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann(val i: Int) +annotation class AnnIA(val ia: IntArray) +annotation class AnnSA(val sa: Array) + +@Ann(MyClass().i) +@Ann(i) +@Ann(i2) +@AnnIA(ia) +@AnnSA(sa) +class Test { + val i = 1 + @Ann(i) val i2 = 1 +} + +var i = 1 +val i2 = foo() + +fun foo(): Int = 1 + +@AnnSA(emptyArray()) +class MyClass { + val i = 1 +} + +val ia: IntArray = intArrayOf(1, 2) +val sa: Array = arrayOf("a", "b") + +annotation class Ann2 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/useOfNonConstVal.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/useOfNonConstVal.fir.kt new file mode 100644 index 00000000000..469e224f7a9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/useOfNonConstVal.fir.kt @@ -0,0 +1,16 @@ +val nonConst = 1 + +const val constConst = nonConst * nonConst + 2 + +annotation class Ann(val x: Int, val y: String) + +@Ann(nonConst, "${nonConst}") +fun foo1() {} + +@Ann(nonConst + constConst, "${constConst}") +fun foo2() {} + +annotation class ArrayAnn(val x: IntArray) + +@ArrayAnn(intArrayOf(1, constConst, nonConst)) +fun foo3() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt new file mode 100644 index 00000000000..12305a83376 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt @@ -0,0 +1,27 @@ +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class Ann(vararg val i: Int) + +@Ann(i) +@Ann(i2) +@Ann(i3) +@Ann(i, i2, i3) +@Ann(*intArrayOf(i)) +@Ann(*intArrayOf(i2)) +@Ann(*intArrayOf(i3)) +@Ann(*intArrayOf(i, i2, i3)) +class Test + +var i = 1 +const val i2 = 1 +val i3 = foo() + +fun foo(): Int = 1 + +@Retention(AnnotationRetention.SOURCE) +@Repeatable +annotation class AnnAnn(vararg val i: Ann) +@AnnAnn(*arrayOf(Ann(1))) +@AnnAnn(*arrayOf(iAnn)) +class TestAnn +val iAnn = Ann(1) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/kt10136.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/kt10136.fir.kt new file mode 100644 index 00000000000..b9baf44eea1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/kt10136.fir.kt @@ -0,0 +1,8 @@ +annotation class A +annotation class A1(val x: Int) + +annotation class B( + val a: A = A(), + val x: Int = A1(42).x, + val aa: Array = arrayOf(A()) +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/nonConstValAsArgument.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/nonConstValAsArgument.fir.kt new file mode 100644 index 00000000000..69c4619f00e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/nonConstValAsArgument.fir.kt @@ -0,0 +1,34 @@ +import kotlin.reflect.KClass + +annotation class Ann( + val a: Array = arrayOf(readOnly), + val b: Array = arrayOf(withGetter), + val c: Array = arrayOf(func()), + val d: IntArray = intArrayOf(ONE, twoWithGetter), + val e: IntArray = intArrayOf(ONE + twoWithGetter), + val f: Array = arrayOf(mutable), + val g: Array = arrayOf(mutableWithGetter), + val h: Array> = arrayOf(WithLateinit.kClass) +) + +const val ONE = 1 + +val twoWithGetter + get() = 2 + +val readOnly = "" + +val withGetter + get() = "" + +fun func() = "" + +var mutable = "" + +var mutableWithGetter + get() = "" + set(x) = TODO() + +object WithLateinit { + lateinit var kClass: KClass<*> +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithValue.fir.kt new file mode 100644 index 00000000000..464d1bced00 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithValue.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public @interface A { + double b(); + Class x1(); + int a(); + String value(); + Class x(); + Class x2(); +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithoutValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithoutValue.fir.kt new file mode 100644 index 00000000000..97e7759bf6c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/orderWithoutValue.fir.kt @@ -0,0 +1,8 @@ +// FILE: A.java +public @interface A { + double b(); + Class x1(); + int a(); + Class x(); + Class x2(); +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArray.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArray.fir.kt new file mode 100644 index 00000000000..7ec64f27b78 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArray.fir.kt @@ -0,0 +1,23 @@ +// FILE: A.java +public @interface A { + String[] value(); + Class x() default Integer.class; + int y(); +} + +// FILE: b.kt +@A("1", "2", "3", y = 1) fun test1() {} + +@A("4", y = 2) fun test2() {} + +@A(*arrayOf("5", "6"), "7", y = 3) fun test3() {} + +@A("1", "2", "3", x = String::class, y = 4) fun test4() {} + +@A("4", y = 5) fun test5() {} + +@A(*arrayOf("5", "6"), "7", x = Any::class, y = 6) fun test6() {} + +@A(y = 7) fun test7() {} + +@A("8", "9", "10") fun test8() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayAndOtherDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayAndOtherDefault.fir.kt new file mode 100644 index 00000000000..1be46380004 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayAndOtherDefault.fir.kt @@ -0,0 +1,27 @@ +// FILE: A.java +public @interface A { + String[] value(); + Class x() default Integer.class; + int y() default 1; +} + +// FILE: b.kt +@A("1", "2", "3") fun test1() {} + +@A("4") fun test2() {} + +@A(*arrayOf("5", "6"), "7") fun test3() {} + +@A("1", "2", "3", x = String::class) fun test4() {} + +@A("4", y = 2) fun test5() {} + +@A(*arrayOf("5", "6"), "7", x = Any::class, y = 3) fun test6() {} + +@A() fun test7() {} + +@A fun test8() {} + +@A(x = Any::class, *arrayOf("5", "6"), "7", y = 3) fun test9() {} +@A(x = Any::class, value = ["5", "6"], "7", y = 3) fun test10() {} +@A(x = Any::class, value = ["5", "6", "7"], y = 3) fun test11() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayOnly.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayOnly.fir.kt new file mode 100644 index 00000000000..7689996da60 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayOnly.fir.kt @@ -0,0 +1,15 @@ +// FILE: A.java +public @interface A { + String[] value(); +} + +// FILE: b.kt +@A("1", "2", "3") fun test1() {} + +@A("4") fun test2() {} + +@A(*arrayOf("5", "6"), "7") fun test3() {} + +@A() fun test4() {} + +@A fun test5() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayWithDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayWithDefault.fir.kt new file mode 100644 index 00000000000..7617ba14f5c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameters/valueArrayWithDefault.fir.kt @@ -0,0 +1,15 @@ +// FILE: A.java +public @interface A { + String[] value() default {"abc", "cde"}; +} + +// FILE: b.kt +@A("1", "2", "3") fun test1() {} + +@A("4") fun test2() {} + +@A(*arrayOf("5", "6"), "7") fun test3() {} + +@A() fun test4() {} + +@A fun test5() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.fir.kt new file mode 100644 index 00000000000..91397e85f6e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.fir.kt @@ -0,0 +1,11 @@ +// !WITH_NEW_INFERENCE + +// FILE: A.java +public @interface A { + String[] value(); +} + +// FILE: b.kt +@A(*arrayOf(1, "b")) +fun test() { +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.fir.kt new file mode 100644 index 00000000000..f0d690e8101 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.fir.kt @@ -0,0 +1,7 @@ +// !WITH_NEW_INFERENCE + +annotation class B(vararg val args: String) + +@B(*arrayOf(1, "b")) +fun test() { +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingLateinitAccessors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingLateinitAccessors.fir.kt new file mode 100644 index 00000000000..2902dc3abda --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingLateinitAccessors.fir.kt @@ -0,0 +1,14 @@ +// Please make sure that this test is consistent with the blackbox test "annotationsOnLateinitAccessors.kt" + +import kotlin.reflect.KProperty + +annotation class Ann +annotation class AnnRepeat + +class LateinitProperties { + @get:Ann + lateinit var y0: String + + @get:Ann + private lateinit var y1: String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingNonExistentAccessor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingNonExistentAccessor.fir.kt new file mode 100644 index 00000000000..0500ddc0805 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationsTargetingNonExistentAccessor.fir.kt @@ -0,0 +1,114 @@ +// Please make sure that this test is consistent with the blackbox test "annotationsOnNonExistentAccessors.kt" + +import kotlin.reflect.KProperty + +annotation class Ann +annotation class AnnRepeat + +class Foo( + @get:Ann private val y0: Int, + @get:Ann private vararg val y1: String +) { + @get:Ann + private val x1 = "" + + @set:Ann + private var x2 = "" + + @setparam:Ann + private var x3 = "" + + @setparam:[Ann AnnRepeat] + private var x4 = "" + + @get:Ann + internal val x5 = "" + + @get:Ann + protected val x6 = "" + + @get:Ann + private val x7: String = "" + @AnnRepeat get + + @get:Ann + @set:Ann + private var x8: String = "" + get() { return "" } + + @get:Ann + @set:Ann + private var x9: String = "" + get() { return "" } + set(f) { field = f } +} + +private class EffetivelyPrivate private constructor( + @get:Ann val x0: Int, + @get:Ann protected val x1: Int, + @get:Ann internal val x2: Int +) { + private class Nested { + @get:Ann + val fofo = 0 + } +} + +class PrivateToThis { + @get:Ann + @set:Ann + @setparam:Ann + private var x0: I = TODO() +} + +class Statics { + companion object { + @JvmField + @get:Ann + val x0 = "" + + @get:Ann + const val x1 = "" + + @JvmStatic + @get:Ann + val x2 = "" + + @JvmStatic + @get:Ann + private val x3 = "" + + @JvmStatic + @get:Ann + private val x4 = "" + } +} + +private class Other(@param:Ann private val param: Int) { + @property:Ann + @field:Ann + private val other = "" + + private fun @receiver:Ann Int.receiver() {} + + @delegate:Ann + @get:Ann + private val delegate by CustomDelegate() +} + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +@Retention(AnnotationRetention.SOURCE) +annotation class SourceAnn + +class WithSource { + @get:SourceAnn + @set:SourceAnn + @setparam:SourceAnn + private var x0 = "" + + private val x1 = "" + @SourceAnn get +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.fir.kt new file mode 100644 index 00000000000..a3c86dac6b0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.fir.kt @@ -0,0 +1,22 @@ +import kotlin.reflect.KClass + +const val CONST = 1 +fun foo() = 1 +val nonConst = foo() + +annotation class ValidAnn( + val p1: Int = 1 + CONST, + val p2: String = "", + val p3: KClass<*> = String::class, + val p4: IntArray = intArrayOf(1, 2, 3), + val p5: Array = arrayOf("abc"), + val p6: Array> = arrayOf(Int::class) +) + +val nonConstKClass = String::class + +annotation class InvalidAnn( + val p1: Int = foo(), + val p2: Int = nonConst, + val p3: KClass<*> = nonConstKClass +) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.fir.kt new file mode 100644 index 00000000000..37c5c87499d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.fir.kt @@ -0,0 +1,9 @@ +@Metadata +class A + +@Metadata(extraString = "_") +annotation class B(val m: Metadata) + +@Metadata(extraInt = 0) +@B(Metadata()) +fun f() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/annotationAsArgument.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/annotationAsArgument.fir.kt new file mode 100644 index 00000000000..68198f63586 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/annotationAsArgument.fir.kt @@ -0,0 +1,19 @@ +// FILE: A.java +public @interface A { + Class arg() default Integer.class; + int x() default 1; + B b(); +} + +// FILE: B.java +public @interface B { + Class arg() default String.class; + int y() default 2; +} + +// FILE: c.kt +@A(arg = String::class, b = B(y = 1)) class MyClass1 + +@A(b = B(y = 3)) class MyClass2 + +@A(arg = String::class, b = B(arg = Boolean::class)) class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/arg.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/arg.fir.kt new file mode 100644 index 00000000000..f315401b9ec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/arg.fir.kt @@ -0,0 +1,7 @@ +// FILE: A.java +public @interface A { + Class arg(); +} + +// FILE: b.kt +@A(arg = String::class) class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argAndOtherDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argAndOtherDefault.fir.kt new file mode 100644 index 00000000000..8c63da99041 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argAndOtherDefault.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public @interface A { + Class arg(); + int x() default 1; +} + +// FILE: b.kt +@A(arg = String::class) class MyClass1 +@A(arg = String::class, x = 2) class MyClass2 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argArray.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argArray.fir.kt new file mode 100644 index 00000000000..df2e3af5c26 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argArray.fir.kt @@ -0,0 +1,7 @@ +// FILE: A.java +public @interface A { + Class[] arg(); +} + +// FILE: b.kt +@A(arg = arrayOf(String::class, Int::class)) class MyClass diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefault.fir.kt new file mode 100644 index 00000000000..4871b8a02be --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefault.fir.kt @@ -0,0 +1,8 @@ +// FILE: A.java +public @interface A { + Class arg() default Integer.class; +} + +// FILE: b.kt +@A(arg = String::class) class MyClass1 +@A class MyClass2 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefaultAndOther.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefaultAndOther.fir.kt new file mode 100644 index 00000000000..3afac3724b5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/argWithDefaultAndOther.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public @interface A { + Class arg() default Integer.class; + int x(); +} + +// FILE: b.kt +@A(arg = String::class, x = 4) class MyClass2 +@A(x = 5) class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/twoArgs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/twoArgs.fir.kt new file mode 100644 index 00000000000..aa9efe04fa6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/twoArgs.fir.kt @@ -0,0 +1,8 @@ +// FILE: A.java +public @interface A { + Class arg1(); + Class arg2(); +} + +// FILE: b.kt +@A(arg1 = String::class, arg2 = Int::class) class MyClass diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/value.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/value.fir.kt new file mode 100644 index 00000000000..ffd1adc3510 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/value.fir.kt @@ -0,0 +1,8 @@ +// FILE: A.java +public @interface A { + Class value(); +} + +// FILE: b.kt +@A(String::class) class MyClass1 +@A(value = String::class) class MyClass2 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueAndOtherDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueAndOtherDefault.fir.kt new file mode 100644 index 00000000000..35a0ee2d2ae --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueAndOtherDefault.fir.kt @@ -0,0 +1,12 @@ +// FILE: A.java +public @interface A { + Class value(); + int x() default 1; +} + +// FILE: b.kt +@A(String::class) class MyClass1 +@A(value = String::class) class MyClass2 + +@A(String::class, x = 2) class MyClass3 +@A(value = String::class, x = 4) class MyClass4 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueArray.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueArray.fir.kt new file mode 100644 index 00000000000..4fb56532c42 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueArray.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public @interface A { + Class[] value(); +} + +// FILE: b.kt +@A(String::class, Int::class) class MyClass1 +@A(*arrayOf(String::class, Int::class)) class MyClass2 +@A(value = [String::class, Int::class]) class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefault.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefault.fir.kt new file mode 100644 index 00000000000..50c72be5673 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefault.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public @interface A { + Class value() default Integer.class; +} + +// FILE: b.kt +@A(String::class) class MyClass1 +@A(value = String::class) class MyClass2 +@A class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefaultAndOther.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefaultAndOther.fir.kt new file mode 100644 index 00000000000..465a8f35e3d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/javaAnnotationsWithKClassParameter/valueWithDefaultAndOther.fir.kt @@ -0,0 +1,10 @@ +// FILE: A.java +public @interface A { + Class value() default Integer.class; + int x(); +} + +// FILE: b.kt +@A(String::class, x = 2) class MyClass1 +@A(value = String::class, x = 4) class MyClass2 +@A(x = 5) class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.fir.kt new file mode 100644 index 00000000000..7aff9dd45a1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.fir.kt @@ -0,0 +1,60 @@ +// !JVM_TARGET: 1.8 +// !JVM_DEFAULT_MODE: enable + +interface A { + @JvmDefault + fun test(p: T) { + } +} + +interface ANonDefault { + fun test(p: String) {} +} + +interface B : A { + + override fun test(p: T) + {} +} + +interface C : A, ANonDefault { + + override fun test(p: T) + {} + + override fun test(p: String) { + } +} + +interface C1 : C { + override fun test(p: String) { + + } +} + +interface C2 : C, ANonDefault { + override fun test(p: String) { + + } +} + +interface D : ANonDefault, A { + + override fun test(p: T) + {} + + override fun test(p: String) { + } +} + +interface D1 : D { + override fun test(p: String) { + + } +} + +interface D2 : ANonDefault, D { + override fun test(p: String) { + + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.fir.kt new file mode 100644 index 00000000000..c1c6958efb7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.fir.kt @@ -0,0 +1,72 @@ +// !JVM_DEFAULT_MODE: enable +// !JVM_TARGET: 1.8 + +// FILE: JavaInterface.java +public interface JavaInterface { + default void test() {} + + default void testForNonDefault() {} + + void testAbstract(); +} + +// FILE: 1.kt + +interface KotlinInterface : JavaInterface { + @JvmDefault + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +interface KotlinInterface2 : JavaInterface, KotlinInterface { + @JvmDefault + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + + +interface KotlinInterfaceForIndirect : JavaInterface { + +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect { + + @JvmDefault + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +open class KotlinClass : JavaInterface { + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +interface KotlinInterfaceX { + + fun test() {} + + fun testForNonDefault() {} + + fun testAbstract() {} +} + +interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX { + @JvmDefault + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.fir.kt new file mode 100644 index 00000000000..b9e1fa92a73 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.fir.kt @@ -0,0 +1,36 @@ +// !JVM_TARGET: 1.8 + +interface A { + @JvmDefault + fun test() { + } +} + +interface B : A { + +} + + +open class Foo : B +open class Foo2 : B, A + +open class FooNoError : B { + override fun test() { + } +} +open class Foo2NoError : B, A { + override fun test() { + } +} + +class Bar : Foo() +class Bar2 : Foo(), A +class Bar3 : Foo(), B + +open class BarWithJvmDefault : B { + @JvmDefault + override fun test() { + } +} + +class BarWithJvmDefaultSuper: BarWithJvmDefault() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt new file mode 100644 index 00000000000..bc1be09e34d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt @@ -0,0 +1,322 @@ +// !JVM_DEFAULT_MODE: enable +// !JVM_TARGET: 1.8 + +public interface KInterface { + @JvmDefault + fun test(): String { + return "OK"; + } + + @JvmDefault + val property: String + get() = "OK" + + + fun testNonDefault(): String { + return "OK"; + } + + val propertyNonDefault: String + get() = "OK" +} + +// FILE: 1.kt + +interface KotlinInterface : KInterface { + @JvmDefault + fun fooo() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterface.test() + super@KotlinInterface.property + + super@KotlinInterface.testNonDefault() + super@KotlinInterface.propertyNonDefault + } + } + } + + @JvmDefault + val propertyy: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterface.test() + super@KotlinInterface.property + + super@KotlinInterface.testNonDefault() + super@KotlinInterface.propertyNonDefault + } + } + return "" + } + + fun foooNonDefault() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterface.test() + super@KotlinInterface.property + + super@KotlinInterface.testNonDefault() + super@KotlinInterface.propertyNonDefault + } + } + } + + val propertyyNonDefault: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterface.test() + super@KotlinInterface.property + + super@KotlinInterface.testNonDefault() + super@KotlinInterface.propertyNonDefault + } + } + return "" + } + + +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + @JvmDefault + fun foooo() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.property + + super@KotlinInterfaceIndirectInheritance.testNonDefault() + super@KotlinInterfaceIndirectInheritance.propertyNonDefault + } + } + } + + @JvmDefault + val propertyyy: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.property + + super@KotlinInterfaceIndirectInheritance.testNonDefault() + super@KotlinInterfaceIndirectInheritance.propertyNonDefault + } + } + return "" + } + + fun fooooNonDefault() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.property + + super@KotlinInterfaceIndirectInheritance.testNonDefault() + super@KotlinInterfaceIndirectInheritance.propertyNonDefault + } + } + } + + val propertyyyNonDefault: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.property + + super@KotlinInterfaceIndirectInheritance.testNonDefault() + super@KotlinInterfaceIndirectInheritance.propertyNonDefault + } + } + return "" + } +} + +open class KotlinClass : KInterface { + fun foo() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClass.test() + super@KotlinClass.property + + super@KotlinClass.testNonDefault() + super@KotlinClass.propertyNonDefault + } + } + } + + val xproperty: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClass.test() + super@KotlinClass.property + + super@KotlinClass.testNonDefault() + super@KotlinClass.propertyNonDefault + } + } + + return "" + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.property + + super@KotlinClassIndirectInheritance.testNonDefault() + super@KotlinClassIndirectInheritance.propertyNonDefault + } + } + + } + + val property2: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.property + + super@KotlinClassIndirectInheritance.testNonDefault() + super@KotlinClassIndirectInheritance.propertyNonDefault + } + } + return "" + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.property + + super@KotlinClassIndirectInheritance2.testNonDefault() + super@KotlinClassIndirectInheritance2.propertyNonDefault + } + } + } + + val xproperty: String + get() { + super.test() + super.property + + super.testNonDefault() + super.propertyNonDefault + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.property + + super@KotlinClassIndirectInheritance2.testNonDefault() + super@KotlinClassIndirectInheritance2.propertyNonDefault + } + } + return "" + } +} + +fun test() { + KotlinClass().test() + KotlinClass().property + KotlinClass().propertyNonDefault + KotlinClassIndirectInheritance2().test() + KotlinClassIndirectInheritance2().testNonDefault() + KotlinClassIndirectInheritance2().propertyyy + KotlinClassIndirectInheritance2().propertyyyNonDefault + + KotlinClass().test() + KotlinClass().testNonDefault() + KotlinClass().property + KotlinClass().propertyNonDefault +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt new file mode 100644 index 00000000000..7c75e729663 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt @@ -0,0 +1,162 @@ +// !JVM_DEFAULT_MODE: enable +// !JVM_TARGET: 1.8 +// FILE: JavaInterface.java + +public interface JavaInterface { + default String test() { + return "OK"; + } + + default String testOverride() { + return "OK"; + } +} + +// FILE: 1.kt + +interface KotlinInterface : JavaInterface { + @JvmDefault + fun fooo() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + } + + @JvmDefault + val propertyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + return "" + } + + @JvmDefault + override fun testOverride(): String { + return "OK"; + } +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + @JvmDefault + fun foooo() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + } + + @JvmDefault + val propertyyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + return "" + } +} + +open class KotlinClass : JavaInterface { + fun foo() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + } + + val property2: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + return "" + } +} + +fun test() { + KotlinClass().foo() + KotlinClass().property + KotlinClassIndirectInheritance2().foo() + KotlinClassIndirectInheritance2().property + + KotlinClass().test() + KotlinClass().property + KotlinClass().testOverride() + KotlinClassIndirectInheritance().testOverride() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.fir.kt new file mode 100644 index 00000000000..b61ce7a12bb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.fir.kt @@ -0,0 +1,29 @@ +// !JVM_TARGET: 1.8 + +interface B { + + @JvmDefault + fun test() {} + + @JvmDefault + abstract fun test2(s: String = "") + + @JvmDefault + abstract fun test3() + + + @JvmDefault + abstract val prop: String + + @JvmDefault + abstract val prop2: String + + @JvmDefault + val prop3: String + get() = "" + + @JvmDefault + var prop4: String + get() = "" + set(value) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.fir.kt new file mode 100644 index 00000000000..73c1c6de9ae --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.fir.kt @@ -0,0 +1,22 @@ +// !JVM_TARGET: 1.8 + +abstract class A { + + @JvmDefault + fun test() {} + + @JvmDefault + abstract fun test2(s: String = "") + + @JvmDefault + abstract fun test3() +} + +object B { + + @JvmDefault + fun test() {} + + @JvmDefault + fun test2(s: String = "") {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.fir.kt new file mode 100644 index 00000000000..7ac115521e6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.fir.kt @@ -0,0 +1,14 @@ +// !JVM_TARGET: 1.8 +// !JVM_DEFAULT_MODE: enable + +interface B { + + @JvmDefault + val prop1: String + @JvmDefault get() = "" + + + var prop2: String + @JvmDefault get() = "" + @JvmDefault set(value) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.fir.kt new file mode 100644 index 00000000000..9e1c054796d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.fir.kt @@ -0,0 +1,31 @@ +// !JVM_TARGET: 1.8 +// !JVM_DEFAULT_MODE: enable + +interface A { + @JvmDefault + fun test() {} +} + +interface Abstract : A { + override fun test() +} + +interface ANonDefault { + fun test() {} +} + +interface B: A { + override fun test() {} +} + +interface C: ANonDefault, A { + override fun test() {} +} + +interface D: A, ANonDefault { + override fun test() {} +} + +class Foo : A { + override fun test() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.fir.kt new file mode 100644 index 00000000000..f5b65653e85 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.fir.kt @@ -0,0 +1,32 @@ +// !JVM_TARGET: 1.8 +// !JVM_DEFAULT_MODE: enable + +interface A { + @JvmDefault + val test: String + get() = "OK" +} + +interface Abstract : A { + override val test: String +} + +interface ANonDefault { + val test: String + get() = "ANonDefault" +} + +interface B: A { + override val test: String + get() = "B" +} + +interface C: ANonDefault, A { + override val test: String + get() = "C" +} + +interface D: A, ANonDefault { + override val test: String + get() = "C" +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.fir.kt new file mode 100644 index 00000000000..55ae915c290 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.fir.kt @@ -0,0 +1,62 @@ +// !JVM_TARGET: 1.8 +// FILE: 1.kt +interface A { + @JvmDefault + fun test() { + } +} + +// FILE: 2.kt +interface B : A { + +} + +interface C : B { + @JvmDefault + override fun test() { + super.test() + } +} + +open class Foo : B { + override fun test() { + super.test() + } +} +open class Foo2 : B + +open class Bar : Foo2() { + override fun test() { + super.test() + } +} + +open class Bar2 : Bar() { + override fun test() { + super.test() + } +} + +class ManySupers: Foo2(), B { + fun foo() { + super.test() + super.test() + super.test() + } +} + +class ManySupers2: Foo2(), C { + fun foo() { + super.test() + super.test() + super.test() + } +} + +class ManySupers3: Bar2(), C { + fun foo() { + super.test() + super.test() + super.test() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.fir.kt new file mode 100644 index 00000000000..675f9586dc7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.fir.kt @@ -0,0 +1,32 @@ +// !JVM_TARGET: 1.8 +interface A { + @JvmDefault + fun test() { + } +} + +interface B{ + fun test() { + } +} + +interface AB: A, B + +interface BA: B, A + + +interface C : A, B { + @JvmDefault + override fun test() { + super.test() + super.test() + } +} + +interface D : B, A { + @JvmDefault + override fun test() { + super.test() + super.test() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.fir.kt new file mode 100644 index 00000000000..cd2701cd0c0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.fir.kt @@ -0,0 +1,32 @@ +// !JVM_TARGET: 1.8 +interface A { + @JvmDefault + fun test() +} + +interface B{ + fun test() { + } +} + +interface AB: A, B + +interface BA: B, A + +class C : A, B { + override fun test() { + super.test() + } +} + +class D : B, A { + override fun test() { + super.test() + } +} + +class E: B, A { + fun foo() { + super.test() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.fir.kt new file mode 100644 index 00000000000..8df79b04f13 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.fir.kt @@ -0,0 +1,31 @@ +// !JVM_TARGET: 1.8 +interface A { + @JvmDefault + fun test() { + + } +} + +interface B{ + fun test() +} +interface AB : A, B +interface BA : B, A + +class C : A, B { + override fun test() { + super.test() + } +} + +class D : B, A { + override fun test() { + super.test() + } +} + +class E: B, A { + fun foo() { + super.test() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.fir.kt new file mode 100644 index 00000000000..6c733fee156 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.fir.kt @@ -0,0 +1,29 @@ +// !JVM_TARGET: 1.6 + +interface B { + + @JvmDefault + fun test() {} + + @JvmDefault + abstract fun test2(s: String = "") + + @JvmDefault + abstract fun test3() + + + @JvmDefault + abstract val prop: String + + @JvmDefault + abstract val prop2: String + + @JvmDefault + val prop3: String + get() = "" + + @JvmDefault + var prop4: String + get() = "" + set(value) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.fir.kt new file mode 100644 index 00000000000..35b71d2bba0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.fir.kt @@ -0,0 +1,30 @@ +// !JVM_TARGET: 1.8 +// !JVM_DEFAULT_MODE: enable + +interface B { + + @JvmDefault + fun test() {} + + @JvmDefault + abstract fun test2(s: String = "") + + @JvmDefault + abstract fun test3() + + + @JvmDefault + abstract val prop: String + + @JvmDefault + abstract val prop2: String + + @JvmDefault + val prop3: String + get() = "" + + @JvmDefault + var prop4: String + get() = "" + set(value) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/clashWithCompanionObjectField.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/clashWithCompanionObjectField.fir.kt new file mode 100644 index 00000000000..6d48f4be934 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/clashWithCompanionObjectField.fir.kt @@ -0,0 +1,8 @@ +class A { + + @JvmField val clash = 1; + + companion object { + val clash = 1; + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inMultiFileFacade.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inMultiFileFacade.fir.kt new file mode 100644 index 00000000000..968c887cb2a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inMultiFileFacade.fir.kt @@ -0,0 +1,13 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:JvmName("SomeName") + +@JvmField +val c = 4 + +@JvmField +var g = 5 + +class C { + @JvmField + var g = 5 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inSingleFileFacade.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inSingleFileFacade.fir.kt new file mode 100644 index 00000000000..5422d3c7004 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/inSingleFileFacade.fir.kt @@ -0,0 +1,12 @@ +@file:JvmName("SomeName") + +@JvmField +val c = 4 + +@JvmField +var g = 5 + +class C { + @JvmField + var g = 5 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/interface13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/interface13.fir.kt new file mode 100644 index 00000000000..79b17440a69 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/interface13.fir.kt @@ -0,0 +1,59 @@ +// !LANGUAGE: +JvmFieldInInterface + +interface A { + + companion object { + @JvmField + val c = 3 + } +} + + +interface B { + + companion object { + @JvmField + val c = 3 + + @JvmField + val a = 3 + } +} + +interface C { + companion object { + @JvmField + val c = 3 + + val a = 3 + } +} + +interface D { + companion object { + @JvmField + var c = 3 + } +} + + +interface E { + companion object { + @JvmField + private val a = 3 + + @JvmField + internal val b = 3 + + @JvmField + protected val c = 3 + } +} + + +interface F { + companion object { + @JvmField + open val a = 3 + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/jvmFieldApplicability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/jvmFieldApplicability.fir.kt new file mode 100644 index 00000000000..81ad67b7c2f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField/jvmFieldApplicability.fir.kt @@ -0,0 +1,143 @@ +// !LANGUAGE: +NestedClassesInAnnotations +InlineClasses +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +@kotlin.jvm.JvmField +fun foo() { + @kotlin.jvm.JvmField val x = "A" +} + +annotation class DemoAnnotation + +@JvmField +abstract class C : I{ + + @kotlin.jvm.JvmField constructor(s: String) { + } + + @kotlin.jvm.JvmField private fun foo(s: String = "OK") { + } + + @JvmField val a: String by lazy { "A" } + + @JvmField open val b: Int = 3 + + @JvmField abstract val c: Int + + @JvmField + val customGetter: String = "" + get() = field + + @JvmField + val explicitDefaultGetter: String = "" + get + + @JvmField + var explicitDefaultSetter: String = "" + set + + @JvmField + val explicitDefaultAnnotatedGetter: String = "" + @DemoAnnotation get + + @JvmField + var explicitDefaultAnnotatedSetter: String = "" + @DemoAnnotation set + + @JvmField + var customSetter: String = "" + set(s) { + field = s + } + + @JvmField + val noBackingField: String + get() = "a" + + @JvmField + final override val ai = 3 + + @JvmField + private val private = 3 +} + +interface I { + @JvmField val ai: Int + @JvmField val bi: Int + get() = 5 +} + +class G { + @JvmField + lateinit var lateInit: String + + @delegate:JvmField + val s: String by lazy { "s" } +} + +@JvmField +const val Const = 4 + +@JvmField +var i = 5 + +class H { + companion object { + @JvmField + var c = 3 + } +} + +interface K { + + val i: Int + val j: Int + + companion object { + @JvmField + var c = 3 + + var x = 3 + } +} + +class KK : K { + @JvmField + override val i: Int = 0 + @JvmField + override final val j: Int = 0 +} + +open class KKK : K { + @JvmField + override val i: Int = 0 + @JvmField + override final val j: Int = 0 +} + +annotation class L { + companion object { + @JvmField + var c = 3 + } +} + +object O { + @JvmField + val c = 3 +} + +@JvmField +private val private = 3 + +inline class Foo(val x: Int) + +object IObject { + @JvmField + val c: Foo = Foo(42) + + @JvmField + val u = 42u + + @JvmField + private val r: Result = TODO() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/JvmOverloadWithNoDefaults.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/JvmOverloadWithNoDefaults.fir.kt new file mode 100644 index 00000000000..5ddbe4cea11 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/JvmOverloadWithNoDefaults.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class C { + @kotlin.jvm.JvmOverloads constructor() { + } + + @kotlin.jvm.JvmOverloads fun foo(s: String) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAbstractMethods.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAbstractMethods.fir.kt new file mode 100644 index 00000000000..ab222d7bc41 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAbstractMethods.fir.kt @@ -0,0 +1,11 @@ +interface T { + @kotlin.jvm.JvmOverloads fun foo(s: String = "OK") + + @kotlin.jvm.JvmOverloads fun bar(s: String = "OK") { + } +} + + +abstract class C { + @kotlin.jvm.JvmOverloads abstract fun foo(s: String = "OK") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_3.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_3.fir.kt new file mode 100644 index 00000000000..f28b42adf09 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_3.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: -ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses + +annotation class A1 @JvmOverloads constructor(val x: Int = 1) +annotation class A2 @JvmOverloads constructor() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_4.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_4.fir.kt new file mode 100644 index 00000000000..576ebfa6b2f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnAnnotationClassConstructor_1_4.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: +ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses + +annotation class A1 @JvmOverloads constructor(val x: Int = 1) +annotation class A2 @JvmOverloads constructor() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnPrivate.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnPrivate.fir.kt new file mode 100644 index 00000000000..95fc927051a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/jvmOverloadsOnPrivate.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class C { + @kotlin.jvm.JvmOverloads private fun foo(s: String = "OK") { + } + + @kotlin.jvm.JvmOverloads fun bar(s: String = "OK") { + } +} + +fun foo() { + @kotlin.jvm.JvmOverloads fun quux(s: String = "OK") { + } + + class D { + @kotlin.jvm.JvmOverloads fun foo(s: String = "OK") { + } + } + + val x = object { + @kotlin.jvm.JvmOverloads fun foo(s: String = "OK") { + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.fir.kt new file mode 100644 index 00000000000..12ce9ee1123 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE + +// FILE: b.kt +@file:JvmPackageName("") +package b +fun b() {} + +// FILE: c.kt +@file:JvmPackageName("invalid-fq-name") +package c +fun c() {} + +// FILE: d.kt +@file:JvmPackageName("d") +package d +class D +fun d() {} + +// FILE: e.kt +@file:JvmPackageName(42) +package e +fun e() {} + +// FILE: f.kt +@file:JvmPackageName(f) +package f +const val name = "f" diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmSpecialFunctions/apiVersionIsAtLeastHasConstArguments.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmSpecialFunctions/apiVersionIsAtLeastHasConstArguments.fir.kt new file mode 100644 index 00000000000..29c9bf90911 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmSpecialFunctions/apiVersionIsAtLeastHasConstArguments.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT +// FILE: test.kt +package test + +import kotlin.internal.* + +const val ZERO = 0 +const val ONE = 1 + +fun zero() = 0 +val one = 1 + +val test0 = apiVersionIsAtLeast(0, 0, 0) +val testConstVals = apiVersionIsAtLeast(ONE, ONE, ZERO) +val testConstExprs = apiVersionIsAtLeast(ONE + 0, 1 + 0, ((0 + 1 + 0))) +val testNonConstExprs = apiVersionIsAtLeast(one, zero(), one + 1) + +// FILE: apiVersionIsAtLeast.kt +package kotlin.internal + +fun apiVersionIsAtLeast(epic: Int, major: Int, minor: Int): Boolean = + false \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constOrJvmFieldProperty.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constOrJvmFieldProperty.fir.kt new file mode 100644 index 00000000000..3a29c08a590 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constOrJvmFieldProperty.fir.kt @@ -0,0 +1,18 @@ +class A { + + companion object { + + @JvmStatic const val z = 1; + + @JvmStatic @JvmField val x = 1; + } + +} + + +object B { + + @JvmStatic const val z = 1; + + @JvmStatic @JvmField val x = 1; +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty.fir.kt new file mode 100644 index 00000000000..38faac870eb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: -JvmStaticInInterface +class A(@JvmStatic val z: Int) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty_LL13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty_LL13.fir.kt new file mode 100644 index 00000000000..5de49892b9a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructorProperty_LL13.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: +JvmStaticInInterface +class A(@JvmStatic val z: Int) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructors.fir.kt new file mode 100644 index 00000000000..1a3bde84266 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/constructors.fir.kt @@ -0,0 +1,8 @@ +class A { + @JvmStatic constructor() {} + inner class B { + @JvmStatic constructor() {} + } +} + +class C @JvmStatic constructor() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/finalAndAbstract.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/finalAndAbstract.fir.kt new file mode 100644 index 00000000000..a37ff0e192d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/finalAndAbstract.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +abstract class A { + + open fun a() {} + + abstract fun b() + + open fun c() {} +} + +object B: A() { + + @JvmStatic override fun a() {} + + @JvmStatic override fun b() {} + + @JvmStatic final override fun c() {} + + @JvmStatic open fun d() {} +} + +class C { + + companion object: A() { + @JvmStatic override fun a() {} + + @JvmStatic override fun b() {} + + @JvmStatic final override fun c() {} + + @JvmStatic open fun d() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions.fir.kt new file mode 100644 index 00000000000..d638e96691d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions.fir.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: -JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +class A { + companion object { + @JvmStatic fun a1() { + + } + } + + object A { + @JvmStatic fun a2() { + + } + } + + fun test() { + val s = object { + @JvmStatic fun a3() { + + } + } + } + + @JvmStatic fun a4() { + + } +} + +interface B { + companion object { + @JvmStatic fun a1() { + + } + } + + object A { + @JvmStatic fun a2() { + + } + } + + fun test() { + val s = object { + @JvmStatic fun a3() { + + } + } + } + + @JvmStatic fun a4() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.fir.kt new file mode 100644 index 00000000000..9ae6708cd09 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.fir.kt @@ -0,0 +1,53 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: +JvmStaticInInterface +class A { + companion object { + @JvmStatic fun a1() { + + } + } + + object A { + @JvmStatic fun a2() { + + } + } + + fun test() { + val s = object { + @JvmStatic fun a3() { + + } + } + } + + @JvmStatic fun a4() { + + } +} + +interface B { + companion object { + @JvmStatic fun a1() { + + } + } + + object A { + @JvmStatic fun a2() { + + } + } + + fun test() { + val s = object { + @JvmStatic fun a3() { + + } + } + } + + @JvmStatic fun a4() { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt new file mode 100644 index 00000000000..7f69d354701 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt @@ -0,0 +1,54 @@ +// !LANGUAGE: -JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +interface B { + companion object { + @JvmStatic fun a1() { + + } + + @JvmStatic private fun a2() { + + } + + @JvmStatic protected fun a3() { + + } + + @JvmStatic internal fun a4() { + + } + + @JvmStatic + var foo = 1 + + @JvmStatic + var foo1 = 1 + protected set + + @JvmStatic + var foo2 = 1 + private set + + @JvmStatic + private var foo3 = 1 + + @JvmStatic + protected var foo4 = 1 + + @JvmStatic + protected var foo5 = 1 + + @JvmStatic + val foo6 = 1 + + val foo7 = 1 + @JvmStatic get + + private var foo8 = 1 + @JvmStatic public set + + public var foo9 = 1 + @JvmStatic private set + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt new file mode 100644 index 00000000000..073edc66c0f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt @@ -0,0 +1,55 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: +JvmStaticInInterface +interface B { + companion object { + @JvmStatic fun a1() { + + } + + @JvmStatic private fun a2() { + + } + + @JvmStatic protected fun a3() { + + } + + @JvmStatic internal fun a4() { + + } + + @JvmStatic + var foo = 1 + + @JvmStatic + var foo1 = 1 + protected set + + @JvmStatic + var foo2 = 1 + private set + + @JvmStatic + private var foo3 = 1 + + @JvmStatic + protected var foo4 = 1 + + @JvmStatic + protected var foo5 = 1 + + @JvmStatic + val foo6 = 1 + + val foo7 = 1 + @JvmStatic get + + private var foo8 = 1 + @JvmStatic public set + + public var foo9 = 1 + @JvmStatic private set + + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt new file mode 100644 index 00000000000..aafae7e4f93 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt @@ -0,0 +1,56 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !LANGUAGE: +JvmStaticInInterface +// !JVM_TARGET: 1.8 +interface B { + companion object { + @JvmStatic fun a1() { + + } + + @JvmStatic private fun a2() { + + } + + @JvmStatic protected fun a3() { + + } + + @JvmStatic internal fun a4() { + + } + + @JvmStatic + var foo = 1 + + @JvmStatic + var foo1 = 1 + protected set + + @JvmStatic + var foo2 = 1 + private set + + @JvmStatic + private var foo3 = 1 + + @JvmStatic + protected var foo4 = 1 + + @JvmStatic + protected var foo5 = 1 + + @JvmStatic + val foo6 = 1 + + val foo7 = 1 + @JvmStatic get + + private var foo8 = 1 + @JvmStatic public set + + public var foo9 = 1 + @JvmStatic private set + + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.fir.kt new file mode 100644 index 00000000000..b80f0bdead0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: -JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +fun main() { + @JvmStatic fun a(){ + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun_LL13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun_LL13.fir.kt new file mode 100644 index 00000000000..0892836749c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun_LL13.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +fun main() { + @JvmStatic fun a(){ + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property.fir.kt new file mode 100644 index 00000000000..5913ec6959e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: -JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +open class B { + public open val base1 : Int = 1 + public open val base2 : Int = 1 +} + +class A { + companion object : B() { + var p1:Int = 1 + @JvmStatic set(p: Int) { + p1 = 1 + } + + @JvmStatic val z = 1; + + @JvmStatic override val base1: Int = 0 + + override val base2: Int = 0 + @JvmStatic get + } + + object A : B() { + var p:Int = 1 + @JvmStatic set(p1: Int) { + p = 1 + } + + @JvmStatic val z = 1; + + @JvmStatic override val base1: Int = 0 + + @JvmStatic open fun f() {} + + override val base2: Int = 0 + @JvmStatic get + } + + var p:Int = 1 + @JvmStatic set(p1: Int) { + p = 1 + } + + @JvmStatic val z2 = 1; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property_LL13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property_LL13.fir.kt new file mode 100644 index 00000000000..3d44a883fa3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/property_LL13.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +JvmStaticInInterface +// !DIAGNOSTICS: -UNUSED_VARIABLE +open class B { + public open val base1 : Int = 1 + public open val base2 : Int = 1 +} + +class A { + companion object : B() { + var p1:Int = 1 + @JvmStatic set(p: Int) { + p1 = 1 + } + + @JvmStatic val z = 1; + + @JvmStatic override val base1: Int = 0 + + override val base2: Int = 0 + @JvmStatic get + } + + object A : B() { + var p:Int = 1 + @JvmStatic set(p1: Int) { + p = 1 + } + + @JvmStatic val z = 1; + + @JvmStatic override val base1: Int = 0 + + @JvmStatic open fun f() {} + + override val base2: Int = 0 + @JvmStatic get + } + + var p:Int = 1 + @JvmStatic set(p1: Int) { + p = 1 + } + + @JvmStatic val z2 = 1; +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.fir.kt new file mode 100644 index 00000000000..c9bcbb129f4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE + +import kotlin.reflect.KClass + +open class A +class B1 : A() +class B2 : A() + +annotation class Ann1(val arg: Array>) + +@Ann1(arrayOf(A::class)) +class MyClass1 + +@Ann1(arrayOf(Any::class)) +class MyClass1a + +@Ann1(arrayOf(B1::class)) +class MyClass2 + +annotation class Ann2(val arg: Array>) + +@Ann2(arrayOf(A::class)) +class MyClass3 + +@Ann2(arrayOf(B1::class)) +class MyClass4 + +@Ann2(arrayOf(B2::class)) +class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.fir.kt new file mode 100644 index 00000000000..4c8f7fa4288 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.fir.kt @@ -0,0 +1,29 @@ +// !WITH_NEW_INFERENCE + +import kotlin.reflect.KClass + +open class A +class B1 : A() +class B2 : A() + +annotation class Ann1(val arg: Array>) + +@Ann1(arrayOf(A::class)) +class MyClass1 + +@Ann1(arrayOf(Any::class)) +class MyClass1a + +@Ann1(arrayOf(B1::class)) +class MyClass2 + +annotation class Ann2(val arg: Array>) + +@Ann2(arrayOf(A::class)) +class MyClass3 + +@Ann2(arrayOf(B1::class)) +class MyClass4 + +@Ann2(arrayOf(B2::class)) +class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotation.fir.kt new file mode 100644 index 00000000000..640ea5cfb18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotation.fir.kt @@ -0,0 +1,20 @@ +import kotlin.reflect.KClass + +annotation class Ann1(val arg: KClass<*>) +annotation class Ann2(vararg val arg: KClass<*>) +annotation class Ann3(val arg: Array>) + +class A1 +class A2 + +@Ann1(A1::class) +@Ann2(A1::class, A2::class) +@Ann3(arrayOf(A1::class, A2::class)) +class MyClass1 + +@Ann1(A3::class) +class MyClass2 + +val x = A1::class +@Ann1(x) +class MyClass3 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsInVariance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsInVariance.fir.kt new file mode 100644 index 00000000000..0a6c837b9db --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsInVariance.fir.kt @@ -0,0 +1,27 @@ +import kotlin.reflect.KClass + +open class A +class B1 : A() +class B2 : A() + +annotation class Ann1(val arg: KClass) + +@Ann1(A::class) +class MyClass1 + +@Ann1(Any::class) +class MyClass1a + +@Ann1(B1::class) +class MyClass2 + +annotation class Ann2(val arg: KClass) + +@Ann2(A::class) +class MyClass3 + +@Ann2(B1::class) +class MyClass4 + +@Ann2(B2::class) +class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsOutVariance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsOutVariance.fir.kt new file mode 100644 index 00000000000..c8f3653fa84 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInAnnotationsOutVariance.fir.kt @@ -0,0 +1,27 @@ +import kotlin.reflect.KClass + +open class A +class B1 : A() +class B2 : A() + +annotation class Ann1(val arg: KClass) + +@Ann1(A::class) +class MyClass1 + +@Ann1(Any::class) +class MyClass1a + +@Ann1(B1::class) +class MyClass2 + +annotation class Ann2(val arg: KClass) + +@Ann2(A::class) +class MyClass3 + +@Ann2(B1::class) +class MyClass4 + +@Ann2(B2::class) +class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInvariantTP.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInvariantTP.fir.kt new file mode 100644 index 00000000000..d29699497ad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassInvariantTP.fir.kt @@ -0,0 +1,23 @@ +import kotlin.reflect.KClass + +open class A +class B : A() + +annotation class Ann1(val arg: KClass) + +@Ann1(A::class) +class MyClass1 + +@Ann1(Any::class) +class MyClass1a + +@Ann1(B::class) +class MyClass2 + +annotation class Ann2(val arg: KClass) + +@Ann2(A::class) +class MyClass3 + +@Ann2(B::class) +class MyClass4 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassOutArrayInAnnotationsOutVariance.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassOutArrayInAnnotationsOutVariance.fir.kt new file mode 100644 index 00000000000..948fc6161b0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassOutArrayInAnnotationsOutVariance.fir.kt @@ -0,0 +1,7 @@ +import kotlin.reflect.KClass + +open class A +class B1 : A() +class B2 : A() + +annotation class Ann1(val arg: Array>) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/kotlinAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/kotlinAnnotation.fir.kt new file mode 100644 index 00000000000..be23e84ff89 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/kotlinAnnotation.fir.kt @@ -0,0 +1,5 @@ +annotation class Ann(val x: Int, val value: String, val y: Double) + +@Ann(value = "a", x = 1, y = 1.0) fun foo1() {} +@Ann(2, "b", 2.0) fun foo2() {} +@Ann(3, "c", y = 2.0) fun foo3() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt new file mode 100644 index 00000000000..170d4221995 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt @@ -0,0 +1,11 @@ +// FILE: A.java +public @interface A { + int a(); + double b(); + boolean x(); +} + +// FILE: b.kt +@A(false, +1.0, +false, 1, 2) fun foo1() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/typeMismatch.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/typeMismatch.fir.kt new file mode 100644 index 00000000000..3b5db4e2084 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/typeMismatch.fir.kt @@ -0,0 +1,13 @@ +// FILE: A.java +public @interface A { + int a(); + double b(); + boolean x(); +} + +// FILE: b.kt +@A(false, +1.0, +false) fun foo1() {} + +@A(2.0, x = true, b = 2.0) fun foo2() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withValue.fir.kt new file mode 100644 index 00000000000..d2766ff2519 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withValue.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java +public @interface A { + int a(); + double b(); + String value(); + boolean x(); +} + +// FILE: b.kt +@A("v1", 1, +1.0, +false) fun foo1() {} + +@A("v2", 2, x = true, b = 2.0) fun foo2() {} + +@A("v2", x = true, b = 3.0, a = 4) fun foo3() {} +@A(value = "v2", x = true, b = 3.0, a = 4) fun foo4() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.fir.kt new file mode 100644 index 00000000000..b0c8cf02472 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.fir.kt @@ -0,0 +1,17 @@ +// FILE: A.java +public @interface A { + int a(); + double b(); + boolean x(); +} + +// FILE: b.kt +@A(1, +1.0, +false) fun foo1() {} + +@A(2, x = true, b = 2.0) fun foo2() {} + +@A(x = true, b = 3.0, a = 4) fun foo3() {} + + diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.fir.kt new file mode 100644 index 00000000000..3ec4a43aa00 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -JAVA_LANG_CLASS_PARAMETER_IN_ANNOTATION +package a.b.c + +@kotlin.Deprecated("aaa") +@ann1(kotlin.Deprecated("aaa")) + +@a.b.c.ann1() +@ann2(a.b.c.ann1()) + +@A.IAnn() +@ann3(A.IAnn()) + +@a.b.c.A.IAnn() +@ann3(a.b.c.A.IAnn()) + +@annArray(kotlin.arrayOf("a")) +fun test() = 1 + +annotation class ann1(val p: Deprecated = kotlin.Deprecated("aaa")) +annotation class ann2(val p: ann1 = a.b.c.ann1()) +annotation class ann3(val p: A.IAnn = A.IAnn(), val p2: A.IAnn = a.b.c.A.IAnn()) + +annotation class annArray(val p: Array = kotlin.arrayOf("a")) + +class A { + annotation class IAnn +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/strictfpOnClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/strictfpOnClass.fir.kt new file mode 100644 index 00000000000..8d3aa87090d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/strictfpOnClass.fir.kt @@ -0,0 +1,17 @@ +@kotlin.jvm.Strictfp class A { + +} + +@kotlin.jvm.Strictfp object B { + +} + +@kotlin.jvm.Strictfp interface C { + +} + +fun foo() { + @kotlin.jvm.Strictfp class D + + @kotlin.jvm.Strictfp object: Any() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/targetuse.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/targetuse.fir.kt new file mode 100644 index 00000000000..e460ad515b3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/targetuse.fir.kt @@ -0,0 +1,21 @@ +// FILE: TargetUse.java + +import java.lang.annotation.Target; + +public class TargetUse { + public static String foo(kotlin.annotation.Target aTarget) { + return aTarget.toString(); + } + + public static String bar(Target aTarget) { + return aTarget.toString(); + } +} + +// FILE: TargetUse.kt + +import java.lang.annotation.Target as JTarget + +fun fooUse(aTarget: Target): String = TargetUse.foo(aTarget) + +fun barUse(aTarget: JTarget): String = TargetUse.bar(aTarget) diff --git a/compiler/testData/diagnostics/testsWithStdLib/assert/cast.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/assert/cast.fir.kt new file mode 100644 index 00000000000..11505fccf9a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/assert/cast.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// !IGNORE_DATA_FLOW_IN_ASSERT +// SKIP_TXT +// WITH_RUNTIME + +interface A {} + +class B: A { + fun bool() = true +} + +fun test1(a: A) { + assert((a as B).bool()) + a.bool() +} + +fun test2() { + val a: A? = null; + assert((a as B).bool()) + a?.bool() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt new file mode 100644 index 00000000000..dbacaa18056 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/assert/safeCall.fir.kt @@ -0,0 +1,38 @@ +// !WITH_NEW_INFERENCE +// !IGNORE_DATA_FLOW_IN_ASSERT +// SKIP_TXT +// WITH_RUNTIME + +fun test1(s: String?) { + assert(s!!.isEmpty()) + s?.length +} + +fun test2(s: String?) { + assert(s!!.isEmpty()) + s!!.length +} + +fun test3(s: String?) { + assert(s!!.isEmpty()) + s.length +} + +fun test4() { + val s: String? = null; + assert(s!!.isEmpty()) + s?.length +} + +fun test5() { + val s: String? = null; + assert(s!!.isEmpty()) + s!!.length +} + +fun test6() { + val s: String? = null; + assert(s!!.isEmpty()) + s.length +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/builtins/arraysAreCloneable.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builtins/arraysAreCloneable.fir.kt new file mode 100644 index 00000000000..a0cc68a4eec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builtins/arraysAreCloneable.fir.kt @@ -0,0 +1,25 @@ +// !CHECK_TYPE + +fun foo(x: Cloneable) = x + +fun test() { + foo(arrayOf("")) + foo(intArrayOf()) + foo(longArrayOf()) + foo(shortArrayOf()) + foo(byteArrayOf()) + foo(charArrayOf()) + foo(doubleArrayOf()) + foo(floatArrayOf()) + foo(booleanArrayOf()) + + arrayOf("").clone() checkType { _>() } + intArrayOf().clone() checkType { _() } + longArrayOf().clone() checkType { _() } + shortArrayOf().clone() checkType { _() } + byteArrayOf().clone() checkType { _() } + charArrayOf().clone() checkType { _() } + doubleArrayOf().clone() checkType { _() } + floatArrayOf().clone() checkType { _() } + booleanArrayOf().clone() checkType { _() } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/cast/AsInsideIn.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/cast/AsInsideIn.fir.kt new file mode 100644 index 00000000000..7ed4970bc2f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/cast/AsInsideIn.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +// See also KT-10386 +interface A +class B : A +fun foo1(list: List, arg: B?): Boolean { + // Type mismatch + return arg in list // resolved to extension +} +fun foo2(list: List, arg: B?): Boolean { + // FAKE: no cast needed + return arg as A? in list +} +fun foo3(list: List, arg: B?): Boolean { + // No warning but KNPE risk + return arg!! in list +} +// But +fun foo4(list: List, arg: B): Boolean { + // Ok + return arg in list +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.fir.kt new file mode 100644 index 00000000000..b2cfa383fc3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.fir.kt @@ -0,0 +1,5 @@ +fun f(a: Array) = a.isArrayOf() + +fun f1(a: Array) = a is Array<*> + +fun f2(a: Array) = a is Array \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/cast/IsReified.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/cast/IsReified.fir.kt new file mode 100644 index 00000000000..7ebb11298d0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/cast/IsReified.fir.kt @@ -0,0 +1 @@ +fun ff(a: Any) = a is Array<*> && a.isArrayOf() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/commonCollections.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/commonCollections.fir.kt new file mode 100644 index 00000000000..95dad6f9565 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/commonCollections.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE + +import java.util.* +fun foo() { + val al = ArrayList() + al.size + al.contains(1) + al.contains("") + + al.remove("") + al.removeAt(1) + + val hs = HashSet() + hs.size + hs.contains(1) + hs.contains("") + + hs.remove("") + + + val hm = HashMap() + hm.size + hm.containsKey(1) + hm.containsKey("") + + hm[1] + hm[""] + + hm.remove("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/breakContinuesInInlinedLambda.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/breakContinuesInInlinedLambda.fir.kt new file mode 100644 index 00000000000..4451a6280ab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/breakContinuesInInlinedLambda.fir.kt @@ -0,0 +1,51 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun getBoolean(): Boolean = false + +fun test() { + val x: Int + + if (getBoolean()) + myRun { + while (getBoolean()) { + do { + myRun { + if (getBoolean()) { + x = 42 // No reassignment because of break + } + else { + x = 43 // No reassignment because of break + } + } + break + } while (getBoolean()) + // Loop executed exectly once, initializing x + myRun { x.inc() } + + myRun { x = 42 } + break + } + // x is I?D here because loop could've been execited + // VAL_REASSIGNMENT isn't reported because of repeating diagnostic + x = 42 + // x is ID now + } + else + myRun { + x = 42 + } + // x is ID because both branches are ID + + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/expressionBody.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/expressionBody.fir.kt new file mode 100644 index 00000000000..58dd06fbec4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/expressionBody.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun functionWithExpressionBody(x: Int): Boolean = myRun { + if (x == 0) return true + if (x == 1) return false + return functionWithExpressionBody(x - 2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/implicitCastToAnyInReturnType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/implicitCastToAnyInReturnType.fir.kt new file mode 100644 index 00000000000..5b0f4b45bb1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/implicitCastToAnyInReturnType.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun functionWithSideEffects(x: Int): Int = x + 1 // ...and some other useful side-effects + +fun log(s: String) = Unit // some logging or println or whatever returning Unit + +fun implicitCastWithIf(s: String) { + myRun { if (s == "") functionWithSideEffects(42) else log(s) } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/inlinedLambdaAlwaysThrows.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/inlinedLambdaAlwaysThrows.fir.kt new file mode 100644 index 00000000000..8ccf5757a7f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/inlinedLambdaAlwaysThrows.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> Unit): Unit { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun test() { + myRun { throw java.lang.IllegalArgumentException() } + val x: Int = 42 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/irrelevantUnknownClosure.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/irrelevantUnknownClosure.fir.kt new file mode 100644 index 00000000000..7f121224199 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/irrelevantUnknownClosure.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> Unit): Unit { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +inline fun unknownRun(block: () -> Unit) { block() } + +fun foo() { + val x: Int + myRun { + unknownRun { println("shouldn't change anything") } + x = 42 + } + println(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt new file mode 100644 index 00000000000..93b55158aba --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt @@ -0,0 +1,86 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +inline fun T.myLet(block: (T) -> R): R { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block(this) +} + +inline fun unknownRun(block: () -> Unit) = block() + +fun getBool(): Boolean = false + +fun threeLevelsReturnNoInitialization(x: Int?): Int? { + // Inner always jumps to outer + // And middle always calls inner + // So, in fact, middle never finished normally + // Hence 'y = 54' in middle is unreachable, and middle doesn't performs definite initialization + // Hence, outer doesn't performs definite initialization + val y: Int + myRun outer@ { + myRun middle@ { + x.myLet inner@ { + if (it == null) { + y = 42 + return@outer Unit + } + else { + return@outer Unit + } + } + } + // Possible to report unreachable here + y = 54 + } + return y.inc() +} + +fun threeLevelsReturnWithInitialization(x: Int?): Int? { + val y: Int + myRun outer@ { + myRun middle@ { + x.myLet inner@ { + if (it == null) { + y = 42 + return@outer Unit + } + else { + y = 34 + return@outer Unit + } + } + } + } + return y.inc() +} + +fun threeLevelsReturnWithUnknown(x: Int?): Int? { + val y: Int + myRun outer@ { + unknownRun middle@ { + x.myLet inner@ { + if (it == null) { + y = 42 + return@outer Unit + } + else { + y = 34 + return@outer Unit + } + } + } + } + return y.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchFinally.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchFinally.fir.kt new file mode 100644 index 00000000000..db6eeffc9b5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchFinally.fir.kt @@ -0,0 +1,98 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -INVISIBLE_MEMBER -INVISIBLE_REFERENCE +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun innerComputation(): Int = 42 +fun outerComputation(): Int = 52 + +fun log() = Unit + +fun outerFinallyInitializes() { + val x: Int + + try { + myRun { + try { + x = innerComputation() + } catch (e: java.lang.Exception) { + log() + } + // possible reassignment if innerComputation finished + x = 42 + // x is ID here + } + + // Definite reassignment here, cause can get here only if myRun finished + // Not reported because of repeating diagnostic + x = outerComputation() + } catch (e: java.lang.Exception) { + // can catch exception thrown by the inner, so x can be not initialized + x.inc() + log() + } finally { + // Possible reassignment (e.g. if everything finished) + // Not reported because of repeating diagnostic + x = 42 + } + + // Properly initialized + x.inc() +} + +fun innerFinallyInitializes() { + val x: Int + try { + myRun { + try { + innerComputation() + } catch (e: java.lang.Exception) { + log() + } finally { + x = 42 + } + } + + // Properly initialized + x.inc() + } catch (e: java.lang.Exception) { + log() + } + + // Still can be unitialized because we don't know what can happen in try-block + // (e.g., OutOfMemory exception could've happened even before myRun was executed) + x.inc() +} + + +fun innerFinallyInitializesOuterRethrows() { + val x: Int + try { + myRun { + try { + innerComputation() + } catch (e: java.lang.Exception) { + log() + } finally { + x = 42 + } + } + + // Properly initialized + x.inc() + } catch (e: java.lang.Exception) { + log() + throw e + } + + // Guaranteed to be initialized because all catch-clauses are rethrowing + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt new file mode 100644 index 00000000000..af0e303142f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nestedTryCatchs.fir.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun innerComputation(): Int = 42 +fun outerComputation(): Int = 52 + +fun innerTryCatchInitializes() { + val x: Int + + try { + myRun { + try { + x = innerComputation() + x.inc() + } + catch (e: java.lang.Exception) { + // Potential reassignment because x.inc() could threw + x = 42 + x.inc() + } + } + // Can get here only when inlined lambda exited properly, i.e. x is initialized + x.inc() + outerComputation() + + } catch (e: java.lang.Exception) { + // Can get here if innerComputation() threw an exception that wasn't catched by the inner catch (x is not initialized) + // OR if outerComputation() threw an exception (x is initialized because we reach outer computation only when inner finished ok) + // So, x=I? here + x.inc() + + // Potential reasignment + x = 42 + } + // Here x=I because outer try-catch either exited normally (x=I) or catched exception (x=I, with reassingment, though) + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonLocalReturn.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonLocalReturn.fir.kt new file mode 100644 index 00000000000..6b5347c24ce --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonLocalReturn.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun T.myLet(block: (T) -> R): R { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block(this) +} + + +fun nonLocalReturnWithElvis(x: Int?): Int? { + x?.myLet { return 42 } + return x?.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonReturningInlinedLambda.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonReturningInlinedLambda.fir.kt new file mode 100644 index 00000000000..c1a05e5289b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/nonReturningInlinedLambda.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> Unit): Unit { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun getBool(): Boolean = false + +fun withLabeledReturn() { + val y: Int + + val x = myRun outer@ { + myRun { return@outer Unit } + y = 42 + } + + println(y) + println(x) +} + +fun withLabeledReturn2(y: Int) { + myRun outer@ { + myRun { return@outer Unit } + println(y) + } + println(y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/safeCallAndInPlaceReturn.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/safeCallAndInPlaceReturn.fir.kt new file mode 100644 index 00000000000..c154232b52f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/safeCallAndInPlaceReturn.fir.kt @@ -0,0 +1,23 @@ +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun Any?.myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun bad(): String { + val x: String? = null + + x?.myRun { return "" } +} + +fun ok(): String { + val x: String? = null + + x?.run { return "non-null" } ?: return "null" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/severalJumpOutsFromInlinedLambda.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/severalJumpOutsFromInlinedLambda.fir.kt new file mode 100644 index 00000000000..75a48f21ad1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/severalJumpOutsFromInlinedLambda.fir.kt @@ -0,0 +1,79 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun exitOnlyThroughLocalReturns(b: Boolean) { + var x: Int + var s: String + + myRun { + if (b) { + x = 42 + return@myRun + } + + if (!b) { + s = "hello" + x = 42 + return@myRun + } + else { + s = "world" + x = 239 + } + } + + x.inc() + s.length +} + +fun exitOnlyThroughNonLocalReturns(b: Boolean?) { + var x: Int + var s: String + myRun { + if (b == null) { + x = 42 + return + } + + if (b.not()) { + x = 54 + } + + if (x == 42) { + return + } + else { + x = 42 + s = "hello" + return + } + } + + x.inc() + s.length +} + +fun nonLocalReturnAndOrdinaryExit(b: Boolean) { + var x: Int + var s: String + myRun { + if (b) { + x = 42 + return + } + x = 54 + s = "hello" + } + x.inc() + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt new file mode 100644 index 00000000000..326fedbe978 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/throwIfNotCalled.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +inline fun unknownRun(block: () -> T): T = block() + +fun throwIfNotCalled() { + val x: Int + myRun outer@ { + unknownRun { + myRun { + x = 42 + return@outer + } + } + throw java.lang.IllegalArgumentException() + } + // x *is* initialized here, because if myRun was never called -> exception + // were thrown and control flow wouldn't be here + println(x) +} + +fun catchThrowIfNotCalled() { + val x: Int + try { + myRun outer@ { + unknownRun { + myRun { + x = 42 + return@outer + } + } + throw java.lang.IllegalArgumentException() + } + } catch (ignored: java.lang.IllegalArgumentException) { } + + // x *isn't* initialized here! + println(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt new file mode 100644 index 00000000000..f616a5fec21 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatch.fir.kt @@ -0,0 +1,58 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun someComputation(): Int = 42 + +fun tryCatchInlined() { + val x: Int + + myRun { + try { + x = someComputation() + x.inc() + } + catch (e: java.lang.Exception) { + x.inc() + } + } + x = 42 + x.inc() +} + +fun possibleReassignmentInTryCatch() { + val x: Int + + myRun { + try { + x = someComputation() + x.inc() + } + catch (e: java.lang.Exception) { + x = 42 + x.inc() + } + x.inc() + } + x.inc() +} + +fun tryCatchOuter() { + val x: Int + try { + myRun { x = someComputation() } + x.inc() + } + catch (e: java.lang.Exception) { + x.inc() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatchFinally.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatchFinally.fir.kt new file mode 100644 index 00000000000..f4f20190699 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/tryCatchFinally.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_PARAMETER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun someComputation(): Int = 42 + +fun report(x: Int) = Unit + +fun innerTryCatchFinally() { + val x: Int + + myRun { + try { + x = someComputation() + report(x) + } catch (e: java.lang.Exception) { + x = 42 + report(x) + } finally { + x = 0 + } + } + + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/typeMismatch.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/typeMismatch.fir.kt new file mode 100644 index 00000000000..e0015888b81 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/typeMismatch.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun foo(x: Int): Int = x + 1 + +fun typeMismatchInLambda(y: String): Int { + val x = myRun { foo(y) } + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/unreachableCode.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/unreachableCode.fir.kt new file mode 100644 index 00000000000..46fa3404a18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/unreachableCode.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun throwInLambda(): Int { + val x = myRun { throw java.lang.IllegalArgumentException(); 42 } + return x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/valDefiniteReassignment.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/valDefiniteReassignment.fir.kt new file mode 100644 index 00000000000..0618ddbddf3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/valDefiniteReassignment.fir.kt @@ -0,0 +1,75 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun runTwice(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() + return block(); +}; + +fun runOnce(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block(); +}; + +fun valueReassignment() { + val x: Int + x.inc() + runTwice { x = 42 } + x.inc() +} + +fun shadowing() { + val x: Int + runTwice { val x: Int; x = 42; x.inc() } + x.inc() +} + +fun branchingFlow(a: Any?) { + val x: Int + x.inc() + if (a is String) { + runTwice { x = 42 } + } + else { + x = 43 + } + x.inc() +} + +fun branchingFlowWithMissingBranches(a: Any?) { + val x: Int + if (a is String) { + runTwice { x = 42 } + } + + x.inc() +} + +fun repeatingFlow(n: Int) { + val x: Int + x.inc() + + for (i in 1..n) { + runTwice { x = 42 } + } + + x.inc() +} + +fun repeatingFlow2(n: Int) { + val x: Int + + for (i in 1..n) { + runTwice { x = 42 } + } + + x.inc() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varDefiniteInitialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varDefiniteInitialization.fir.kt new file mode 100644 index 00000000000..52614a207e6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varDefiniteInitialization.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun runTwice(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() + return block(); +}; + +fun testInitialization() { + var x: Int + x.inc() + runTwice { x = 42 } + x.inc() + x = 43 + x.inc() +} + +fun repeatingFlow(n: Int) { + var x: Int + for (i in 1..n) { + runTwice { x = 42 } + } + x.inc() +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varIndefiniteIntialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varIndefiniteIntialization.fir.kt new file mode 100644 index 00000000000..5495be36dbf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/atLeastOnce/varIndefiniteIntialization.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun runTwice(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.AT_LEAST_ONCE) + } + block() + return block(); +}; + +fun funWithUnknownInvocations(block: () -> T) = block() + +fun indefiniteFlow() { + var x: Int + + funWithUnknownInvocations { runTwice { x = 42 } } + + x.inc() +} + +fun shadowing() { + var x: Int + runTwice { val x: Int; x = 42; x.inc() } + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt new file mode 100644 index 00000000000..51af3aa7e9d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteInitialization.fir.kt @@ -0,0 +1,92 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun initialization() { + val x: Int + myRun { + x = 42 + 42 + } + x.inc() +} + +fun shadowing() { + val x = 42 + myRun { + val x = 43 + x.inc() + } + x.inc() +} + +fun nestedDefiniteAssignment() { + val x: Int + myRun { + val y = "Hello" + myRun { + x = 42 + } + y.length + } + x.inc() +} + +fun deeplyNestedDefiniteAssignment() { + val x: Int + myRun { + val y: String + myRun { + val z: String + myRun { + z = "Hello" + y = "World" + x = 42 + } + z.length + } + y.length + } + x.inc() +} + +fun branchingFlow(a: Any?) { + val x: Int + + if (a is String) { + myRun { x = 42 } + } + else { + myRun { x = 43 } + } + + x.inc() +} + +fun returningValue() { + val x: Int + val hello = myRun { x = 42; "hello" } + x.inc() + hello.length +} + +fun unknownRun(block: () -> Unit) = block() + +class DefiniteInitializationInInitSection { + val x: Int + val y: Int + + init { + myRun { x = 42 } + unknownRun { y = 239 } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteReassignment.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteReassignment.fir.kt new file mode 100644 index 00000000000..facb05750e3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valDefiniteReassignment.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun reassignmentInUsualFlow() { + val x: Int + myRun { x = 42 } + x = 43 + x.inc() +} + +fun reassignment() { + val x = 42 + myRun { + x = 43 + } + x.inc() +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valIndefiniteInitialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valIndefiniteInitialization.fir.kt new file mode 100644 index 00000000000..f8189380d92 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/valIndefiniteInitialization.fir.kt @@ -0,0 +1,68 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun myRepeat(n: Int, action: () -> Unit) { + contract { + callsInPlace(action) + } + for (i in 1..n) action() +} + +fun branchingIndetermineFlow(a: Any?) { + val x: Int + + if (a is String) { + myRepeat(a.length) { + // Val reassignment because we know that repeat's lambda called in-place + myRun { x = 42 } + } + } + else { + myRun { x = 43 } + } + + x.inc() +} + +fun nonAnonymousLambdas() { + val x: Int + val initializer = { x = 42 } + myRun(initializer) + x.inc() +} + +fun multipleAssignments() { + val x: Int + myRepeat(42) { + // Val reassignment because we know that repeat's lambda called in-place + myRun { x = 42 } + } + x.inc() +} + +fun funWithUnknownInvocations(block: () -> Unit) = block() + +fun nestedIndefiniteAssignment() { + val x: Int + // Captured val initialization reported, because we don't know anything about funWithUnknownInvocations + funWithUnknownInvocations { myRun { x = 42 } } + x.inc() +} + +class InitializationForbiddenInNonInitSection { + val x: Int + + fun setup() { + myRun { x = 42 } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varDefiniteInitalization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varDefiniteInitalization.fir.kt new file mode 100644 index 00000000000..a8f603bad54 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varDefiniteInitalization.fir.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun definiteVarInitialization() { + var x: Int + myRun { x = 42 } + x.inc() +} + +fun definiteVarReassignment() { + var x: Int + myRun { x = 42 } + x.inc() + myRun { x = 43 } + x.inc() + x = 44 + x.inc() +} + +fun nestedVarInitialization() { + var x: Int + myRun { myRun { myRun { x = 42 } } } + x.inc() + myRun { myRun { myRun { x = 42 } } } +} + + +fun notAnExpression() { + var x: Int = 0 + myRun { if (true) x = 42 } + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varIndefiniteInitialization.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varIndefiniteInitialization.fir.kt new file mode 100644 index 00000000000..0c426acd468 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/varIndefiniteInitialization.fir.kt @@ -0,0 +1,51 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myRun(block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block() +} + +fun indefiniteVarReassignment(n: Int) { + var x: Int + repeat(n) { + myRun { x = 42 } + } + x.inc() +} + +fun nonAnonymousLambdas() { + // Named lambdas are not inlined, even in theory it could be done for some simple cases as this one + var x: Int + val initializer = { x = 42 } + myRun(initializer) + x.inc() +} + +fun branchingIndetermineFlow(a: Any) { + var x: Int + + if (a is String) { + repeat(a.length) { + myRun { x = 42 } + } + } + else { + myRun { x = 43 } + } + + x.inc() +} + +fun funWithUnknownInvocations(block: () -> Unit) = block() + +fun nestedIndefiniteAssignment() { + val x: Int + funWithUnknownInvocations { myRun { x = 42 } } + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/withReceiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/withReceiver.fir.kt new file mode 100644 index 00000000000..d6874031a9b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/exactlyOnce/withReceiver.fir.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun T.myLet(block: (T) -> R): R { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + return block(this) +} + +fun initializationWithReceiver(y: String) { + val x: Int + y.myLet { x = 42 } + x.inc() +} + +fun initializationWithSafeCall(y: String?) { + val x: Int + y?.myLet { x = 42 } + x.inc() +} + +fun sanityCheck(x: Int, y: String): Int { + y.let { return x } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/unknown/unknownInvocations.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/unknown/unknownInvocations.fir.kt new file mode 100644 index 00000000000..31a9ce473a5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/initialization/unknown/unknownInvocations.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun inPlace(block: () -> T): T { + contract { + callsInPlace(block) + } + return block() +} + +fun reassignmentAndNoInitializaiton() { + val x: Int + inPlace { x = 42 } + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/callUsualContractFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/callUsualContractFunction.fir.kt new file mode 100644 index 00000000000..1c03aa81914 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/callUsualContractFunction.fir.kt @@ -0,0 +1,42 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +package my + +// Accepts block, can't be distinguished from kotlin.contract without resolve +fun contract(block: () -> Unit) {} + +// Accepts int, potentially can be distinguished from kotlin.contract by PSI, +// but as of Kotlin 1.3.0, we don't do that +fun contract(i: Int) {} + +fun doStuff() {} + +class SomeClass { + + fun contract() {} + + fun callMemberContractWithThis() { + this.contract() + } + + fun callMemberContractWithoutThis() { + contract() + } + + fun callTopLevelSamePsiInMember() { + contract { } + } +} + +fun callTopLevelSamePsi() { + contract { } +} + +fun callTopLevelDifferentPsi() { + contract(42) +} + +fun callTopLevelSamePsiNotFirstStatement() { + doStuff() + contract { } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/booleanComparisons.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/booleanComparisons.fir.kt new file mode 100644 index 00000000000..c0c46f6f189 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/booleanComparisons.fir.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun foo(b: Boolean): Boolean { + contract { + // pointless, can be reduced to just "b" + returns(true) implies (b == true) + } + + return b +} + +fun bar(b: Boolean?): Boolean { + contract { + // not pointless, but not supported yet + returns(true) implies (b == true) + } + if (b == null) throw java.lang.IllegalArgumentException("") + return b +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.fir.kt new file mode 100644 index 00000000000..a4bf44632ad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/callInContractDescription.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun bar(x: Int): Boolean = x == 0 + +fun foo(x: Int): Boolean { + contract { + returns(true) implies (bar(x)) + } + return x == 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.fir.kt new file mode 100644 index 00000000000..b90ac27984b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/contractCallSites.fir.kt @@ -0,0 +1,86 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING + +import kotlin.contracts.* + + +// ============= Class ===================== +open class Class { + fun member(x: Boolean) { + contract { returns() implies (x) } + } + + inline fun inlineMember(x: Boolean) { + contract { returns() implies (x) } + } + + abstract fun abstractMember(x: Boolean) { + contract { returns() implies (x) } + } + + open fun openMemeber(x: Boolean) { + contract { returns() implies (x) } + } + + suspend fun suspendMember(x: Boolean) { + contract { returns() implies (x) } + } +} + + +// ============= Top-level ===================== +fun topLevel(x: Boolean) { + contract { returns() implies (x) } +} + +inline fun inlineTopLevel(x: Boolean) { + contract { returns() implies (x) } +} + +suspend fun suspendTopLevel(x: Boolean) { + contract { returns() implies (x) } +} + +// Top-level operator +operator fun Boolean.plus(x: Boolean): Boolean { + contract { returns() implies (x) } + return x +} + +val topLevelLambda: (Boolean) -> Unit = { x: Boolean -> + contract { returns() implies (x) } +} + +val topLevelAnonymousFunction = fun (x: Boolean) { + contract { returns() implies (x) } +} + +var topLevelPropertyAccessors: Int? = 42 + get() { + contract { returns() implies (field != null) } + return 42 + } + set(value) { + contract { returns() implies (field != null) } + } + + +// ============= Local ===================== +fun test() { + fun localDeclaration(x: Boolean) { + contract { returns() implies (x) } + } + + suspend fun suspendlocalDeclaration(x: Boolean) { + contract { returns() implies (x) } + } + + val localAnonymousFunction = fun (x: Boolean) { + contract { returns() implies (x) } + } + + val localLambda: (Boolean) -> Unit = { x: Boolean -> + contract { returns() implies (x) } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/emptyContract.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/emptyContract.fir.kt new file mode 100644 index 00000000000..eaed628ce7b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/emptyContract.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun emptyContract() { + contract { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt new file mode 100644 index 00000000000..e4745964d0a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING + +import kotlin.contracts.* + +fun ifInContract(x: Any?, boolean: Boolean) { + contract { + if (boolean) { + returns() implies (x is String) + } else { + returns() implies (x is Int) + } + } +} + +fun whenInContract(x: Any?, boolean: Boolean) { + contract { + when (boolean) { + true -> returns() implies (x is String) + else -> returns() implies (x is Int) + } + } +} + +fun forInContract(x: Any?) { + contract { + for (i in 0..1) { + returns() implies (x is String) + } + } +} + +fun whileInContract(x: Any?) { + contract { + while (false) { + returns() implies (x is String) + } + } +} + +fun doWhileInContract(x: Any?) { + contract { + do { + returns() implies (x is String) + } while (false) + } +} + +fun localValInContract(x: Any?) { + contract { + val y: Int = 42 + returns() implies (x is String) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalEqualsCondition.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalEqualsCondition.fir.kt new file mode 100644 index 00000000000..7648c66f380 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalEqualsCondition.fir.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun equalsWithVariables(x: Any?, y: Any?) { + contract { + returns() implies (x == y) + } +} + +fun identityEqualsWithVariables(x: Any?, y: Any?) { + contract { + returns() implies (x === y) + } +} + +fun equalConstants() { + contract { + returns() implies (null == null) + } +} + +fun get(): Int? = null +fun equalNullWithCall() { + contract { + returns() implies (get() == null) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nestedConditionalEffects.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nestedConditionalEffects.fir.kt new file mode 100644 index 00000000000..355fe9efdea --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nestedConditionalEffects.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun foo(boolean: Boolean) { + contract { + (returns() implies (boolean)) implies (!boolean) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nonLambdaLiteralAsArgument.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nonLambdaLiteralAsArgument.fir.kt new file mode 100644 index 00000000000..8744ec7d62e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nonLambdaLiteralAsArgument.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -EXPOSED_PARAMETER_TYPE + +import kotlin.contracts.* + +fun passLambdaValue(l: ContractBuilder.() -> Unit) { + contract(l) +} + +fun passAnonymousFunction(x: Boolean) { + contract(fun ContractBuilder.() { + returns() implies x + }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/notFirstStatement.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/notFirstStatement.fir.kt new file mode 100644 index 00000000000..9ac8ce1004c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/notFirstStatement.fir.kt @@ -0,0 +1,76 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE -REDUNDANT_LABEL_WARNING -UNUSED_PARAMETER -NOTHING_TO_INLINE -CAST_NEVER_SUCCEEDS +// Issues: KT-26153, KT-26191 + +import kotlin.contracts.* + +fun foo(y: Boolean) { + val x: Int = 42 + contract { + returns() implies y + } +} + +inline fun case1(block: () -> Unit) { + val contracts = listOf( + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + }, contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + ) + block() +} + +inline fun case_2(block: () -> Unit) = contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) +} + +fun case_3(block: () -> Unit) { + class Class { + fun innerFun(block2: () -> Unit) { + contract { + callsInPlace(block2, InvocationKind.EXACTLY_ONCE) + } + block2() + } + } + return +} + +inline fun case_4(number: Int?): Boolean { + val cond = number != null + contract { + returns(false) implies (cond) + } as ContractBuilder + return number == null +} + +inline fun case_5(cond: Boolean): Boolean { + run { + contract { + returns(true) implies (cond) + } + } + return true +} + +inline fun case_6(cond: Boolean): Boolean { + run { + val x = 10 + contract { + returns(true) implies (cond) + } + } + return true +} + +fun case_7(cond: Boolean): Boolean { + fun innerFun() { + contract { + returns(true) implies (cond) + } + } + return true +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContract.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContract.fir.kt new file mode 100644 index 00000000000..457ee97992e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContract.fir.kt @@ -0,0 +1,25 @@ +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !LANGUAGE: +UseReturnsEffect +// Issue: KT-26386 + +import kotlin.contracts.* + +fun case_1(): Boolean { + contract { returns(null) implies case_1() } + return true +} + +fun case_2(): Boolean { + contract { returns(null) implies case_3() } + return true +} + +fun case_3(): Boolean { + contract { returns(null) implies case_2() } + return true +} + +fun case_4(): Boolean { + kotlin.contracts.contract { returns(null) implies case_1() } + return true +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.fir.kt new file mode 100644 index 00000000000..1b57f6a6d0f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/recursiveContractCustomContractFunction.fir.kt @@ -0,0 +1,39 @@ +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !LANGUAGE: +UseReturnsEffect +// Issue: KT-26386 + +fun myRun(block: () -> Unit) { + block() +} + +fun contract(block: () -> Unit) { + block() +} + +fun case_1(): Boolean? { + contract { case_1() } + return null +} + +fun case_2(): Boolean? { + contract { case_3() } + return null +} + +fun case_3(): Boolean? { + contract { case_2() } + return null +} + +fun case4() { + contract { + myRun { + val s: String + run { + s = "hello" + } + s.length + } + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.fir.kt new file mode 100644 index 00000000000..59f6cc5db43 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/referenceToProperty.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +class Foo(val x: Int?) { + fun isXNull(): Boolean { + contract { + returns(false) implies (x != null) + } + return x != null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.fir.kt new file mode 100644 index 00000000000..54e338c282f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/typeReferences.fir.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +inline fun referToReifiedGeneric(x: Any?) { + contract { + returns() implies (x is T) + } +} + +class Generic { + fun referToCaptured(x: Any?) { + contract { + returns() implies (x is T) + } + } +} + +fun referToSubstituted(x: Any?) { + contract { + returns() implies (x is Generic) + } +} + +fun referToSubstitutedWithStar(x: Any?) { + contract { + returns() implies (x is Generic<*>) + } +} + +typealias GenericString = Generic +typealias FunctionalType = () -> Unit +typealias SimpleType = Int + +fun referToAliasedGeneric(x: Any?) { + contract { + returns() implies (x is GenericString) + } +} + +fun referToAliasedFunctionType(x: Any?) { + contract { + returns() implies (x is FunctionalType) + } +} + +fun referToAliasedSimpleType(x: Any?) { + contract { + returns() implies (x is SimpleType) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/unlabeledReceiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/unlabeledReceiver.fir.kt new file mode 100644 index 00000000000..51f0c4965ac --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/unlabeledReceiver.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun Any?.foo(): Boolean { + contract { + returns(true) implies (this != null) + } + return this != null +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/fqnContractFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/fqnContractFunction.fir.kt new file mode 100644 index 00000000000..12a37c7caf5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/fqnContractFunction.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.InvocationKind + +inline fun foo(block: () -> Unit) { + kotlin.contracts.contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + } + block() +} + +fun main() { + val x: Int + foo { + x = 42 + } + println(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/rewriteAtSliceFunctor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/rewriteAtSliceFunctor.fir.kt new file mode 100644 index 00000000000..4942fcb9448 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/rewriteAtSliceFunctor.fir.kt @@ -0,0 +1,10 @@ +// See KT-28847 + +class Foo(val str: String?) { + val first = run { + str.isNullOrEmpty() + second + } + + val second = str.isNullOrEmpty() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/useBeforeDeclaration.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/useBeforeDeclaration.fir.kt new file mode 100644 index 00000000000..55a1532bced --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/useBeforeDeclaration.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts + +import kotlin.contracts.* + +fun test(x: Any?) { + if (isString(x)) { + x.length + } +} + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.fir.kt new file mode 100644 index 00000000000..c995b305d84 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseReturnsEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +fun testCheckSmartcast(x: Any?) { + check(x is String) + x.length +} + +fun testCheckUnreachableCode() { + check(false) + // Can't be reported without notion of 'iff' + println("Can't get here!") +} + +fun testCheckWithMessage(x: Any?) { + check(x is String) { "x is not String!" } + x.length +} + +fun testCheckWithFailingMessage(x: Any?) { + check(x is String) { throw kotlin.IllegalStateException("What a strange idea") } + x.length +} + +fun testCheckNotNullWithMessage(x: Int?) { + checkNotNull(x) { "x is null!" } + x.inc() +} + +fun testCheckNotNull(x: Int?) { + checkNotNull(x) + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.fir.kt new file mode 100644 index 00000000000..19704fd1dcd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.fir.kt @@ -0,0 +1,110 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseCallsInPlaceEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +fun testRunWithUnitReturn() { + val x: Int + run { x = 42 } + println(x) +} + +fun testRunWithReturnValue() { + val x: Int + val y = run { + x = 42 + "hello" + } + println(x) + println(y) +} + +fun testRunWithCoercionToUnit() { + val x: Int + run { + x = 42 + "hello" + } +} + +fun testRunWithReceiver(x: Int) { + val s: String + x.run { + s = this.toString() + } + println(s) +} + +fun testWith(x: Int) { + val s: String + with(x) { + s = toString() + } + println(s) +} + +fun testApply(x: Int) { + val y: Int + val z: Int = x.apply { y = 42 } + println(y) + println(z) +} + +fun testAlso(x: Int) { + val y: Int + x.also { y = it + 1 } + println(y) +} + +fun testLet(x: Int) { + val z: Int + val y: String = x.let { + z = 42 + (it + 1).toString() + } + println(z) + println(y) +} + +fun testTakeIf(x: Int?) { + val y: Int + x.takeIf { + y = 42 + it != null + } + println(y) +} + +fun testTakeUnless(x: Int?) { + val y: Int + x.takeIf { + y = 42 + it != null + } + println(y) +} + +fun testRepeatOnVal(x: Int) { + val y: Int + repeat(x) { + // reassignment instead of captured val initialization + y = 42 + } + println(y) +} + +fun testRepeatOnVar(x: Int) { + var y: Int + repeat(x) { + // no reassignment reported + y = 42 + } + // but here we still unsure if 'y' was initialized + println(y) +} + +fun testRepeatOnInitializedVar(x: Int) { + var y: Int = 24 + repeat(x) { + y = 42 + } + println(y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.fir.kt new file mode 100644 index 00000000000..40960b5b21e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseReturnsEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +fun testIsNullOrBlank(x: String?) { + if (x.isNullOrBlank()) { + x.length + } + else { + x.length + } +} + +fun testIsNotNullOrBlank(x: String?) { + if (!x.isNullOrBlank()) { + x.length + } + + x.length +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.fir.kt new file mode 100644 index 00000000000..f33d9520b95 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseReturnsEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +fun testIsNullOrEmpty(x: String?) { + if (x.isNullOrEmpty()) { + x.length + } + else { + x.length + } +} + +fun testIsNotNullOrEmpty(x: String?) { + if (!x.isNullOrEmpty()) { + x.length + } + + x.length +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.fir.kt new file mode 100644 index 00000000000..69c93de9dab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseReturnsEffect +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +fun testRequireSmartcast(x: Any?) { + require(x is String) + x.length +} + +fun testRequireUnreachableCode() { + require(false) + println("Can't get here!") +} + +fun testRequireWithMessage(x: Any?) { + require(x is String) { "x is not String!" } + x.length +} + +fun testRequireWithFailingMessage(x: Any?) { + require(x is String) { throw kotlin.IllegalStateException("What a strange idea") } + x.length +} + +fun tesRequireNotNullWithMessage(x: Int?) { + requireNotNull(x) { "x is null!"} + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.fir.kt new file mode 100644 index 00000000000..7af925daf1b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/synchronize.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +ReadDeserializedContracts +UseCallsInPlaceEffect + +fun test(lock: Any) { + val x: Int + + synchronized(lock) { + x = 42 + } + + x.inc() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/callWithDefaultValue.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/callWithDefaultValue.fir.kt new file mode 100644 index 00000000000..5a9eb941860 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/callWithDefaultValue.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myAssert(condition: Boolean, message: String = "") { + contract { + returns() implies (condition) + } + if (!condition) throw kotlin.IllegalArgumentException(message) +} + +fun test(x: Any?) { + myAssert(x is String) + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/catchExceptionSpilling.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/catchExceptionSpilling.fir.kt new file mode 100644 index 00000000000..1ff2a9cb789 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/catchExceptionSpilling.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myAssert(condition: Boolean) { + contract { + returns() implies (condition) + } + if (!condition) throw kotlin.IllegalArgumentException("Assertion failed") +} + +fun testWithCatch(x: Any?) { + try { + myAssert(x is String) + x.length + } catch (e: java.lang.IllegalArgumentException) { } + + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.fir.kt new file mode 100644 index 00000000000..63f22fe0615 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.fir.kt @@ -0,0 +1,70 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun testEqualsWithConstant(x: Any?) { + if (isString(x) == true) { + x.length + } + else { + x.length + } +} + +fun testNotEqualsWithConstant(x: Any?) { + if (isString(x) != true) { + x.length + } + else { + x.length + } +} + +fun unknownFunction(): Any? = 42 + +fun testEqualsWithUnknown(x: Any?) { + if (isString(x) == unknownFunction()) { + x.length + } + else { + x.length + } + x.length +} + +fun testNotEqualsWithUnknown(x: Any?) { + if (isString(x) != unknownFunction()) { + x.length + } + else { + x.length + } + x.length +} + +fun testEqualsWithVariable(x: Any?, b: Boolean) { + if (isString(x) == b) { + x.length + } + else { + x.length + } +} + +fun testNotEqualsWithVariable(x: Any?, b: Boolean) { + if (isString(x) != b) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt new file mode 100644 index 00000000000..547e0691f2c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt @@ -0,0 +1,104 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun myAssert(condition: Boolean) { + contract { + returns() implies (condition) + } + if (!condition) throw kotlin.IllegalArgumentException("Assertion failed") +} + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun isInt(x: Any?): Boolean { + contract { + returns(true) implies (x is Int) + } + return x is Int +} + +fun notEqualsNull(x: Any?): Boolean { + contract { + returns(true) implies (x != null) + } + return x != null +} + +fun equalsTrue(x: Boolean): Boolean { + contract { + returns(true) implies x + } + return x == true +} + +fun nullWhenNotString(x: Any?): String? { + contract { + returnsNotNull() implies (x is String) + } + return x as? String +} + + + + +// ========== Actual tests ============ + +fun nested1(x: Any?) { + if (equalsTrue(isString(x))) { + x.length + } + else { + x.length + } +} + +fun nested2(x: Any?) { + myAssert(equalsTrue(isString(x))) + x.length +} + +fun nested3(x: Any?) { + myAssert(equalsTrue(notEqualsNull(nullWhenNotString(x)))) + x.length +} + +fun branchedAndNested(x: Any?, y: Any?) { + myAssert(equalsTrue(notEqualsNull(nullWhenNotString(x))) && equalsTrue(isString(y))) + x.length + y.length +} + + +fun br(y: Any?) { + if (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) { + y.length + y.inc() + } +} + +fun branchedAndNestedWithNativeOperators(x: Any?, y: Any?) { + myAssert( + equalsTrue(notEqualsNull(nullWhenNotString(x))) // x is String + && + ( + (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) // y is Int, String + || + equalsTrue(isInt(y) && isString(y)) // y is Int, String + ) + && + (1 == 2 || y is Int || isString(y)) + ) + x.length + y.length + y.inc() +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt new file mode 100644 index 00000000000..809b6ab375b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// +// ISSUE: KT-28672 + +import kotlin.contracts.* + +fun CharSequence?.isNullOrEmpty(): Boolean { + contract { + returns(false) implies (this@isNullOrEmpty != null) + } + + return this == null || this.length == 0 +} + +fun smartcastOnReceiver(s: String?) { + with(s) { + if (isNullOrEmpty()) { + length + } + else { + length + } + } +} + +fun mixedReceiver(s: String?) { + if (!s.isNullOrEmpty()) { + with(s) { + length + } + } else { + with(s) { + length + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.fir.kt new file mode 100644 index 00000000000..d0ba672130a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +ContractsOnCallsWithImplicitReceiver +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// +// ISSUE: KT-28672 + +import kotlin.contracts.* + +fun CharSequence?.isNullOrEmpty(): Boolean { + contract { + returns(false) implies (this@isNullOrEmpty != null) + } + + return this == null || this.length == 0 +} + +fun smartcastOnReceiver(s: String?) { + with(s) { + if (isNullOrEmpty()) { + length + } + else { + length + } + } +} + +fun mixedReceiver(s: String?) { + if (!s.isNullOrEmpty()) { + with(s) { + length + } + } else { + with(s) { + length + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt new file mode 100644 index 00000000000..36be683de7a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt @@ -0,0 +1,61 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + + +fun notIsString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun notIsInt(x: Any?): Boolean { + contract { + returns(false) implies (x !is Int) + } + return x !is Int +} + +fun intersectingInfo(x: Any?, y: Any?) { + if ((isString(x) && y is String) || (!notIsString(x) && !notIsInt(y))) { + x.length + y.length + y.inc() + } + else { + x.length + y.length + y.inc() + } +} + +fun intersectingInfo2(x: Any?, y: Any?) { + // In each arg of "||"-operator presented fact "x is String" which should lead to smartcast. + // Also there are 3 additional facts: "x is Int", "y is String", "y is Int". One + // of them is absent in each arg of "||"-operator, so they *shouldn't* lead to smartcast + + if ((isString(x) && !notIsInt(x) && y is String) || + (!notIsString(x) && isString(y) && y is Int) || + (x is String && !notIsInt(y) && x is Int)) { + x.length + x.inc() + y.length + y.inc() + } + x.length + x.inc() + y.length + y.inc() +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectionTypes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectionTypes.fir.kt new file mode 100644 index 00000000000..145c2eae9bd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectionTypes.fir.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun notIsString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun notIsInt(x: Any?): Boolean { + contract { + returns(false) implies (x is Int) + } + return x !is Int +} + +fun testDeMorgan(x: Any?) { + // !(x !is String || x !is Int) + // x is String && x is Int + if (!(notIsString(x) || notIsInt(x))) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun testDeMorgan2(x: Any?) { + // x !is String || x !is Int + if (notIsString(x) || notIsInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/implicitIff.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/implicitIff.fir.kt new file mode 100644 index 00000000000..e9d58ce0f67 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/implicitIff.fir.kt @@ -0,0 +1,87 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun onlyTrue(b: Boolean): Boolean { + contract { + returns(true) implies (b) + } + return b +} + +fun onlyFalse(b: Boolean): Boolean { + contract { + returns(false) implies (!b) + } + return b +} + +fun trueAndFalse(b: Boolean): Boolean { + contract { + returns(true) implies (b) + returns(false) implies (!b) + } + return b +} + + + +// ==== actual tests ==== + +fun useOnlyTrueInTrueBranch(x: Any?) { + if (onlyTrue(x is String)) { + x.length + } + else { + x.length + } +} + +fun useOnlyTrueInFalseBranch(x: Any?) { + if (onlyTrue(x !is String)) { + x.length + } + else { + // No smartcast here, we don't know that condition is false here + x.length + } +} + +fun useOnlyFalseInTrueBranch(x: Any?) { + if (onlyFalse(x is String)) { + // No smartcast here, we don't know that condition is true here + x.length + } + else { + x.length + } +} + +fun useOnlyFalseInFalseBranch(x: Any?) { + if (onlyFalse(x !is String)) { + x.length + } + else { + x.length + } +} + +fun useTrueAndFalseInTrueBranch(x: Any?) { + if (trueAndFalse(x is String)) { + x.length + } + else { + x.length + } +} + +fun useTrueAndFalseInFalseBranch(x: Any?) { + if (trueAndFalse(x !is String)) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/returnsAndCalls.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/returnsAndCalls.fir.kt new file mode 100644 index 00000000000..003741e33ad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/multieffect/returnsAndCalls.fir.kt @@ -0,0 +1,68 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +UseCallsInPlaceEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun callsAndInverts(b: Boolean, block: () -> Unit): Boolean { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + returns(true) implies (!b) + returns(false) implies b + } + + block() + return !b +} + + + +fun smartcastAndInitialization(x: Any?) { + val y: Int + + if (callsAndInverts(x !is String) { y = 42 }) { + println(y) + x.length + } else { + println(y) + x.length + } + println(y) +} + +fun inPresenceOfLazy(x: Any?, unknownBoolean: Boolean) { + val y: Int + + if (unknownBoolean && callsAndInverts(x !is String) { y = 42 }) { + println(y) + x.length + } + else { + println(y) + x.length + } + println(y) +} + +fun isPresenceOfLazy2(x: Any?, unknownBoolean: Boolean) { + val y: Int + if (unknownBoolean && callsAndInverts(x !is String) { y = 42 }) { + x.length + } + else { + println(y) + x.length + } + println(y) +} + +fun isPresenceOfLazy3(x: Any?, unknownBoolean: Boolean) { + val y: Int + if (unknownBoolean && callsAndInverts(x !is String) { y = 42 }) { + x.length + } + else { + x.length + } + println(y) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/nullabilitySmartcastWhenNullability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/nullabilitySmartcastWhenNullability.fir.kt new file mode 100644 index 00000000000..f91f8ddd50a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/nullabilitySmartcastWhenNullability.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun nullWhenNull(x: Int?): Int? { + contract { + returnsNotNull() implies (x != null) + } + return x?.inc() +} + +fun testNullWhenNull(x: Int?) { + if (nullWhenNull(x) == null) { + x.dec() + } + else { + x.dec() + } + + if (nullWhenNull(x) != null) { + x.dec() + } + else { + x.dec() + } + + x.dec() +} + +// NB. it is the same function as `nullWhenNull`, but annotations specifies other facet of the function behaviour +fun notNullWhenNotNull (x: Int?): Int? { + contract { + returns(null) implies (x == null) + } + return x?.inc() +} + +fun testNotNullWhenNotNull (x: Int?) { + if (notNullWhenNotNull(x) == null) { + x == null + } + else { + x.dec() + } + + if (notNullWhenNotNull(x) != null) { + x.dec() + } + else { + x == null + } + + x.dec() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperator.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperator.fir.kt new file mode 100644 index 00000000000..c71e14966dd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperator.fir.kt @@ -0,0 +1,81 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun trueWhenInt(x: Any?): Boolean { + contract { + returns(true) implies (x is Int) + } + return x is Int +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun falseWhenInt(x: Any?): Boolean { + contract { + returns(false) implies (x is Int) + } + return x !is Int +} + + +// ==== Actual tests ==== + +fun truetrue(x: Any?) { + if (trueWhenString(x) && trueWhenInt(x)) { + x.length + x.inc() + } + x.length + x.inc() +} + +fun truefalse(x: Any?) { + if (trueWhenString(x) && falseWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun falsetrue(x: Any?) { + if (falseWhenString(x) && trueWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun falsefalse(x: Any?) { + if (falseWhenString(x) && falseWhenInt(x)) { + x.length + x.inc() + } + else { + // Note that we can't argue that we have any of smartcasts here, + // because we don't know which one of both arguments was 'false' to bring us here + x.length + x.inc() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithConstant.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithConstant.fir.kt new file mode 100644 index 00000000000..6ef3ca6f18c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithConstant.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + + + + +fun annotatedTrueAndTrue(x: Any?) { + if (trueWhenString(x) && true) { + x.length + } + else { + x.length + } +} + +fun annotatedTrueAndFalse(x: Any?) { + if (trueWhenString(x) && false) { + // Unreachable + x.length + } + else { + x.length + } +} + +fun annotatedFalseAndTrue(x: Any?) { + if (falseWhenString(x) && true) { + x.length + } + else { + x.length + } +} + +fun annotatedFalseAndFalse(x: Any?) { + if (falseWhenString(x) && false) { + // Unreachable + x.length + } + else { + x.length + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithUnknown.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithUnknown.fir.kt new file mode 100644 index 00000000000..79bd086d88b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperatorWithUnknown.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun unknownFunction(x: Any?) = x == 42 + + + + +fun annotatedTrue(x: Any?) { + if (trueWhenString(x) && unknownFunction(x)) { + x.length + } + else { + x.length + } +} + +fun annotatedFalse(x: Any?) { + if (falseWhenString(x) && unknownFunction(x)) { + x.length + } + else { + x.length + } +} + +fun annotatedTrueWithVariable(x: Any?, b: Boolean) { + if (trueWhenString(x) && b) { + x.length + } + else { + x.length + } +} + +fun annotatedFalseWithVariable(x: Any?, b: Boolean) { + if (falseWhenString(x) && b) { + x.length + } + else { + x.length + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsOperator.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsOperator.fir.kt new file mode 100644 index 00000000000..db2ed812e47 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsOperator.fir.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun myEqualsNull(x: Int?): Boolean { + contract { + returns(false) implies (x != null) + } + return x == null +} + +fun myEqualsNotNull(x: Int?): Boolean { + contract { + returns(true) implies (x != null) + } + return x != null +} + +fun testBasicEquals(x: Int?) { + x.inc() + + if (myEqualsNull(x)) { + x.inc() + } + else { + x.inc() + } + + x.inc() +} + +fun testBasicNotEquals(x: Int?) { + x.inc() + + if (myEqualsNotNull(x)) { + x.inc() + } + else { + x.inc() + } + + x.inc() +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsWithNullableBoolean.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsWithNullableBoolean.fir.kt new file mode 100644 index 00000000000..74db3f0de4e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/equalsWithNullableBoolean.fir.kt @@ -0,0 +1,69 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun safeIsString(x: Any?): Boolean? { + contract { + returns(true) implies (x is String) + } + return x?.let { it is String } +} + + + + +fun equalsTrue(x: Any?) { + if (safeIsString(x) == true) { + x.length + } + else { + x.length + } +} + +fun equalsFalse(x: Any?) { + if (safeIsString(x) == false) { + x.length + } + else { + x.length + } +} + +fun equalsNull(x: Any?) { + if (safeIsString(x) == null) { + x.length + } + else { + x.length + } +} + +fun notEqualsTrue(x: Any?) { + if (safeIsString(x) != true) { + x.length + } + else { + x.length + } +} + +fun notEqualsFalse(x: Any?) { + if (safeIsString(x) != false) { + x.length + } + else { + x.length + } +} + +fun notEqualsNull(x: Any?) { + if (safeIsString(x) != null) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/isInstanceOperator.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/isInstanceOperator.fir.kt new file mode 100644 index 00000000000..87ca4fe3448 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/isInstanceOperator.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + + +fun notIsString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + + + + +fun testSimple(x: Any?) { + x.length + + if (isString(x)) { + x.length + } + else { + x.length + } +} + +fun testSpilling(x: Any?) { + x.length + + if (isString(x)) x.length + + x.length +} + +fun testInversion(x: Any?) { + if (notIsString(x)) { + x.length + } + else { + x.length + } +} + +fun testInversionSpilling(x: Any?) { + x.length + + if (notIsString(x)) else x.length + + x.length +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperator.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperator.fir.kt new file mode 100644 index 00000000000..2d34f9ab762 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperator.fir.kt @@ -0,0 +1,78 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun trueWhenInt(x: Any?): Boolean { + contract { + returns(true) implies (x is Int) + } + return x is Int +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun falseWhenInt(x: Any?): Boolean { + contract { + returns(false) implies (x is Int) + } + return x !is Int +} + +fun truetrue(x: Any?) { + if (trueWhenString(x) || trueWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun truefalse(x: Any?) { + if (trueWhenString(x) || falseWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun falsetrue(x: Any?) { + if (falseWhenString(x) || trueWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} + +fun falsefalse(x: Any?) { + if (falseWhenString(x) || falseWhenInt(x)) { + x.length + x.inc() + } + else { + x.length + x.inc() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithConstant.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithConstant.fir.kt new file mode 100644 index 00000000000..d23f3ec6f34 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithConstant.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun annotatedTrueOrTrue(x: Any?) { + if (trueWhenString(x) || true) { + x.length + } + else { + // Unreachable + x.length + } +} + +fun annotatedTrueOrFalse(x: Any?) { + if (trueWhenString(x) || false) { + x.length + } + else { + x.length + } +} + +fun annotatedFalseOrTrue(x: Any?) { + if (falseWhenString(x) || true) { + x.length + } + else { + // Unreachable + x.length + } +} + +fun annotatedFalseOrFalse(x: Any?) { + if (falseWhenString(x) || false) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithUnknown.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithUnknown.fir.kt new file mode 100644 index 00000000000..c923d79e88e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/orOperatorWithUnknown.fir.kt @@ -0,0 +1,60 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun trueWhenString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun falseWhenString(x: Any?): Boolean { + contract { + returns(false) implies (x is String) + } + return x !is String +} + +fun unknownFunction(x: Any?) = x == 42 + + + + +fun annotatedTrue(x: Any?) { + if (trueWhenString(x) || unknownFunction(x)) { + x.length + } + else { + x.length + } +} + +fun annotatedFalse(x: Any?) { + if (falseWhenString(x) || unknownFunction(x)) { + x.length + } + else { + x.length + } +} + +fun annotatedTrueWithVariable(x: Any?, b: Boolean) { + if (trueWhenString(x) || b) { + x.length + } + else { + x.length + } +} + +fun annotatedFalseWithVariable(x: Any?, b: Boolean) { + if (falseWhenString(x) || b) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/partiallyIncorrect.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/partiallyIncorrect.fir.kt new file mode 100644 index 00000000000..5b0a30c506d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/partiallyIncorrect.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun incorrectPartDoesntMatter(x: Any?) { + if (isString(x) && 1) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.fir.kt new file mode 100644 index 00000000000..9d993cd451f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// !WITH_NEW_INFERENCE + +import kotlin.contracts.* + +fun Any?.isNull(): Boolean { + contract { + returns(false) implies (this@isNull != null) + } + return this == null +} + +fun smartcastOnReceiver(x: Int?) { + if (x.isNull()) { + x.inc() + } + else { + x.dec() + } +} + +class UnstableReceiver { + var x: Int? = 42 + + fun smartcastOnUnstableReceiver() { + if (x.isNull()) { + x.inc() + } + else { + x.dec() + } + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.fir.kt new file mode 100644 index 00000000000..96916e514e9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts + +import kotlin.contracts.* + +fun Any.nullWhenString(): Any? { + contract { + returns(null) implies (this@nullWhenString is String) + } + return if (this is String) null else this +} + +fun test(x: Int?) { + if (x?.nullWhenString() == null) { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.fir.kt new file mode 100644 index 00000000000..9a045826426 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.fir.kt @@ -0,0 +1,66 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun myAssert(condition: Boolean) { + contract { + returns() implies (condition) + } + if (!condition) throw kotlin.IllegalArgumentException("Assertion failed") +} + +fun testAssertSmartcast(x: Any?) { + myAssert(x is String) + x.length +} + +fun testInvertedAssert(x: Any?) { + myAssert(x !is String) + x.length +} + +fun testSpilling(x: Any?) { + if (x != null) { + myAssert(x is String) + x.length + } + x.length +} + +fun testAssertInIf(x: Any?) { + if (myAssert(x is String) == Unit) { + x.length + } + else { + x.length + } +} + +fun testTryCatch(x: Any?) { + try { + myAssert(x is String) + x.length + } catch (e: kotlin.IllegalArgumentException) { + + } + x.length +} + +fun testUncertainFlow(x: Any?) { + repeat(x.toString().length) { + myAssert(x is String) + x.length + } + x.length +} + +fun testAtLeastOnceFlow(x: Any?) { + do { + myAssert(x is String) + x.length + } while (x != null) + + x.length +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/typeSmartcastWhenNullability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/typeSmartcastWhenNullability.fir.kt new file mode 100644 index 00000000000..5c032d8b228 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/typeSmartcastWhenNullability.fir.kt @@ -0,0 +1,59 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + + +fun nullWhenString(x: Any?): Int? { + contract { + returns(null) implies (x is String) + } + return if (x is String) null else 42 +} + +fun nullWhenNotString(x: Any?): Int? { + contract { + returns(null) implies (x !is String) + } + return if (x !is String) null else 42 +} + + + + + +// ==== Actual tests ===== + + +fun test1(x: Any?) { + // condition == true <=> function returned null <=> 'x' is String + if (nullWhenString(x) == null) { + x.length + } + else { + x.length + } +} + +fun test2(x: Any?) { + // Observe that condition == false <=>* function returned null <=> 'x' is String + // *correct only for at most binary types, which is exactly the case for nullability comparisons + if (nullWhenString(x) != null) { + x.length + } + else { + x.length + } +} + + +fun test3(x: Any?) { + // condition == false <=> function returned not-null, but we don't know anything about when function returns not-null + if (nullWhenNotString(x) == null) { + x.length + } + else { + x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/unreachableBranches.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/unreachableBranches.fir.kt new file mode 100644 index 00000000000..12cf3f1112b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/unreachableBranches.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +// ===== Definitions ==== +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + + +// ==== Actual tests ======= + +fun implicitAlwaysFalse(x: Any?) { + if (isString(x) && !isString(x)) { + x.length + } + else { + x.length + } +} + +fun implicitAlwaysFalseSpilling(x: Any?) { + if (isString(x) && !isString(x)) { + x.length + } + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/valueOfContractedFunctionIngored.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/valueOfContractedFunctionIngored.fir.kt new file mode 100644 index 00000000000..00937d84442 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/valueOfContractedFunctionIngored.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun f3(value: String?) { + if (!value.isNullOrEmpty() is Boolean) { + value.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubject.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubject.fir.kt new file mode 100644 index 00000000000..0315f2c2357 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubject.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun exhaustive(x: Any?) { + when (isString(x)) { + true -> x.length + false -> x.length + } + + when(!isString(x)) { + true -> x.length + false -> x.length + } +} + +fun smartcastInElse(x: Any?) { + when (isString(x)) { + false -> x.length + else -> x.length + } + + when (!isString(x)) { + true -> x.length + else -> x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubjectNullableBoolean.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubjectNullableBoolean.fir.kt new file mode 100644 index 00000000000..c0e3058acae --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withSubjectNullableBoolean.fir.kt @@ -0,0 +1,56 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun safeIsString(x: Any?): Boolean? { + contract { + returns(true) implies (x is String) + } + return x?.let { it is String } +} + +fun elseWithNullableResult(x: Any?) { + when (safeIsString(x)) { + false -> x.length + else -> x.length + } + + when (safeIsString(x)) { + true -> x.length + else -> x.length + } + + when (safeIsString(x)) { + true -> x.length + false -> x.length + else -> x.length + } + + when (safeIsString(x)) { + true -> x.length + null -> x.length + else -> x.length + } +} + +fun exhaustiveWithNullableResult(x: Any?) { + when (safeIsString(x)) { + true -> x.length + false -> x.length + null -> x.length + } + + when (safeIsString(x)) { + false -> x.length + true -> x.length + null -> x.length + } + + when (safeIsString(x)) { + false -> x.length + null -> x.length + true -> x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withoutSubject.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withoutSubject.fir.kt new file mode 100644 index 00000000000..aea3e2db6da --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/when/withoutSubject.fir.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER + +import kotlin.contracts.* + +fun isString(x: Any?): Boolean { + contract { + returns(true) implies (x is String) + } + return x is String +} + +fun exhaustive(x: Any?) { + when { + isString(x) -> x.length + !isString(x) -> x.length + } + + when { + !isString(x) -> x.length + isString(x) -> x.length + } +} + +fun smartcastInElse(x: Any?) { + when { + !isString(x) -> x.length + else -> x.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.fir.kt new file mode 100644 index 00000000000..f00e93f243d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.fir.kt @@ -0,0 +1,7 @@ +import java.io.InputStream + +fun InputStream.test() { + readBytes() + + readBytes(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.fir.kt new file mode 100644 index 00000000000..df951011425 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.fir.kt @@ -0,0 +1,9 @@ +// !API_VERSION: 1.2 + +import java.io.InputStream + +fun InputStream.test() { + readBytes() + + readBytes(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.fir.kt new file mode 100644 index 00000000000..2af8869417b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.fir.kt @@ -0,0 +1,7 @@ +import kotlin.properties.ReadWriteProperty +import kotlin.properties.Delegates + +class C { + val `x$delegate`: ReadWriteProperty? = null + val x: String? by Delegates.notNull() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNames.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNames.fir.kt new file mode 100644 index 00000000000..6add6273f2c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNames.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@JvmName("bar") +fun foo(a: Any) {} + +fun Any.foo() {} + +@JvmName("barInt") +fun bar(x: List) {} + +@JvmName("barStr") +fun bar(x: List) {} + +class C { + var rwProp: Int + @JvmName("get_rwProp") + get() = 0 + @JvmName("set_rwProp") + set(v) {} + + fun getRwProp(): Int = 123 + fun setRwProp(v: Int) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNamesDuplicate.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNamesDuplicate.fir.kt new file mode 100644 index 00000000000..10d82927fd3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmNamesDuplicate.fir.kt @@ -0,0 +1,53 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@JvmName("bar") +fun foo(a: Any) {} + +fun bar(a: Any) {} + +class C { + @JvmName("foo1") + fun foo(list: List) {} + + @JvmName("foo1") + fun foo(list: List) {} +} + +// Conflicts in inheritance. + +// A1 -> B1 with accidental override + +open class A1 { + @JvmName("bar") + open fun foo() {} +} + +class B1 : A1() { + fun bar() {} +} + +// A2 -> B2 with intended override and conflicting JVM declarations + +open class A2 { + @JvmName("bar") + open fun foo() {} +} + +class B2 : A2() { + override fun foo() {} + + fun bar() {} +} + +// A3 -> B3 -> C3 with accidental override + +open class A3 { + @JvmName("bar") + open fun foo() {} +} + +open class B3: A3() { +} + +class C3: B3() { + fun bar() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.fir.kt new file mode 100644 index 00000000000..a394011a653 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class A { + @kotlin.jvm.JvmOverloads fun foo(s: String = "") { + } + + fun foo() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInClassObject.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInClassObject.fir.kt new file mode 100644 index 00000000000..75dbf07a49b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInClassObject.fir.kt @@ -0,0 +1,9 @@ +open class Base { + fun foo() {} +} + +class Derived : Base() { + companion object { + @JvmStatic fun foo() {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInObject.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInObject.fir.kt new file mode 100644 index 00000000000..4d62b986a12 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmStaticInObject.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class Base { + fun `foo$default`(i: Int, mask: Int, mh: Any) {} +} + +object Derived : Base() { + @JvmStatic fun foo(i: Int = 0) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jjk.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jjk.fir.kt new file mode 100644 index 00000000000..15daf06a85c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jjk.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: B.java + +public class B extends A { + public static void bar(int i) {} +} + +// FILE: K.kt + +open class K : B() { + companion object { + @JvmStatic + fun foo() {} + @JvmStatic + fun foo(a: Any) {} + @JvmStatic + fun bar(i: Int) {} + @JvmStatic + fun bar(i: String) {} + @JvmStatic + fun baz(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jk.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jk.fir.kt new file mode 100644 index 00000000000..afa092473d0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jk.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: K.kt + +open class K : A() { + companion object { + @JvmStatic + fun foo() {} + @JvmStatic + fun foo(i: Int) {} + @JvmStatic + fun baz(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jkjk.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jkjk.fir.kt new file mode 100644 index 00000000000..4cbfbe6900e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/jkjk.fir.kt @@ -0,0 +1,36 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: A.java + +public class A { + public static void foo() {} + public static void baz(String s) {} +} + +// FILE: B.kt + +open class B : A() { +} + +// FILE: C.java + +public class C extends B { + public static void bar(int i) {} +} + +// FILE: K.kt + +open class K : C() { + companion object { + @JvmStatic + fun foo() {} + @JvmStatic + fun foo(a: Any) {} + @JvmStatic + fun bar(i: Int) {} + @JvmStatic + fun bar(i: String) {} + @JvmStatic + fun baz(i: Int) {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt new file mode 100644 index 00000000000..8b4d5883db4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/statics/kotlinMembersVsJavaNonVisibleStatics.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: foo/A.java + +package foo; + +public class A { + private static void foo(int s) {} + static void bar(double s) {} +} + +// FILE: K.kt +import foo.A + +open class K : A() { + companion object { + @JvmStatic + fun foo(i: Int) {} + @JvmStatic + fun bar(d: Double) {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.fir.kt new file mode 100644 index 00000000000..9c95f9f8929 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE + +// FILE: P.java + +import java.util.ArrayList; +import java.util.List; + +public class P { + public List getList() { + return new ArrayList(); + } +} + +// FILE: Test.kt + +fun foo(c: P): MutableList { + // Error should be here: see KT-8168 Typechecker fails for platform collection type + return c.getList() ?: listOf() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/elvisOnUnitInLet.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/elvisOnUnitInLet.fir.kt new file mode 100644 index 00000000000..a4e9d5b483f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/elvisOnUnitInLet.fir.kt @@ -0,0 +1,9 @@ +fun foo(x: Int?) { + // Both parts of the Elvis should be alive, see KT-7936 + x?.let { + smth() + }?: orElse() +} + +fun smth() {} +fun orElse() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.fir.kt new file mode 100644 index 00000000000..031c167292b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/annotation.fir.kt @@ -0,0 +1,136 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS, + AnnotationTarget.VALUE_PARAMETER) +annotation class ExperimentalAPI + +@ExperimentalAPI +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS, + AnnotationTarget.VALUE_PARAMETER) +annotation class EAnno + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +@ExperimentalAPI +@EAnno fun function() {} + +@ExperimentalAPI +fun parameter(@EAnno p: String) {} + +@ExperimentalAPI +fun parameterType(p: @EAnno String) {} + +@ExperimentalAPI +fun returnType(): @EAnno Unit {} + +@ExperimentalAPI +@EAnno val property = "" + +@ExperimentalAPI +@EAnno typealias Typealias = Unit + +@ExperimentalAPI +@EAnno class Klass + +@ExperimentalAPI +annotation class AnnotationArgument(val p: EAnno) + +@ExperimentalAPI +fun insideBody() { + @EAnno fun local() {} +} + +@ExperimentalAPI +fun inDefaultArgument(f: () -> Unit = @EAnno fun() {}) {} + +@ExperimentalAPI +val inProperty = @EAnno fun() {} + +@ExperimentalAPI +val inPropertyAccessor: () -> Unit + get() = @EAnno fun() {} + +// FILE: usage-use.kt + +package usage2 + +import api.* + +@UseExperimental(ExperimentalAPI::class) +@EAnno fun function() {} + +@UseExperimental(ExperimentalAPI::class) +fun parameter(@EAnno p: String) {} + +@UseExperimental(ExperimentalAPI::class) +fun parameterType(p: @EAnno String) {} + +@UseExperimental(ExperimentalAPI::class) +fun returnType(): @EAnno Unit {} + +@UseExperimental(ExperimentalAPI::class) +@EAnno val property = "" + +@UseExperimental(ExperimentalAPI::class) +@EAnno typealias Typealias = Unit + +@UseExperimental(ExperimentalAPI::class) +@EAnno class Klass + +@UseExperimental(ExperimentalAPI::class) +annotation class AnnotationArgument(val p: EAnno) + +fun insideBody() { + @UseExperimental(ExperimentalAPI::class) @EAnno fun local() {} +} + +fun inDefaultArgument(@UseExperimental(ExperimentalAPI::class) f: () -> Unit = @EAnno fun() {}) {} + +@UseExperimental(ExperimentalAPI::class) +val inProperty = @EAnno fun() {} + +val inPropertyAccessor: () -> Unit + @UseExperimental(ExperimentalAPI::class) + get() = @EAnno fun() {} + +// FILE: usage-none.kt + +package usage3 + +import api.* + +@EAnno fun function() {} + +fun parameter(@EAnno p: String) {} + +fun parameterType(p: @EAnno String) {} + +fun returnType(): @EAnno Unit {} + +@EAnno val property = "" + +@EAnno typealias Typealias = Unit + +@EAnno class Klass + +annotation class AnnotationArgument(val p: EAnno) + +fun insideBody() { + @EAnno fun local() {} +} + +fun inDefaultArgument(f: () -> Unit = @EAnno fun() {}) {} + +val inProperty = @EAnno fun() {} + +val inPropertyAccessor: () -> Unit + get() = @EAnno fun() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.fir.kt new file mode 100644 index 00000000000..0e2663bf6bd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsages.fir.kt @@ -0,0 +1,30 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +annotation class ExperimentalAPI + +interface I + +@ExperimentalAPI +class Impl : I + +// FILE: usage.kt + +package usage + +import api.* + +open class Base(val i: I) + +@UseExperimental(ExperimentalAPI::class) +class Derived : Base(Impl()) + +@UseExperimental(ExperimentalAPI::class) +class Delegated : I by Impl() + +@UseExperimental(ExperimentalAPI::class) +val delegatedProperty by Impl() +operator fun I.getValue(x: Any?, y: Any?) = null diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsagesAndInline.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsagesAndInline.fir.kt new file mode 100644 index 00000000000..d9629d2f927 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/bodyUsagesAndInline.fir.kt @@ -0,0 +1,83 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +annotation class API + +@API +fun f() {} + +// FILE: usage.kt + +package usage + +import api.* + +fun use1() { + f() +} + +val use2 = f() + +// FILE: inline-usage.kt + +package usage + +import api.* + +inline fun inlineUse1() { + f() +} + +inline var inlineUse2: Unit + get() { + f() + } + set(value) { + f() + } + +var inlineUse3: Unit + inline get() { + f() + } + @API + inline set(value) { + f() + } + +@API +inline fun inlineUse4() { + f() +} + +// FILE: private-inline-usage.kt + +package usage + +import api.* + +private inline fun privateInline1() { + f() +} + +internal inline fun privateInline2() { + f() +} + +private inline var privateInline3: Unit + get() { + f() + } + set(value) { + f() + } + +internal class InternalClass { + inline fun privateInline4() { + f() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.fir.kt new file mode 100644 index 00000000000..0c8699c638b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembers.fir.kt @@ -0,0 +1,88 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) +annotation class ExperimentalAPI + +@ExperimentalAPI +class C { + fun function(): String = "" + val property: String = "" + class Nested + inner class Inner +} + +@ExperimentalAPI +fun C.extension() {} + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +@ExperimentalAPI +fun useAll() { + val c: C = C() + c.function() + c.property + C.Nested() + c.Inner() + c.extension() +} + +@ExperimentalAPI +class Use { + fun useAll(c: C) { + c.function() + c.property + C.Nested() + c.Inner() + c.extension() + } +} + +// FILE: usage-use.kt + +package usage2 + +import api.* + +@UseExperimental(ExperimentalAPI::class) +fun useAll() { + val c: C = C() + c.function() + c.property + C.Nested() + c.Inner() + c.extension() +} + +@UseExperimental(ExperimentalAPI::class) +class Use { + fun useAll(c: C) { + c.function() + c.property + C.Nested() + c.Inner() + c.extension() + } +} + +// FILE: usage-none.kt + +package usage3 + +import api.* + +fun use() { + val c: C = C() + c.function() + c.property + C.Nested() + c.Inner() + c.extension() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.fir.kt new file mode 100644 index 00000000000..ca6192f1c87 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/classMembersOverlyExperimental.fir.kt @@ -0,0 +1,36 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +annotation class ExperimentalAPI + +@ExperimentalAPI +class C { + @ExperimentalAPI + fun function() {} + + @ExperimentalAPI + val property: String = "" + + @ExperimentalAPI + class Nested { + @ExperimentalAPI + fun nestedFunction() {} + } +} + +// FILE: usage.kt + +package usage + +import api.* + +fun use() { + val c: C = C() + c.function() + c.property + C.Nested().nestedFunction() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.fir.kt new file mode 100644 index 00000000000..229705b4db8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.fir.kt @@ -0,0 +1,43 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION) +annotation class ExperimentalAPI + +@ExperimentalAPI +const val MEANING = 42 + +annotation class Anno(val value: Int) + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +@ExperimentalAPI +@Anno(MEANING) +fun usage() {} + +// FILE: usage-use.kt + +@file:UseExperimental(ExperimentalAPI::class) +package usage2 + +import api.* + +// TODO: there should be no warning here +@Anno(MEANING) +fun usage() {} + +// FILE: usage-none.kt + +package usage3 + +import api.* + +@Anno(MEANING) +fun usage() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.fir.kt new file mode 100644 index 00000000000..518fe17fea4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/deeplyNestedClass.fir.kt @@ -0,0 +1,57 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) +annotation class ExperimentalAPI + +@ExperimentalAPI +class C { + class D { + class E { + class F + } + } +} + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +@ExperimentalAPI +fun use1() { + C.D.E.F() +} + +@ExperimentalAPI +fun use2(f: C.D.E.F) = f.hashCode() + +// FILE: usage-use.kt + +package usage2 + +import api.* + +@UseExperimental(ExperimentalAPI::class) +fun use1() { + C.D.E.F() +} + +@UseExperimental(ExperimentalAPI::class) +fun use2(f: C.D.E.F) = f.hashCode() + +// FILE: usage-none.kt + +package usage3 + +import api.* + +fun use1() { + C.D.E.F() +} + +fun use2(f: C.D.E.F) = f.hashCode() diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.fir.kt new file mode 100644 index 00000000000..1152354a790 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/errors.fir.kt @@ -0,0 +1,26 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental +annotation class E + +open class Base { + @E + open fun foo() {} +} + +// FILE: usage.kt + +package usage + +import api.* + +class Derived : Base() { + override fun foo() {} +} + +fun test(b: Base) { + b.foo() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.fir.kt new file mode 100644 index 00000000000..4c9a92f8f84 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalIsNotEnabled.fir.kt @@ -0,0 +1,23 @@ +// FILE: api.kt + +@Experimental +annotation class Marker + +@Marker +fun f() {} + +// FILE: usage.kt + +fun use1() { + f() +} + +@Marker +fun use2() { + f() +} + +@UseExperimental(Marker::class) +fun use3() { + f() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.fir.kt new file mode 100644 index 00000000000..b05884b7a67 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalOnWholeModule.fir.kt @@ -0,0 +1,23 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// !EXPERIMENTAL: api.ExperimentalAPI +// MODULE: api +// FILE: api.kt + +package api + +@Experimental +annotation class ExperimentalAPI + +@ExperimentalAPI +fun function(): String = "" + +// MODULE: usage(api) +// FILE: usage.kt + +package usage + +import api.* + +fun use() { + function() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalUnsignedLiterals.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalUnsignedLiterals.fir.kt new file mode 100644 index 00000000000..2542462f639 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/experimentalUnsignedLiterals.fir.kt @@ -0,0 +1,33 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -UNUSED_EXPRESSION, -UNUSED_VARIABLE, -UNUSED_PARAMETER + +fun test() { + 42u + 21UL + val list = listOf( + 1u, + 0xFFu, + 0xbbU + ) + + takeAll( + 1u, + 2u, + 3u, + 4u, + 5u + ) + + @UseExperimental(ExperimentalUnsignedTypes::class) 42u +} + +fun takeAll( + b: UByte, + s: UShort, + i: UInt, + l: ULong, + vararg uints: UInt +) {} + +const val unsignedConst = 0u +const val unsignedLongConst = 0uL diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/fullFqNameUsage.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/fullFqNameUsage.fir.kt new file mode 100644 index 00000000000..f3ef9111d2c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/fullFqNameUsage.fir.kt @@ -0,0 +1,12 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental + +package test.abc + +@Experimental +annotation class E + +@UseExperimental(test.abc.E::class) +fun f() {} + +@test.abc.E +fun g() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/importStatement.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/importStatement.fir.kt new file mode 100644 index 00000000000..724647e4367 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/importStatement.fir.kt @@ -0,0 +1,27 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package feature.experimental.self + +@Experimental +annotation class ImportedMarker + +@ImportedMarker +object ImportedClass { + @ImportedMarker + fun importedObjectMember() {} +} + +@ImportedMarker +fun importedFunction() {} + +@ImportedMarker +val importedProperty = Unit + +// FILE: usage.kt + +import feature.experimental.self.ImportedMarker +import feature.experimental.self.ImportedClass +import feature.experimental.self.importedFunction +import feature.experimental.self.importedProperty +import feature.experimental.self.ImportedClass.importedObjectMember diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.fir.kt new file mode 100644 index 00000000000..72719d13e86 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectTargetsForExperimentalAnnotation.fir.kt @@ -0,0 +1,25 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +import kotlin.annotation.AnnotationTarget.* + +@Experimental(Experimental.Level.WARNING) +@Target(CLASS, ANNOTATION_CLASS, TYPE_PARAMETER, PROPERTY, FIELD, LOCAL_VARIABLE, VALUE_PARAMETER, CONSTRUCTOR, FUNCTION, + PROPERTY_GETTER, PROPERTY_SETTER, TYPE, TYPEALIAS) +annotation class E1 + +@Experimental(Experimental.Level.WARNING) +@Target(FILE) +annotation class E2 + +@Experimental(Experimental.Level.WARNING) +@Target(EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class E3 + +@Experimental(Experimental.Level.WARNING) +@Target(FILE, EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class E4 diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.fir.kt new file mode 100644 index 00000000000..afe947cad08 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/incorrectUseExperimental.fir.kt @@ -0,0 +1,9 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental + +annotation class NotAMarker + +@UseExperimental +fun f1() {} + +@UseExperimental(NotAMarker::class) +fun f2() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/override.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/override.fir.kt new file mode 100644 index 00000000000..5af4512d79f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/override.fir.kt @@ -0,0 +1,44 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +annotation class E + +open class Base { + @E + open fun foo() {} +} + +class DerivedInSameModule : Base() { + override fun foo() {} +} + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +open class Derived : Base() { + @E + override fun foo() {} +} + +class SubDerived : Derived() + +@E +class Derived2 : Base() { + override fun foo() {} +} + +// FILE: usage-none.kt + +package usage2 + +import api.* + +class Derived : Base() { + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.fir.kt new file mode 100644 index 00000000000..a0702b4b150 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/overrideDifferentExperimentalities.fir.kt @@ -0,0 +1,35 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental + +@Experimental(Experimental.Level.WARNING) +annotation class E1 +@Experimental(Experimental.Level.WARNING) +annotation class E3 + +interface Base1 { + @E1 + fun foo() +} + +interface Base2 { + fun foo() +} + +interface Base3 { + @E3 + fun foo() +} + +class DerivedA : Base1, Base2, Base3 { + override fun foo() {} +} + +class DerivedB : Base1, Base3 { + @E3 + override fun foo() {} +} + +class DerivedC : Base1, Base2, Base3 { + @E1 + @E3 + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.fir.kt new file mode 100644 index 00000000000..71779d83afa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/topLevel.fir.kt @@ -0,0 +1,78 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS, + AnnotationTarget.VALUE_PARAMETER) +annotation class ExperimentalAPI + +@ExperimentalAPI +fun function(): String = "" + +@ExperimentalAPI +val property: String = "" + +@ExperimentalAPI +typealias Typealias = String + +// FILE: usage-propagate.kt + +package usage1 + +import api.* + +@ExperimentalAPI +fun useAll() { + function() + property + val s: Typealias = "" +} + +@ExperimentalAPI +class Use { + fun useAll() { + function() + property + val s: Typealias = "" + } +} + +// FILE: usage-use.kt + +package usage2 + +import api.* + +fun useAll() { + @UseExperimental(ExperimentalAPI::class) + { + function() + property + val s: Typealias = "" + }() +} + +@UseExperimental(ExperimentalAPI::class) +class Use { + fun useAll() { + function() + property + val s: Typealias = "" + } +} + +// FILE: usage-none.kt + +package usage3 + +import api.* + +fun use() { + function() + property + val s: Typealias = "" + s.hashCode() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.fir.kt new file mode 100644 index 00000000000..b101b799956 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/typealias.fir.kt @@ -0,0 +1,13 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental +@Target(AnnotationTarget.CLASS) +annotation class ExperimentalAPI + +@ExperimentalAPI +class Foo + +typealias Bar = Foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/usageNotAsAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/usageNotAsAnnotation.fir.kt new file mode 100644 index 00000000000..fd4db89d150 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/usageNotAsAnnotation.fir.kt @@ -0,0 +1,77 @@ +// !LANGUAGE: +NestedClassesInAnnotations +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: api.kt + +package test + +import kotlin.reflect.KClass + +// Usages in import should be OK +import kotlin.Experimental.Level.* +import kotlin.Experimental.Level +import kotlin.Experimental + +// Usages with FQ names should be OK + +@kotlin.Experimental(kotlin.Experimental.Level.ERROR) +annotation class M + + +// Usages as types should be errors + +fun f1(e: Experimental) {} +fun f2(u: UseExperimental?) {} + +typealias Experimental0 = Experimental +typealias UseExperimental0 = UseExperimental +fun f3(e: Experimental0 /* TODO */) {} +fun f4(u: UseExperimental0 /* TODO */) {} + + +// Usages as ::class literals should be errors + +annotation class VarargKClasses(vararg val k: KClass<*>) + +@VarargKClasses( + Experimental::class, + UseExperimental::class, + kotlin.Experimental::class, + kotlin.UseExperimental::class +) +fun f5() {} + + +// Usages of markers as types should be errors + +@Experimental +annotation class Marker { + class NestedClass + + companion object { + const val value = 42 + } +} + +fun f6(m: Marker) {} +fun f7(): List? = null +fun f8(): test.Marker? = null + +typealias Marker0 = Marker + +fun f9(m: Marker0) {} + + +// Usages of markers as qualifiers are errors as well (we can lift this restriction for select cases) + +fun f10(m: Marker.NestedClass) { + Marker.value +} + +// FILE: usage-from-other-file.kt + +// Usages of markers in import statements should be OK, but not as qualifiers to import their nested classes + +import test.Marker +import test.Marker.NestedClass +import test.Marker.Companion diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.fir.kt new file mode 100644 index 00000000000..4eade3474ec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFile.fir.kt @@ -0,0 +1,37 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.FUNCTION) +annotation class ExperimentalAPI1 + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.FUNCTION) +annotation class ExperimentalAPI2 + +@ExperimentalAPI1 +fun compilation() {} + +@ExperimentalAPI2 +fun runtime() {} + +// FILE: usage.kt + +@file:UseExperimental(ExperimentalAPI1::class) +package usage + +import api.* + +fun use() { + compilation() + runtime() +} + +class Use { + fun use() { + compilation() + runtime() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.fir.kt new file mode 100644 index 00000000000..02dea53ad33 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnFileWithVeryExperimentalMarker.fir.kt @@ -0,0 +1,30 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +annotation class ExperimentalAPI + +@ExperimentalAPI +@Experimental(Experimental.Level.WARNING) +annotation class VeryExperimentalAPI + +@ExperimentalAPI +@VeryExperimentalAPI +fun f() {} + +@ExperimentalAPI +fun g() {} + +// FILE: usage.kt + +@file:UseExperimental(ExperimentalAPI::class, VeryExperimentalAPI::class) +package usage + +import api.* + +fun usage() { + f() + g() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.fir.kt new file mode 100644 index 00000000000..ceef76351ea --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalOnWholeModule.fir.kt @@ -0,0 +1,22 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental api.ExperimentalAPI +// MODULE: api +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.ERROR) +annotation class ExperimentalAPI + +@ExperimentalAPI +fun function(): String = "" + +// MODULE: usage(api) +// FILE: usage.kt + +package usage + +import api.* + +fun use() { + function() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.fir.kt new file mode 100644 index 00000000000..ca8d9b387c9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalTargets.fir.kt @@ -0,0 +1,57 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.CLASS) +annotation class E + +@E +open class Foo(val s: String = "") + +// FILE: usage.kt + +import api.* + +@UseExperimental(E::class) +class Klass { + init { + Foo() + } +} + +class Constructor { + @UseExperimental(E::class) constructor() { + Foo() + } +} + +@UseExperimental(E::class) +val property = Foo().s + +@UseExperimental(E::class) +fun function() { + Foo() +} + +fun valueParameter(@UseExperimental(E::class) p: String = Foo().s): String { + @UseExperimental(E::class) + val localVariable: String = Foo().s + return localVariable +} + +var propertyAccessors: String + @UseExperimental(E::class) + get() = Foo().s + @UseExperimental(E::class) + set(value) { Foo() } + +fun expression(): String { + val s = @UseExperimental(E::class) Foo().s + return s +} + +@UseExperimental(E::class) +typealias TypeAlias = Foo diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.fir.kt new file mode 100644 index 00000000000..6a86758cd63 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/useExperimentalWithSeveralAnnotations.fir.kt @@ -0,0 +1,52 @@ +// !USE_EXPERIMENTAL: kotlin.Experimental +// FILE: api.kt + +package api + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.FUNCTION) +annotation class E1 + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.FUNCTION) +annotation class E2 + +@Experimental(Experimental.Level.WARNING) +@Target(AnnotationTarget.FUNCTION) +annotation class E3 + +@E1 +fun e1() {} + +@E2 +fun e2() {} + +@E3 +fun e3() {} + +// FILE: usage.kt + +package usage + +import api.* + +@UseExperimental(E1::class, E2::class, E3::class) +fun use1() { + e1() + e2() + e3() +} + +@UseExperimental(E1::class, E3::class) +fun use2() { + e1() + @UseExperimental(E2::class) e2() + e3() +} + +@UseExperimental(E1::class, E2::class) +fun use3() { + e1() + e2() + e3() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.fir.kt new file mode 100644 index 00000000000..258ab24a5e5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.fir.kt @@ -0,0 +1,59 @@ +// !API_VERSION: 1.2 +// !USE_EXPERIMENTAL: kotlin.Experimental +// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -NEWER_VERSION_IN_SINCE_KOTLIN -UNUSED_PARAMETER + +@SinceKotlin("1.3") +fun newPublishedFun() {} + + +@Experimental +annotation class Marker + +@SinceKotlin("1.3") +@WasExperimental(Marker::class) +fun newFunExperimentalInThePast() {} + +@SinceKotlin("1.3") +@WasExperimental(Marker::class) +val newValExperimentalInThePast = "" + +@SinceKotlin("1.3") +@WasExperimental(Marker::class) +class NewClassExperimentalInThePast + +@SinceKotlin("1.3") +@WasExperimental(Marker::class) +typealias TypeAliasToNewClass = NewClassExperimentalInThePast + + +fun use1( + c1: NewClassExperimentalInThePast, + t1: TypeAliasToNewClass +) { + newPublishedFun() + newFunExperimentalInThePast() + newValExperimentalInThePast + NewClassExperimentalInThePast() +} + +@UseExperimental(Marker::class) +fun use2( + c2: NewClassExperimentalInThePast, + t2: TypeAliasToNewClass +) { + newPublishedFun() + newFunExperimentalInThePast() + newValExperimentalInThePast + NewClassExperimentalInThePast() +} + +@Marker +fun use3( + c3: NewClassExperimentalInThePast, + t3: TypeAliasToNewClass +) { + newPublishedFun() + newFunExperimentalInThePast() + newValExperimentalInThePast + NewClassExperimentalInThePast() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.fir.kt new file mode 100644 index 00000000000..698cda9a46c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.fir.kt @@ -0,0 +1,103 @@ +// !LANGUAGE: -ProperForInArrayLoopRangeVariableAssignmentSemantic +// !DIAGNOSTICS: -UNUSED_VALUE +// SKIP_TXT + +fun testArrayCapturedInLocalFun() { + var xs = arrayOf("a", "b", "c") + + fun updateXs() { + xs = arrayOf("d", "e", "f") + } + + for (x in xs) { + println(x) + updateXs() + } +} + +fun testArrayCapturedInLabmda() { + var xs = arrayOf("a", "b", "c") + + val updateXs = { xs = arrayOf("d", "e", "f") } + + for (x in xs) { + println(x) + updateXs() + } +} + +fun testArrayCapturedInInlineLambda() { + var xs = arrayOf("a", "b", "c") + + for (x in xs) { + println(x) + run { + xs = arrayOf("d", "e", "f") + } + } +} + +fun testArrayCapturedInLocalObject() { + var xs = arrayOf("a", "b", "c") + + val updateXs = object : () -> Unit { + override fun invoke() { + xs = arrayOf("d", "e", "f") + } + } + + for (x in xs) { + println(x) + updateXs() + } +} + +fun testArrayCapturedInLocalClass() { + var xs = arrayOf("a", "b", "c") + + class LocalClass { + fun updateXs() { + xs = arrayOf("d", "e", "f") + } + } + + val updater = LocalClass() + + for (x in xs) { + println(x) + updater.updateXs() + } +} + +fun testCapturedInLambdaAfterLoop() { + // NB false positive + var xs = intArrayOf(1, 2, 3) + for (x in xs) { + println(x) + xs = intArrayOf(4, 5, 6) + } + val lambda = { xs = intArrayOf() } + lambda() +} + +fun testCapturedInLambdaInLoopAfterAssignment() { + // NB false positive + var xs = intArrayOf(1, 2, 3) + for (x in xs) { + println(x) + xs = intArrayOf(4, 5, 6) + val lambda = { xs = intArrayOf() } + lambda() + } +} + +fun testCapturedInNonChangingClosure() { + // NB false positive + var xs = intArrayOf(1, 2, 3) + val lambda = { println(xs) } + for (x in xs) { + println(x) + xs = intArrayOf(4, 5, 6) + lambda() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/forInFieldUpdatedInLoopBodyBefore13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/forInFieldUpdatedInLoopBodyBefore13.fir.kt new file mode 100644 index 00000000000..134a2ccb6cb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/forInFieldUpdatedInLoopBodyBefore13.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: -ProperForInArrayLoopRangeVariableAssignmentSemantic +// !DIAGNOSTICS: -UNUSED_VALUE +// SKIP_TXT + +var xs: IntArray = intArrayOf(1, 2, 3) + get() = field + set(ys) { + var sum = 0 + for (x in field) { + sum = sum * 10 + x + field = intArrayOf(4, 5, 6) + } + if (sum != 123) throw AssertionError("sum=$sum") + field = ys + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.fir.kt new file mode 100644 index 00000000000..64edb6438df --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: -ProperForInArrayLoopRangeVariableAssignmentSemantic +// !DIAGNOSTICS: -UNUSED_VALUE +// SKIP_TXT + +class Delegate(var v: T) { + operator fun getValue(thisRef: Any?, kProp: Any?) = v + operator fun setValue(thisRef: Any?, kProp: Any?, value: T) { v = value } +} + +fun testLocalDelegatedProperty() { + var xs by Delegate(arrayOf("a", "b", "c")) + for (x in xs) { + println(x) + xs = arrayOf("d", "e", "f") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.fir.kt new file mode 100644 index 00000000000..1689dd22563 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +ProperForInArrayLoopRangeVariableAssignmentSemantic +// !DIAGNOSTICS: -UNUSED_VALUE +// SKIP_TXT + +fun testObjectArray() { + var xs = arrayOf("a", "b", "c") + for (x in xs) { + println(x) + xs = arrayOf("d", "e", "f") + } +} + +fun testPrimitiveArray() { + var xs = intArrayOf(1, 2, 3) + for (x in xs) { + println(x) + xs = intArrayOf(4, 5, 6) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.fir.kt new file mode 100644 index 00000000000..746ef0634d7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.fir.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: -ProperForInArrayLoopRangeVariableAssignmentSemantic +// !DIAGNOSTICS: -UNUSED_VALUE +// SKIP_TXT + +fun testObjectArray() { + var xs = arrayOf("a", "b", "c") + for (x in xs) { + println(x) + xs = arrayOf("d", "e", "f") + } +} + +fun testPrimitiveArray() { + var xs = intArrayOf(1, 2, 3) + for (x in xs) { + println(x) + xs = intArrayOf(4, 5, 6) + } +} + +var global = arrayOf("a", "b", "c") + +fun testGlobalArray() { + for (x in global) { + println(x) + global = arrayOf("d", "e", "f") + } +} + +fun testAssignmentNotInLoop() { + var xs = intArrayOf(1, 2, 3) + println(xs) + xs = intArrayOf(7, 8, 9) + for (x in xs) { + println(x) + } + xs = intArrayOf(4, 5, 6) + println(xs) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.fir.kt new file mode 100644 index 00000000000..3816b2688dd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.fir.kt @@ -0,0 +1,371 @@ +import java.util.HashMap + +private fun unaryOperation( + a: CompileTimeType, + functionName: String, + operation: Function1, + checker: Function1 +) = UnaryOperationKey(a, functionName) to Pair(operation, checker) as Pair, Function1> + +private fun binaryOperation( + a: CompileTimeType, + b: CompileTimeType, + functionName: String, + operation: Function2, + checker: Function2 +) = BinaryOperationKey(a, b, functionName) to Pair(operation, checker) as Pair, Function2> + +private data class UnaryOperationKey(val f: CompileTimeType, val functionName: String) +//HashMap, Pair, Function2>> +private data class BinaryOperationKey(val f: CompileTimeType, val g: CompileTimeType, val functionName: String) + +private class CompileTimeType + +private val BYTE = CompileTimeType() +private val CHAR = CompileTimeType() +private val BOOLEAN = CompileTimeType() +private val DOUBLE = CompileTimeType() +private val FLOAT = CompileTimeType() +private val INT = CompileTimeType() +private val LONG = CompileTimeType() +private val SHORT = CompileTimeType() +private val STRING = CompileTimeType() +private val ANY = CompileTimeType() + + +private val emptyBinaryFun: Function2 = { a, b -> BigInteger("0") } +private val emptyUnaryFun: Function1 = { a -> 1.toLong() } + +private val unaryOperations: HashMap, Pair, Function1>> + = hashMapOf, Pair, Function1>>( + unaryOperation(BOOLEAN, "not!", { a -> a.not() }, emptyUnaryFun), + unaryOperation(BYTE, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(BYTE, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), + unaryOperation(BYTE, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), + unaryOperation(BYTE, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(BYTE, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(BYTE, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(BYTE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(BYTE, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(BYTE, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(BYTE, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(CHAR, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(CHAR, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(CHAR, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(CHAR, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(CHAR, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(CHAR, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(CHAR, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(DOUBLE, "minus", { a -> a.unaryMinus() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(DOUBLE, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(DOUBLE, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(FLOAT, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(FLOAT, "minus", { a -> a.unaryMinus() }, emptyUnaryFun), + unaryOperation(FLOAT, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(FLOAT, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(FLOAT, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(FLOAT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(FLOAT, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(FLOAT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(FLOAT, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(INT, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(INT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(INT, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(INT, "inv", { a -> a.inv() }, emptyUnaryFun), + unaryOperation(INT, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(INT, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), + unaryOperation(INT, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(INT, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(INT, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(INT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(LONG, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(LONG, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(LONG, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(LONG, "inv", { a -> a.inv() }, emptyUnaryFun), + unaryOperation(LONG, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(LONG, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), + unaryOperation(LONG, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(LONG, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(LONG, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(LONG, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(SHORT, "toInt", { a -> a.toInt() }, emptyUnaryFun), + unaryOperation(SHORT, "minus", { a -> a.unaryMinus() }, { a -> a.unaryMinus() }), + unaryOperation(SHORT, "toChar", { a -> a.toChar() }, emptyUnaryFun), + unaryOperation(SHORT, "toLong", { a -> a.toLong() }, emptyUnaryFun), + unaryOperation(SHORT, "plus", { a -> a.unaryPlus() }, emptyUnaryFun), + unaryOperation(SHORT, "toFloat", { a -> a.toFloat() }, emptyUnaryFun), + unaryOperation(SHORT, "toDouble", { a -> a.toDouble() }, emptyUnaryFun), + unaryOperation(SHORT, "toShort", { a -> a.toShort() }, emptyUnaryFun), + unaryOperation(SHORT, "toByte", { a -> a.toByte() }, emptyUnaryFun), + unaryOperation(STRING, "toString", { a -> a.toString() }, emptyUnaryFun) +) + +private val binaryOperations: HashMap, Pair, Function2>> + = hashMapOf, Pair, Function2>>( + binaryOperation(BOOLEAN, BOOLEAN, "xor", { a, b -> a.xor(b) }, emptyBinaryFun), + binaryOperation(BOOLEAN, BOOLEAN, "or", { a, b -> a.or(b) }, emptyBinaryFun), + binaryOperation(BOOLEAN, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(BOOLEAN, BOOLEAN, "and", { a, b -> a.and(b) }, emptyBinaryFun), + binaryOperation(BOOLEAN, BOOLEAN, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, BYTE, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(BYTE, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(BYTE, LONG, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(BYTE, SHORT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(BYTE, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(BYTE, BYTE, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(BYTE, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(BYTE, LONG, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(BYTE, SHORT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(BYTE, BYTE, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(BYTE, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(BYTE, LONG, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(BYTE, SHORT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(BYTE, BYTE, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(BYTE, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(BYTE, LONG, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(BYTE, SHORT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(BYTE, BYTE, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(BYTE, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(BYTE, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(BYTE, INT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(BYTE, LONG, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(BYTE, SHORT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(BYTE, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(CHAR, CHAR, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(CHAR, CHAR, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(CHAR, INT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(CHAR, INT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(CHAR, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, BYTE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, INT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, LONG, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, SHORT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(DOUBLE, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(FLOAT, BYTE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, INT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, LONG, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, SHORT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(FLOAT, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(INT, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(INT, BYTE, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(INT, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(INT, LONG, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(INT, SHORT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(INT, INT, "shl", { a, b -> a.shl(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "ushr", { a, b -> a.ushr(b) }, emptyBinaryFun), + binaryOperation(INT, BYTE, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(INT, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(INT, LONG, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(INT, SHORT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(INT, INT, "shr", { a, b -> a.shr(b) }, emptyBinaryFun), + binaryOperation(INT, BYTE, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(INT, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(INT, LONG, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(INT, SHORT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(INT, BYTE, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(INT, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(INT, LONG, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(INT, SHORT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(INT, INT, "or", { a, b -> a.or(b) }, { a, b -> a.or(b) }), + binaryOperation(INT, BYTE, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(INT, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(INT, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(INT, INT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(INT, LONG, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(INT, SHORT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(INT, INT, "and", { a, b -> a.and(b) }, { a, b -> a.and(b) }), + binaryOperation(INT, INT, "xor", { a, b -> a.xor(b) }, { a, b -> a.xor(b) }), + binaryOperation(INT, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(LONG, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(LONG, BYTE, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(LONG, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(LONG, LONG, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(LONG, SHORT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(LONG, INT, "shl", { a, b -> a.shl(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "ushr", { a, b -> a.ushr(b) }, emptyBinaryFun), + binaryOperation(LONG, BYTE, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(LONG, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(LONG, LONG, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(LONG, SHORT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(LONG, INT, "shr", { a, b -> a.shr(b) }, emptyBinaryFun), + binaryOperation(LONG, BYTE, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(LONG, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(LONG, LONG, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(LONG, SHORT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(LONG, BYTE, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(LONG, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(LONG, LONG, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(LONG, SHORT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(LONG, LONG, "or", { a, b -> a.or(b) }, { a, b -> a.or(b) }), + binaryOperation(LONG, BYTE, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(LONG, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(LONG, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(LONG, INT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(LONG, LONG, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(LONG, SHORT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(LONG, LONG, "and", { a, b -> a.and(b) }, { a, b -> a.and(b) }), + binaryOperation(LONG, LONG, "xor", { a, b -> a.xor(b) }, { a, b -> a.xor(b) }), + binaryOperation(LONG, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(SHORT, BYTE, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(SHORT, DOUBLE, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "minus", { a, b -> a.minus(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(SHORT, LONG, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(SHORT, SHORT, "minus", { a, b -> a.minus(b) }, { a, b -> a.subtract(b) }), + binaryOperation(SHORT, BYTE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, LONG, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, SHORT, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun), + binaryOperation(SHORT, BYTE, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(SHORT, DOUBLE, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(SHORT, LONG, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(SHORT, SHORT, "plus", { a, b -> a.plus(b) }, { a, b -> a.add(b) }), + binaryOperation(SHORT, BYTE, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(SHORT, DOUBLE, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "div", { a, b -> a.div(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(SHORT, LONG, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(SHORT, SHORT, "div", { a, b -> a.div(b) }, { a, b -> a.divide(b) }), + binaryOperation(SHORT, BYTE, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(SHORT, DOUBLE, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "mod", { a, b -> a.mod(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(SHORT, LONG, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(SHORT, SHORT, "mod", { a, b -> a.mod(b) }, { a, b -> a.mod(b) }), + binaryOperation(SHORT, BYTE, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(SHORT, DOUBLE, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(SHORT, FLOAT, "times", { a, b -> a.times(b) }, emptyBinaryFun), + binaryOperation(SHORT, INT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(SHORT, LONG, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(SHORT, SHORT, "times", { a, b -> a.times(b) }, { a, b -> a.multiply(b) }), + binaryOperation(SHORT, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(STRING, ANY, "plus", { a, b -> a.plus(b) }, emptyBinaryFun), + binaryOperation(STRING, INT, "get", { a, b -> a.get(b) }, emptyBinaryFun), + binaryOperation(STRING, ANY, "equals", { a, b -> a.equals(b) }, emptyBinaryFun), + binaryOperation(STRING, STRING, "compareTo", { a, b -> a.compareTo(b) }, emptyBinaryFun) +) + +//from library +class BigInteger(val value: String) { + fun add(o: BigInteger): BigInteger = o + fun divide(o: BigInteger): BigInteger = o + fun mod(o: BigInteger): BigInteger = o + fun multiply(o: BigInteger): BigInteger = o + fun subtract(o: BigInteger): BigInteger = o + fun or(o: BigInteger): BigInteger = o + fun and(o: BigInteger): BigInteger = o + fun xor(o: BigInteger): BigInteger = o +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/hugeUnresolvedKotlinxHtml.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/hugeUnresolvedKotlinxHtml.fir.kt new file mode 100644 index 00000000000..3ee51c17e15 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/hugeUnresolvedKotlinxHtml.fir.kt @@ -0,0 +1,60 @@ +class A { + fun bar() { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + div { + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + +(foo ?: "") + } + } + } + } + } + } + } + } + } + } + } + + } + } + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.fir.kt new file mode 100644 index 00000000000..abfc08fe611 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.fir.kt @@ -0,0 +1,16 @@ +// FILE: Java.java + +import java.util.List; + +class Java { + public static List get(List o) { return o; } +} + +// FILE: test.kt + +import java.util.ArrayList + +fun call(): List { + // No errors should be here + return Java.get(if (true) ArrayList() else listOf(0)) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.fir.kt new file mode 100644 index 00000000000..71bd847a1a7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.fir.kt @@ -0,0 +1,34 @@ +// !WITH_NEW_INFERENCE + +var longWords = 0 +val smallWords = hashSetOf() + +fun test1(word: String) = + run { + if (word.length > 4) { + longWords++ + } + else { + smallWords.add(word) + } + } + +fun test2(word: String) = + run { + if (word.length > 4) { + if (word.startsWith("a")) longWords++ + } + else { + smallWords.add(word) + } + } + +fun test3(word: String) = + run { + if (word.length > 4) { + longWords++ + } + else { + System.out?.println(word) // Unit? + } + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt new file mode 100644 index 00000000000..8f28742410d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt @@ -0,0 +1,12 @@ +//!DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List<@kotlin.internal.Exact T>.firstTyped(): U = throw Exception() + +fun test1(l: List) { + + val i: Int = l.firstTyped() + + val s: String = l.firstTyped() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/explicitTypeArgumentAsValidInputType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/explicitTypeArgumentAsValidInputType.fir.kt new file mode 100644 index 00000000000..25ce8b26d85 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/explicitTypeArgumentAsValidInputType.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -UNUSED_PARAMETER + +interface Parent +object ChildA : Parent +object ChildB : Parent + +fun <@kotlin.internal.OnlyInputTypes T> select(a: T, b: T) {} + +fun test() { + select(ChildA, ChildB) // should be error + select(ChildA, ChildB) // should be ok +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.fir.kt new file mode 100644 index 00000000000..86a57e0c766 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.fir.kt @@ -0,0 +1,30 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun Iterable<*>.filterIsInstance1(): List<@kotlin.internal.NoInfer R> = throw Exception() + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List<*>.filterIsInstance2(): @kotlin.internal.NoInfer List = throw Exception() + +fun test(list: List) { + list.filterIsInstance1().map { it * 2 } + list.filterIsInstance2().filter { it > 10 } +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun foo(t: R): List<@kotlin.internal.NoInfer R> = throw Exception("$t") + +fun test() { + foo(1).map { it * 2 } +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List.foo(): @kotlin.internal.NoInfer R = throw Exception() + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun bar(r: R, f: Function1<@kotlin.internal.NoInfer R, Unit>): Nothing = throw Exception() + +fun test1() { + listOf("").foo().length + bar(1) { x -> x + 1 } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt26698.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt26698.fir.kt new file mode 100644 index 00000000000..9ae24ea52d4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt26698.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +open class Base() +class CX : Base() +class CY : Base() + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T> foo(a: T, b: T) {} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T : Any> fooA(a: T, b: T) {} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T : Base> fooB(a: T, b: T) {} + + +fun usage(x: CX, y: CY) { + foo(x, y) // expected err, got err + fooA(x, y) // expected err, got ok + fooB(x, y) // expected err, got ok +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.fir.kt new file mode 100644 index 00000000000..a2cad2370d9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// ISSUE: KT-29307 + +fun test_1(map: Map) { + val x = map[42] // OK +} + +open class A + +class B : A() + +fun test_2(map: Map) { + val x = map[42] +} + +fun test_3(m: Map<*, String>) { + val x = m[42] // should be ok +} + +fun test_4(m: Map) { + val x = m.get(42) // should be ok +} + +fun test_5(map: Map, a: A) { + map.get(a) +} + +fun test_6(map: Map, b: B) { + map.get(b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.fir.kt new file mode 100644 index 00000000000..157865a7ac9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.fir.kt @@ -0,0 +1,16 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.jvm.JvmName("containsAny") +@kotlin.internal.LowPriorityInOverloadResolution +public fun Iterable.contains1(element: T): Int = null!! + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun Iterable.contains1(element: @kotlin.internal.NoInfer T): Boolean = null!! + + +fun test() { + val a: Boolean = listOf(1).contains1("") + val b: Boolean = listOf(1).contains1(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.fir.kt new file mode 100644 index 00000000000..dc5e2fb9d17 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.fir.kt @@ -0,0 +1,33 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun test1(t1: T, t2: @kotlin.internal.NoInfer T): T = t1 + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun @kotlin.internal.NoInfer T.test2(t1: T): T = t1 + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun test3(t1: @kotlin.internal.NoInfer T): T = t1 + +fun usage() { + test1(1, "312") + 1.test2("") + test3("") +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List.contains1(e: @kotlin.internal.NoInfer T): Boolean = true + +fun test(i: Int?, a: Any, l: List) { + l.contains1(a) + l.contains1("") + l.contains1(i) +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun assertEquals1(e1: T, e2: @kotlin.internal.NoInfer T): Boolean = true + +fun test(s: String) { + assertEquals1(s, 11) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/notNullAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/notNullAnnotation.fir.kt new file mode 100644 index 00000000000..8d588891567 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/notNullAnnotation.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NewInference + +// FILE: SmartFMap.java + +public class SmartFMap implements java.util.Map { + public static < K, V> SmartFMap emptyMap() { + return null; + } + + public SmartFMap < K, V> plus(@org.jetbrains.annotations.NotNull K key, V value) { + return null; + } +} + +// FILE: main.kt + +class KotlinType + +interface TypePredicate : (KotlinType) -> Boolean { + override fun invoke(typeToCheck: KotlinType): Boolean +} + +fun TypePredicate.expectedTypeFor(keys: Iterable): Map = + keys.fold(SmartFMap.emptyMap()) { map, key -> + map.plus(key, this) + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypes.fir.kt new file mode 100644 index 00000000000..b72dfbd7e0d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypes.fir.kt @@ -0,0 +1,47 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> Iterable.contains1(element: T): Boolean = null!! + +class In + +class Out + +class Inv + +fun test_1(list: List>, x: In, y: In, z: In) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} + +fun test_2(list: List>, x: In, y: In, z: In) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} + +fun test_3(list: List>, x: Out, y: Out, z: Out) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} + +fun test_4(list: List>, x: Out, y: Out, z: Out) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} + +fun test_5(list: List>, x: Inv, y: Inv, z: Inv) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} + +fun test_6(list: List>, x: Inv, y: Inv, z: Inv) { + list.contains1(x) + list.contains1(y) + list.contains1(z) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndLowPriority.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndLowPriority.fir.kt new file mode 100644 index 00000000000..08a1cd0160a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndLowPriority.fir.kt @@ -0,0 +1,26 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.jvm.JvmName("containsAny") +@kotlin.internal.LowPriorityInOverloadResolution +public fun Iterable.contains1(element: T): Int = null!! + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> Iterable.contains1(element: T): Boolean = null!! + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@JvmName("getAny") +@kotlin.internal.LowPriorityInOverloadResolution +public fun Map.get1(key: Any?): Int = null!! + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes K, V> Map.get1(key: K): V? = null!! + +fun test(map: Map) { + val a: Int = listOf(1).contains1("") + val b: Boolean = listOf(1).contains1(1) + + val c: String? = map.get1("") + val d: String? = map.get1(1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndTopLevelCapturedTypes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndTopLevelCapturedTypes.fir.kt new file mode 100644 index 00000000000..5236ae74b83 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndTopLevelCapturedTypes.fir.kt @@ -0,0 +1,73 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +class Inv + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes K> Inv.onlyOut(e: K) {} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes K : Number> Inv.onlyOutUB(e: K) {} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes K> Inv.onlyIn(e: K) {} + +fun test( + invStar: Inv<*>, + invOut: Inv, + invIn: Inv +) { + invStar.onlyOut("str") + invOut.onlyOut(42) + invOut.onlyOut(1L) + + invOut.onlyOutUB("str") + invStar.onlyOutUB(0) + invOut.onlyOutUB(42) + invOut.onlyOutUB(1L) + + invIn.onlyIn("str") + invIn.onlyIn(42) + invIn.onlyIn(1L) +} + +// From KT-32157 +fun test2(value: Any?) { + val result = (value as? Map<*, *>)?.get("result") +} + +// From KT-32116 +fun test3(h: HashMap<*, *>) { + val a = h["str"] + val b = h[1] + val c = h["other"] as? Double +} + +// From KT-32218 +fun test4() { + val map: Map = mapOf( + true to true, + 1L to 1L + ) + val test = map[1L] +} + +// From KT-32235 + +class A { + val children = mutableListOf>() +} + +class B + +class Test5 { + var a: A<*>? = null + var b: B<*>? = null + set(value) { + if (value != null) { + val a = a + require(a != null && value in a.children) + } + field = value + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.fir.kt new file mode 100644 index 00000000000..154c475e0c7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.fir.kt @@ -0,0 +1,19 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + +//FILE:Foo.java + +public class Foo { + public static String foo() { + return null; + } +} + +//FILE:Bar.kt + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T> assertEquals1(t1: T, t2: T) {} + +fun test() { + assertEquals1(null, Foo.foo()) + assertEquals1("", Foo.foo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCaptured.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCaptured.fir.kt new file mode 100644 index 00000000000..a75fd93f946 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesCaptured.fir.kt @@ -0,0 +1,113 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// Issue: KT-26698 + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> Iterable.contains1(element: T): Boolean = null!! + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> Iterable.foo(element: T): T = null!! + +class Inv +class Inv2 + +class In +class Out + +// ------------------------------------------------------- + +fun test_0(x: Inv2, list: List>) { + list.foo(x) +} + +// ------------------------- Inv ------------------------- + +fun test_1(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_2(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_3(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_4(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_5(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_6(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_7(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_8(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_9(x: Inv, list: List>) { + list.contains1(x) +} + +// ------------------------- In ------------------------- + +fun test_11(x: In, list: List>) { + list.contains1(x) +} + +fun test_12(x: In, list: List>) { + list.contains1(x) +} + +fun test_13(x: In, list: List>) { + list.contains1(x) +} + +// ------------------------- Out ------------------------- + +fun test_21(x: Out, list: List>) { + list.contains1(x) +} + +fun test_22(x: Out, list: List>) { + list.contains1(x) +} + +fun test_23(x: Out, list: List>) { + list.contains1(x) +} + +// -------------------------------------------------------- + +fun test_31(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_32(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_33(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_34(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_35(x: Inv, list: List>) { + list.contains1(x) +} + +fun test_36(x: Inv, list: List>) { + list.contains1(x) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesWithVarargs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesWithVarargs.fir.kt new file mode 100644 index 00000000000..4e73147cdc6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesWithVarargs.fir.kt @@ -0,0 +1,26 @@ +fun test1(ns: String?, vararg nullableStrs: String?) { + nullableStrs.contains("x") + nullableStrs.contains(ns) + "x" in nullableStrs + ns in nullableStrs +} + +fun test2(ns: String?, vararg nonNullableStrs: String) { + nonNullableStrs.contains("x") + nonNullableStrs.contains(ns) + "x" in nonNullableStrs + ns in nonNullableStrs +} + +fun test3(ns: String?, nullableStrs: Array, nonNullableStrs: Array) { + nullableStrs.contains("x") + nonNullableStrs.contains("x") + + nullableStrs.contains(ns) + nonNullableStrs.contains(ns) + + "x" in nullableStrs + "x" in nonNullableStrs + ns in nullableStrs + ns in nonNullableStrs +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.fir.kt new file mode 100644 index 00000000000..7f7e91045c1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +private object TopLevelTypeVariable { + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + fun foo(): @kotlin.internal.NoInfer T = TODO() + + fun bar(k: K) {} + + fun test() { + bar(foo()) + } +} + +private object NestedTypeVariable { + class Inv + + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + fun foo(): Inv<@kotlin.internal.NoInfer T> = TODO() + + fun bar(p: Inv) {} + + fun test() { + bar(foo()) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.fir.kt new file mode 100644 index 00000000000..6c9fe7a7efa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.fir.kt @@ -0,0 +1,25 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T> assertEquals1(t1: T, t2: T) {} + +open class A +class B: A() +class C: A() +class D + +fun test1(a: A, b: B, c: C) { + assertEquals1(a, b) + assertEquals1(b, c) + + assertEquals1(3, 3) + assertEquals1(1 or 2, 2 or 1) +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> expect1(expected: T, block: () -> T) {} + +fun test() { + expect1(2) { byteArrayOf(1, 2, 3).indexOf(3) } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.fir.kt new file mode 100644 index 00000000000..919b8578b2d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.fir.kt @@ -0,0 +1,14 @@ +// !CHECK_TYPE + +package b + +fun bar() { + val a1 = Array(1, {i: Int -> i}) + val a2 = Array(1, {i: Int -> "$i"}) + val a3 = Array(1, {it}) + + checkSubtype>(a1) + checkSubtype>(a2) + checkSubtype>(a3) +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.fir.kt new file mode 100644 index 00000000000..a024bc2848f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.fir.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -USELESS_ELVIS -UNUSED_EXPRESSION + +class X { + fun toLong(): Long? = TODO() +} + +fun getLong(): Long = TODO() + +fun test_1(list: List) { + val props = list.map { it.toLong() ?: 0 } + props +} + +fun test_2(cond: Boolean) { + val props = if (cond) getLong() else 0 + props +} + +fun test_3(list: List) { + val props = list.map { Pair(it.toLong() ?: 0, it.toLong() ?: 0) } + props +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt new file mode 100644 index 00000000000..0b312e318b3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/intersectionInputType.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference + +import kotlin.test.assertEquals + +fun test() { + val u = when (true) { + true -> 42 + else -> 1.0 + } + + assertEquals(42, u) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.fir.kt new file mode 100644 index 00000000000..e7ceb67e29a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.fir.kt @@ -0,0 +1,4 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE + +fun foo(first: Array, second: Array) = Pair(first.toCollection(), second.toCollection()) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt12008.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt12008.fir.kt new file mode 100644 index 00000000000..c6128f73444 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt12008.fir.kt @@ -0,0 +1,12 @@ +// FULL_JDK + +import java.util.* + +fun foo(o: Optional) {} + +class Test(nullable: String?) { + private val nullableOptional = Optional.ofNullable(nullable) + fun doIt() { + foo(nullableOptional) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.fir.kt new file mode 100644 index 00000000000..ab5614de074 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.fir.kt @@ -0,0 +1,26 @@ +// !CHECK_TYPE + +//KT-1558 Exception while analyzing +package j + +fun T?.sure() : T = this!! + +fun List<*>.toArray(ar: Array): Array = ar + +fun testArrays(ci: List, cii: List?) { + val c1: Array = cii.sure().toArray(Array) + + val c2: Array = ci.toArray(Array()) + + val c3 = Array() + + val c4 = ci.toArray(Array()) + + val c5 = ci.toArray(Array()) + + checkSubtype>(c1) + checkSubtype>(c2) + checkSubtype>(c3) + checkSubtype>(c4) + checkSubtype>(c5) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt new file mode 100644 index 00000000000..12ae9041270 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt @@ -0,0 +1,9 @@ +// !WITH_NEW_INFERENCE + +fun foo(resources: List) { + resources.map { runCatching { it } }.mapNotNull { it.getOrNull() } +} + +fun bar(resources: List) { + resources.map { runCatching { it } }.mapNotNull { it.getOrNull() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.fir.kt new file mode 100644 index 00000000000..1c164720a43 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +NewInference + +fun test(ls: List) { + ls.takeIf(Collection<*>::isNotEmpty) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt32345.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt32345.fir.kt new file mode 100644 index 00000000000..2de407aaef6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt32345.fir.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import kotlin.reflect.KProperty +import kotlin.properties.ReadWriteProperty + +class CleanupTestExample { + val cleanUpBlocks: MutableList Unit>> = mutableListOf() + + class CleaningDelegate( + initialValue: T? = null, + val cleanupBlocks: MutableList Unit>>, + val block: (T) -> Unit + ) : ReadWriteProperty { + private var value: T? = initialValue + + init { + addCleanupBlock(initialValue) + } + + override fun getValue(thisRef: Any?, property: KProperty<*>): T { + return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.") + } + + @Suppress("UNCHECKED_CAST") + override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { + addCleanupBlock(value) + this.value = value + } + + fun addCleanupBlock(value: T?) { + if (value != null) { + @Suppress("UNCHECKED_CAST") + cleanupBlocks.add((value to block) as Pair Unit>) + } + + } + } + + data class TestHolder(val num: Int) + + fun cleanup(initialValue: T? = null, block: (T) -> Unit) = CleaningDelegate(initialValue, cleanUpBlocks, block) + + fun testWithCleanup() { + val testHolder = TestHolder(1) + + var thing: TestHolder by CleaningDelegate(testHolder, cleanupBlocks = cleanUpBlocks, block = { println("cleaning up $it") }) + var thing2: TestHolder by cleanup(testHolder) { println("cleaning up $it") } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.fir.kt new file mode 100644 index 00000000000..8fc7524f41e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.fir.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +import java.io.File + +fun test() { + val dir = File("dir") + val files = dir.listFiles()?.toList() ?: listOf() // error + files checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.fir.kt new file mode 100644 index 00000000000..7a9267a731e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.fir.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +fun bar(f: () -> T) : T = f() + +fun test(map: MutableMap) { + val r = bar { + map[1] = 2 + } + r checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.fir.kt new file mode 100644 index 00000000000..6bac4f49b01 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -UNUSED_PARAMETER -NULLABLE_INLINE_PARAMETER + +@kotlin.internal.InlineOnly +inline fun test() { + +} + +@kotlin.internal.InlineOnly +inline fun test3(noinline s : (Int) -> Int) { + +} + +@kotlin.internal.InlineOnly +inline fun test4(noinline s : Int.() -> Int) { + +} + +@kotlin.internal.InlineOnly +inline fun Function1?.test5() { + +} + +@kotlin.internal.InlineOnly +inline fun Function1?.test6() { + +} + +@kotlin.internal.InlineOnly +inline fun test2(s : ((Int) -> Int)?) { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.fir.kt new file mode 100644 index 00000000000..fecc57b0e10 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@Synchronized +inline fun foo(f: () -> Unit): Unit = f() + +var bar: String + @Synchronized + inline get() = "" + @Synchronized + inline set(value) {} + +inline var baz: String + @Synchronized + get() = "" + @Synchronized + set(value) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/instar.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/instar.fir.kt new file mode 100644 index 00000000000..74992217ab5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/instar.fir.kt @@ -0,0 +1,11 @@ +// Reproduces exception in TypeResolver.kt: EA-66870 + +import java.util.ArrayList + +abstract class J { + public abstract fun , S : List> foo(x: T) + fun bar() { + val s = ArrayList>() + foo(s) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContains.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContains.fir.kt new file mode 100644 index 00000000000..ec611b6920f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContains.fir.kt @@ -0,0 +1,79 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +class A : java.util.concurrent.ConcurrentHashMap() { + operator fun contains(x: Char): Boolean = true +} +class B : java.util.concurrent.ConcurrentHashMap() { + override fun contains(value: Any?): Boolean { + return super.contains(value) + } +} + +class C : java.util.concurrent.ConcurrentHashMap() { + operator override fun contains(value: Any?): Boolean { + return super.contains(value) + } +} + +fun main() { + val hm = java.util.concurrent.ConcurrentHashMap() + "" in hm + "" !in hm + 1 !in hm + 2 in hm + + hm.contains("") + hm.contains(1) + + "" in (hm as Map) + "" !in (hm as Map) + 1 in (hm as Map) + 1 !in (hm as Map) + + val a = A() + "" in a + "" !in a + 1 !in a + 2 in a + + ' ' in a + ' ' !in a + a.contains("") + a.contains(1) + + "" in (a as Map) + "" !in (a as Map) + 1 in (a as Map) + 1 !in (a as Map) + + val b = B() + "" in b + "" !in b + 1 !in b + 2 in b + + b.contains("") + b.contains(1) + + "" in (b as Map) + "" !in (b as Map) + 1 in (b as Map) + 1 !in (b as Map) + + // Actually, we could've allow calls here because the owner explicitly declared as operator, but semantics is still weird + val c = C() + "" in c + "" !in c + 1 !in c + 2 in c + + c.contains("") + c.contains(1) + + "" in (c as Map) + "" !in (c as Map) + 1 in (c as Map) + 1 !in (c as Map) +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContainsError.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContainsError.fir.kt new file mode 100644 index 00000000000..187378a6acc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/java/concurrentHashMapContainsError.fir.kt @@ -0,0 +1,80 @@ +// !LANGUAGE: +ProhibitConcurrentHashMapContains +// !WITH_NEW_INFERENCE +// FULL_JDK + +class A : java.util.concurrent.ConcurrentHashMap() { + operator fun contains(x: Char): Boolean = true +} +class B : java.util.concurrent.ConcurrentHashMap() { + override fun contains(value: Any?): Boolean { + return super.contains(value) + } +} + +class C : java.util.concurrent.ConcurrentHashMap() { + operator override fun contains(value: Any?): Boolean { + return super.contains(value) + } +} + +fun main() { + val hm = java.util.concurrent.ConcurrentHashMap() + "" in hm + "" !in hm + 1 !in hm + 2 in hm + + hm.contains("") + hm.contains(1) + + "" in (hm as Map) + "" !in (hm as Map) + 1 in (hm as Map) + 1 !in (hm as Map) + + val a = A() + "" in a + "" !in a + 1 !in a + 2 in a + + ' ' in a + ' ' !in a + a.contains("") + a.contains(1) + + "" in (a as Map) + "" !in (a as Map) + 1 in (a as Map) + 1 !in (a as Map) + + val b = B() + "" in b + "" !in b + 1 !in b + 2 in b + + b.contains("") + b.contains(1) + + "" in (b as Map) + "" !in (b as Map) + 1 in (b as Map) + 1 !in (b as Map) + + // Actually, we could've allow calls here because the owner explicitly declared as operator, but semantics is still weird + val c = C() + "" in c + "" !in c + 1 !in c + 2 in c + + c.contains("") + c.contains(1) + + "" in (c as Map) + "" !in (c as Map) + 1 in (c as Map) + 1 !in (c as Map) +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt new file mode 100644 index 00000000000..428ca22b761 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/java/functionN.fir.kt @@ -0,0 +1,58 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER + +// FILE: KI.kt + +interface KI { + fun manyParams(x: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String) -> Unit) +} + +// FILE: A.java + +import kotlin.jvm.functions.FunctionN; + +public class A implements KI { + public FunctionN field; + + public A(FunctionN w) {} + + public void foo(FunctionN x) { + + } + + public FunctionN bar() { + return null; + } + + public void baz(java.util.List> z) { + + } + + public void manyParams(FunctionN x) { + + } +} + +// FILE: main.kt + +fun any(): T = null!! + +fun main() { + val a: A = A(null) + + a.field.hashCode(); + a.field = null; + + a.foo(null) + a.bar() + a.baz(listOf()) + + a.manyParams(null) + a.manyParams(any>()) + + // Potentially, this would have better to forbid calling manyParams, too. + // But it might be complicated because we need to match that it is an override + // Seems to be fine because `A::manyParams` is anyway an override in JVM and can be called with (a as K) + a.manyParams { + x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32 -> + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/inheritedFunctionN.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/inheritedFunctionN.fir.kt new file mode 100644 index 00000000000..8ca90683387 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/java/inheritedFunctionN.fir.kt @@ -0,0 +1,16 @@ + +// FILE: A.java + +import kotlin.jvm.functions.FunctionN; + +public class A { + public void foo(FunctionN w) { } +} + +// FILE: main.kt + +class B : A() + +fun foo() { + object : A() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/java/patternCompileCallableReference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/java/patternCompileCallableReference.fir.kt new file mode 100644 index 00000000000..ed1d3830493 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/java/patternCompileCallableReference.fir.kt @@ -0,0 +1,8 @@ +// FULL_JDK +// SKIP_TXT + +import java.util.regex.Pattern + +val strs: List = listOf("regex1", "regex2") + +val patterns: List = strs.map(Pattern::compile) diff --git a/compiler/testData/diagnostics/testsWithStdLib/javaClassOnCompanion.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/javaClassOnCompanion.fir.kt new file mode 100644 index 00000000000..1a1936414f9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/javaClassOnCompanion.fir.kt @@ -0,0 +1,32 @@ +package test + +class A { + companion object +} + +object O + +enum class E { + ENTRY +} + + +val a0 = A.javaClass +val a1 = test.A.javaClass +val a2 = A.Companion.javaClass +val a3 = A::class.java +val a4 = test.A::class.java +val a5 = A.Companion::class.java + +val o0 = O.javaClass +val o1 = O::class.java + +val e0 = E.javaClass +val e1 = E::class.java +val e2 = E.ENTRY.javaClass + +val int0 = Int.javaClass +val int1 = Int::class.java + +val string0 = String.javaClass +val string1 = String::class.java diff --git a/compiler/testData/diagnostics/testsWithStdLib/javaForKClass.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/javaForKClass.fir.kt new file mode 100644 index 00000000000..2b484f7a656 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/javaForKClass.fir.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE + +// FILE: A.java +import kotlin.reflect.KClass; + +public class A { + public static A getA() { + return null; + } + + public static KClass getKClass() { + return null; + } +} + + +// types checked by txt file + +// FILE: 1.kt +inline fun test1() = X::class.java +inline fun test2() = X::class.java +inline fun test3() = X::class.java +inline fun test4() = X::class.java +inline fun test5() = X::class.java + +fun test6() = A.getA()::class.java +fun test7() = A.getKClass().java + diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.fir.kt new file mode 100644 index 00000000000..3867393a3f2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/kt7585/delegate.fir.kt @@ -0,0 +1,76 @@ +// !WITH_NEW_INFERENCE +// NI_EXPECTED_FILE +// JAVAC_EXPECTED_FILE +// FILE: Base.java + +public interface Base {} + +// FILE: Other.java + +public interface Other {} + +// FILE: Derived.java + +public final class Derived implements Base, Other {} + +// FILE: Exotic.java + +public final class Exotic implements Base, Other { + + int x; + + Exotic(int x) { + this.x = x; + } +} + +// FILE: Properties.java + +import kotlin.jvm.functions.Function0; + +class Val { + + Function0 initializer; + + Val(Function0 initializer) { + this.initializer = initializer; + } + + T getValue(Object instance, Object metadata) { + return initializer.invoke(); + } +} + +class Properties { + static Val calcVal(Function0 initializer) { + return new Val(initializer); + } +} + +// FILE: My.kt + +open class Wrapper(val v: T) + +class DerivedWrapper(v: Derived<*>): Wrapper>(v) + +class ExoticWrapper(v: Exotic): Wrapper(v) + +object MyBase { + + fun derived() = Derived() + fun exotic(x: Int) = Exotic(x) + + fun derivedWrapper() = DerivedWrapper(derived()) + fun exoticWrapper(x: Int) = ExoticWrapper(exotic(x)) +} + +class My(val x: Int) { + val wrapper/*: Wrapper<*>*/ by Properties.calcVal { + val y = x + 1 + when { + y > 0 -> MyBase.derivedWrapper() + x < 0 -> MyBase.exoticWrapper(x) + else -> throw java.lang.NullPointerException("") + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt8050.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/kt8050.fir.kt new file mode 100644 index 00000000000..fa84db2e1e8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/kt8050.fir.kt @@ -0,0 +1,11 @@ +private class X + +private operator fun X?.plus(p: Int) = X() + +class C { + private val map = hashMapOf() + + fun f() { + map[""] += 1 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt9078.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/kt9078.fir.kt new file mode 100644 index 00000000000..12aa7946ceb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/kt9078.fir.kt @@ -0,0 +1,12 @@ +// KT-9078 (NPE in control flow analysis); EA-71535 +abstract class KFunctionKt9005WorkAround(private val _functionInstance: Function) { + private val _reflectedFunction: kotlin.reflect.KFunction = _functionInstance.reflect() ?: throw IllegalStateException("") + + private val _parameters: List = run { + _functionInstance.javaClass.methods.first().parameters.map { + object : kotlin.reflect.KParameter { + override val index: Int = 0 + } + } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/kt9985.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/kt9985.fir.kt new file mode 100644 index 00000000000..a99da78ab1c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/kt9985.fir.kt @@ -0,0 +1,3 @@ +fun foo(l: List?) { + Pair(l?.joinToString(), "") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/lateinit/isInitialized.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/lateinit/isInitialized.fir.kt new file mode 100644 index 00000000000..681023b0659 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/lateinit/isInitialized.fir.kt @@ -0,0 +1,87 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE +// FILE: test.kt + +interface Base { + var x: String +} + +open class Foo : Base { + override lateinit var x: String + private lateinit var y: String + + var nonLateInit: Int = 1 + + fun ok() { + val b: Boolean = this::x.isInitialized + + val otherInstance = Foo() + otherInstance::x.isInitialized + + (this::x).isInitialized + (@Suppress("ALL") (this::x)).isInitialized + + object { + fun local() { + class Local { + val xx = this@Foo::x.isInitialized + val yy = this@Foo::y.isInitialized + } + } + } + } + + fun onLiteral() { + val p = this::x + p.isInitialized + } + + fun onNonLateinit() { + this::nonLateInit.isInitialized + } + + inline fun inlineFun() { + this::x.isInitialized + + object { + val z = this@Foo::x.isInitialized + } + } + + inner class InnerSubclass : Foo() { + fun innerOk() { + // This is access to Foo.x declared lexically above + this@Foo::x.isInitialized + + // This is access to InnerSubclass.x which is inherited from Foo.x + this::x.isInitialized + } + } +} + +fun onNonAccessible() { + Foo()::x.isInitialized +} + +fun onNonLateinit() { + Foo()::nonLateInit.isInitialized +} + +object Unrelated { + fun onNonAccessible() { + Foo()::x.isInitialized + } +} + +class FooImpl : Foo() { + fun onNonAccessible() { + this::x.isInitialized + } +} + +// FILE: other.kt + +class OtherFooImpl : Foo() { + fun onNonAccessible() { + this::x.isInitialized + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/multiplatform/jvmOverloads.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/multiplatform/jvmOverloads.fir.kt new file mode 100644 index 00000000000..427d84be1c8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/multiplatform/jvmOverloads.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +expect fun foo(x: String, y: Int = -1) + +// MODULE: m2-jvm(m1-common) +// FILE: jvm.kt + +@JvmOverloads +actual fun foo(x: String, y: Int) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/abstract.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/abstract.fir.kt new file mode 100644 index 00000000000..aaab812e231 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/abstract.fir.kt @@ -0,0 +1,11 @@ +import kotlin.jvm.* + +abstract class C { + abstract external fun foo() +} + +fun test() { + abstract class Local { + abstract external fun foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/body.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/body.fir.kt new file mode 100644 index 00000000000..47810841b9e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/body.fir.kt @@ -0,0 +1,25 @@ +import kotlin.jvm.* + +external fun foo() {} + +class C { + external fun foo() {} + + companion object { + external fun foo() {} + } +} + +object O { + external fun foo() {} +} + +fun test() { + class Local { + external fun foo() {} + } + + object { + external fun foo() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.fir.kt new file mode 100644 index 00000000000..3c11f664fd8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.fir.kt @@ -0,0 +1,10 @@ +class A { + external constructor() {} + inner class B { + external constructor() {} + } + + external constructor(x: Int) +} + +class C external constructor() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/inline.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/inline.fir.kt new file mode 100644 index 00000000000..bc87beed226 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/inline.fir.kt @@ -0,0 +1,11 @@ +import kotlin.jvm.* + +abstract class C { + inline external fun foo() +} + +fun test() { + abstract class Local { + inline external fun foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/noBody.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/noBody.fir.kt new file mode 100644 index 00000000000..3d262f82bb0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/noBody.fir.kt @@ -0,0 +1,25 @@ +import kotlin.jvm.* + +external fun foo() + +class C { + external fun foo() + + companion object { + external fun foo() + } +} + +object O { + external fun foo() +} + +fun test() { + class Local { + external fun foo() + } + + object { + external fun foo() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.fir.kt new file mode 100644 index 00000000000..1755e7f8d60 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/nonFunction.fir.kt @@ -0,0 +1,9 @@ +external class A + +external val foo: Int = 23 + +class B { + external class A + + external val foo: Int = 23 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/override.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/override.fir.kt new file mode 100644 index 00000000000..7662d324aa0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/override.fir.kt @@ -0,0 +1,9 @@ +import kotlin.jvm.* + +interface Base { + fun foo() +} + +class Derived : Base { + override external fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/reified.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/reified.fir.kt new file mode 100644 index 00000000000..1dd7ee2ac95 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/reified.fir.kt @@ -0,0 +1,4 @@ +import kotlin.jvm.* + +external fun foo() +inline external fun bar() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/trait.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/native/trait.fir.kt new file mode 100644 index 00000000000..b05f86c1f69 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/native/trait.fir.kt @@ -0,0 +1,11 @@ +import kotlin.jvm.* + +interface Tr { + external fun foo() + external fun bar() {} + + companion object { + external fun foo() + external fun bar() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/outstar.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/outstar.fir.kt new file mode 100644 index 00000000000..97dbf9f9e05 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/outstar.fir.kt @@ -0,0 +1,11 @@ +// Reproduces exception in TypeResolver.kt: EA-66870 + +import java.util.ArrayList + +abstract class J { + public abstract fun , S : List> foo(x: T) + fun bar() { + val s = ArrayList>() + foo(s) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/overrideWithFunctionalType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/overrideWithFunctionalType.fir.kt new file mode 100644 index 00000000000..b00b584bd5e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/overrideWithFunctionalType.fir.kt @@ -0,0 +1,17 @@ +// FILE: Derived.java +import kotlin.jvm.functions.Function0; +import org.jetbrains.annotations.NotNull; + +public class Derived implements Base { + @Override + public void foo(@NotNull Function0 compute) {} +} + +// FILE: main.kt +interface Base { + fun foo(compute: () -> V?) +} + +fun main() { + Derived().foo { "" } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/pureReifiable.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/pureReifiable.fir.kt new file mode 100644 index 00000000000..648e86cbe34 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/pureReifiable.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +inline fun foo(x: T) {} + +fun test() { + foo>(listOf("")) + foo(listOf("")) + + foo>(arrayOf("")) + foo(arrayOf("")) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/pureReifiableArrayOperations.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/pureReifiableArrayOperations.fir.kt new file mode 100644 index 00000000000..57cad51a93e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/pureReifiableArrayOperations.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun test() { + arrayOf>(listOf("")) + arrayOf(listOf("")) + + arrayOf>(arrayOf("")) + arrayOf(arrayOf("")) + + arrayOfNulls>(1) + + Array>(1) { arrayOf("") } + Array(1) { arrayOf("") } + Array(1) { arrayOf("") } + + emptyArray>() + val x: Array> = emptyArray() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.fir.kt new file mode 100644 index 00000000000..b2f9ec43367 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayList.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +import java.util.* + +fun bar(): String? = null + +fun foo() { + var x = ArrayList() + x.add(null) + x.add(bar()) + x.add("") + + x[0] = null + x[0] = bar() + x[0] = "" + + val b1: MutableList = x + val b2: MutableList = x + val b3: List = x + + val b4: Collection = x + val b6: MutableCollection = x +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayListNullable.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayListNullable.fir.kt new file mode 100644 index 00000000000..17cb82eb4c8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/arrayListNullable.fir.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +import java.util.* + +fun bar(): String? = null + +fun foo() { + var x = ArrayList() + x.add(null) + x.add(bar()) + x.add("") + + x[0] = null + x[0] = bar() + x[0] = "" + + val b1: MutableList = x + val b2: MutableList = x + val b3: List = x + + val b4: Collection = x + val b6: MutableCollection = x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableCollection.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableCollection.fir.kt new file mode 100644 index 00000000000..5bedf9d6c26 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableCollection.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// JAVAC_EXPECTED_FILE + +import java.util.*; + +// FILE: A.java +@kotlin.jvm.PurelyImplements("kotlin.collections.MutableCollection") +class A extends AbstractCollection { + @Override + public Iterator iterator() { + return null; + } + + @Override + public int size() { + return 0; + } +} + +// FILE: b.kt + +fun bar(): String? = null + +fun foo() { + var x = A() + x.add(null) + x.add(bar()) + x.add("") + + val b1: Collection = x + val b2: MutableCollection = x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.fir.kt new file mode 100644 index 00000000000..6a4b798bea1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/customClassMutableList.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// JAVAC_EXPECTED_FILE + +import java.util.*; + +// FILE: A.java +@kotlin.jvm.PurelyImplements("kotlin.collections.MutableList") +class A extends AbstractList { + @Override + public T get(int index) { + return null; + } + + @Override + public int size() { + return 0; + } +} + +// FILE: b.kt + +fun bar(): String? = null + +fun foo() { + var x = A() + x.add(null) + x.add(bar()) + x.add("") + + x[0] = null + x[0] = bar() + x[0] = "" + + val b1: MutableList = x + val b2: MutableList = x + val b3: List = x + + val b4: Collection = x + val b6: MutableCollection = x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.fir.kt new file mode 100644 index 00000000000..80c8397edc9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/invalidFqName.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE + +// FILE: A.java +import java.util.*; + +@kotlin.jvm.PurelyImplements("") +public class A extends AbstractList { + @Override + public T get(int index) { + return null; + } + + @Override + public int size() { + return 0; + } +} + +// FILE: B.java +import java.util.*; + +@kotlin.jvm.PurelyImplements("[INVALID]") +public class B extends AbstractList {} + +// FILE: main.kt +val x = A() +val y = B() diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/maps.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/maps.fir.kt new file mode 100644 index 00000000000..26697f2a424 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/maps.fir.kt @@ -0,0 +1,81 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.* +import java.util.concurrent.* + +fun bar(): String? = null +val nullableInt: Int? = null + +fun hashMapTest() { + var x: HashMap = HashMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} + +fun treeMapTest() { + var x: TreeMap = TreeMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} + +fun concurrentHashMapTest() { + var x: ConcurrentHashMap = ConcurrentHashMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableKey.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableKey.fir.kt new file mode 100644 index 00000000000..d139896edca --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableKey.fir.kt @@ -0,0 +1,57 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.* + +fun bar(): String? = null +val nullableInt: Int? = null + +fun hashMapTest() { + var x: HashMap = HashMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x[null] + val b8: Int = x.get("") + + val b9: Int? = x.get("") +} + +fun treeMapTest() { + var x: TreeMap = TreeMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableValues.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableValues.fir.kt new file mode 100644 index 00000000000..f06efd6038e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/mapsWithNullableValues.fir.kt @@ -0,0 +1,56 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.* + +fun bar(): String? = null +val nullableInt: Int? = null + +fun hashMapTest() { + var x: HashMap = HashMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} + +fun treeMapTest() { + var x: TreeMap = TreeMap() + x.put(null, null) + x.put("", null) + x.put(bar(), 1) + x.put("", 1) + + x[null] = 1 + x[bar()] = 1 + x[""] = nullableInt + x[""] = 1 + + val b1: MutableMap = x + val b2: MutableMap = x + val b3: Map = x + val b4: Map = x + val b5: Map = x + + val b6: Int = x[""] + val b7: Int = x.get("") + + val b8: Int? = x.get("") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/sets.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/sets.fir.kt new file mode 100644 index 00000000000..b50262fefeb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/sets.fir.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// FULL_JDK + +import java.util.* + +fun bar(): String? = null + +fun fooHashSet() { + var x = HashSet() + x.add(null) + x.add(bar()) + x.add("") + + val b1: MutableSet = x + val b2: MutableSet = x + val b3: Set = x + + val b4: Collection = x + val b6: MutableCollection = x +} + +fun fooTreeSet() { + var x = TreeSet() + x.add(null) + x.add(bar()) + x.add("") + + val b1: MutableSet = x + val b2: MutableSet = x + val b3: Set = x + + val b4: Collection = x + val b6: MutableCollection = x +} + +fun fooLinkedHashSet() { + var x = LinkedHashSet() + x.add(null) + x.add(bar()) + x.add("") + + val b1: MutableSet = x + val b2: MutableSet = x + val b3: Set = x + + val b4: Collection = x + val b6: MutableCollection = x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.fir.kt new file mode 100644 index 00000000000..1fb450aad86 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/purelyImplementedCollection/wrongTypeParametersCount.fir.kt @@ -0,0 +1,40 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// JAVAC_EXPECTED_FILE + +import java.util.*; + +// FILE: A.java +@kotlin.jvm.PurelyImplements("kotlin.collections.MutableList") +class A extends AbstractList { + @Override + public T get(int index) { + return null; + } + + @Override + public int size() { + return 0; + } +} + +// FILE: b.kt + +fun bar(): String? = null + +fun foo() { + var x = A() + x.add(null) + x.add(bar()) + x.add("") + + x[0] = null + x[0] = bar() + x[0] = "" + + val b1: MutableList = x + val b2: MutableList = x + val b3: List = x + + val b4: Collection = x + val b6: MutableCollection = x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/reflection/typeOfWithNonReifiedParameter.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reflection/typeOfWithNonReifiedParameter.fir.kt new file mode 100644 index 00000000000..2f910a1e162 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reflection/typeOfWithNonReifiedParameter.fir.kt @@ -0,0 +1,35 @@ +// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi +// !LANGUAGE: +ProhibitNonReifiedArraysAsReifiedTypeArguments + +import kotlin.reflect.typeOf + +inline fun test1() { + typeOf() + typeOf>() + typeOf>() + + typeOf() + + typeOf() + typeOf?>() + typeOf>() +} + + +class Test2 { + fun test2() { + typeOf() + typeOf>() + typeOf>() + } +} + + +inline fun f() { + typeOf() +} + +fun test3() { + // We don't report anything here because we can't know in frontend how the corresponding type parameter is used in f + f>() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea63992.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea63992.fir.kt new file mode 100644 index 00000000000..6fdd50da1ad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea63992.fir.kt @@ -0,0 +1,7 @@ +fun add(a: Int, b: Int) = a + b +interface A { + fun shuffle(x: List): List + fun foo(f : (List) -> List, x : List) + +fun f() : (Int, Int) -> Int = ::add +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea65206.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea65206.fir.kt new file mode 100644 index 00000000000..09dbc59c925 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea65206.fir.kt @@ -0,0 +1,9 @@ +class A { + val x = arrayListOf<(A<>) -> Unit>() + + // Here we got an exception during type comparison + fun foo(){ + x.add {} + } + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea66827_dataClassWrongToString.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea66827_dataClassWrongToString.fir.kt new file mode 100644 index 00000000000..9cc1a6bf83d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea66827_dataClassWrongToString.fir.kt @@ -0,0 +1,7 @@ +data class A(val x: Int) { + fun toArray(): IntArray = + intArrayOf(x) + + override fun toString() = + toArray().takeWhile { it != -1 } // .joinToString() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.fir.kt new file mode 100644 index 00000000000..b94f4ee0b6a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.fir.kt @@ -0,0 +1,17 @@ +class O : Function2 { + override fun invoke(p1: Int, p2: String) { + } +} + +fun test() { + val a = fun(o: O) { + } + a {} +} + +class Ext : String.() -> Unit { +} + +fun test2() { + val f: Ext = {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea70880_illegalJvmName.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70880_illegalJvmName.fir.kt new file mode 100644 index 00000000000..c1ce1e4d6b1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70880_illegalJvmName.fir.kt @@ -0,0 +1,8 @@ +@JvmName() +fun foo() {} + +@JvmName(42) +fun bar() {} + +@JvmName("a", "b") +fun baz() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt new file mode 100644 index 00000000000..1f2bc054fdf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt @@ -0,0 +1,9 @@ +fun foo1(p: Pair): Int { + if (p.first != null) return p.first!! + return p.second +} + +fun foo2(p: Pair): Int { + if (p.first != null) return p.first + return p.second +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt new file mode 100644 index 00000000000..0548489ea06 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.fir.kt @@ -0,0 +1,10 @@ +fun foo(c : Collection) = { + c.filter{ + val s : String? = bar() + if (s == null) false // here! + zoo(s) + } +} + +fun bar() : String? = null +fun zoo(s : String) : Boolean = true \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt26806.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt26806.fir.kt new file mode 100644 index 00000000000..5ab2c2ff4bc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt26806.fir.kt @@ -0,0 +1,9 @@ +const val myPi = kotlin.math.PI + +annotation class Anno(val d: Double) + +@Anno(kotlin.math.PI) +fun f() {} + +@Anno(myPi) +fun g() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.fir.kt new file mode 100644 index 00000000000..63db720eb0d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt34391.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference + +fun main() { + val list = listOf(A()) + list.forEach(A::foo) + list.forEach { + it.foo() + } +} + +class A { + @ExperimentalTime + fun foo() { + println("a") + } +} + +@Experimental(level = Experimental.Level.ERROR) +annotation class ExperimentalTime diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.fir.kt new file mode 100644 index 00000000000..5e21e489ac9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9345.fir.kt @@ -0,0 +1,3 @@ +//KT-9345 Type inference failure + +fun Class<*>.foo(): Any? = kotlin.objectInstance \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.fir.kt new file mode 100644 index 00000000000..a5feb405213 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt9820_javaFunctionTypeInheritor.fir.kt @@ -0,0 +1,16 @@ +// FILE: J.java + +import kotlin.jvm.functions.Function1; + +public interface J extends Function1 { +} + +// FILE: 1.kt + +fun useJ(j: J) { + j(42) +} + +fun jj() { + useJ({}) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.fir.kt new file mode 100644 index 00000000000..fba40c1657f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.fir.kt @@ -0,0 +1,18 @@ +// !WITH_NEW_INFERENCE + +fun fail1(): Array = Array(1) { null!! } +fun ok1(block: () -> Array): Array = block() +inline fun ok2(): Array = Array(1) { null!! } + + +fun fail2(): Array = ok1 { Array(1) { null!! } } +fun ok3(block: () -> Array): Array = ok1 { block() } +inline fun ok4(): Array = ok1 { Array(1) { null!! } } + +fun fail3(block: () -> T): Pair, Array> = Pair(arrayOf( + block()), arrayOf() +) +inline fun ok5(block: () -> T): Pair, Array> = Pair( + arrayOf(block()), arrayOf() +) + diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/arrayOfNullsReified.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayOfNullsReified.fir.kt new file mode 100644 index 00000000000..e418e602769 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayOfNullsReified.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + val x = arrayOfNulls(5) +} + +inline fun bar() { + val x = arrayOfNulls(5) +} + +fun baz() { + bar() + val x: Array = arrayOfNulls(5) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/kt11881.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/kt11881.fir.kt new file mode 100644 index 00000000000..77fe0056f6a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/kt11881.fir.kt @@ -0,0 +1,9 @@ +class Inv + +inline operator fun Inv.invoke() {} + +operator fun Inv.get(i: Int): Inv = this + +fun test(a: Inv) { + a[1]() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/nonCallableReiefied.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/nonCallableReiefied.fir.kt new file mode 100644 index 00000000000..df17f0fad3e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/nonCallableReiefied.fir.kt @@ -0,0 +1,11 @@ +class A(val x: Array) { + val y: Int = x[0].toString().length + + fun foo(a: T) { + x[0] = a + } + + fun bar(a: Array): Int = a[0].toString().length +} + +fun baz(a: Array): String = a[0].toString() diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.fir.kt new file mode 100644 index 00000000000..988bf2ee966 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/reifiedNothingSubstitution.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -DEPRECATION +// !WITH_NEW_INFERENCE + +inline fun foo(block: () -> T): String = block().toString() + +inline fun javaClass(): Class = T::class.java + +fun box() { + val a = arrayOf(null!!) + val b = Array(5) { null!! } + val c = foo() { null!! } + val d = foo { null!! } + val e = foo { "1" as Nothing } + val e1 = foo { "1" as Nothing? } + + val f = javaClass() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.fir.kt new file mode 100644 index 00000000000..db29f51110a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers.fir.kt @@ -0,0 +1,52 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: 2.kt +package b + +import a.A + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.HidesMembers +fun A.forEach(i: Int) = i + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.HidesMembers +fun A.forEach(s: String) {} + + +// FILE: 1.kt +package a + +import b.* + +class A { + fun forEach() = this + fun forEach(i: Int) = this + fun forEach(i: String) = this +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.HidesMembers +fun A.forEach() = "" + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.HidesMembers +fun A.forEach(s: String) {} + +fun test(a: A) { + a.forEach() checkType { _() } + + a.forEach(1) checkType { _() } + + a.forEach("") + + with(a) { + forEach() checkType { _() } + + forEach(1) checkType { _() } + + forEach("") + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.fir.kt new file mode 100644 index 00000000000..6d0bf09ce25 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/hidesMembers2.fir.kt @@ -0,0 +1,42 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +class A { + fun forEach() = this + fun forEach(i: Int) = this +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.HidesMembers +fun A.forEach(i: Int) = i + +class B { + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + @kotlin.internal.HidesMembers + fun A.forEach() = this@B + + fun test(a: A) { + a.forEach() checkType { _() } // todo + + with(a) { + forEach() checkType { _() } // todo + } + } +} + +fun test2(a: A) { + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + @kotlin.internal.HidesMembers + fun A.forEach() = "" + + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + @kotlin.internal.HidesMembers + fun A.forEach(i: Int) = "" + + a.forEach() checkType { _() } + a.forEach(1) + + with(a) { + forEach() checkType { _() } + forEach(1) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/javaPackageMembers.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/javaPackageMembers.fir.kt new file mode 100644 index 00000000000..16749b92a94 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/javaPackageMembers.fir.kt @@ -0,0 +1,9 @@ +fun fn(): Nothing = throw java.lang.RuntimeException("oops") + +val x: Nothing = throw java.lang.RuntimeException("oops") + +class SomeClass { + fun method() { + throw java.lang.AssertionError("!!!") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/javaStaticMembers.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/javaStaticMembers.fir.kt new file mode 100644 index 00000000000..56b7c6ab3f2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/javaStaticMembers.fir.kt @@ -0,0 +1,12 @@ +// FILE: Test.java +public class Test { + public static final String FOO = "test"; +} + +// FILE: test.kt +fun ff() { + val a = Test.FOO + val b = Test?.FOO + System.out.println(a + b) + System?.out.println(a + b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10103.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10103.fir.kt new file mode 100644 index 00000000000..986bf3b6bae --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10103.fir.kt @@ -0,0 +1 @@ +val stringReversed = String::reversed \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10732a.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10732a.fir.kt new file mode 100644 index 00000000000..f7ac21f1f61 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt10732a.fir.kt @@ -0,0 +1,10 @@ +fun List?.foo() {} + +@JvmName("foo1") +fun List.foo() {} + + +fun bar(x: List) = x + +@JvmName("bar1") +fun bar(x: List?) = x diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.fir.kt new file mode 100644 index 00000000000..3c7c16d90e8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.fir.kt @@ -0,0 +1,21 @@ +// !WITH_NEW_INFERENCE +//KT-4711 Error type with no error reported from type inference + +fun main() { + val n = 100 + val delta = 1.0 / n + val startTimeNanos = System.nanoTime() + + // the problem sits on the next line: + val pi = 4.0.toDouble() * delta * (1..n).reduce( + {t, i -> + val x = (i - 0.5) * delta + t + 1.0 / (1.0 + x * x) + + }) + // !!! pi has error type here + + val elapseTime = (System.nanoTime() - startTimeNanos) / 1e9 + + println("pi_sequential_reduce $pi $n $elapseTime") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samAgainstFunctionalType.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samAgainstFunctionalType.fir.kt new file mode 100644 index 00000000000..16c870e7f15 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samAgainstFunctionalType.fir.kt @@ -0,0 +1,30 @@ +// !WITH_NEW_INFERENCE +// !CHECK_TYPE + +// FILE: StaticOverrides.java + +import kotlin.Unit; +import kotlin.jvm.functions.Function0; + +public class StaticOverrides { + public static class A { + public static int foo(Runnable x) { return 0; } + public static boolean foo(Function0 x) { return true; } + } + + public static class B { + public static String foo(Runnable x) { return ""; } + } + + public static class C extends A { + public static String foo(Runnable x) { return ""; } + } +} + +// FILE: test.kt + +fun test() { + StaticOverrides.A.foo {} checkType { _() } + StaticOverrides.B.foo {} checkType { _() } + StaticOverrides.C.foo {} checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samConstructorVsFun.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samConstructorVsFun.fir.kt new file mode 100644 index 00000000000..57eb8e96916 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samConstructorVsFun.fir.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// FILE: s/SamConstructor.java +package s; + +public class SamConstructor { + public SamConstructor(Runnable r) { + } + + public static void foo(Runnable r) {} +} + +// FILE: 1.kt +package a + +fun SamConstructor(a: () -> Unit) {} + +// FILE: 2.kt + +package b + +import s.SamConstructor +import a.* + +fun test() { + val a: s.SamConstructor = SamConstructor { } + + val b: s.SamConstructor = SamConstructor(null) + + SamConstructor.foo(null) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenerics.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenerics.fir.kt new file mode 100644 index 00000000000..68cd3929737 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenerics.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE + +// FILE: Foo.java +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +class Foo { + interface FObject { + void invoke(T i); + } + + public String foo(FObject f) { return ""; } + public int foo(Function1 f) { return 1; } + + public String bar(FObject f) { return ""; } + public int bar(Function1 f) { return 1; } +} + +// FILE: 1.kt +fun test() { + Foo().foo {} checkType { _() } + Foo().bar {} checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenericsWithoutRefinedSams.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenericsWithoutRefinedSams.fir.kt new file mode 100644 index 00000000000..39ea5223af3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithGenericsWithoutRefinedSams.fir.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: -RefinedSamAdaptersPriority +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE + +// FILE: Foo.java +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +class Foo { + interface FObject { + void invoke(T i); + } + + public String foo(FObject f) { return ""; } + public int foo(Function1 f) { return 1; } + + public String bar(FObject f) { return ""; } + public int bar(Function1 f) { return 1; } +} + +// FILE: 1.kt +fun test() { + Foo().foo {} checkType { _() } + Foo().bar {} checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunction.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunction.fir.kt new file mode 100644 index 00000000000..394b4ee42b7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunction.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +// FILE: Foo.java +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +public class Foo { + interface FObject { + void invoke(Object i); + } + + public String test(FObject f) { return ""; } + public int test(Function1 f) { return 1; } +} + +// FILE: 1.kt +fun bar() { + Foo().test {} checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunctionWithoutRefinedSams.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunctionWithoutRefinedSams.fir.kt new file mode 100644 index 00000000000..db8e64fa963 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/samOverloadsWithKtFunctionWithoutRefinedSams.fir.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: -RefinedSamAdaptersPriority +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE +// !WITH_NEW_INFERENCE + +// FILE: Foo.java +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +public class Foo { + interface FObject { + void invoke(Object i); + } + + public String test(FObject f) { return ""; } + public int test(Function1 f) { return 1; } +} + +// FILE: 1.kt +fun bar() { + Foo().test {} checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/shadowingInDestructuring.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/shadowingInDestructuring.fir.kt new file mode 100644 index 00000000000..51e32baee57 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/shadowingInDestructuring.fir.kt @@ -0,0 +1,10 @@ +data class XY(val x: Int, val y: Int) + +fun foo(list: List) { + for ((x1, y1) in list) { + for ((x2, y2) in list) { + if (x1 == y2 && x2 == y1) return + } + list.map { (x3, y3) -> x3 + y3 } + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachSafe.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachSafe.fir.kt new file mode 100644 index 00000000000..3eb045d61d2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachSafe.fir.kt @@ -0,0 +1,12 @@ +// !WITH_NEW_INFERENCE +// KT-7186: False "Type mismatch" error + +fun indexOfMax(a: IntArray): Int? { + var maxI: Int? = null + a.forEachIndexed { i, value -> + if (maxI == null || value >= a[maxI]) { + maxI = i + } + } + return maxI +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachUnsafe.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachUnsafe.fir.kt new file mode 100644 index 00000000000..2972e263e69 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/forEachUnsafe.fir.kt @@ -0,0 +1,14 @@ +// KT-7186: False "Type mismatch" error + +fun indexOfMax(a: IntArray): Int? { + var maxI: Int? = 0 + a.forEachIndexed { i, value -> + if (value >= a[maxI]) { + maxI = i + } + else if (value < 0) { + maxI = null + } + } + return maxI +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/kt10463.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/kt10463.fir.kt new file mode 100644 index 00000000000..dcaeb8aa146 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/kt10463.fir.kt @@ -0,0 +1,6 @@ +val test: Int = listOf().map { + when (it) { + is Int -> it + else -> throw AssertionError() + } +}.sum() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/lazyDeclaresAndModifies.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/lazyDeclaresAndModifies.fir.kt new file mode 100644 index 00000000000..7536bd51c83 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/lazyDeclaresAndModifies.fir.kt @@ -0,0 +1,11 @@ +class My(val x: Int?) { + val y: Int? by lazy { + var z = x + while (z != null) { + z = z.hashCode() + if (z < 0) return@lazy z + if (z == 0) z = null + } + return@lazy null + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letAlwaysChangesToNotNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letAlwaysChangesToNotNull.fir.kt new file mode 100644 index 00000000000..3fa4b2468ec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letAlwaysChangesToNotNull.fir.kt @@ -0,0 +1,7 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun foo(y: String) { + var x: String? = null + y.let { x = it } + x.length // Smart cast is not possible +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNotNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNotNull.fir.kt new file mode 100644 index 00000000000..529c3172b29 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNotNull.fir.kt @@ -0,0 +1,7 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun foo(y: String?) { + var x: String? = null + y?.let { x = it } + x.length // Smart cast is not possible +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNull.fir.kt new file mode 100644 index 00000000000..06db53d4e93 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNull.fir.kt @@ -0,0 +1,9 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun foo(y: String?) { + var x: String? = "" + if (x != null) { + y?.let { x = null } + x.length // Smart cast is not possible + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNullComplex.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNullComplex.fir.kt new file mode 100644 index 00000000000..ddee7e5b9df --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letChangesToNullComplex.fir.kt @@ -0,0 +1,11 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun bar(z: String?) = z + +fun foo(y: String?) { + var x: String? = "" + if (x != null) { + bar(y?.let { x = null; it }).length + x.length // Smart cast is not possible + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letMergeNotNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letMergeNotNull.fir.kt new file mode 100644 index 00000000000..833bb2fecce --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letMergeNotNull.fir.kt @@ -0,0 +1,9 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun foo(y: String?) { + var x: String? = null + if (x != null) { + y?.let { x = it } + x.length // not-null or not-null + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letStable.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letStable.fir.kt new file mode 100644 index 00000000000..fe36fbf9f68 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letStable.fir.kt @@ -0,0 +1,10 @@ +// KT-9051: Allow smart cast for captured variables if they are not modified + +fun foo(y: String?) { + var x: String? = "" + if (x != null) { + y?.let { x != y } + // x is not changed, smart cast is possible + x.length + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letUsesOwnReceiver.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letUsesOwnReceiver.fir.kt new file mode 100644 index 00000000000..0e3733de8c6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/letUsesOwnReceiver.fir.kt @@ -0,0 +1,7 @@ +// Based on KT-9033 +fun f(s: String) = s + +fun foo(s: String?) { + s?.let { f(s) } + s?.let { f(it) } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/listOfGeneric.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/listOfGeneric.fir.kt new file mode 100644 index 00000000000..f9611264f24 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/listOfGeneric.fir.kt @@ -0,0 +1,8 @@ +// See KT-9529 Smart cast causes code to be incompilable + +fun foo(o: T): Collection { + if (o is String) { + return listOf(o) + } + return listOf(o) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/smartcasts/withChangesToNull.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/withChangesToNull.fir.kt new file mode 100644 index 00000000000..56035143ab2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/smartcasts/withChangesToNull.fir.kt @@ -0,0 +1,10 @@ +fun foo(y: String?) { + var x: String? = "" + if (x != null) { + with(y?.let { x = null; it }) { + this.length + x.length + } + x.length + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/sourceCompatibility/noDefaultImportOfKotlinComparisons.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/sourceCompatibility/noDefaultImportOfKotlinComparisons.fir.kt new file mode 100644 index 00000000000..17bb9e1fbab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/sourceCompatibility/noDefaultImportOfKotlinComparisons.fir.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: -DefaultImportOfPackageKotlinComparisons + +fun foo() = compareBy { it.length } diff --git a/compiler/testData/diagnostics/testsWithStdLib/streams.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/streams.fir.kt new file mode 100644 index 00000000000..a447b3bba69 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/streams.fir.kt @@ -0,0 +1,9 @@ +// FULL_JDK +// STDLIB_JDK8 + +import java.util.* +import kotlin.streams.toList + +fun testStreams(list: ArrayList) { + list.stream().toList() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt new file mode 100644 index 00000000000..cb006fee726 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt @@ -0,0 +1,22 @@ +// !WITH_NEW_INFERENCE +// FULL_JDK + +abstract class A : MutableList { + override fun sort(/*0*/ p0: java.util.Comparator) { + super.sort(p0) + } +} + +fun foo(x: MutableList, y: java.util.ArrayList, z: A, p: java.util.Comparator) { + x.sort(p) + y.sort(p) + + z.sort(p) +} + +fun bar(x: MutableList, y: java.util.ArrayList, z: A) { + x.sort { a, b -> a.length - b.length } + y.sort { a, b -> a.length - b.length } + + z.sort { a, b -> a.length - b.length } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/unsupportedFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/unsupportedFeature.fir.kt new file mode 100644 index 00000000000..5839abbd937 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/unsupportedFeature.fir.kt @@ -0,0 +1,66 @@ +// !CHECK_TYPE +// !LANGUAGE: -AdditionalBuiltInsMembers +// !WITH_NEW_INFERENCE +// SKIP_TXT +// FULL_JDK + +class A : java.util.ArrayList() { + // `stream` is defined in ArrayList, so it was impossible to override it in 1.0 + override fun stream(): java.util.stream.Stream = super.stream() + + // `sort` is defined in ArrayList, so it was possible to override it in 1.0 + override fun sort(c: Comparator?) { + super.sort(c) + } +} + +class A1 : java.util.ArrayList() { + // `stream` is defined in ArrayList, so it was possible to declare it in 1.0 without an 'override' keyword + fun stream(): java.util.stream.Stream = super.stream() + + // `sort` is defined in ArrayList, so it was impossible to declare it in 1.0 without an 'override' keyword + fun sort(c: Comparator?) { + super.sort(c) + } +} + +interface A2 : List { + override fun stream(): java.util.stream.Stream = null!! +} + +class B : Throwable("", null, false, false) + +class B1 : RuntimeException() { + override fun fillInStackTrace(): Throwable { // 'override' keyword must be prohibited, as it was in 1.0.x + return this + } +} + +class A3(val x: List) : List by x + +fun Throwable.fillInStackTrace() = 1 + +fun foo(x: List, y: Throwable, z: A3) { + x.stream() + java.util.ArrayList().stream() + + y.fillInStackTrace() checkType { _() } + + HashMap().getOrDefault(Any(), null) + + // Falls back to extension in stdlib + y.printStackTrace() + + z.stream() +} + +interface X { + fun foo(): Int = 1 + val hidden: Boolean +} + +class Y : X { + // There should not be UNSUPPORTED_FEATURE diagnostic + override fun foo() = 1 + override var hidden: Boolean = true +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..0238b3d455e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithDisabledFeature.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_DESTRUCTURED_PARAMETER_ENTRY, -UNUSED_ANONYMOUS_PARAMETER + +data class Foo1(val x: String, val y: String, val z: String = "") + +fun main() { + val (x1,y1,) = Pair(1,2) + val (x2, y2: Number,) = Pair(1,2) + val (x3,y3,z3,) = Foo1("", "", ) + val (x4,y4: CharSequence,) = Foo1("", "", "",) + val (x41,y41: CharSequence,/**/) = Foo1("", "", "",) + + val x5: (Pair, Int) -> Unit = { (x,y,),z, -> } + val x6: (Foo1, Int) -> Any = { (x,y,z: CharSequence,), z1: Number, -> 1 } + val x61: (Foo1, Int) -> Any = { (x,y,z: CharSequence,/**/), z1: Number,/**/ -> 1 } + + for ((i, j,) in listOf(Pair(1,2))) {} + for ((i: Any,) in listOf(Pair(1,2))) {} + for ((i: Any,/**/) in listOf(Pair(1,2))) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..4bf34c3afc0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/multiVariableDeclarationWithEnabledFeature.fir.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_DESTRUCTURED_PARAMETER_ENTRY, -UNUSED_ANONYMOUS_PARAMETER +// !LANGUAGE: +TrailingCommas + +data class Foo1(val x: String, val y: String, val z: String = "") + +fun main() { + val (x1,y1,) = Pair(1, 2) + val (x2, y2: Number,) = Pair(1,2) + val (x3,y3,z3,) = Foo1("", "",) + val (x4,y4: CharSequence,) = Foo1("", "", "",) + val (x41,y41: CharSequence,/**/) = Foo1("", "", "",) + + val x5: (Pair, Int) -> Unit = { (x,y,),z, -> } + val x6: (Foo1, Int) -> Any = { (x,y,z: CharSequence,), z2: Number, -> 1 } + val x61: (Foo1, Int) -> Any = { (x,y,z: CharSequence,/**/), z2: Number,/**/ -> 1 } + + for ((i, j) in listOf(Pair(1,2))) {} + for ((i: Any,) in listOf(Pair(1,2))) {} + for ((i: Any,/**/) in listOf(Pair(1,2))) {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/noDisambiguation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/noDisambiguation.fir.kt new file mode 100644 index 00000000000..78df6b74bc2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/noDisambiguation.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER +// !LANGUAGE: +TrailingCommas + +fun foo(vararg x: Int) = false +fun foo() = true + +fun main() { + val x = foo() + val y = foo(,) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..7d12e9427a7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithDisabledFeature.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_TYPEALIAS_PARAMETER, -CAST_NEVER_SUCCEEDS + +class Foo1 {} + +interface Foo2 + +fun foo3() {} + +typealias Foo4 = Int + +class Foo5: Foo2 + +fun foo() { + val x1 = Foo1() + val x2: Foo2? = null + val x21: Foo2? = null + val x3 = foo3< + Int, + String, + Float, + >() + val x4: Foo4, Iterable,>, Double, T, + >? = null as Foo4, Iterable,>, Double, T,> + val x5: (Float,) -> Unit = {} + val x6: Pair<(Float, Comparable,) -> Unit, (Float,) -> Unit,>? = null + val x61: Pair<(Float, Comparable,/**/) -> Unit, (Float,/**/) -> Unit,/**/>? = null +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..3485444781e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeArgumentsWithEnabledFeature.fir.kt @@ -0,0 +1,28 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_TYPEALIAS_PARAMETER, -CAST_NEVER_SUCCEEDS +// !LANGUAGE: +TrailingCommas + +class Foo1 {} + +interface Foo2 + +fun foo3() {} + +typealias Foo4 = Int + +class Foo5: Foo2 + +fun foo () { + val x1 = Foo1() + val x2: Foo2? = null + val x21: Foo2? = null + val x3 = foo3< + Int, + String, + Float, + >() + val x4: Foo4, Iterable,>, Double, T, + >? = null as Foo4, Iterable,>, Double, T,> + val x5: (Float,) -> Unit = {} + val x6: Pair<(Float, Comparable,) -> Unit, (Float,) -> Unit,>? = null + val x61: Pair<(Float, Comparable,/**/) -> Unit, (Float,/**/) -> Unit,/**/>? = null +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..a6b085bd057 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithDisabledFeature.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_TYPEALIAS_PARAMETER + +@Target(AnnotationTarget.TYPE) +annotation class Anno + +class Foo1 + +class Foo2< + T1, + T2: T1, + > { + fun foo2() {} + + internal inner class B +} + +interface A + +interface A1 + +fun foo1() {} + +fun foo11() {} + +fun T2?.foo2() {} + +val T.bar1 get() = null + +var < + T4, + > T4?.bar2 + get() = null + set(value) { + + } + +typealias Foo3 = List + +typealias Foo4 = List + +fun main() { + fun foo10() { + fun foo10() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..bb48ef27620 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/typeParametersWithEnabledFeature.fir.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_TYPEALIAS_PARAMETER +// !LANGUAGE: +TrailingCommas + +@Target(AnnotationTarget.TYPE) +annotation class Anno + +class Foo1 + +class Foo2< + T1, + T2: T1, + > { + fun foo2() {} + + internal inner class B +} + +interface A + +interface A1 + +fun foo1() {} + +fun foo11() {} + +inline fun foo2() {} + +fun T2?.foo3() {} + +val T.bar1 get() = null + +var < + T4, + > T4?.bar2 + get() = null + set(value) { + + } + +typealias Foo3 = List + +typealias Foo4 = List + +fun main() { + fun foo10() { + fun foo10() {} + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..989def7b079 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithDisabledFeature.fir.kt @@ -0,0 +1,73 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -UNUSED_ANONYMOUS_PARAMETER + +@Target(AnnotationTarget.TYPE) +annotation class Anno1(val x: IntArray) + +@Target(AnnotationTarget.TYPEALIAS) +annotation class Anno2(val x: DoubleArray) + +fun foo1(vararg x: Any) {} +fun foo2(x: (Any, Any) -> Unit) {} +fun foo3(x: Any, y: () -> Unit) {} + +open class A1(vararg x: Any) { + operator fun get(x: Any, y: Any) = 10 +} + +open class A2(x: Int, y: () -> Unit) {} + +class B(): A1({},) { + +} + +@Anno2( + [ + 0.4, + .1, + ] +) +typealias A3 = B + +fun main1() { + foo1(1, 2, 3,) + foo1({},) + foo3(10,) {} + foo3(10,/**/) {} + + val x1 = A1(1, 2, 3,) + val y1 = A1({},) + val z1 = A2(10,) {} + + foo2({ x, y -> kotlin.Unit },) + foo2({ x, y -> kotlin.Unit },/**/) + + val foo = listOf( + println(1), + "foo bar something", + ) + + val x2 = x1[ + 1, + 2, + ] + + val x3 = x1[{},{},] + val x31 = x1[{},{},/**/] + + val x4: @Anno1([ + 1, 2, + ]) Float = 0f + + foo1(object {},) + foo1(object {},/**/) + foo1(fun () {},) + foo1(if (true) 1 else 2,) + + foo1(return,) +} + +fun main2(x: A1) { + val x1 = x[object {}, return, ] + val x2 = x[fun () {}, throw Exception(), ] + val x3 = x[fun () {}, throw Exception(),/**/ ] +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..7c3473a0f05 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueArgumentsWithEnabledFeature.fir.kt @@ -0,0 +1,69 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE, -UNUSED_ANONYMOUS_PARAMETER +// !LANGUAGE: +TrailingCommas + +@Target(AnnotationTarget.TYPE) +annotation class Anno1(val x: IntArray) + +@Target(AnnotationTarget.TYPEALIAS) +annotation class Anno2(val x: DoubleArray) + +fun foo1(vararg x: Any) {} +fun foo2(x: (Any, Any) -> Unit) {} +fun foo3(x: Any, y: () -> Unit) {} + +open class A1(vararg x: Any) { + operator fun get(x: Any, y: Any) = 10 +} + +open class A2(x: Any, y: () -> Unit) + +class B(): A1({},) { + +} + +@Anno2( + [ + 0.4, + .1, + ] +) +typealias A3 = B + +fun main1() { + foo1(1, 2, 3,/**/) + foo1({},) + foo3(10,/**/) {} + + val x1 = A1(1, 2, 3,) + val y1 = A1({},) + val z1 = A2(10,) {} + + foo2({ x, y -> kotlin.Unit },/**/) + + val foo = listOf( + println(1), + "foo bar something", + ) + + val x2 = x1[ + 1, + 2, + ] + + val x3 = x1[{},{},/**/] + + val x4: @Anno1([ + 1, 2,/**/ + ]) Float = 0f + + foo1(object {},) + foo1(fun () {},) + foo1(if (true) 1 else 2,/**/) + + foo1(return,) +} + +fun main2(x: A1) { + val x1 = x[object {}, return, ] + val x2 = x[fun () {}, throw Exception(), /**/] +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..24092568b53 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithDisabledFeature.fir.kt @@ -0,0 +1,120 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +open class Foo1(x: Int = 10, y: Float = 0f,) + +class Foo2( + val x: Int = 10, + var y: Float, +): Foo1(x, y,) { + constructor( + x: Float, + y: Int = 10, + ): this(1, 1f,) {} + + var x1: Int + get() = 10 + set(value,) { + + } + + var x2: Int + get() = 10 + set( + x2, + ) {} + + var x3: (Int) -> Unit + get() = {} + set(x2: (Int) -> Unit,) {} + + var x4: (Int) -> Unit + get() = {} + set(x2: (Int) -> Unit,/**/) {} +} + +enum class Foo3(x: Int, ) + +fun foo4(x: Int, y: Comparable,) {} + +fun foo5(x: Int = 10,) {} + +fun foo6(vararg x: Int,) {} + +fun foo7(y: Float, vararg x: Int,) {} + +val foo8: (Int, Int,) -> Int = fun( + x, + y, + ): Int { + return x + y +} + +val foo9: (Int, Int, Int,) -> Int = + fun (x, y: Int, z,): Int { + return x + y + } + +open class Foo10(x: Int = 10, y: Float = 0f) + +class Foo11: Foo10 { + constructor( + x: Float + ): super(1, 1f,) +} + +class Foo12: Foo10 { + constructor( + x: Float + ): super(1, 1f,/**/) +} + +fun main() { + val x1 = { + x: Comparable>, + y: Iterable>, + -> + println("1") + } + val x2 = { x: Comparable>, + -> println("1") + } + val x3: ((Int,) -> Int) -> Unit = { x: (Int,) -> Int, -> println("1") } + val x4: ((Int,) -> Int) -> Unit = { x, -> println("1") } + + fun foo10(x:Int,y:Int,) { + fun foo10(x:Int,y:Int,) {} + } + fun foo101(x:Int,y:Int,/**/) { + fun foo10(x:Int,y:Int,/**/) {} + } + + try { + println(1) + } catch (e: Exception,) { + + } + + try { + println(1) + } catch (e: Exception,) { + + } catch (e: Exception,) { + + } + + try { + println(1) + } catch (e: Exception,) { + + } finally { + + } + + try { + println(1) + } catch (e: Exception,/**/) { + + } finally { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..649e2491779 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/valueParametersWithEnabledFeature.fir.kt @@ -0,0 +1,104 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_ANONYMOUS_PARAMETER, -UNUSED_VARIABLE +// !LANGUAGE: +TrailingCommas + +open class Foo1(x: Int = 10, y: Float = 0f,) + +class Foo2( + val x: Int = 10, + var y: Float, +): Foo1(x, y) { + constructor( + x: Float, + y: Int = 10, + ): this(1, 1f,) { + + } +} + +enum class Foo3(x: Int, ) + +fun foo4(x: Int, y: Comparable,) {} + +fun foo5(x: Int = 10,) {} + +fun foo6(vararg x: Int,) {} + +fun foo61(vararg x: Int,/**/) {} + +fun foo7(y: Float, vararg x: Int,) {} + +val foo8: (Int, Int,) -> Int = fun( + x, + y, + ): Int { + return x + y +} + +val foo9: (Int, Int, Int,) -> Int = + fun (x, y: Int, z,): Int { + return x + y + } + +open class Foo10(x: Int = 10, y: Float = 0f) + +class Foo11: Foo10 { + constructor( + x: Float + ): super(1, 1f,) +} + +class Foo12: Foo10 { + constructor( + x: Float + ): super(1, 1f,/**/) +} + +fun main() { + val x1 = { + x: Comparable>, + y: Iterable>, + -> + println("1") + } + val x11 = { + x: Comparable>, + y: Iterable>,/**/ + -> + println("1") + } + val x2 = { x: Comparable>, + -> println("1") + } + val x3: ((Int,) -> Int) -> Unit = { x: (Int,) -> Int, -> println("1") } + val x4: ((Int,) -> Int) -> Unit = { x, -> println("1") } + + try { + println(1) + } catch (e: Exception,) { + + } + + try { + println(1) + } catch (e: Exception,) { + + } catch (e: Exception,) { + + } + + try { + println(1) + } catch (e: Exception,) { + + } finally { + + } + + try { + println(1) + } catch (e: Exception,/**/) { + + } finally { + + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithDisabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithDisabledFeature.fir.kt new file mode 100644 index 00000000000..46094fed33d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithDisabledFeature.fir.kt @@ -0,0 +1,49 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_EXPRESSION -NAME_SHADOWING + +fun foo1(x: Any) = when (x) { + Comparable::class, + Iterable::class, + String::class, + -> println(1) + else -> println(3) +} + +fun foo2(x: Any) { + val z = when (val y: Int = x as Int) { + 1, -> println(1) + else -> println(3) + } +} + +fun foo3(x: (Any) -> Any) { + val z = when (val y: (Any) -> Any = x) { + {x: Any, -> x}, {y: Any, -> y}, -> println(1) + else -> println(3) + } +} + +fun foo4(x: Any) { + val z = when (x) { + is Int, is Double, -> println(1) + else -> println(3) + } +} + +fun foo5(x: Int, y: IntArray, z: IntArray) { + val u = when (x) { + in y, + in z, + -> println(1) + else -> println(3) + } +} + +fun foo6(x: Boolean?) = when (x) { + true, false, -> println(1) + null, -> println(1) +} + +fun foo7(x: Boolean?) = when (x) { + true, false,/**/ -> println(1) + null,/**/ -> println(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..aabceebf900 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/trailingComma/whenEntryWithEnabledFeature.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -NAME_SHADOWING +// !LANGUAGE: +TrailingCommas + +fun foo1(x: Any) = when (x) { + Comparable::class, + Iterable::class, + String::class, + -> println(1) + else -> println(3) +} + +fun foo2(x: Any) { + val z = when (val y: Int = x as Int) { + 1, -> println(1) + else -> println(3) + } +} + +fun foo3(x: (Any) -> Any) { + val z = when (val y: (Any) -> Any = x) { + {x: Any, -> x}, {y: Any, -> y}, -> println(1) + else -> println(3) + } +} + +fun foo4(x: Any) { + val z = when (x) { + is Int, is Double, -> println(1) + else -> println(3) + } +} + +fun foo5(x: Int, y: IntArray, z: IntArray) { + val u = when (x) { + in y, + in z, + -> println(1) + else -> println(3) + } +} + +fun foo6(x: Boolean?) = when (x) { + true, false, -> println(1) + null, -> println(1) +} + +fun foo7(x: Boolean?) = when (x) { + true, false,/**/ -> println(1) + null,/**/ -> println(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.fir.kt new file mode 100644 index 00000000000..abf739ca63f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/assignTry.fir.kt @@ -0,0 +1,111 @@ +// !WITH_NEW_INFERENCE +// SKIP_TXT + +class ExcA : Exception() + +class ExcB : Exception() + +fun test2() { + val s: String? = try { + "" + } + catch (e: ExcA) { + null + } + catch (e: ExcB) { + 10 + } + s.length +} + +fun test3() { + val s: String? = try { + "" + } + catch (e: ExcA) { + null + } + catch (e: ExcB) { + return + } + s.length +} + +fun test4() { + val s: String? = try { + "" + } + catch (e: ExcA) { + null + } + finally { + "" + } + s.length +} + +fun test5() { + val s: String? = try { + "" + } + catch (e: ExcA) { + null + } + finally { + return + } + s.length +} + +fun test6() { + val s: String? = try { + "" + } + catch (e: ExcA) { + return + } + catch (e: ExcB) { + return + } + s.length +} + +fun test7() { + val s: String? = try { + "" + } + catch (e: ExcA) { + "" + } + catch (e: ExcB) { + "" + } + s.length +} + +fun test8() { + val s = try { + "" + } catch (e: ExcA) { + null + } + s.length +} + +fun test9() { + val s = try { + "" + } catch (e: ExcA) { + "" + } + s.length +} + +fun test10() { + val x = try { + "" + } finally { + 42 + } + x.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/boundedSmartcasts.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/boundedSmartcasts.fir.kt new file mode 100644 index 00000000000..ea8f2aab7a3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/boundedSmartcasts.fir.kt @@ -0,0 +1,101 @@ +// !WTIH_NEW_INFERENCE +// SKIP_TXT + +class ExcA : Exception() +class ExcB : Exception() + +fun test0(x: Int?) { + val y = try { + x + } finally { + + } + + if (x != null) { + x.inc() + y.inc() + } + + if (y != null) { + x.inc() + y.inc() + } +} + +fun test1(x: Int?) { + val y = try { + x + } + catch (e: Exception) { + 42 + } + + if (x != null) { + x.inc() + y.inc() + } + + if (y != null) { + x.inc() + y.inc() + } +} + +fun test2(x: Int?) { + val y = try { + x + } + catch (e: Exception) { + x + } + + if (x != null) { + x.inc() + y.inc() + } + + if (y != null) { + x.inc() + y.inc() + } +} + +fun test3(x: Int?) { + val y = try { + x + } catch (e: Exception) { + return + } + + if (x != null) { + x.inc() + y.inc() + } + + if (y != null) { + x.inc() + y.inc() + } +} + +fun test5(x: Int?) { + val y = try { + x + } + catch (e: ExcA) { + return + } + catch (e: ExcB) { + x + } + + if (x != null) { + x.inc() + y.inc() + } + + if (y != null) { + x.inc() + y.inc() + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/catchRedeclaration.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/catchRedeclaration.fir.kt new file mode 100644 index 00000000000..71268d77c13 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/catchRedeclaration.fir.kt @@ -0,0 +1,54 @@ +// !WTIH_NEW_INFERENCE +// SKIP_TXT + +class MyException : Exception() { + val myField = "field" + + fun myFun() {} +} + +fun test1() { + val e = "something" + try {} + catch (e: Exception) { + e.message + e.length + } +} + +fun test2() { + try {} + catch (e: Exception) { + val e = "something" + e.message + e.length + } +} + +fun test3() { + try {} + catch (e: MyException) { + e.myField + } +} + +fun test4() { + try {} + catch (e: Exception) { + val a = 42 + val a = "foo" + } +} + +fun test5() { + try {} + catch (e: Exception) { + val a: Int = 42 + try {} + catch (e: MyException) { + e.myFun() + val a: String = "" + a.length + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts.fir.kt new file mode 100644 index 00000000000..2170cb05df1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts.fir.kt @@ -0,0 +1,88 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// SKIP_TXT +// Related issue: KT-28370 + +class ExcA : Exception() +class ExcB : Exception() + +fun test1(s: String?) { + var t2: Boolean? = true + if (t2 != null) { + try { + t2 = null + } + catch (e: Exception) { + requireNotNull(s) + } + t2.not() + s.length + } +} + +fun test2(s: String?) { + var t2: Boolean? = true + if (t2 != null) { + try { + t2 = null + } + finally { + requireNotNull(s) + t2 = true + } + t2.not() + s.length + } +} + +fun test3() { + var s: String? = null + s = "" + try { + + } + catch (e: Exception) { + s = null + return + } + s.length +} + +fun test4() { + var s: String? = null + s = "" + try { + + } + catch (e: ExcA) { + s = null + return + } + catch (e: ExcB) { + + } + s.length +} + +fun test5(s: String?) { + try { + requireNotNull(s) + } + catch (e: ExcA) { + return + } + catch (e: ExcB) { + + } + s.length +} + +fun test6(s: String?) { + try { + requireNotNull(s) + } + catch (e: Exception) { + return + } + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts_after.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts_after.fir.kt new file mode 100644 index 00000000000..67e4ab0e4cc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/correctSmartcasts_after.fir.kt @@ -0,0 +1,89 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +NewDataFlowForTryExpressions +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// SKIP_TXT +// Related issue: KT-28370 + +class ExcA : Exception() +class ExcB : Exception() + +fun test1(s: String?) { + var t2: Boolean? = true + if (t2 != null) { + try { + t2 = null + } + catch (e: Exception) { + requireNotNull(s) + } + t2.not() + s.length + } +} + +fun test2(s: String?) { + var t2: Boolean? = true + if (t2 != null) { + try { + t2 = null + } + finally { + requireNotNull(s) + t2 = true + } + t2.not() + s.length + } +} + +fun test3() { + var s: String? = null + s = "" + try { + + } + catch (e: Exception) { + s = null + return + } + s.length +} + +fun test4() { + var s: String? = null + s = "" + try { + + } + catch (e: ExcA) { + s = null + return + } + catch (e: ExcB) { + + } + s.length +} + +fun test5(s: String?) { + try { + requireNotNull(s) + } + catch (e: ExcA) { + return + } + catch (e: ExcB) { + + } + s.length +} + +fun test6(s: String?) { + try { + requireNotNull(s) + } + catch (e: Exception) { + return + } + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts.fir.kt new file mode 100644 index 00000000000..80e1ae92909 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts.fir.kt @@ -0,0 +1,19 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// Related issue: KT-28370 + +fun test1(s1: String?) { + var s: String? = null + s = "" + try { + s = "" + requireNotNull(s1) + } + catch (e: Exception) { + return + } + finally { + s.length + } + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts_after.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts_after.fir.kt new file mode 100644 index 00000000000..511efb38d57 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falseNegativeSmartcasts_after.fir.kt @@ -0,0 +1,20 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +NewDataFlowForTryExpressions +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// Related issue: KT-28370 + +fun test1(s1: String?) { + var s: String? = null + s = "" + try { + s = "" + requireNotNull(s1) + } + catch (e: Exception) { + return + } + finally { + s.length + } + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts.fir.kt new file mode 100644 index 00000000000..cb73d68b460 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts.fir.kt @@ -0,0 +1,106 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// SKIP_TXT +// Related issue: KT-28370 + +class ExcA : Exception() +class ExcB : Exception() + +fun test1() { + var x: String? = null + x = "" + + try { + x = null + } catch (e: Exception) { + x.length // smartcast shouldn't be allowed (OOME could happen after `x = null`) + throw e + } + finally { + // smartcast shouldn't be allowed, `x = null` could've happened + x.length + } + // smartcast shouldn't be allowed, `x = null` could've happened + x.length +} + +// With old DFA of try/catch info about unsound smartcasts after try +// removes only if there is at least one catch branch that not returns Nothing +fun test2() { + var x: String? = null + x = "" + + try { + x = null + } catch (e: Exception) { + x.length + } + finally { + x.length + } + x.length +} + +fun test3() { + var t2: Boolean? = true + if (t2 != null) { // or `t2 is Boolean` + try { + throw Exception() + } catch (e: Exception) { + t2 = null + } + t2.not() // wrong smartcast, NPE + } +} + +fun test4() { + var t2: Boolean? = true + if (t2 != null) { // or `t2 is Boolean` + try { + t2 = null + } finally { } + t2.not() // wrong smartcast, NPE + } +} + +fun test5() { + var s1: String? = null + var s2: String? = null + s1 = "" + s2 = "" + try { + TODO() + } + catch (e: ExcA) { + s1 = "" + } + catch (e: ExcB) { + s2 = null + return + } + finally { + s1.length + s2.length + } + s1.length + s2.length +} + +fun test6(s1: String?, s2: String?) { + var s: String? = null + s = "" + try { + s = null + requireNotNull(s1) + } + catch (e: Exception) { + return + } + finally { + s.length + requireNotNull(s2) + } + s.length + s1.length + s2.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts_after.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts_after.fir.kt new file mode 100644 index 00000000000..44309a29e07 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/falsePositiveSmartcasts_after.fir.kt @@ -0,0 +1,108 @@ +// !WITH_NEW_INFERENCE +// !LANGUAGE: +NewDataFlowForTryExpressions +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// SKIP_TXT +// Related issue: KT-28370 + +class ExcA : Exception() +class ExcB : Exception() + +fun test1() { + var x: String? = null + x = "" + + try { + x = null + } catch (e: Exception) { + x.length // smartcast shouldn't be allowed (OOME could happen after `x = null`) + throw e + } + finally { + // smartcast shouldn't be allowed, `x = null` could've happened + x.length + } + // smartcast shouldn't be allowed, `x = null` could've happened + x.length +} + +// With old DFA of try/catch info about unsound smartcasts after try +// removes only if there is at least one catch branch that not returns Nothing +fun test2() { + var x: String? = null + x = "" + + try { + x = null + } catch (e: Exception) { + // BAD + x.length + } + finally { + x.length + } + x.length +} + +fun test3() { + var t2: Boolean? = true + if (t2 != null) { // or `t2 is Boolean` + try { + throw Exception() + } catch (e: Exception) { + t2 = null + } + t2.not() // wrong smartcast, NPE + } +} + +fun test4() { + var t2: Boolean? = true + if (t2 != null) { // or `t2 is Boolean` + try { + t2 = null + } finally { } + t2.not() // wrong smartcast, NPE + } +} + +fun test5() { + var s1: String? = null + var s2: String? = null + s1 = "" + s2 = "" + try { + TODO() + } + catch (e: ExcA) { + s1 = "" + } + catch (e: ExcB) { + s2 = null + return + } + finally { + s1.length + s2.length + } + s1.length + s2.length +} + +fun test6(s1: String?, s2: String?) { + var s: String? = null + s = "" + try { + s = null + requireNotNull(s1) + } + catch (e: Exception) { + return + } + finally { + s.length + requireNotNull(s2) + } + s.length + s1.length + s2.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.fir.kt new file mode 100644 index 00000000000..dfb2e98a923 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.fir.kt @@ -0,0 +1,35 @@ +// !WITH_NEW_INFERENCE +// SKIP_TXT + +class ExcA : Exception() + +class ExcB(val map: Map) : Exception() + +fun test0(): List = run { + try { + emptyList() + } finally { + "" + fun foo() {} + } +} + +fun test1(): Map = run { + try { + emptyMap() + } catch (e: ExcA) { + emptyMap() + } catch (e: ExcB) { + e.map + } finally { + "" + } +} + +fun test2(): Map = run { + try { + emptyMap() + } catch (e: ExcA) { + mapOf("" to "") + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliases.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliases.fir.kt new file mode 100644 index 00000000000..f986b5d6eb6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliases.fir.kt @@ -0,0 +1,3 @@ +// FILE: test.kt +val fooException = Exception("foo") +val barException = kotlin.Exception("bar") diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithApiVersion1_0.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithApiVersion1_0.fir.kt new file mode 100644 index 00000000000..80cc7440061 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithApiVersion1_0.fir.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +TypeAliases +// !API_VERSION: 1.0 +// FILE: test.kt +val fooException = Exception("foo") +val barException = kotlin.Exception("bar") diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithoutFeature.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithoutFeature.fir.kt new file mode 100644 index 00000000000..66b41670c8e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/exceptionTypeAliasesInvisibleWithoutFeature.fir.kt @@ -0,0 +1,4 @@ +// !LANGUAGE: -TypeAliases +// FILE: test.kt +val fooException = Exception("foo") +val barException = kotlin.Exception("bar") diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/hashMapTypeAlias.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/hashMapTypeAlias.fir.kt new file mode 100644 index 00000000000..1cb5f2b94a5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/hashMapTypeAlias.fir.kt @@ -0,0 +1,20 @@ +import kotlin.test.* +import java.util.* + +typealias HM = HashMap + +fun >> updateMap(map: M, k: K, v: V): M { + map[k]!!.add(v) + return map +} + +val nameToTeam = listOf("Alice" to "Marketing", "Bob" to "Sales", "Carol" to "Marketing") +val namesByTeam = nameToTeam.groupBy({ it.second }, { it.first }) + +val mutableNamesByTeam1 = updateMap(HM(), "", "") +val mutableNamesByTeam2 = updateMap(HashMap(), "", "") + +fun test() { + assertEquals(namesByTeam, mutableNamesByTeam1) + assertEquals(namesByTeam, mutableNamesByTeam2) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt new file mode 100644 index 00000000000..64b9eb0da5b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt @@ -0,0 +1,8 @@ +// FILE: test.kt +typealias RunnableT = java.lang.Runnable +typealias ComparatorT = java.util.Comparator +typealias ComparatorStrT = ComparatorT + +val test1 = RunnableT { } +val test2 = ComparatorT { s1, s2 -> s1.compareTo(s2) } +val test3 = ComparatorStrT { s1, s2 -> s1.compareTo(s2) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt new file mode 100644 index 00000000000..a745898d565 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt @@ -0,0 +1,27 @@ +// FILE: JHost.java +public class JHost { + public static interface Runnable { + void run(); + } + + public static interface Consumer { + void consume(T x); + } + + public static interface Consumer2 { + void run(T1 x1, T2 x2); + } +} + +// FILE: test.kt +typealias R = JHost.Runnable +typealias C = JHost.Consumer +typealias CStr = JHost.Consumer +typealias CStrList = JHost.Consumer> +typealias C2 = JHost.Consumer2 + +val test1 = R { } +val test2 = C { s -> println(s.length) } +val test3 = CStr { s -> println(s.length) } +val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } +val test5 = C2 { a, b -> val x: Int = a + b; println(x)} diff --git a/compiler/testData/diagnostics/testsWithStdLib/varargs/kt3213.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt3213.fir.kt new file mode 100644 index 00000000000..33f8c6d3900 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt3213.fir.kt @@ -0,0 +1,7 @@ +// !CHECK_TYPE + +fun test(a: Array) { + val b = a.toList() + + b checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/varargs/kt4172j.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt4172j.fir.kt new file mode 100644 index 00000000000..4ab40699fd5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt4172j.fir.kt @@ -0,0 +1,9 @@ +// FILE: A.java +public class A { + public static void main(String[] args) {} +} + +// FILE: 1.kt +fun main() { + A.main(arrayOf()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/varargs/kt5534.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt5534.fir.kt new file mode 100644 index 00000000000..f98f23dd0ac --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/varargs/kt5534.fir.kt @@ -0,0 +1,6 @@ +fun test() { + val p: Array = arrayOf("a") + foo(*p) +} + +fun foo(vararg a: String?) = a \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/kt10192.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/when/kt10192.fir.kt new file mode 100644 index 00000000000..bb4ed7a89dd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/when/kt10192.fir.kt @@ -0,0 +1,20 @@ +fun test1() { + if (true) { + when (true) { + true -> println() + } + } else { + System.out?.println() // kotlin.Unit? + } +} + +fun test2() { + val mlist = arrayListOf("") + if (true) { + when (true) { + true -> println() + } + } else { + mlist.add("") // kotlin.Boolean + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/kt10807.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/when/kt10807.fir.kt new file mode 100644 index 00000000000..20ea3211028 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/when/kt10807.fir.kt @@ -0,0 +1,17 @@ +import java.util.* +import kotlin.comparisons.compareBy +import kotlin.comparisons.nullsLast + +class Foo(val a: String, val b: Int) + +fun getComp(): Comparator = + when { + else -> nullsLast(compareBy({ it.a }, { it.b })) + } + +fun getCompInverted(): Comparator = + nullsLast( + when { + else -> compareBy({ it.a }, { it.b }) + } + ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt new file mode 100644 index 00000000000..b7212bcb280 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt @@ -0,0 +1,43 @@ +// !WITH_NEW_INFERENCE + +import java.util.* + +fun nullable(x: T): T? = x + +@Suppress("UNUSED_PARAMETER") +fun select(x1: T, x2: T): T = x1 + +val test1 = + listOf(1, 2, 3).mapNotNullTo(ArrayList()) { + if (true) nullable(it) else null + } + +val test2: MutableList = + listOf(1, 2, 3).mapNotNullTo(ArrayList()) { + if (true) nullable(it) else null + } + +val test3: MutableList = + listOf(1, 2, 3).mapNotNullTo(ArrayList()) { + if (true) nullable(it) else null + } + +val test4: Collection = + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + listOf(it) + } + +val test5: Collection = + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { // TODO + if (true) listOf(it) else listOf(it) + } + +val test6: Collection = + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + if (true) listOf(it) else listOf(it) + } + +val test7: Collection = + listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { + select(listOf(it), listOf(it)) + } \ No newline at end of file -- GitLab