diff --git a/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt b/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt new file mode 100644 index 00000000000..da715e91046 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt @@ -0,0 +1,31 @@ +class A { + companion object Comp {} + + fun foo() { + Comp() + } +} + +object B { + private val x = B() +} + +class D { + companion object Comp2 { + operator fun invoke() {} + } + + fun foo() { + Comp2() + } +} + +enum class E { + X { + + }; + + fun foo() { + X() + } +} diff --git a/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.txt b/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.txt new file mode 100644 index 00000000000..6058cc99938 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.txt @@ -0,0 +1,70 @@ +FILE: singletonConstructors.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final companion object Comp : R|kotlin/Any| { + private constructor(): R|A.Comp| { + super() + } + + } + + public final fun foo(): R|kotlin/Unit| { + #() + } + + } + public final object B : R|kotlin/Any| { + private constructor(): R|B| { + super() + } + + private final val x: = #() + private get(): + + } + public final class D : R|kotlin/Any| { + public constructor(): R|D| { + super() + } + + public final companion object Comp2 : R|kotlin/Any| { + private constructor(): R|D.Comp2| { + super() + } + + public final operator fun invoke(): R|kotlin/Unit| { + } + + } + + public final fun foo(): R|kotlin/Unit| { + Q|D.Comp2|.R|/D.Comp2.invoke|() + } + + } + public final enum class E : R|kotlin/Enum| { + private constructor(): R|E| { + super|>() + } + + public final static enum entry X: R|E| = object : R|E| { + private constructor(): R|anonymous| { + super() + } + + } + + public final fun foo(): R|kotlin/Unit| { + #() + } + + public final static fun values(): R|kotlin/Array| { + } + + public final static fun valueOf(value: R|kotlin/String|): R|E| { + } + + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 09fe1e4be65..e85b2b31546 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -2172,5 +2172,10 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { public void testProtectedInCompanion() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/visibility/protectedInCompanion.kt"); } + + @TestMetadata("singletonConstructors.kt") + public void testSingletonConstructors() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt"); + } } } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 9dc356fbc66..5d7f9fc822b 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -2172,5 +2172,10 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testProtectedInCompanion() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/visibility/protectedInCompanion.kt"); } + + @TestMetadata("singletonConstructors.kt") + public void testSingletonConstructors() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt"); + } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index 84f7c3b755e..615d8b7f45f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -476,6 +476,9 @@ internal object CheckVisibility : CheckerStage() { val classSymbol = provider.getClassLikeSymbolByFqName(ownerClassId) if (classSymbol is FirRegularClassSymbol) { + if (classSymbol.fir.classKind.isSingleton) { + sink.yieldApplicability(CandidateApplicability.HIDDEN) + } checkVisibility(classSymbol.fir, classSymbol, sink, callInfo) } } diff --git a/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt index 6d5db3d3892..963a57289f6 100644 --- a/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt @@ -1,11 +1,11 @@ object A1() { - constructor(x: Int = "", y: Int) : this() { + constructor(x: Int = "", y: Int) : this() { x + y } } object A2 public constructor(private val prop: Int) { - constructor(x: Int = "", y: Int) : this(x * y) { + constructor(x: Int = "", y: Int) : this(x * y) { x + y } } @@ -19,6 +19,6 @@ val x = object (val prop: Int) { class A3 { companion object B(val prop: Int) { - public constructor() : this(2) + public constructor() : this(2) } -} \ No newline at end of file +}