From 3b92cab9e05623d150a39111180800c6b508004a Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 3 Feb 2015 21:09:49 +0300 Subject: [PATCH] Changed containing declaration for PropertyDeclarationInnerScope --- .../kotlin/resolve/BodyResolver.java | 4 +-- .../kotlin/resolve/DescriptorResolver.java | 2 +- .../kotlin/resolve/OverloadResolver.java | 4 +-- .../kotlin/resolve/scopes/JetScopeUtils.java | 11 ++++--- .../ambiguousObjectExpressionType.txt | 30 +++++++++---------- .../unambiguousObjectExpressionType.txt | 16 +++++----- .../diagnostics/tests/regressions/Jet81.txt | 4 +-- .../diagnostics/tests/scopes/kt1806.txt | 2 +- .../subtyping/memberAnonymousObjects.txt | 2 +- .../infos/PropertiesWithBackingFields.kt | 6 ++-- .../liftAnonymousToSupertype1.kt | 2 +- .../liftAnonymousToSupertype1.kt.after | 2 +- ...closureThisByUsingMethodFromParentClass.kt | 12 ++++---- 13 files changed, 48 insertions(+), 49 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 9235bee7fed..1136d8d6a7b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -646,7 +646,7 @@ public class BodyResolver { } JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer( - propertyScope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace); + propertyDescriptor, propertyScope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace); JetScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor( propertyDescriptor, parentScopeForAccessor, trace); @@ -674,7 +674,7 @@ public class BodyResolver { @NotNull JetScope scope ) { JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer( - scope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace); + propertyDescriptor, scope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace); JetType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; CompileTimeConstant compileTimeInitializer = propertyDescriptor.getCompileTimeInitializer(); if (compileTimeInitializer == null) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 8aa6a217927..12d059e75b3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -424,7 +424,7 @@ public class DescriptorResolver { ? Visibilities.INHERITED : Visibilities.INTERNAL; } - else if (containingDescriptor instanceof FunctionDescriptor) { + else if (containingDescriptor instanceof FunctionDescriptor || containingDescriptor instanceof PropertyDescriptor) { defaultVisibility = Visibilities.LOCAL; } else { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java index 0164e441805..57caee25245 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java @@ -64,8 +64,8 @@ public class OverloadResolver { @NotNull MultiMap inPackages ) { for (ClassDescriptorWithResolutionScopes klass : c.getDeclaredClasses().values()) { - if (klass.getKind().isSingleton()) { - // Constructors of singletons aren't callable from the code, so they shouldn't participate in overload name checking + if (klass.getKind().isSingleton() || klass.getName().isSpecial()) { + // Constructors of singletons or anonymous object aren't callable from the code, so they shouldn't participate in overload name checking continue; } DeclarationDescriptor containingDeclaration = klass.getContainingDeclaration(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java index e63b3f5a6cc..87d3f56d597 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java @@ -91,17 +91,17 @@ public final class JetScopeUtils { } public static JetScope getPropertyDeclarationInnerScopeForInitializer( + @NotNull PropertyDescriptor propertyDescriptor, @NotNull JetScope outerScope, @NotNull List typeParameters, @Nullable ReceiverParameterDescriptor receiver, BindingTrace trace ) { - return getPropertyDeclarationInnerScope(null, outerScope, typeParameters, receiver, trace, false); + return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, trace, false); } private static JetScope getPropertyDeclarationInnerScope( - @Nullable PropertyDescriptor propertyDescriptor, - // PropertyDescriptor can be null for property scope which hasn't label to property (in this case addLabelForProperty parameter must be false + @NotNull PropertyDescriptor propertyDescriptor, @NotNull JetScope outerScope, @NotNull List typeParameters, @Nullable ReceiverParameterDescriptor receiver, @@ -115,7 +115,7 @@ public final class JetScopeUtils { @NotNull private static JetScope getPropertyDeclarationInnerScope( - @Nullable PropertyDescriptor propertyDescriptor, + @NotNull PropertyDescriptor propertyDescriptor, @NotNull JetScope outerScope, @NotNull List typeParameters, @Nullable ReceiverParameterDescriptor receiver, @@ -123,10 +123,9 @@ public final class JetScopeUtils { boolean addLabelForProperty ) { WritableScopeImpl result = new WritableScopeImpl( - outerScope, outerScope.getContainingDeclaration(), redeclarationHandler, + outerScope, propertyDescriptor, redeclarationHandler, "Property declaration inner scope"); if (addLabelForProperty) { - assert propertyDescriptor != null : "PropertyDescriptor can be null for property scope which hasn't label to property"; result.addLabeledDeclaration(propertyDescriptor); } for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.txt b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.txt index e16348c86d8..0eb34a7d1cd 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.txt +++ b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.txt @@ -1,10 +1,10 @@ package -internal val packageInternal2Property: -internal val packageInternalProperty: -private val packagePrivateProperty: -protected val packageProtectedProperty: -public val packagePublicProperty: +internal val packageInternal2Property: packageInternal2Property. +internal val packageInternalProperty: packageInternalProperty. +private val packagePrivateProperty: packagePrivateProperty. +protected val packageProtectedProperty: packageProtectedProperty. +public val packagePublicProperty: packagePublicProperty. internal fun fooPackage(): kotlin.Unit internal fun packageInternal2Function(): packageInternal2Function. internal fun packageInternalFunction(): packageInternalFunction. @@ -13,11 +13,11 @@ public fun packagePublicFunction(): packagePublicFunction. internal final class Foo { public constructor Foo() - internal final val internal2Property: Foo.. - internal final val internalProperty: Foo.. - private final val privateProperty: Foo.. - protected final val protectedProperty: Foo.. - public final val publicProperty: Foo.. + internal final val internal2Property: Foo.internal2Property. + internal final val internalProperty: Foo.internalProperty. + private final val privateProperty: Foo.privateProperty. + protected final val protectedProperty: Foo.protectedProperty. + public final val publicProperty: Foo.publicProperty. public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean internal final fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -30,11 +30,11 @@ internal final class Foo { internal final class FooInner { public constructor FooInner() - internal final val internal2Property: Foo.FooInner.. - internal final val internalProperty: Foo.FooInner.. - private final val privatePropertyInner: Foo.FooInner.. - protected final val protectedProperty: Foo.FooInner.. - public final val publicProperty: Foo.FooInner.. + internal final val internal2Property: Foo.FooInner.internal2Property. + internal final val internalProperty: Foo.FooInner.internalProperty. + private final val privatePropertyInner: Foo.FooInner.privatePropertyInner. + protected final val protectedProperty: Foo.FooInner.protectedProperty. + public final val publicProperty: Foo.FooInner.publicProperty. public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int internal final fun internal2Function(): Foo.FooInner.internal2Function. diff --git a/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.txt b/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.txt index def1b452167..2ab75b058d6 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.txt +++ b/compiler/testData/diagnostics/tests/declarationChecks/unambiguousObjectExpressionType.txt @@ -3,9 +3,9 @@ package internal val packageInternal2Property: MyClass internal val packageInternalProperty: MyClass private val packagePrivateProperty: MyClass -protected val packageProtectedProperty: +protected val packageProtectedProperty: packageProtectedProperty. public val packagePublic2Property: MyClass -public val packagePublicProperty: +public val packagePublicProperty: packagePublicProperty. internal fun fooPackage(): kotlin.Unit internal fun internal2Function(): MyClass internal fun internalFunction(): MyClass @@ -20,11 +20,11 @@ internal final class Foo { public constructor Foo() internal final val internal2Property: MyClass internal final val internalProperty: MyClass - private final val privateProperty: Foo.. + private final val privateProperty: Foo.privateProperty. protected final val protected2Property: MyClass - protected final val protectedProperty: Foo.. + protected final val protectedProperty: Foo.protectedProperty. public final val public2Property: MyClass - public final val publicProperty: Foo.. + public final val publicProperty: Foo.publicProperty. public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean internal final fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -43,11 +43,11 @@ internal final class Foo { public constructor FooInner() internal final val internal2Property: MyClass internal final val internalProperty: MyClass - private final val privateProperty: Foo.FooInner.. + private final val privateProperty: Foo.FooInner.privateProperty. protected final val protected2Property: MyClass - protected final val protectedProperty: Foo.FooInner.. + protected final val protectedProperty: Foo.FooInner.protectedProperty. public final val public2Property: MyClass - public final val publicProperty: Foo.FooInner.. + public final val publicProperty: Foo.FooInner.publicProperty. public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int internal final fun internal2Function(): MyClass diff --git a/compiler/testData/diagnostics/tests/regressions/Jet81.txt b/compiler/testData/diagnostics/tests/regressions/Jet81.txt index bc0be0eef1d..2fb0dc6e2b0 100644 --- a/compiler/testData/diagnostics/tests/regressions/Jet81.txt +++ b/compiler/testData/diagnostics/tests/regressions/Jet81.txt @@ -10,7 +10,7 @@ internal object A { internal final class Test { public constructor Test() - private final val y: Test.. + private final val y: Test.y. internal final val z: [ERROR : Type for y] public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -19,7 +19,7 @@ internal final class Test { internal final class Test2 { public constructor Test2() - private final val a: Test2.. + private final val a: Test2.a. internal final val b: [ERROR : ] internal final val c: kotlin.Int = 1 public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/scopes/kt1806.txt b/compiler/testData/diagnostics/tests/scopes/kt1806.txt index 90f26f2052c..2ada7b10ea2 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt1806.txt +++ b/compiler/testData/diagnostics/tests/scopes/kt1806.txt @@ -14,7 +14,7 @@ package kt1806 { internal final class Test { public constructor Test() - private final val MyObject1: kt1806.Test.. + private final val MyObject1: kt1806.Test.MyObject1. public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int internal final fun test2(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.txt b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.txt index bcbde5378ee..27ce3b78a80 100644 --- a/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.txt +++ b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.txt @@ -2,7 +2,7 @@ package internal final class Test { public constructor Test() - private final var x: Test.. + private final var x: Test.x. 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 diff --git a/idea/testData/checker/infos/PropertiesWithBackingFields.kt b/idea/testData/checker/infos/PropertiesWithBackingFields.kt index ea997261f10..23e9c579677 100644 --- a/idea/testData/checker/infos/PropertiesWithBackingFields.kt +++ b/idea/testData/checker/infos/PropertiesWithBackingFields.kt @@ -42,12 +42,12 @@ open class Super(i : Int) -class TestPCParameters(w : Int, x : Int, val y : Int, var z : Int) : Super(w) { +class TestPCParameters(w : Int, x : Int, val y : Int, var z : Int) : Super(w) { - val xx = w + val xx = w init { - w + 1 + w + 1 } fun foo() = x diff --git a/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt b/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt index 70a40ada81c..fe58c289548 100644 --- a/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt +++ b/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt @@ -1,4 +1,4 @@ -// PARAM_DESCRIPTOR: local final class defined in root package +// PARAM_DESCRIPTOR: local final class defined in x // PARAM_TYPES: kotlin.Any // WITH_RUNTIME diff --git a/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt.after b/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt.after index 5322722e10d..87067bb7987 100644 --- a/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt.after +++ b/idea/testData/refactoring/extractFunction/parameters/candidateTypes/liftAnonymousToSupertype1.kt.after @@ -1,4 +1,4 @@ -// PARAM_DESCRIPTOR: local final class defined in root package +// PARAM_DESCRIPTOR: local final class defined in x // PARAM_TYPES: kotlin.Any // WITH_RUNTIME diff --git a/js/js.translator/testData/closure/cases/closureThisByUsingMethodFromParentClass.kt b/js/js.translator/testData/closure/cases/closureThisByUsingMethodFromParentClass.kt index 6a5f9bfe06c..9dbe138c245 100644 --- a/js/js.translator/testData/closure/cases/closureThisByUsingMethodFromParentClass.kt +++ b/js/js.translator/testData/closure/cases/closureThisByUsingMethodFromParentClass.kt @@ -5,9 +5,9 @@ package foo native val ROOT = "Kotlin.modules.JS_TESTS" native -val PATH_TO_F_CREATOR = "foo.B.B\$f" +val PATH_TO_F_CREATOR = "foo.B.far\$f" native -val PATH_TO_G_CREATOR = "foo.B.B\$f_0" +val PATH_TO_G_CREATOR = "foo.B.gar\$f" native("$ROOT.$PATH_TO_F_CREATOR") val F_CREATOR: Any = noImpl @@ -24,15 +24,15 @@ open class A { class B : A() { fun boo() = "B::boo" - val f = { foo() } - val g = { boo() } + val far = { foo() } + val gar = { boo() } } fun box(): String { val b = B() - val f = b.f - val g = b.g + val f = b.far + val g = b.gar assertEquals("A::foo", f()) assertEquals("B::boo", g())