Skip to content

[KT-76629] FIR: Fix wrong implicit visibility on Sealed classes. #5462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// FIR_IDENTICAL
// RUN_PIPELINE_TILL: FRONTEND
// KT-76629

sealed class A(val x: Int) {
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(s: String) : this(s.length)

class A1 : A(100)
class A2 : A("String")
}


sealed class B <!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(val x: Int) {
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(s: String) : this(s.length)

class B1 : B(100)
class B2 : B("String")
}

sealed class C private constructor(val x: Int) {
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(s: String) : this(s.length)

class C1 : C(100)
class C2 : C("String")
}

sealed class C3 : <!INVISIBLE_REFERENCE!>C<!>(200)

sealed class D {
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(x: Int)
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(s: String) : this(s.length)

class D1 : D(100)
class D2 : D("String")
}

sealed class E() {
private constructor(x: Int) : this()
<!REDUNDANT_VISIBILITY_MODIFIER!>protected<!> constructor(x: Byte) : this()
<!NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>internal constructor(x: Short) : this()<!>
<!NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>public constructor(x: Long) : this()<!>
constructor(x: Double) : this()
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,11 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi

this is FirConstructor -> {
val classSymbol = this.getContainingClassSymbol()
if (
classSymbol is FirRegularClassSymbol
&& (classSymbol.isEnumClass || classSymbol.isSealed)
) {
Visibilities.Private
} else {
defaultVisibility
when {
classSymbol !is FirRegularClassSymbol -> defaultVisibility
classSymbol.isEnumClass -> Visibilities.Private
classSymbol.isSealed -> Visibilities.Protected
else -> defaultVisibility
}
}

Expand Down