Effective visibility: local is now considered private, TYPE_DEPENDS_ON_LOCAL_CLASS diagnostics removed as repeated #KT-9542 Fixed #KT-9526 Fixed
This commit is contained in:
@@ -399,9 +399,6 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<JetParameter> USELESS_VARARG_ON_PARAMETER = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<JetFunction, ClassDescriptor> FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS = DiagnosticFactory1.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory1<JetProperty, ClassDescriptor> PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS = DiagnosticFactory1.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
|
||||
// Named parameters
|
||||
|
||||
DiagnosticFactory0<JetParameter> DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE = DiagnosticFactory0.create(ERROR, PARAMETER_DEFAULT_VALUE);
|
||||
|
||||
-2
@@ -270,8 +270,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
|
||||
MAP.put(UNUSED_EXPRESSION, "The expression is unused");
|
||||
MAP.put(UNUSED_FUNCTION_LITERAL, "The function literal is unused. If you mean block, you can use 'run { ... }'");
|
||||
MAP.put(FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS, "Function return type depends on local class or object {0}", NAME);
|
||||
MAP.put(PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS, "Property type depends on local class or object {0}", NAME);
|
||||
|
||||
MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME);
|
||||
MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME);
|
||||
|
||||
@@ -689,58 +689,6 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLocalTypesInFunctionReturnType(@NotNull JetFunction function, @NotNull FunctionDescriptor functionDescriptor) {
|
||||
if (functionDescriptor instanceof ConstructorDescriptor) return;
|
||||
if (!isExposedAsPublicAPI(functionDescriptor)) return;
|
||||
JetType returnType = functionDescriptor.getReturnType();
|
||||
if (returnType == null) return;
|
||||
checkLocalTypesExposedInType(function, functionDescriptor, returnType,
|
||||
FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS,
|
||||
new HashSet<JetType>());
|
||||
}
|
||||
|
||||
private void checkLocalTypesInPropertyType(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
if (!isExposedAsPublicAPI(propertyDescriptor)) return;
|
||||
JetType propertyType = propertyDescriptor.getType();
|
||||
checkLocalTypesExposedInType(property, propertyDescriptor, propertyType,
|
||||
PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS,
|
||||
new HashSet<JetType>());
|
||||
}
|
||||
|
||||
private static boolean isExposedAsPublicAPI(@NotNull DeclarationDescriptor descriptor) {
|
||||
for (DeclarationDescriptor finger = descriptor; finger != null; finger = finger.getContainingDeclaration()) {
|
||||
if (finger instanceof DeclarationDescriptorWithVisibility) {
|
||||
Visibility visibility = ((DeclarationDescriptorWithVisibility) finger).getVisibility();
|
||||
if (Visibilities.isPrivate(visibility) || visibility == Visibilities.LOCAL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private <D extends JetDeclaration> void checkLocalTypesExposedInType(
|
||||
@NotNull D reportOnDeclaration,
|
||||
@NotNull DeclarationDescriptor parentDeclarationDescriptor,
|
||||
@NotNull JetType type,
|
||||
@NotNull DiagnosticFactory1<D, ClassDescriptor> diagnostic,
|
||||
@NotNull Set<JetType> visitedTypes
|
||||
) {
|
||||
visitedTypes.add(type);
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(type);
|
||||
if (classDescriptor != null) {
|
||||
if (DescriptorUtils.isLocal(classDescriptor) && DescriptorUtils.isAncestor(parentDeclarationDescriptor, classDescriptor, true)) {
|
||||
trace.report(diagnostic.on(reportOnDeclaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
JetType projectedType = projection.getType();
|
||||
if (!visitedTypes.contains(projectedType)) {
|
||||
checkLocalTypesExposedInType(reportOnDeclaration, parentDeclarationDescriptor, projectedType, diagnostic, visitedTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPropertyExposedType(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
EffectiveVisibility propertyVisibility = EffectiveVisibility.Companion.forMember(propertyDescriptor);
|
||||
EffectiveVisibility typeVisibility = EffectiveVisibility.Companion.forType(propertyDescriptor.getType());
|
||||
@@ -748,7 +696,6 @@ public class DeclarationsChecker {
|
||||
trace.report(EXPOSED_PROPERTY_TYPE.on(property, propertyVisibility, typeVisibility));
|
||||
}
|
||||
checkMemberReceiverExposedType(property.getReceiverTypeReference(), propertyDescriptor);
|
||||
checkLocalTypesInPropertyType(property, propertyDescriptor);
|
||||
}
|
||||
|
||||
protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
|
||||
@@ -818,7 +765,6 @@ public class DeclarationsChecker {
|
||||
i++;
|
||||
}
|
||||
checkMemberReceiverExposedType(function.getReceiverTypeReference(), functionDescriptor);
|
||||
checkLocalTypesInFunctionReturnType(function, functionDescriptor);
|
||||
}
|
||||
|
||||
private void checkAccessors(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
+24
-24
@@ -16,13 +16,13 @@ class Foo {
|
||||
privateProperty.f2()
|
||||
}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected val protectedProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val internalProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>internal2Property<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val internal2Property<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val publicProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
|
||||
private fun privateFunction() = object : MyClass(), MyTrait {}
|
||||
@@ -32,13 +32,13 @@ class Foo {
|
||||
privateFunction().f2()
|
||||
}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected fun <!EXPOSED_FUNCTION_RETURN_TYPE!>protectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!EXPOSED_FUNCTION_RETURN_TYPE!>internalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>internal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!EXPOSED_FUNCTION_RETURN_TYPE!>internal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!EXPOSED_FUNCTION_RETURN_TYPE!>publicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ class Foo {
|
||||
privatePropertyInner.f2()
|
||||
}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected val protectedProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val internalProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>internal2Property<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val internal2Property<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val publicProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
|
||||
private fun privateFunctionInner() = object : MyClass(), MyTrait {}
|
||||
@@ -66,13 +66,13 @@ class Foo {
|
||||
privateFunctionInner().f2()
|
||||
}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>protected fun <!EXPOSED_FUNCTION_RETURN_TYPE!>protectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!EXPOSED_FUNCTION_RETURN_TYPE!>internalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>internal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!EXPOSED_FUNCTION_RETURN_TYPE!>internal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!EXPOSED_FUNCTION_RETURN_TYPE!>publicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,21 +90,21 @@ class Foo {
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>private val packagePrivateProperty<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!><!WRONG_MODIFIER_TARGET!>protected<!> val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageProtectedProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!><!WRONG_MODIFIER_TARGET!>protected<!> val packageProtectedProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageInternalProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>val packageInternalProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageInternal2Property<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal val packageInternal2Property<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>packagePublicProperty<!><!> = object : MyClass(), MyTrait {}
|
||||
<!EXPOSED_PROPERTY_TYPE!><!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val packagePublicProperty<!> = object : MyClass(), MyTrait {}<!>
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!><!WRONG_MODIFIER_TARGET!>protected<!> fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageProtectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!><!WRONG_MODIFIER_TARGET!>protected<!> fun <!EXPOSED_FUNCTION_RETURN_TYPE!>packageProtectedFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageInternalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>fun <!EXPOSED_FUNCTION_RETURN_TYPE!>packageInternalFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>packageInternal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>internal fun <!EXPOSED_FUNCTION_RETURN_TYPE!>packageInternal2Function<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>packagePublicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public fun <!EXPOSED_FUNCTION_RETURN_TYPE!>packagePublicFunction<!>()<!> = object : MyClass(), MyTrait {}
|
||||
|
||||
fun fooPackage() {
|
||||
val packageLocalVar = object : MyClass(), MyTrait {}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
interface Your
|
||||
|
||||
class My {
|
||||
internal val x = object : Your {}
|
||||
|
||||
internal fun <!EXPOSED_FUNCTION_RETURN_TYPE!>foo<!>() = {
|
||||
class Local
|
||||
Local()
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public final class My {
|
||||
public constructor My()
|
||||
internal final val x: Your
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): My.foo.<anonymous>.Local
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Your {
|
||||
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
|
||||
}
|
||||
+2
-2
@@ -3,13 +3,13 @@ fun <T> run(f: () -> T): T {
|
||||
}
|
||||
|
||||
// invalid, depends on local class
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>foo<!>() = run {
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>foo<!>() = run {
|
||||
class A
|
||||
A()
|
||||
}
|
||||
|
||||
// invalid, depends on local class
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>gav<!>() = {
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>gav<!>() = {
|
||||
class B
|
||||
B()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class My {
|
||||
internal open class ThreadLocal
|
||||
// Private from local: ???
|
||||
private val values =
|
||||
// Local from internal: Ok
|
||||
object: ThreadLocal() {}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public final class My {
|
||||
public constructor My()
|
||||
private final val values: My.values.<no name provided>
|
||||
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
|
||||
|
||||
internal open class ThreadLocal {
|
||||
public constructor ThreadLocal()
|
||||
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,15 @@
|
||||
class A {
|
||||
private open class B
|
||||
fun f() {
|
||||
// Local from private: Ok
|
||||
class C : B()
|
||||
}
|
||||
}
|
||||
|
||||
private open class D
|
||||
|
||||
fun f(): Int {
|
||||
// Local from private: Ok
|
||||
val x = object : D() { }
|
||||
return x.hashCode()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public fun f(): kotlin.Int
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun f(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
private open class B {
|
||||
public constructor B()
|
||||
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 open class D {
|
||||
public constructor D()
|
||||
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
|
||||
}
|
||||
@@ -6,21 +6,21 @@ class My<T>(val value: T)
|
||||
|
||||
open class Base
|
||||
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid1<!>() = run {
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>invalid1<!>() = run {
|
||||
class Local
|
||||
My(Local())
|
||||
}
|
||||
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid2<!>() = My(object {})
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>invalid2<!>() = My(object {})
|
||||
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid3<!>() = My(object : Base() {})
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>invalid3<!>() = My(object : Base() {})
|
||||
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid4<!>() = run {
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>invalid4<!>() = run {
|
||||
class Local
|
||||
My(My(Local()))
|
||||
}
|
||||
|
||||
fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid5<!>() = run {
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>invalid5<!>() = run {
|
||||
fun invalid5a() = run {
|
||||
class Local
|
||||
Local()
|
||||
|
||||
@@ -7,9 +7,9 @@ class Something {
|
||||
internal val internalVal1 = object { override fun toString() = "!" }
|
||||
private val privateVal1 = object { override fun toString() = "!" }
|
||||
|
||||
public val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicVal2<!> = run { class A; A() }
|
||||
protected val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedVal2<!> = run { class A; A() }
|
||||
internal val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalVal2<!> = run { class A; A() }
|
||||
<!EXPOSED_PROPERTY_TYPE!>public val publicVal2 = run { class A; A() }<!>
|
||||
<!EXPOSED_PROPERTY_TYPE!>protected val protectedVal2 = run { class A; A() }<!>
|
||||
<!EXPOSED_PROPERTY_TYPE!>internal val internalVal2 = run { class A; A() }<!>
|
||||
private val privateVal2 = run { class A; A() }
|
||||
|
||||
public fun publicFun1() = object { override fun toString() = "!" }
|
||||
@@ -17,8 +17,8 @@ class Something {
|
||||
internal fun internalFun1() = object { override fun toString() = "!" }
|
||||
private fun privateFun1() = object { override fun toString() = "!" }
|
||||
|
||||
public fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>publicFun2<!>() = run { class A; A() }
|
||||
protected fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>protectedFun2<!>() = run { class A; A() }
|
||||
internal fun <!FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS!>internalFun2<!>() = run { class A; A() }
|
||||
public fun <!EXPOSED_FUNCTION_RETURN_TYPE!>publicFun2<!>() = run { class A; A() }
|
||||
protected fun <!EXPOSED_FUNCTION_RETURN_TYPE!>protectedFun2<!>() = run { class A; A() }
|
||||
internal fun <!EXPOSED_FUNCTION_RETURN_TYPE!>internalFun2<!>() = run { class A; A() }
|
||||
private fun privateFun2() = run { class A; A() }
|
||||
}
|
||||
@@ -6,27 +6,27 @@ class My<T>(val value: T)
|
||||
|
||||
open class Base
|
||||
|
||||
val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid1<!> = run {
|
||||
<!EXPOSED_PROPERTY_TYPE!>val invalid1 = run {
|
||||
class Local
|
||||
My(Local())
|
||||
}
|
||||
}<!>
|
||||
|
||||
val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid2<!> = My(object {})
|
||||
<!EXPOSED_PROPERTY_TYPE!>val invalid2 = My(object {})<!>
|
||||
|
||||
val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid3<!> = My(object : Base() {})
|
||||
<!EXPOSED_PROPERTY_TYPE!>val invalid3 = My(object : Base() {})<!>
|
||||
|
||||
val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid4<!> = run {
|
||||
<!EXPOSED_PROPERTY_TYPE!>val invalid4 = run {
|
||||
class Local
|
||||
My(My(Local()))
|
||||
}
|
||||
}<!>
|
||||
|
||||
val <!PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS!>invalid5<!> = run {
|
||||
<!EXPOSED_PROPERTY_TYPE!>val invalid5 = run {
|
||||
fun invalid5a() = run {
|
||||
class Local
|
||||
Local()
|
||||
}
|
||||
My(invalid5a())
|
||||
}
|
||||
}<!>
|
||||
|
||||
// Valid: effectively Any
|
||||
val valid1 = object {}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
interface Your
|
||||
|
||||
class My {
|
||||
// private from local: ???
|
||||
private val x = object : Your {}
|
||||
|
||||
// private from local: ???
|
||||
private fun foo() = {
|
||||
class Local
|
||||
Local()
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public final class My {
|
||||
public constructor My()
|
||||
private final val x: My.x.<no name provided>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
private final fun foo(): My.foo.<anonymous>.Local
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Your {
|
||||
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
|
||||
}
|
||||
@@ -5808,12 +5808,30 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("internalFromLocal.kt")
|
||||
public void testInternalFromLocal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/internalFromLocal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("local.kt")
|
||||
public void testLocal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/local.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localFromInternal.kt")
|
||||
public void testLocalFromInternal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/localFromInternal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localFromPrivate.kt")
|
||||
public void testLocalFromPrivate() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/localFromPrivate.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localInFunReturnType.kt")
|
||||
public void testLocalInFunReturnType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/localInFunReturnType.kt");
|
||||
@@ -5838,6 +5856,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateFromLocal.kt")
|
||||
public void testPrivateFromLocal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/privateFromLocal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("protected.kt")
|
||||
public void testProtected() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/protected.kt");
|
||||
|
||||
@@ -34,11 +34,18 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
// \ / /InternalProtected(Derived)
|
||||
// \InternalProtectedBound/
|
||||
// |
|
||||
// Private
|
||||
// Private = Local
|
||||
|
||||
|
||||
object Private : EffectiveVisibility("private") {
|
||||
override fun relation(other: EffectiveVisibility) =
|
||||
if (this == other) Permissiveness.SAME else Permissiveness.LESS
|
||||
if (this == other || Local == other) Permissiveness.SAME else Permissiveness.LESS
|
||||
}
|
||||
|
||||
// Effectively same as Private
|
||||
object Local : EffectiveVisibility("local") {
|
||||
override fun relation(other: EffectiveVisibility) =
|
||||
if (this == other || Private == other) Permissiveness.SAME else Permissiveness.LESS
|
||||
}
|
||||
|
||||
object Public : EffectiveVisibility("public") {
|
||||
@@ -49,14 +56,14 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
object Internal : EffectiveVisibility("internal") {
|
||||
override fun relation(other: EffectiveVisibility) = when (other) {
|
||||
Public -> Permissiveness.LESS
|
||||
Private, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE
|
||||
Private, Local, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE
|
||||
Internal -> Permissiveness.SAME
|
||||
ProtectedBound, is Protected -> Permissiveness.UNKNOWN
|
||||
}
|
||||
|
||||
override fun lowerBound(other: EffectiveVisibility) = when (other) {
|
||||
Public -> this
|
||||
Private, InternalProtectedBound, Internal, is InternalProtected -> other
|
||||
Private, Local, InternalProtectedBound, Internal, is InternalProtected -> other
|
||||
is Protected -> InternalProtected(other.container)
|
||||
ProtectedBound -> InternalProtectedBound
|
||||
}
|
||||
@@ -72,7 +79,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
|
||||
override fun relation(other: EffectiveVisibility) = when (other) {
|
||||
Public -> Permissiveness.LESS
|
||||
Private, ProtectedBound, InternalProtectedBound -> Permissiveness.MORE
|
||||
Private, Local, ProtectedBound, InternalProtectedBound -> Permissiveness.MORE
|
||||
is Protected -> containerRelation(container, other.container)
|
||||
is InternalProtected -> when (containerRelation(container, other.container)) {
|
||||
// Protected never can be less permissive than internal & protected
|
||||
@@ -84,7 +91,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
|
||||
override fun lowerBound(other: EffectiveVisibility) = when (other) {
|
||||
Public -> this
|
||||
Private, ProtectedBound, InternalProtectedBound -> other
|
||||
Private, Local, ProtectedBound, InternalProtectedBound -> other
|
||||
is Protected -> when (relation(other)) {
|
||||
Permissiveness.SAME, Permissiveness.MORE -> this
|
||||
Permissiveness.LESS -> other
|
||||
@@ -102,14 +109,14 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
object ProtectedBound : EffectiveVisibility("protected (in different classes)") {
|
||||
override fun relation(other: EffectiveVisibility) = when (other) {
|
||||
Public, is Protected -> Permissiveness.LESS
|
||||
Private, InternalProtectedBound -> Permissiveness.MORE
|
||||
Private, Local, InternalProtectedBound -> Permissiveness.MORE
|
||||
ProtectedBound -> Permissiveness.SAME
|
||||
Internal, is InternalProtected -> Permissiveness.UNKNOWN
|
||||
}
|
||||
|
||||
override fun lowerBound(other: EffectiveVisibility) = when (other) {
|
||||
Public, is Protected -> this
|
||||
Private, ProtectedBound, InternalProtectedBound -> other
|
||||
Private, Local, ProtectedBound, InternalProtectedBound -> other
|
||||
Internal, is InternalProtected -> InternalProtectedBound
|
||||
}
|
||||
}
|
||||
@@ -125,7 +132,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
|
||||
override fun relation(other: EffectiveVisibility) = when (other) {
|
||||
Public, Internal -> Permissiveness.LESS
|
||||
Private, InternalProtectedBound -> Permissiveness.MORE
|
||||
Private, Local, InternalProtectedBound -> Permissiveness.MORE
|
||||
is InternalProtected -> containerRelation(container, other.container)
|
||||
is Protected -> when (containerRelation(container, other.container)) {
|
||||
// Internal & protected never can be more permissive than just protected
|
||||
@@ -137,7 +144,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
|
||||
override fun lowerBound(other: EffectiveVisibility) = when (other) {
|
||||
Public, Internal -> this
|
||||
Private, InternalProtectedBound -> other
|
||||
Private, Local, InternalProtectedBound -> other
|
||||
is Protected, is InternalProtected -> when (relation(other)) {
|
||||
Permissiveness.SAME, Permissiveness.MORE -> this
|
||||
Permissiveness.LESS -> other
|
||||
@@ -151,7 +158,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
object InternalProtectedBound : EffectiveVisibility("internal & protected (in different classes)") {
|
||||
override fun relation(other: EffectiveVisibility) = when (other) {
|
||||
Public, is Protected, is InternalProtected, ProtectedBound, Internal -> Permissiveness.LESS
|
||||
Private -> Permissiveness.MORE
|
||||
Private, Local -> Permissiveness.MORE
|
||||
InternalProtectedBound -> Permissiveness.SAME
|
||||
}
|
||||
}
|
||||
@@ -206,8 +213,7 @@ sealed class EffectiveVisibility(val name: String) {
|
||||
Visibilities.PROTECTED -> Protected(descriptor)
|
||||
Visibilities.INTERNAL -> Internal
|
||||
Visibilities.PUBLIC -> Public
|
||||
// Considered effectively public
|
||||
Visibilities.LOCAL -> Public
|
||||
Visibilities.LOCAL -> Local
|
||||
else -> this.effectiveVisibility(descriptor)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user