From 686abb112d3362d76127348d917efd7aa597fbf7 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 29 Nov 2023 12:00:02 +0200 Subject: [PATCH] [FIR] Properly set sources of intersection overrides Otherwise, they may point to one of the base intersected functions, and if we start reporting diagnostics on them, they'll appear on base functions. --- .../kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt | 7 ++++--- .../fir/scopes/impl/FirTypeIntersectionScopeContext.kt | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt index 1c5208069e4..f00ddd9aa04 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt @@ -121,9 +121,9 @@ object FirFakeOverrideGenerator { newModality: Modality? = null, newVisibility: Visibility? = null, deferredReturnTypeCalculation: CallableCopyDeferredReturnTypeCalculation? = null, - newSource: KtSourceElement? = null, + newSource: KtSourceElement? = derivedClassLookupTag?.toSymbol(session)?.source ?: baseFunction.source, ): FirSimpleFunction = buildSimpleFunction { - source = newSource ?: derivedClassLookupTag?.toSymbol(session)?.source ?: baseFunction.source + source = newSource moduleData = session.nullableModuleData ?: baseFunction.moduleData this.origin = origin name = baseFunction.name @@ -401,8 +401,9 @@ object FirFakeOverrideGenerator { newModality: Modality? = null, newVisibility: Visibility? = null, deferredReturnTypeCalculation: CallableCopyDeferredReturnTypeCalculation? = null, + newSource: KtSourceElement? = derivedClassLookupTag?.toSymbol(session)?.source ?: baseProperty.source, ): FirProperty = buildProperty { - source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseProperty.source + source = newSource moduleData = session.nullableModuleData ?: baseProperty.moduleData this.origin = origin name = baseProperty.name diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScopeContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScopeContext.kt index ad957682535..fba9607217c 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScopeContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScopeContext.kt @@ -358,6 +358,7 @@ class FirTypeIntersectionScopeContext( newDispatchReceiverType = dispatchReceiverType, deferredReturnTypeCalculation = deferredReturnTypeCalculation, newReturnType = if (!forClassUseSiteScope && deferredReturnTypeCalculation == null) intersectReturnTypes(mostSpecific) else null, + newSource = dispatchReceiverType.toSymbol(session)?.source, ).apply { originalForIntersectionOverrideAttr = keyFir } @@ -385,7 +386,8 @@ class FirTypeIntersectionScopeContext( deferredReturnTypeCalculation = deferredReturnTypeCalculation, // If any of the properties are vars and the types are not equal, these declarations are conflicting // anyway and their uses should result in an overload resolution error. - newReturnType = returnType + newReturnType = returnType, + newSource = dispatchReceiverType.toSymbol(session)?.source, ) } }