From 284d5437e5609b960813bada6d8aa87063658b8e Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Tue, 12 Mar 2024 11:38:41 +0100 Subject: [PATCH] [FIR] Don't transform call arguments during TYPES phase Instead, it should happen during BODY_RESOLVE phase. This fixes KT-66150. The problem was, that `super.f()` expression in delegated constructor call was transformed during TYPES phase, and type transformer has no special logic for allowing bare types in super qualifiers, like the one in expressions transformer (see `org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer.transformSuperReceiver`). As a result, `B` without type argument leads to WrongNumberOfTypeArgumentsError. It looks incorrect that expressions in constructor call resolved during TYPES phase, so skipping transformation of argument list seems like the best solution here. ^KT-66150 Fixed --- ...ypeArgsInDelegatedConstructorLocalClass.txt | 8 +++++--- .../transformers/FirTypeResolveTransformer.kt | 9 ++++++++- ...erTypeArgsInDelegatedConstructorCall.fir.kt | 15 --------------- ...lifierTypeArgsInDelegatedConstructorCall.kt | 1 + ...ierTypeArgsInDelegatedConstructorCall.ll.kt | 18 ------------------ 5 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.ll.kt diff --git a/analysis/low-level-api-fir/testData/lazyResolve/superQualifierTypeArgsInDelegatedConstructorLocalClass.txt b/analysis/low-level-api-fir/testData/lazyResolve/superQualifierTypeArgsInDelegatedConstructorLocalClass.txt index bbad64816cc..c78f7a0c726 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/superQualifierTypeArgsInDelegatedConstructorLocalClass.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/superQualifierTypeArgsInDelegatedConstructorLocalClass.txt @@ -309,7 +309,9 @@ FILE: [ResolvedTo(IMPORTS)] superQualifierTypeArgsInDelegatedConstructorLocalCla BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] superQualifierTypeArgsInDelegatedConstructorLocalClass.kt public abstract [ResolvedTo(STATUS)] interface B<[ResolvedTo(STATUS)] T> : R|kotlin/Any| { - public open [ResolvedTo(STATUS)] fun f(): { LAZY_BLOCK } + public open [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun f(): R|kotlin/Boolean| { + ^f Boolean(true) + } } public open [ResolvedTo(STATUS)] class A<[ResolvedTo(STATUS)] T> : R|kotlin/Any| { @@ -328,7 +330,7 @@ FILE: [ResolvedTo(IMPORTS)] superQualifierTypeArgsInDelegatedConstructorLocalCla public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| { local final [ResolvedTo(BODY_RESOLVE)] class LocalClass : R|one/A| { public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=LocalClass] constructor(): R|/LocalClass| { - super|>(this@R|one/C|.super<>.#()) + super|>(this@R|one/C|.super|>.R|SubstitutionOverride|()) } } @@ -361,7 +363,7 @@ FILE: [ResolvedTo(BODY_RESOLVE)] superQualifierTypeArgsInDelegatedConstructorLoc public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| { local final [ResolvedTo(BODY_RESOLVE)] class LocalClass : R|one/A| { public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=LocalClass] constructor(): R|/LocalClass| { - super|>(this@R|one/C|.super<>.#()) + super|>(this@R|one/C|.super|>.R|SubstitutionOverride|()) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index 68b8ff25b2f..b5f0b511f9b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -12,7 +12,9 @@ import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.* -import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.copyWithNewSourceKind +import org.jetbrains.kotlin.fir.correspondingProperty import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isFromVararg import org.jetbrains.kotlin.fir.declarations.utils.isInner @@ -31,6 +33,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstit import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef import org.jetbrains.kotlin.fir.visitors.transformSingle +import org.jetbrains.kotlin.fir.whileAnalysing import org.jetbrains.kotlin.util.PrivateForInline import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled @@ -348,6 +351,10 @@ open class FirTypeResolveTransformer( return block } + override fun transformArgumentList(argumentList: FirArgumentList, data: Any?): FirArgumentList { + return argumentList + } + override fun transformAnnotation(annotation: FirAnnotation, data: Any?): FirStatement { shouldNotBeCalled() } diff --git a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.fir.kt b/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.fir.kt deleted file mode 100644 index e72c7aef7e4..00000000000 --- a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -interface B { - fun f() = true -} - -open class A(b: Boolean) - -class C : B { - inner class Inner : A(super<B>.f()) - inner class Inner2 : A(super>.f()) - - fun test() { - class LocalClass : A(super<B>.f()) - class LocalClass2 : A(super>.f()) - } -} diff --git a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.kt b/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.kt index 77df453f144..3c9512e0d6e 100644 --- a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.kt +++ b/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface B { fun f() = true } diff --git a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.ll.kt b/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.ll.kt deleted file mode 100644 index 59ee93817ee..00000000000 --- a/compiler/testData/diagnostics/tests/superQualifierTypeArgsInDelegatedConstructorCall.ll.kt +++ /dev/null @@ -1,18 +0,0 @@ -// LL_FIR_DIVERGENCE -// WRONG_NUMBER_OF_TYPE_ARGUMENTS not reported in Inner class because of BodyBuildingMode.LAZY_BODIES -// LL_FIR_DIVERGENCE -interface B { - fun f() = true -} - -open class A(b: Boolean) - -class C : B { - inner class Inner : A(super.f()) - inner class Inner2 : A(super>.f()) - - fun test() { - class LocalClass : A(super<B>.f()) - class LocalClass2 : A(super>.f()) - } -}