[FE] Assume that effective visibility of sealed class constructor is internal

#KT-45033 Fixed
#KT-45043
This commit is contained in:
Dmitriy Novozhilov
2021-02-18 18:10:15 +03:00
committed by TeamCityServer
parent b08eb6cf4c
commit 88c43e7f7b
9 changed files with 121 additions and 1 deletions
@@ -24313,6 +24313,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/sealed/inheritorInDifferentModule.kt");
}
@Test
@TestMetadata("internalTypeInConstructor.kt")
public void testInternalTypeInConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/internalTypeInConstructor.kt");
}
@Test
@TestMetadata("kt44316.kt")
public void testKt44316() throws Exception {
@@ -24433,6 +24439,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
}
@Test
@TestMetadata("privateTypeInConstructor.kt")
public void testPrivateTypeInConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt");
}
@Test
@TestMetadata("protectedConstructors_disabled.kt")
public void testProtectedConstructors_disabled() throws Exception {
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory3
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifier
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.isError
@@ -80,7 +81,10 @@ class ExposedVisibilityChecker(private val trace: BindingTrace? = null) {
// for checking situation with modified basic visibility
visibility: DescriptorVisibility = functionDescriptor.visibility
): Boolean {
val functionVisibility = functionDescriptor.effectiveVisibility(visibility)
var functionVisibility = functionDescriptor.effectiveVisibility(visibility)
if (functionDescriptor is ConstructorDescriptor && functionDescriptor.constructedClass.isSealed() && function.visibilityModifier() == null) {
functionVisibility = EffectiveVisibility.Private
}
var result = true
if (function !is KtConstructor<*>) {
val restricting = functionDescriptor.returnType?.leastPermissiveDescriptor(functionVisibility)
@@ -0,0 +1,9 @@
// ISSUE: KT-45033
// DIAGNOSTICS: -UNUSED_PARAMETER
internal class Bar
sealed class Foo(
<!EXPOSED_PARAMETER_TYPE!>internal val x: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>y: Bar<!>
)
@@ -0,0 +1,9 @@
// ISSUE: KT-45033
// DIAGNOSTICS: -UNUSED_PARAMETER
internal class Bar
sealed class Foo(
internal val x: Bar,
y: Bar
)
@@ -0,0 +1,16 @@
package
internal final class Bar {
public constructor Bar()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public sealed class Foo {
protected constructor Foo(/*0*/ x: Bar, /*1*/ y: Bar)
internal final val x: Bar
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,16 @@
// ISSUE: KT-45043
// DIAGNOSTICS: -UNUSED_PARAMETER
private class Bar
sealed class SealedFoo(
<!EXPOSED_PARAMETER_TYPE!>val <!EXPOSED_PROPERTY_TYPE!>x<!>: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>private val y: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>z: Bar<!>
)
abstract class AbstractFoo(
<!EXPOSED_PARAMETER_TYPE!>val <!EXPOSED_PROPERTY_TYPE!>x<!>: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>private val y: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>z: Bar<!>
)
@@ -0,0 +1,16 @@
// ISSUE: KT-45043
// DIAGNOSTICS: -UNUSED_PARAMETER
private class Bar
sealed class SealedFoo(
<!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR!>val x: Bar<!>,
private val y: Bar,
z: Bar
)
abstract class AbstractFoo(
<!EXPOSED_PARAMETER_TYPE!>val x: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>private val y: Bar<!>,
<!EXPOSED_PARAMETER_TYPE!>z: Bar<!>
)
@@ -0,0 +1,26 @@
package
public abstract class AbstractFoo {
public constructor AbstractFoo(/*0*/ x: Bar, /*1*/ y: Bar, /*2*/ z: Bar)
public final val x: Bar
private final val y: Bar
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
private final class Bar {
public constructor Bar()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public sealed class SealedFoo {
protected constructor SealedFoo(/*0*/ x: Bar, /*1*/ y: Bar, /*2*/ z: Bar)
public final val x: Bar
private final val y: Bar
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -24403,6 +24403,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/sealed/inheritorInDifferentModule.kt");
}
@Test
@TestMetadata("internalTypeInConstructor.kt")
public void testInternalTypeInConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/internalTypeInConstructor.kt");
}
@Test
@TestMetadata("kt44316.kt")
public void testKt44316() throws Exception {
@@ -24523,6 +24529,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
}
@Test
@TestMetadata("privateTypeInConstructor.kt")
public void testPrivateTypeInConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt");
}
@Test
@TestMetadata("protectedConstructors_disabled.kt")
public void testProtectedConstructors_disabled() throws Exception {