diff --git a/compiler/testData/codegen/box/delegation/delegationWithPrivateConstructor.kt b/compiler/testData/codegen/box/delegation/delegationWithPrivateConstructor.kt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.kt b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.kt new file mode 100644 index 00000000000..bcfc88c8f58 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.kt @@ -0,0 +1,20 @@ + +private const val A = 0L +private val B = 0L +private fun sample() = 0L + +private class PrivateClass + +class Foo { + var bar: Long = 0 + private var other: PrivateClass? = null + + init { + bar = A + bar = B + bar = sample() + other = PrivateClass() + } + + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.txt b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.txt new file mode 100644 index 00000000000..3943ec37cca --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.txt @@ -0,0 +1,21 @@ +package + +private const val A: kotlin.Long = 0.toLong() +private val B: kotlin.Long = 0.toLong() +private fun sample(): kotlin.Long + +public final class Foo { + public constructor Foo() + public final var bar: kotlin.Long + private final var other: PrivateClass? + 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 final class PrivateClass { + public constructor PrivateClass() + 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 48bba762f01..9a72cd3c6b1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -3406,6 +3406,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("initializerWithSecondaryConstructor.kt") + public void testInitializerWithSecondaryConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/initializerWithSecondaryConstructor.kt"); + doTest(fileName); + } + @TestMetadata("initwithgetter.kt") public void testInitwithgetter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/initwithgetter.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java index 679e6546bc5..4c77faff58c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,8 @@ public class Visibilities { return true; } + // Note that this method returns false if `from` declaration is `init` initializer + // because initializer does not have source element private boolean inSameFile(@NotNull DeclarationDescriptor what, @NotNull DeclarationDescriptor from) { SourceFile fromContainingFile = DescriptorUtils.getContainingSourceFile(from); if (fromContainingFile != SourceFile.NO_SOURCE_FILE) { @@ -47,9 +49,13 @@ public class Visibilities { return false; } + private boolean hasContainingSourceFile(@NotNull DeclarationDescriptor descriptor) { + return DescriptorUtils.getContainingSourceFile(descriptor) != SourceFile.NO_SOURCE_FILE; + } + @Override public boolean isVisible(@Nullable ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) { - if (DescriptorUtils.isTopLevelDeclaration(what)) { + if (DescriptorUtils.isTopLevelDeclaration(what) && hasContainingSourceFile(from)) { return inSameFile(what, from); }