Dont show warning for KT-21515 with LV>=1.3

This commit is contained in:
Dmitry Savvinov
2020-09-15 14:01:17 +03:00
parent 57ceb0fa20
commit 6a55475392
9 changed files with 41 additions and 32 deletions
@@ -652,6 +652,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
} }
} }
@Override
protected boolean getShouldReportCyclicScopeWithCompanionWarning() {
return !c.getLanguageVersionSettings()
.supportsFeature(LanguageFeature.ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion);
}
@Override @Override
protected void reportScopesLoopError(@NotNull KotlinType type) { protected void reportScopesLoopError(@NotNull KotlinType type) {
PsiElement reportOn = DescriptorToSourceUtils.getSourceFromDescriptor(type.getConstructor().getDeclarationDescriptor()); PsiElement reportOn = DescriptorToSourceUtils.getSourceFromDescriptor(type.getConstructor().getDeclarationDescriptor());
@@ -2,14 +2,14 @@
// see https://youtrack.jetbrains.com/issue/KT-21515 // see https://youtrack.jetbrains.com/issue/KT-21515
open class Container { open class Container {
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!> { open class Base {
open fun m() {} open fun m() {}
} }
// note that Base() supertype will be resolved in scope that was created on recursion // note that Base() supertype will be resolved in scope that was created on recursion
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : Base() abstract class DerivedAbstract : Base()
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() { companion object : DerivedAbstract() {
override fun m() {} override fun m() {}
} }
} }
@@ -1,15 +1,15 @@
// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion // !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion
// see https://youtrack.jetbrains.com/issue/KT-21515 // see https://youtrack.jetbrains.com/issue/KT-21515
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() { abstract class DerivedAbstract : C.Base() {
open class Data open class Data
} }
public class C { public class C {
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!> () open class Base ()
class Foo : <!UNRESOLVED_REFERENCE!>Data<!>() class Foo : <!UNRESOLVED_REFERENCE!>Data<!>()
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() companion object : DerivedAbstract()
} }
@@ -6,13 +6,13 @@ open class Container {
// (this is case because we can't know if there are any loops without resolving, but resolving // (this is case because we can't know if there are any loops without resolving, but resolving
// itself provokes loops) // itself provokes loops)
interface <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!> { interface Base {
open fun m() {} open fun m() {}
} }
interface <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : Base interface DerivedAbstract : Base
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract { companion object : DerivedAbstract {
override fun m() {} override fun m() {}
} }
} }
@@ -1,20 +1,20 @@
// see https://youtrack.jetbrains.com/issue/KT-21515 // see https://youtrack.jetbrains.com/issue/KT-21515
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() { abstract class DerivedAbstract : C.Base() {
override abstract fun m() override abstract fun m()
} }
public class C { public class C {
class Data class Data
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!> () { open class Base () {
open fun m() {} open fun m() {}
} }
// Note that Data is resolved successfully here because we don't step on error-scope // Note that Data is resolved successfully here because we don't step on error-scope
val data: Data = Data() val data: Data = Data()
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() { companion object : DerivedAbstract() {
override fun m() {} override fun m() {}
} }
} }
@@ -4,7 +4,7 @@
interface SomeIrrelevantInterface interface SomeIrrelevantInterface
// note that C.Base() supertype will be resolved in normal scope // note that C.Base() supertype will be resolved in normal scope
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() abstract class DerivedAbstract : C.Base()
class Data class Data
@@ -14,7 +14,7 @@ public class C {
// Note that any supertype of Base will be resolved in error-scope, even if it absolutely irrelevant // Note that any supertype of Base will be resolved in error-scope, even if it absolutely irrelevant
// to the types in cycle. // to the types in cycle.
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!>() : SomeIrrelevantInterface open class Base() : SomeIrrelevantInterface
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() companion object : DerivedAbstract()
} }
@@ -2,37 +2,37 @@
// see https://youtrack.jetbrains.com/issue/KT-21515 // see https://youtrack.jetbrains.com/issue/KT-21515
object WithFunctionInBase { object WithFunctionInBase {
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() abstract class DerivedAbstract : C.Base()
class Data class Data
public class C { public class C {
val data: Data = Data() val data: Data = Data()
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!>() { open class Base() {
fun foo(): Int = 42 fun foo(): Int = 42
} }
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() companion object : DerivedAbstract()
} }
} }
object WithPropertyInBase { object WithPropertyInBase {
// This case is very similar to previous one, but there are subtle differences from POV of implementation // This case is very similar to previous one, but there are subtle differences from POV of implementation
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() abstract class DerivedAbstract : C.Base()
class Data class Data
public class C { public class C {
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!>() { open class Base() {
val foo: Int = 42 val foo: Int = 42
} }
val data: Data = Data() val data: Data = Data()
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() companion object : DerivedAbstract()
} }
} }
@@ -41,18 +41,18 @@ object WithPropertyInBaseDifferentOrder {
// Note how position of property in file affected order of resolve, and, consequently, its results and // Note how position of property in file affected order of resolve, and, consequently, its results and
// diagnostics. // diagnostics.
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() abstract class DerivedAbstract : C.Base()
class Data class Data
public class C { public class C {
val data: Data = Data() val data: Data = Data()
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!>() { open class Base() {
val foo: Int = 42 val foo: Int = 42
} }
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() companion object : DerivedAbstract()
} }
} }
@@ -1,17 +1,17 @@
// see https://youtrack.jetbrains.com/issue/KT-21515 // see https://youtrack.jetbrains.com/issue/KT-21515
abstract class <!CYCLIC_SCOPES_WITH_COMPANION!>DerivedAbstract<!> : C.Base() abstract class DerivedAbstract : C.Base()
class Data class Data
open class C { open class C {
open class <!CYCLIC_SCOPES_WITH_COMPANION!>Base<!> { open class Base {
open fun m() {} open fun m() {}
} }
val field = Data() val field = Data()
companion <!CYCLIC_SCOPES_WITH_COMPANION!>object<!> : DerivedAbstract() { companion object : DerivedAbstract() {
override fun m() {} override fun m() {}
} }
} }
@@ -97,11 +97,13 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon
// We also check if there are a loop with additional edges going from owner of companion to // We also check if there are a loop with additional edges going from owner of companion to
// the companion itself. // the companion itself.
// Note that we use already disconnected types to not report two diagnostics on cyclic supertypes // Note that we use already disconnected types to not report two diagnostics on cyclic supertypes
supertypeLoopChecker.findLoopsInSupertypesAndDisconnect( if (shouldReportCyclicScopeWithCompanionWarning) {
this, resultWithoutCycles, supertypeLoopChecker.findLoopsInSupertypesAndDisconnect(
{ it.computeNeighbours(useCompanions = true) }, this, resultWithoutCycles,
{ reportScopesLoopError(it) } { it.computeNeighbours(useCompanions = true) },
) { reportScopesLoopError(it) }
)
}
supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List<KotlinType>) ?: resultWithoutCycles.toList() supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List<KotlinType>) ?: resultWithoutCycles.toList()
}) })
@@ -118,6 +120,7 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon
// TODO: overload in AbstractTypeParameterDescriptor? // TODO: overload in AbstractTypeParameterDescriptor?
protected open fun reportScopesLoopError(type: KotlinType) {} protected open fun reportScopesLoopError(type: KotlinType) {}
protected open val shouldReportCyclicScopeWithCompanionWarning: Boolean = false
protected open fun getAdditionalNeighboursInSupertypeGraph(useCompanions: Boolean): Collection<KotlinType> = emptyList() protected open fun getAdditionalNeighboursInSupertypeGraph(useCompanions: Boolean): Collection<KotlinType> = emptyList()
protected open fun defaultSupertypeIfEmpty(): KotlinType? = null protected open fun defaultSupertypeIfEmpty(): KotlinType? = null