From b1e3e1c32ddba638293f195afe01c750de7c898a Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 25 Jan 2016 16:44:38 +0300 Subject: [PATCH] A few forgotten checks added for objects (function members effective visibility, multiple varargs) #KT-10753 Fixed --- .../kotlin/resolve/DeclarationsChecker.kt | 7 ++- .../mulitpleVarargParameters.kt | 8 +++ .../mulitpleVarargParameters.txt | 17 +++++ .../diagnostics/tests/exposed/object.kt | 30 +++++++++ .../diagnostics/tests/exposed/object.txt | 63 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++ 6 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/exposed/object.kt create mode 100644 compiler/testData/diagnostics/tests/exposed/object.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index 1b006c8c4eb..e075067da32 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -98,10 +98,11 @@ class DeclarationsChecker( for ((classOrObject, classDescriptor) in bodiesResolveContext.declaredClasses.entries) { checkSupertypesForConsistency(classDescriptor, classOrObject) checkTypesInClassHeader(classOrObject) + checkClassOrObjectMembers(classDescriptor) when (classOrObject) { is KtClass -> { - checkClass(classOrObject, classDescriptor) + checkClassButNotObject(classOrObject, classDescriptor) descriptorResolver.checkNamesInConstraints( classOrObject, classDescriptor, classDescriptor.scopeForClassHeaderResolution, trace) } @@ -315,7 +316,7 @@ class DeclarationsChecker( } } - private fun checkClass(aClass: KtClass, classDescriptor: ClassDescriptorWithResolutionScopes) { + private fun checkClassButNotObject(aClass: KtClass, classDescriptor: ClassDescriptorWithResolutionScopes) { checkOpenMembers(classDescriptor) checkTypeParameters(aClass) checkTypeParameterConstraints(aClass) @@ -336,7 +337,9 @@ class DeclarationsChecker( else if (aClass is KtEnumEntry) { checkEnumEntry(aClass, classDescriptor) } + } + private fun checkClassOrObjectMembers(classDescriptor: ClassDescriptorWithResolutionScopes) { for (memberDescriptor in classDescriptor.declaredCallableMembers) { if (memberDescriptor.kind != CallableMemberDescriptor.Kind.DECLARATION) continue val member = DescriptorToSourceUtils.descriptorToDeclaration(memberDescriptor) as? KtFunction diff --git a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt index f2ca787a5f1..18cb39641c0 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.kt @@ -25,3 +25,11 @@ abstract class C(vararg x1: Int, vararg x1: Int, vararg x2: Int) {} + + class CC(vararg x1: Int, vararg x2: Int, b: Boolean) { + constructor(vararg x1: Int, vararg x2: Int) {} + fun test(vararg x1: Int, vararg x2: Int) {} + } +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.txt b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.txt index ff7fc3f08d8..c9eb4d5132f 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.txt +++ b/compiler/testData/diagnostics/tests/declarationChecks/mulitpleVarargParameters.txt @@ -27,3 +27,20 @@ public interface I { public abstract fun test(/*0*/ vararg x1: kotlin.Int /*kotlin.IntArray*/, /*1*/ vararg x2: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +public object O { + private constructor O() + 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 final fun test(/*0*/ vararg x1: kotlin.Int /*kotlin.IntArray*/, /*1*/ vararg x2: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class CC { + public constructor CC(/*0*/ vararg x1: kotlin.Int /*kotlin.IntArray*/, /*1*/ vararg x2: kotlin.Int /*kotlin.IntArray*/) + public constructor CC(/*0*/ vararg x1: kotlin.Int /*kotlin.IntArray*/, /*1*/ vararg x2: kotlin.Int /*kotlin.IntArray*/, /*2*/ b: kotlin.Boolean) + 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 final fun test(/*0*/ vararg x1: kotlin.Int /*kotlin.IntArray*/, /*1*/ vararg x2: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/object.kt b/compiler/testData/diagnostics/tests/exposed/object.kt new file mode 100644 index 00000000000..109fc25d91e --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/object.kt @@ -0,0 +1,30 @@ +// From KT-10753 +object My : Inter() { + fun foo(arg: Inter): Inter = arg + val x: Inter? = null +} + +internal open class Inter + +// From KT-10799 +open class Test { + protected class Protected + + fun foo(x: Protected) = x + + interface NestedInterface { + fun create(x: Protected) + } + + class NestedClass { + fun create(x: Protected) = x + } + + object NestedObject { + fun create(x: Protected) = x + } + + companion object { + fun create(x: Protected) = x + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/object.txt b/compiler/testData/diagnostics/tests/exposed/object.txt new file mode 100644 index 00000000000..9ad20f77b5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/object.txt @@ -0,0 +1,63 @@ +package + +internal open class Inter { + public constructor Inter() + 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 object My : Inter { + private constructor My() + public final val x: Inter? = null + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ arg: Inter): Inter + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Test { + public constructor Test() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ x: Test.Protected): Test.Protected + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public companion object Companion { + private constructor Companion() + public final fun create(/*0*/ x: Test.Protected): Test.Protected + 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 final class NestedClass { + public constructor NestedClass() + public final fun create(/*0*/ x: Test.Protected): Test.Protected + 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 interface NestedInterface { + public abstract fun create(/*0*/ x: Test.Protected): kotlin.Unit + 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 object NestedObject { + private constructor NestedObject() + public final fun create(/*0*/ x: Test.Protected): Test.Protected + 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 + } + + protected final class Protected { + public constructor Protected() + 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/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 97c01a342dd..6a0c1017c2a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6210,6 +6210,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("object.kt") + public void testObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/object.kt"); + doTest(fileName); + } + @TestMetadata("packagePrivate.kt") public void testPackagePrivate() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/packagePrivate.kt");