From 69f2e8826aa61c3217d2bb639c1245e4e0265847 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Thu, 5 Jan 2023 15:00:30 +0100 Subject: [PATCH] FIR: fix a bunch of issues after DiagnosticsReporter refactoring related to reporting diagnostic on null source --- .../bad/callsInPlace/inAnonymousObject.kt | 2 +- .../fromSource/bad/callsInPlace/inLocalClass.kt | 4 ++-- .../bad/callsInPlace/inLocalFunction.kt | 2 +- .../declaration/FirJsExternalChecker.kt | 12 ++++++------ .../FirJvmInlineApplicabilityChecker.kt | 8 +++----- .../native/checkers/FirNativeThrowsChecker.kt | 4 ++-- .../analysis/cfa/FirReturnsImpliesAnalyzer.kt | 2 +- .../declaration/FirDynamicUnsupportedChecker.kt | 5 ++--- .../declaration/FirEnumClassSimpleChecker.kt | 17 ++++++++++++----- .../declaration/FirFunctionParameterChecker.kt | 6 +----- .../FirPrimaryConstructorSuperTypeChecker.kt | 2 +- .../FirPropertyAccessorsTypesChecker.kt | 11 +++++++++++ .../declaration/FirSupertypesChecker.kt | 3 +++ .../declaration/FirThrowableSubclassChecker.kt | 4 +++- .../FirValueClassDeclarationChecker.kt | 4 ++-- .../FirReturnSyntaxAndLabelChecker.kt | 5 ++++- ...PlatformClassMappedToKotlinTypeRefChecker.kt | 2 +- .../extended/RedundantExplicitTypeChecker.kt | 1 + .../checkers/type/FirTypeAnnotationChecker.kt | 2 ++ .../kotlin/fir/builder/ConversionUtils.kt | 1 + .../tower/FirInvokeResolveTowerExtension.kt | 4 ++++ .../defaultArguments/useNextParamInLambda.kt | 2 ++ ...essValueParameterInDefaultValue_after.fir.kt | 2 +- ...ssValueParameterInDefaultValue_before.fir.kt | 2 +- .../experimental/implicitUsages.fir.kt | 4 ++-- .../experimental/implicitUsagesFuture.fir.kt | 2 +- .../parameters/useNextParamInLambda.kt | 3 +++ 27 files changed, 74 insertions(+), 42 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.kt index d08b5aaf341..813a9bf2bad 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.kt @@ -20,7 +20,7 @@ fun foo(a: () -> Unit, b: () -> Unit, c: () -> Unit, d: () -> Unit) { } override fun run() { - c() + c() } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.kt index 8b914b7bb63..0e52e37dc5b 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.kt @@ -17,7 +17,7 @@ fun foo(a: () -> Unit, b: () -> Unit, c: () -> Unit, d: () -> Unit, e: () -> Uni val leaked: Any constructor() { - b() + b() } init { @@ -25,7 +25,7 @@ fun foo(a: () -> Unit, b: () -> Unit, c: () -> Unit, d: () -> Unit, e: () -> Uni } fun run() { - d() + d() } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalFunction.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalFunction.kt index 98b8bacb10f..0ca83e786d1 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalFunction.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalFunction.kt @@ -9,7 +9,7 @@ fun foo(a: () -> Unit, b: () -> Unit) { fun localFun() { a.invoke() - a() + a() } localFun() diff --git a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt index 6294874a9fe..df91dcdf4e3 100644 --- a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt +++ b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt @@ -220,6 +220,12 @@ object FirJsExternalChecker : FirBasicDeclarationChecker() { else -> null } + // we shouldn't check such things as the + // copy() function of a data class + if (source?.kind !is KtRealSourceElementKind) { + return + } + val isWrong = body !is FirSingleExpressionBlock && !hasValidExternalBody() || initializer != null && !initializer.isDefinedExternallyExpression() @@ -229,12 +235,6 @@ object FirJsExternalChecker : FirBasicDeclarationChecker() { reporter.reportOn(initializer.source, FirJsErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION, context) } - // we shouldn't check such things as the - // copy() function of a data class - if (source?.kind !is KtRealSourceElementKind) { - return - } - if (this is FirFunction) { for (defaultValue in valueParameters.mapNotNull { it.defaultValue }) { if (!defaultValue.isDefinedExternallyExpression()) { diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt index d8c4dad9215..f7949ab3c38 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt @@ -24,11 +24,9 @@ object FirJvmInlineApplicabilityChecker : FirRegularClassChecker() { if (annotation != null && !declaration.isInline) { reporter.reportOn(annotation.source, FirJvmErrors.JVM_INLINE_WITHOUT_VALUE_CLASS, context) } else if (annotation == null && declaration.isInline && !declaration.isExpect) { - reporter.reportOn( - declaration.getModifier(KtTokens.VALUE_KEYWORD)?.source, - FirJvmErrors.VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION, - context - ) + // only report if value keyword exists, this ignores the deprecated inline class syntax + val keyword = declaration.getModifier(KtTokens.VALUE_KEYWORD)?.source ?: return + reporter.reportOn(keyword, FirJvmErrors.VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION, context) } } } \ No newline at end of file diff --git a/compiler/fir/checkers/checkers.native/src/org/jetbrains/kotlin/fir/analysis/native/checkers/FirNativeThrowsChecker.kt b/compiler/fir/checkers/checkers.native/src/org/jetbrains/kotlin/fir/analysis/native/checkers/FirNativeThrowsChecker.kt index c04df8eb849..2add93e77bd 100644 --- a/compiler/fir/checkers/checkers.native/src/org/jetbrains/kotlin/fir/analysis/native/checkers/FirNativeThrowsChecker.kt +++ b/compiler/fir/checkers/checkers.native/src/org/jetbrains/kotlin/fir/analysis/native/checkers/FirNativeThrowsChecker.kt @@ -91,10 +91,10 @@ object FirNativeThrowsChecker : FirBasicDeclarationChecker() { val (overriddenMember, overriddenThrows) = inherited.firstOrNull() ?: return true // Should not happen though. - if (decodeThrowsFilter(throwsAnnotation, context.session) != overriddenThrows) { + if (throwsAnnotation?.source != null && decodeThrowsFilter(throwsAnnotation, context.session) != overriddenThrows) { val containingClassSymbol = overriddenMember.containingClassLookupTag()?.toFirRegularClassSymbol(context.session) if (containingClassSymbol != null) { - reporter.reportOn(throwsAnnotation?.source, FirNativeErrors.INCOMPATIBLE_THROWS_OVERRIDE, containingClassSymbol, context) + reporter.reportOn(throwsAnnotation.source, FirNativeErrors.INCOMPATIBLE_THROWS_OVERRIDE, containingClassSymbol, context) } return false } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt index 0042c9f3142..6710becbe75 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt @@ -47,7 +47,7 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() { } val function = graph.declaration as? FirFunction ?: return - if (function !is FirContractDescriptionOwner) return + if (function !is FirContractDescriptionOwner || function.contractDescription.source == null) return val effects = function.contractDescription.effects ?: return val dataFlowInfo = function.controlFlowGraphReference?.dataFlowInfo ?: return for (firEffect in effects) { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDynamicUnsupportedChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDynamicUnsupportedChecker.kt index 84b152c60ea..48f695b4177 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDynamicUnsupportedChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDynamicUnsupportedChecker.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration -import org.jetbrains.kotlin.KtRealSourceElementKind import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext @@ -18,8 +17,8 @@ import org.jetbrains.kotlin.fir.types.coneTypeSafe object FirDynamicUnsupportedChecker : FirTypeRefChecker() { override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) { // It's assumed this checker is only called - // by within the platform that disallows dynamics - if (typeRef.coneTypeSafe() != null) { + // by a platform that disallows dynamics + if (typeRef.source != null && typeRef.coneTypeSafe() != null) { reporter.reportOn(typeRef.source, FirErrors.UNSUPPORTED, "dynamic type", context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirEnumClassSimpleChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirEnumClassSimpleChecker.kt index 7fa31847cd7..d4767ea870b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirEnumClassSimpleChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirEnumClassSimpleChecker.kt @@ -5,13 +5,17 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.findNonInterfaceSupertype -import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors -import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.utils.isEnumClass +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType +import org.jetbrains.kotlin.fir.types.classId +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.name.StandardClassIds object FirEnumClassSimpleChecker : FirRegularClassChecker() { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { @@ -19,9 +23,12 @@ object FirEnumClassSimpleChecker : FirRegularClassChecker() { return } - declaration.findNonInterfaceSupertype(context)?.let { - reporter.reportOn(it.source, FirErrors.CLASS_IN_SUPERTYPE_FOR_ENUM, context) - } + declaration.findNonInterfaceSupertype(context) + // Ignore Enum itself + // If it's explicit, CLASS_CANNOT_BE_EXTENDED_DIRECTLY will be reported instead. + // If it's implicit, it's fine. + ?.takeUnless { it.coneType.fullyExpandedType(context.session).classId == StandardClassIds.Enum } + ?.let { reporter.reportOn(it.source, FirErrors.CLASS_IN_SUPERTYPE_FOR_ENUM, context) } if (declaration.typeParameters.isNotEmpty()) { reporter.reportOn(declaration.typeParameters.firstOrNull()?.source, FirErrors.TYPE_PARAMETERS_IN_ENUM, context) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionParameterChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionParameterChecker.kt index 0ddd5c16d2a..b7892d787f6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionParameterChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirFunctionParameterChecker.kt @@ -96,11 +96,7 @@ object FirFunctionParameterChecker : FirFunctionChecker() { if (referredParameterIndex < 0) return if (index <= referredParameterIndex) { - reporter.reportOn( - qualifiedAccessExpression.source, FirErrors.UNINITIALIZED_PARAMETER, - referredParameter, - context - ) + reporter.reportOn(qualifiedAccessExpression.source, FirErrors.UNINITIALIZED_PARAMETER, referredParameter, context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPrimaryConstructorSuperTypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPrimaryConstructorSuperTypeChecker.kt index 6d9db5e5fb3..ffada1e5d94 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPrimaryConstructorSuperTypeChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPrimaryConstructorSuperTypeChecker.kt @@ -78,7 +78,7 @@ object FirPrimaryConstructorSuperTypeChecker : FirClassChecker() { } val delegatedCallSource = delegatedConstructorCall.source ?: return if (delegatedCallSource.kind !is KtFakeSourceElementKind) return - if (superClassSymbol.classId == StandardClassIds.Enum) return + if (superClassSymbol.classId == StandardClassIds.Enum || superClassSymbol.classId == StandardClassIds.Java.Record) return if (delegatedCallSource.elementType != KtNodeTypes.SUPER_TYPE_CALL_ENTRY) { reporter.reportOn(constructedTypeRef.source, FirErrors.SUPERTYPE_NOT_INITIALIZED, context) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt index a78dd615097..a8aeb175e52 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorsTypesChecker.kt @@ -33,6 +33,10 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { val propertyType = property.returnTypeRef.coneType checkAccessorForDelegatedProperty(property, getter, context, reporter) + + if (getter.isImplicitDelegateAccessor()) { + return + } if (getter.visibility != property.visibility) { reporter.reportOn(getter.source, FirErrors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, context) } @@ -63,6 +67,10 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { reporter.reportOn(setter.source, FirErrors.VAL_WITH_SETTER, context) } checkAccessorForDelegatedProperty(property, setter, context, reporter) + + if (setter.isImplicitDelegateAccessor()) { + return + } val visibilityCompareResult = setter.visibility.compareTo(property.visibility) if (visibilityCompareResult == null || visibilityCompareResult > 0) { reporter.reportOn(setter.source, FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, context) @@ -115,6 +123,9 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() { } } + private fun FirPropertyAccessor.isImplicitDelegateAccessor(): Boolean = + source?.kind == KtFakeSourceElementKind.DelegatedPropertyAccessor + private fun isLegallyAbstract(property: FirProperty, context: CheckerContext): Boolean { return property.isAbstract && context.findClosestClassOrObject().let { it is FirRegularClass && it.canHaveAbstractDeclaration } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt index d9f908bc9ab..0fc88e55080 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt @@ -41,6 +41,9 @@ object FirSupertypesChecker : FirClassChecker() { var classAppeared = false val superClassSymbols = hashSetOf() for (superTypeRef in declaration.superTypeRefs) { + // skip implicit super types like Enum or Any + if (superTypeRef.source == null) continue + val coneType = superTypeRef.coneType if (!nullableSupertypeReported && coneType.nullability == ConeNullability.NULLABLE) { reporter.reportOn(superTypeRef.source, FirErrors.NULLABLE_SUPERTYPE, context) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirThrowableSubclassChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirThrowableSubclassChecker.kt index b56d0a8c0b4..8a2987d3119 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirThrowableSubclassChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirThrowableSubclassChecker.kt @@ -23,7 +23,9 @@ object FirThrowableSubclassChecker : FirClassChecker() { return if (declaration.typeParameters.isNotEmpty()) { - reporter.reportOn(declaration.typeParameters.firstOrNull()?.source, FirErrors.GENERIC_THROWABLE_SUBCLASS, context) + declaration.typeParameters.firstOrNull()?.source?.let { + reporter.reportOn(it, FirErrors.GENERIC_THROWABLE_SUBCLASS, context) + } val shouldReport = when (declaration) { is FirRegularClass -> declaration.isInner || declaration.isLocal diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt index 37a1cec742d..06d9774ae7f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirValueClassDeclarationChecker.kt @@ -20,13 +20,13 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol -import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.isEquals import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.impl.FirImplicitAnyTypeRef import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -56,7 +56,7 @@ object FirValueClassDeclarationChecker : FirRegularClassChecker() { // TODO check absence of context receivers when FIR infrastructure is ready for (supertypeEntry in declaration.superTypeRefs) { - if (supertypeEntry.toRegularClassSymbol(context.session)?.isInterface != true) { + if (supertypeEntry !is FirImplicitAnyTypeRef && supertypeEntry.toRegularClassSymbol(context.session)?.isInterface != true) { reporter.reportOn(supertypeEntry.source, FirErrors.VALUE_CLASS_CANNOT_EXTEND_CLASSES, context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReturnSyntaxAndLabelChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReturnSyntaxAndLabelChecker.kt index 7c5036c8769..35fc332a747 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReturnSyntaxAndLabelChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReturnSyntaxAndLabelChecker.kt @@ -53,7 +53,10 @@ object FirReturnSyntaxAndLabelChecker : FirReturnExpressionChecker() { } val containingDeclaration = context.containingDeclarations.last() - if (containingDeclaration is FirFunction && containingDeclaration.body is FirSingleExpressionBlock) { + if (containingDeclaration is FirFunction && + containingDeclaration.body is FirSingleExpressionBlock && + containingDeclaration.source?.kind != KtFakeSourceElementKind.DelegatedPropertyAccessor + ) { reporter.reportOn(source, FirErrors.RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY, context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/PlatformClassMappedToKotlinTypeRefChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/PlatformClassMappedToKotlinTypeRefChecker.kt index f2327e3b7a9..77c83758a85 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/PlatformClassMappedToKotlinTypeRefChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/PlatformClassMappedToKotlinTypeRefChecker.kt @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.types.classId object PlatformClassMappedToKotlinTypeRefChecker : FirTypeRefChecker() { override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) { - if (typeRef is FirResolvedTypeRef) { + if (typeRef is FirResolvedTypeRef && typeRef.source != null) { val kotlinClass = context.session.platformClassMapper.getCorrespondingKotlinClass(typeRef.type.classId) if (kotlinClass != null) { reporter.reportOn(typeRef.source, FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN, kotlinClass.asSingleFqName(), context) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantExplicitTypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantExplicitTypeChecker.kt index 19daae0a5e2..35b4734f479 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantExplicitTypeChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantExplicitTypeChecker.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.types.ConstantValueKind object RedundantExplicitTypeChecker : FirPropertyChecker() { override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) { if (!declaration.isLocal) return + if (declaration.returnTypeRef.source == null) return val initializer = declaration.initializer ?: return val typeReference = declaration.returnTypeRef.takeUnless { it is FirErrorTypeRef } ?: return diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt index 6c3b57de6f9..31037fa6e0a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt @@ -23,6 +23,8 @@ object FirTypeAnnotationChecker : FirTypeRefChecker() { if (typeRef !is FirResolvedTypeRef) return for (annotation in typeRef.annotations) { + if (annotation.source == null) continue + val annotationTargets = annotation.getAllowedAnnotationTargets(context.session) if (KotlinTarget.TYPE !in annotationTargets) { val useSiteTarget = annotation.useSiteTarget diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 752255e157b..98d6ab5aed4 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -393,6 +393,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( } argumentList = buildBinaryArgumentList(thisRef(forDispatchReceiver = true), propertyRef()) origin = FirFunctionCallOrigin.Operator + source = fakeSource } delegate = delegateBuilder.build() if (getter == null || getter is FirDefaultPropertyAccessor) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt index 21c605b4e1e..8d4944f7e47 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt @@ -5,7 +5,10 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower +import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.fakeElement import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.builder.FirPropertyAccessExpressionBuilder @@ -318,6 +321,7 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable( if (candidate.currentApplicability == CandidateApplicability.K2_PROPERTY_AS_OPERATOR) { nonFatalDiagnostics.add(ConePropertyAsOperator(candidate.symbol as FirPropertySymbol)) } + source = (info.callSite as? FirFunctionCall)?.calleeReference?.source?.fakeElement(KtFakeSourceElementKind.ImplicitInvokeCall) }.build().let { transformQualifiedAccessUsingSmartcastInfo(it) } diff --git a/compiler/testData/codegen/box/defaultArguments/useNextParamInLambda.kt b/compiler/testData/codegen/box/defaultArguments/useNextParamInLambda.kt index cc2c2e296af..ba21ac6af3d 100644 --- a/compiler/testData/codegen/box/defaultArguments/useNextParamInLambda.kt +++ b/compiler/testData/codegen/box/defaultArguments/useNextParamInLambda.kt @@ -1,6 +1,8 @@ // IGNORE_BACKEND: JS, JS_IR, NATIVE, WASM // IGNORE_BACKEND: JS_IR_ES6 +// IGNORE_BACKEND_K2: JVM_IR // WASM_MUTE_REASON: IGNORED_IN_JS +// FIR status: don't support legacy feature. UNINITIALIZED_PARAMETER y. See KT-49800 fun f( f1: () -> String = { f2() }, diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_after.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_after.fir.kt index 2f3d6cf04c0..98f9b53176a 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_after.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_after.fir.kt @@ -14,7 +14,7 @@ fun test_2( ) {} fun test_3( - x: () -> Any = { y() to y.invoke() }, // Error + x: () -> Any = { y() to y.invoke() }, // Error y: () -> String = { "OK" } ) {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_before.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_before.fir.kt index 74a637204fa..114e90c4840 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_before.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_before.fir.kt @@ -14,7 +14,7 @@ fun test_2( ) {} fun test_3( - x: () -> Any = { y() to y.invoke() }, // Error + x: () -> Any = { y() to y.invoke() }, // Error y: () -> String = { "OK" } ) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsages.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsages.fir.kt index 9b16d9b7648..d06242aa192 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsages.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsages.fir.kt @@ -85,7 +85,7 @@ object O { operator fun provideDelegate(x: Any?, y: Any?): C = C() } -val x: String by O +val x: String by O @Marker class OperatorContainer : Comparable { @@ -122,4 +122,4 @@ fun operatorContainerUsage(s: String, a: AnotherContainer) { val res2 = s() val res3 = res1 > res2 for (c in a) {} -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsagesFuture.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsagesFuture.fir.kt index b606163af97..5156426416e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsagesFuture.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/implicitUsagesFuture.fir.kt @@ -85,7 +85,7 @@ object O { operator fun provideDelegate(x: Any?, y: Any?): C = C() } -val x: String by O +val x: String by O @Marker class OperatorContainer : Comparable { diff --git a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.kt b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.kt index 37365373d0d..2cc7c9d25f9 100644 --- a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.kt +++ b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.kt @@ -1,3 +1,6 @@ +// IGNORE_BACKEND_K2: ANY +// accessing uninitialized parameter is illegal in FIR + fun f( f1: () -> String = { f2() }, f2: () -> String = { "FAIL" }