diff --git a/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.fir.txt b/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.fir.txt index 85dbfd9adbe..c97bebb206f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.fir.txt @@ -41,7 +41,7 @@ FILE: inner.kt public final fun test(): R|kotlin/Unit| { lval o: R|Owner| = R|/Owner.Owner|() R|/o|.R|/Owner.foo|() - lval err: = Q|Owner|.#() + lval err: = Q|Owner|.#() R|/err|.#() lval i: R|Owner.Inner| = R|/o|.R|/Owner.Inner.Inner|() R|/i|.R|/Owner.Inner.gau|() diff --git a/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.kt b/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.kt index d6758a13e51..85b94b55aaa 100644 --- a/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.kt +++ b/compiler/fir/analysis-tests/testData/resolve/innerClasses/inner.kt @@ -31,7 +31,7 @@ class Owner { fun test() { val o = Owner() o.foo() - val err = Owner.Inner() + val err = Owner.Inner() err.baz() val i = o.Inner() i.gau() diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index d22825ebe34..495d5816e07 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -124,6 +124,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { parameter("expression") parameter("type") } + val RESOLUTION_TO_CLASSIFIER by error { + parameter("classSymbol") + } } val SUPER by object : DiagnosticGroup("Super") { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 8d09ca5ad78..2c12d6ebdf5 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -134,6 +134,7 @@ object FirErrors { val ILLEGAL_SELECTOR by error0() val NO_RECEIVER_ALLOWED by error0() val FUNCTION_EXPECTED by error2(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED) + val RESOLUTION_TO_CLASSIFIER by error1() // Super val SUPER_IS_NOT_AN_EXPRESSION by error0(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 67e7aaf9d84..7e1b317e86d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -329,6 +329,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REIFIED_TYPE_PARA import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_BOUND import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESERVED_MEMBER_INSIDE_INLINE_CLASS +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESOLUTION_TO_CLASSIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESULT_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_NOT_ALLOWED @@ -502,6 +503,11 @@ class FirDefaultErrorMessages { FUNCTION_EXPECTED, "Expression ''{0}'' of type {1} cannot be invoked as a function. The function 'invoke()' is not found", TO_STRING, RENDER_TYPE ) + map.put( + RESOLUTION_TO_CLASSIFIER, + "Constructor of inner class {0} can be called only with receiver of containing class", + SYMBOL + ) map.put(ILLEGAL_SELECTOR, "The expression cannot be a selector (occur after a dot)") map.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property") diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 3cadc239e53..ee8d4e9e294 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -42,6 +42,7 @@ private fun ConeDiagnostic.toFirDiagnostic( is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier) is ConeFunctionCallExpectedError -> FirErrors.FUNCTION_CALL_EXPECTED.createOn(source, this.name.asString(), this.hasValueParameters) is ConeFunctionExpectedError -> FirErrors.FUNCTION_EXPECTED.createOn(source, this.expression, this.type) + is ConeResolutionToClassifierError -> FirErrors.RESOLUTION_TO_CLASSIFIER.createOn(source, this.classSymbol) is ConeHiddenCandidateError -> FirErrors.INVISIBLE_REFERENCE.createOn(source, this.candidateSymbol) is ConeAmbiguityError -> when { applicability.isSuccess -> FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY.createOn(source, this.candidates.map { it.symbol }) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 1047ba599a5..0f5c8bd64eb 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.* import org.jetbrains.kotlin.fir.resolve.calls.tower.FirTowerResolver import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerResolveManager -import org.jetbrains.kotlin.fir.resolve.dfa.symbol import org.jetbrains.kotlin.fir.resolve.diagnostics.* import org.jetbrains.kotlin.fir.resolve.inference.ResolvedCallableReferenceAtom import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents @@ -605,15 +604,20 @@ class FirCallResolver( candidate?.let { isValueParametersNotEmpty(it) } ?: candidates.any { isValueParametersNotEmpty(it) }) } else { val singleExpectedCandidate = expectedCandidates?.singleOrNull() - if (singleExpectedCandidate?.symbol?.fir is FirRegularClass) { - ConeUnresolvedNameError(name) - // TODO: ConeResolutionToClassifierError() + + var fir = singleExpectedCandidate?.symbol?.fir + if (fir is FirTypeAlias) { + fir = (fir.expandedTypeRef.coneType.fullyExpandedType(session).toSymbol(session) as? FirRegularClassSymbol)?.fir + } + + if (fir is FirRegularClass) { + ConeResolutionToClassifierError(fir.symbol) } else { val coneType = explicitReceiver?.typeRef?.coneType if (coneType != null && !coneType.isUnit) { ConeFunctionExpectedError( name.asString(), - (singleExpectedCandidate?.symbol?.fir as? FirTypedDeclaration)?.returnTypeRef?.coneType ?: coneType + (fir as? FirTypedDeclaration)?.returnTypeRef?.coneType ?: coneType ) } else { ConeUnresolvedNameError(name) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt index 9f7678d406d..7d0759c81bd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt @@ -80,7 +80,7 @@ internal abstract class FirBaseTowerResolveTask( protected fun FirScope.toScopeTowerLevel( extensionReceiver: ReceiverValue? = null, extensionsOnly: Boolean = false, - includeInnerConstructors: Boolean = true + includeInnerConstructors: Boolean = extensionReceiver != null, ): ScopeTowerLevel = ScopeTowerLevel( session, components, this, extensionReceiver, extensionsOnly, includeInnerConstructors diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt index 8c0b53e4bfc..69efd9e6706 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt @@ -54,6 +54,10 @@ class ConeFunctionExpectedError(val expression: String, val type: ConeKotlinType override val reason: String get() = "Expression '$expression' of type '$type' cannot be invoked as a function" } +class ConeResolutionToClassifierError(val classSymbol: FirRegularClassSymbol) : ConeDiagnostic() { + override val reason: String get() = "Resolution to classifier" +} + class ConeHiddenCandidateError( val candidateSymbol: FirBasedSymbol<*> ) : ConeDiagnostic() { diff --git a/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt deleted file mode 100644 index d41aab8ba36..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.fir.kt +++ /dev/null @@ -1,10 +0,0 @@ -// !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/importedInnerConstructor.kt b/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.kt index 9fffdfbffdf..a38287b14ae 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/importedInnerConstructor.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION import A.Inner diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt deleted file mode 100644 index 17977615bd5..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.fir.kt +++ /dev/null @@ -1,34 +0,0 @@ -// !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) - } -} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt index a2ddb0d2c4a..0eda67e19d7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION // !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS diff --git a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt index 38e31fea348..22157af461c 100644 --- a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_after.fir.kt @@ -43,7 +43,7 @@ fun f() { C.O C.O.InO C.A() - C.B() + 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 index 04b28f02060..642f2aaabea 100644 --- a/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/InnerClassAccessThroughEnum_before.fir.kt @@ -43,7 +43,7 @@ fun f() { C.O C.O.InO C.A() - C.B() + C.B() C.E3.O_O C.E3.G() diff --git a/compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.fir.kt b/compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.fir.kt index 55da4c636f0..2085c507099 100644 --- a/compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.fir.kt +++ b/compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.fir.kt @@ -6,7 +6,7 @@ typealias FunAlias = IsolatedFunFace fun referIsolatedFunFace(iff: IsolatedFunFace) {} fun callIsolatedFunFace() { - referIsolatedFunFace(IsolatedFunFace {}) - referIsolatedFunFace(FunAlias {}) + referIsolatedFunFace(IsolatedFunFace {}) + referIsolatedFunFace(FunAlias {}) referIsolatedFunFace({}) } diff --git a/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt b/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt deleted file mode 100644 index 959b9a6d0b5..00000000000 --- a/compiler/testData/diagnostics/tests/inner/constructorAccess.fir.kt +++ /dev/null @@ -1,32 +0,0 @@ -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/constructorAccess.kt b/compiler/testData/diagnostics/tests/inner/constructorAccess.kt index 961c29b2585..0f6dea08c36 100644 --- a/compiler/testData/diagnostics/tests/inner/constructorAccess.kt +++ b/compiler/testData/diagnostics/tests/inner/constructorAccess.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Outer1 { class Nested diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt deleted file mode 100644 index fad06683fbf..00000000000 --- a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.fir.kt +++ /dev/null @@ -1,36 +0,0 @@ -// !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) - } -} diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt index e831c7955a3..d9c0f080c19 100644 --- a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt +++ b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // SKIP_TXT // FILE: Outer.kt diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt index f6aaf5693f1..666dfade84a 100644 --- a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.fir.kt @@ -12,8 +12,8 @@ class Outer { fun baz() { // Diagnostic here could be better (why can't I call the constructor above?) - Inner() - Inner(1) + Inner() + Inner(1) Inner("") } } @@ -31,8 +31,8 @@ import abc.Outer.Inner import abc.Outer.Companion.Inner fun bar() { - Inner() - Inner(1) + Inner() + Inner(1) Inner("") with(Outer()) { diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt index 1de2d58247f..b97b87acb82 100644 --- a/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.fir.kt @@ -10,7 +10,7 @@ class Test { } fun more(): InnerClass { - val b = InnerClass() + val b = InnerClass() val testVal = inClass foo() diff --git a/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt index 60341d7a6ec..10c14b54f07 100644 --- a/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerErrorForObjects.fir.kt @@ -10,7 +10,7 @@ class Test { } fun more(): InnerClass { - val b = InnerClass() + val b = InnerClass() val testVal = inClass foo() diff --git a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt deleted file mode 100644 index c0dc2c60a00..00000000000 --- a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -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/constructNestedClass.kt b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.kt index 8a67ae48bf4..f1e205b5cec 100644 --- a/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.kt +++ b/compiler/testData/diagnostics/tests/inner/qualifiedExpression/constructNestedClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Outer { class Nested { class NestedNested diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt deleted file mode 100644 index efe285ac1af..00000000000 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -// !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 diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.kt index 447883291b5..d2b7f04d66b 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectClassWithoutConstructor.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +MultiPlatformProjects // MODULE: m1-common // FILE: common.kt diff --git a/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt deleted file mode 100644 index 423a1c27326..00000000000 --- a/compiler/testData/diagnostics/tests/regressions/kt4827.fir.kt +++ /dev/null @@ -1,16 +0,0 @@ -// 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/kt4827.kt b/compiler/testData/diagnostics/tests/regressions/kt4827.kt index 76cfccefc69..1e6db596d62 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt4827.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt4827.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // KT-4827 UOE at PackageType.throwException() // EA-53605 diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt deleted file mode 100644 index f884ab6fea4..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -interface MutableMatrix { -} - -fun toMutableMatrix(): MutableMatrix { - return MutableMatrix() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.kt index 3f14c99c456..13c925a09fd 100644 --- a/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.kt +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/kt2787.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface MutableMatrix { } diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt index 66eca0d07d2..f1c9b80554e 100644 --- a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifier.fir.kt @@ -6,7 +6,7 @@ object B class C fun test() { - val interface_as_fun = A() + val interface_as_fun = A() val interface_as_val = A val object_as_fun = B() diff --git a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt index d14d0265f70..8f0ebd30b33 100644 --- a/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/noCandidates/resolvedToClassifierWithReceiver.fir.kt @@ -8,7 +8,7 @@ object X { } fun testX() { - val interface_as_fun = X.A() + val interface_as_fun = X.A() val interface_as_val = X.A val object_as_fun = X.B() @@ -23,7 +23,7 @@ class Y { } fun testY() { - val interface_as_fun = Y.A() + val interface_as_fun = Y.A() val interface_as_val = Y.A val object_as_fun = Y.B() diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt index 144e13eba52..19ca013a42d 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt @@ -4,7 +4,7 @@ class A( n: Nested = foo(), n2: Nested = Nested(), inn: Inner = null!!, - inn2: Inner = Inner(), + inn2: Inner = Inner(), i: Interface = null!!, c: Int = CONST, cc: Int = Companion.CONST, @@ -19,7 +19,7 @@ class A( n: Nested = foo(), n2: Nested = Nested(), inn: Inner = null!!, - inn2: Inner = Inner(), + inn2: Inner = Inner(), i: Interface = null!!, c: Int = CONST, cc: Int = Companion.CONST, @@ -31,7 +31,7 @@ class A( foo(), Nested(), inn, - Inner(), + Inner(), i, CONST, Companion.CONST, diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt deleted file mode 100644 index 2ad72457b4c..00000000000 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.fir.kt +++ /dev/null @@ -1,50 +0,0 @@ -// !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/delegation.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt index 813443209c9..9d745b0ffd2 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER interface I diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt deleted file mode 100644 index df93189da0a..00000000000 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.fir.kt +++ /dev/null @@ -1,48 +0,0 @@ -// !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/superConstructorArguments.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt index ec88083051b..330ef988704 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER open class S( diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt index 065b7f95d9c..2ee44e7e432 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt @@ -17,7 +17,7 @@ class A : S { constructor() : super( foo(), Nested(), - Inner(), + Inner(), CONST, Companion.CONST, Nested.CONST, diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt index 11d03c45f7b..47e0138e40b 100644 --- a/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/innerClasses.fir.kt @@ -35,10 +35,10 @@ class E: A() { object Z { init { - B().foo() - B().bar() + B().foo() + B().bar() - D() + D() C() } } @@ -60,7 +60,7 @@ class F: A() { companion object { init { B().fas() - D().f() + D().f() } } } diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt deleted file mode 100644 index 9902bf9b2ca..00000000000 --- a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.fir.kt +++ /dev/null @@ -1,90 +0,0 @@ -// 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/nestedFromJava.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.kt index dd7d7498570..5f8d4720f80 100644 --- a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.kt +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJava.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java public interface A { public class A_S { // static diff --git a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt deleted file mode 100644 index 793f36adecb..00000000000 --- a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.fir.kt +++ /dev/null @@ -1,82 +0,0 @@ -// 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/nestedFromJavaAfterKotlin.kt b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.kt index e4e00ca3e28..341a0373e4b 100644 --- a/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.kt +++ b/compiler/testData/diagnostics/tests/scopes/inheritance/nestedFromJavaAfterKotlin.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java public interface A { class A_S { diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt index 9f08a417929..b96e3951189 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt @@ -6,6 +6,6 @@ class Outer { } constructor(x: Int) - constructor(x: Int, y: Int, z: Int = x + Inner().prop + this.Inner().prop) : - this(x + Inner().prop + this.Inner().prop) + 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/typealias/typeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt index 74af33068f9..a1d2bdc5a75 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.fir.kt @@ -17,8 +17,8 @@ typealias TI = Interface object AnObject typealias TO = AnObject -val test6 = TI() -val test6a = Interface() +val test6 = TI() +val test6a = Interface() val test7 = TO() val test7a = AnObject() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt index 7696ae222a8..972debe5f71 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorForInterface.fir.kt @@ -2,5 +2,5 @@ interface IFoo typealias Test = IFoo -val testAsFunction = Test() -val testAsValue = Test \ No newline at end of file +val testAsFunction = Test() +val testAsValue = Test diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt index 506603a148d..c8c05cc8aa8 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt @@ -26,8 +26,8 @@ class Outer { } typealias Test5 = Outer.Inner -val test5 = Test5() -val test5a = Outer.Inner() +val test5 = Test5() +val test5a = Outer.Inner() val test5b = Outer.TestInner() val test5c = Outer().TestInner() val test5d = Outer().Inner() diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index c967fded9dc..55b8fbe2fa7 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -335,6 +335,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.RESOLUTION_TO_CLASSIFIER) { firDiagnostic -> + ResolutionToClassifierImpl( + firSymbolBuilder.classifierBuilder.buildClassLikeSymbol(firDiagnostic.a.fir), + firDiagnostic as FirPsiDiagnostic, + token, + ) + } add(FirErrors.SUPER_IS_NOT_AN_EXPRESSION) { firDiagnostic -> SuperIsNotAnExpressionImpl( firDiagnostic as FirPsiDiagnostic, diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 754051e4132..3c9e7f6fb50 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -263,6 +263,11 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val type: KtType } + abstract class ResolutionToClassifier : KtFirDiagnostic() { + override val diagnosticClass get() = ResolutionToClassifier::class + abstract val classSymbol: KtClassLikeSymbol + } + abstract class SuperIsNotAnExpression : KtFirDiagnostic() { override val diagnosticClass get() = SuperIsNotAnExpression::class } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 8cb417b76d2..5faef308a83 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -390,6 +390,14 @@ internal class FunctionExpectedImpl( override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) } +internal class ResolutionToClassifierImpl( + override val classSymbol: KtClassLikeSymbol, + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.ResolutionToClassifier(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} + internal class SuperIsNotAnExpressionImpl( firDiagnostic: FirPsiDiagnostic, override val token: ValidityToken,