diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmOverloadFilter.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmOverloadFilter.kt index 54425d3f0c9..e12f68f3f1c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmOverloadFilter.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmOverloadFilter.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.jvm import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil import org.jetbrains.kotlin.fileClasses.NoResolveFileClassesProvider @@ -40,12 +41,14 @@ object JvmOverloadFilter : OverloadFilter { } for (overload in overloads) { + if (overload is ConstructorDescriptor) continue if (overload !is DeserializedCallableMemberDescriptor) continue val containingDeclaration = overload.containingDeclaration if (containingDeclaration !is PackageFragmentDescriptor) { throw AssertionError("Package member expected; got $overload with containing declaration $containingDeclaration") } + val implClassName = JvmFileClassUtil.getImplClassName(overload) ?: throw AssertionError("No implClassName: $overload") val implClassFQN = containingDeclaration.fqName.child(implClassName) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index ed99c9b7006..e676e1c533c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -297,7 +297,7 @@ public interface Errors { // Members - DiagnosticFactory2 CONFLICTING_OVERLOADS = + DiagnosticFactory2 CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory0 NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticFactory0.create(WARNING, modifierSetPosition( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index a7809882b2f..ed1bbe6e03d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -611,7 +611,7 @@ public class DefaultErrorMessages { MAP.put(MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits multiple interface methods of it", RENDER_CLASS_OR_OBJECT, FQ_NAMES_IN_TYPES); - MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", COMPACT_WITH_MODIFIERS, STRING); + MAP.put(CONFLICTING_OVERLOADS, "''{0}'' conflicts with another declaration: {1}", COMPACT_WITH_MODIFIERS, COMPACT_WITH_MODIFIERS); MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " + "The function '" + OperatorNameConventions.INVOKE.asString() + "()' is not found", diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java index 802cae9c95f..0feb8924694 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.java @@ -28,11 +28,10 @@ import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import java.util.Collection; +import java.util.Iterator; import java.util.Map; import java.util.Set; -import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName; - public class OverloadResolver { @NotNull private final BindingTrace trace; @NotNull private final OverloadFilter overloadFilter; @@ -50,49 +49,43 @@ public class OverloadResolver { } private void checkOverloads(@NotNull BodiesResolveContext c) { - MultiMap inClasses = MultiMap.create(); - MultiMap inPackages = MultiMap.create(); - fillGroupedConstructors(c, inClasses, inPackages); + MultiMap inClasses = findConstructorsInNestedClasses(c); for (Map.Entry entry : c.getDeclaredClasses().entrySet()) { checkOverloadsInAClass(entry.getValue(), entry.getKey(), inClasses.get(entry.getValue())); } - checkOverloadsInPackages(c, inPackages); + checkOverloadsInPackages(c); } - private static void fillGroupedConstructors( - @NotNull BodiesResolveContext c, - @NotNull MultiMap inClasses, - @NotNull MultiMap inPackages - ) { + private static MultiMap findConstructorsInNestedClasses(@NotNull BodiesResolveContext c) { + MultiMap inClasses = MultiMap.create(); + for (ClassDescriptorWithResolutionScopes klass : c.getDeclaredClasses().values()) { 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(); - if (containingDeclaration instanceof ClassDescriptor) { + if (containingDeclaration instanceof ScriptDescriptor) { + // TODO: check overload conflicts of functions with constructors in scripts + } + else if (containingDeclaration instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration; inClasses.putValues(classDescriptor, klass.getConstructors()); } - else if (containingDeclaration instanceof PackageFragmentDescriptor) { - inPackages.putValues(getFqName(klass), klass.getConstructors()); - } - else if (containingDeclaration instanceof ScriptDescriptor) { - // TODO: check overload conflicts of functions with constructors in scripts - } - else if (!(containingDeclaration instanceof FunctionDescriptor || containingDeclaration instanceof PropertyDescriptor)) { + else if (!(containingDeclaration instanceof FunctionDescriptor || + containingDeclaration instanceof PropertyDescriptor || + containingDeclaration instanceof PackageFragmentDescriptor)) { throw new IllegalStateException("Illegal class container: " + containingDeclaration); } } + + return inClasses; } - private void checkOverloadsInPackages( - @NotNull BodiesResolveContext c, - @NotNull MultiMap inPackages - ) { + private void checkOverloadsInPackages(@NotNull BodiesResolveContext c) { MultiMap membersByName = - OverloadUtil.groupModulePackageMembersByFqName(c, inPackages, overloadFilter); + OverloadUtil.groupModulePackageMembersByFqName(c, overloadFilter); for (Map.Entry> e : membersByName.entrySet()) { FqNameUnsafe fqName = e.getKey().parent(); @@ -203,22 +196,38 @@ public class OverloadResolver { return file == null || file2 == null || file != file2; } - private void reportRedeclarations(@NotNull String functionContainer, - @NotNull Set> redeclarations) { + private void reportRedeclarations( + @NotNull String functionContainer, + @NotNull Set> redeclarations + ) { + if (redeclarations.isEmpty()) return; + + Iterator> redeclarationsIterator = redeclarations.iterator(); + CallableMemberDescriptor firstRedeclarationDescriptor = redeclarationsIterator.next().getSecond(); + CallableMemberDescriptor otherRedeclarationDescriptor = redeclarationsIterator.hasNext() + ? redeclarationsIterator.next().getSecond() + : null; + for (Pair redeclaration : redeclarations) { + KtDeclaration ktDeclaration = redeclaration.getFirst(); CallableMemberDescriptor memberDescriptor = redeclaration.getSecond(); - KtDeclaration ktDeclaration = redeclaration.getFirst(); + CallableMemberDescriptor redeclarationDescriptor; + if (otherRedeclarationDescriptor == null) { + redeclarationDescriptor = firstRedeclarationDescriptor; + } + else if (firstRedeclarationDescriptor == memberDescriptor) { + redeclarationDescriptor = otherRedeclarationDescriptor; + } + else { + redeclarationDescriptor = firstRedeclarationDescriptor; + } + if (memberDescriptor instanceof PropertyDescriptor) { trace.report(Errors.REDECLARATION.on(ktDeclaration, memberDescriptor.getName().asString())); } else { - String containingClassName = ktDeclaration instanceof KtSecondaryConstructor ? - ((KtSecondaryConstructor) ktDeclaration).getContainingClassOrObject().getName() : null; - - trace.report(Errors.CONFLICTING_OVERLOADS.on( - ktDeclaration, memberDescriptor, - containingClassName != null ? containingClassName : functionContainer)); + trace.report(Errors.CONFLICTING_OVERLOADS.on(ktDeclaration, memberDescriptor, redeclarationDescriptor)); } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadUtil.kt index d06f20ac265..9a0371bd6ab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadUtil.kt @@ -82,14 +82,18 @@ object OverloadUtil { @JvmStatic fun groupModulePackageMembersByFqName( c: BodiesResolveContext, - constructorsInPackages: MultiMap, overloadFilter: OverloadFilter ): MultiMap { val packageMembersByName = MultiMap() - collectModulePackageMembersWithSameName(packageMembersByName, c.functions.values, overloadFilter) { + collectModulePackageMembersWithSameName(packageMembersByName, c.functions.values + c.declaredClasses.values, overloadFilter) { scope, name -> - scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + val functions = scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + val classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + if (classifier is ClassDescriptor && !classifier.kind.isSingleton) + functions + classifier.constructors + else + functions } collectModulePackageMembersWithSameName(packageMembersByName, c.properties.values, overloadFilter) { @@ -97,15 +101,12 @@ object OverloadUtil { scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS).filterIsInstance() } - // TODO handle constructor redeclarations in modules. See also: https://youtrack.jetbrains.com/issue/KT-3632 - packageMembersByName.putAllValues(constructorsInPackages) - return packageMembersByName } private inline fun collectModulePackageMembersWithSameName( packageMembersByName: MultiMap, - interestingDescriptors: Collection, + interestingDescriptors: Collection, overloadFilter: OverloadFilter, getMembersByName: (MemberScope, Name) -> Collection ) { @@ -123,20 +124,25 @@ object OverloadUtil { } private inline fun getModulePackageMembersWithSameName( - packageMember: CallableMemberDescriptor, + descriptor: DeclarationDescriptor, overloadFilter: OverloadFilter, getMembersByName: (MemberScope, Name) -> Collection ): Collection { - val containingPackage = packageMember.containingDeclaration + val containingPackage = descriptor.containingDeclaration if (containingPackage !is PackageFragmentDescriptor) { - throw AssertionError("$packageMember is not a top-level package member") + throw AssertionError("$descriptor is not a top-level package member") } - val containingModule = DescriptorUtils.getContainingModuleOrNull(packageMember) ?: return listOf(packageMember) + val containingModule = DescriptorUtils.getContainingModuleOrNull(descriptor) ?: + return when (descriptor) { + is CallableMemberDescriptor -> listOf(descriptor) + is ClassDescriptor -> descriptor.constructors + else -> throw AssertionError("Unexpected descriptor kind: $descriptor") + } val containingPackageScope = containingModule.getPackage(containingPackage.fqName).memberScope val possibleOverloads = - getMembersByName(containingPackageScope, packageMember.name).filter { + getMembersByName(containingPackageScope, descriptor.name).filter { // NB memberScope for PackageViewDescriptor includes module dependencies DescriptorUtils.getContainingModule(it) == containingModule } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt index 662dc21d5b6..c0af18a12d5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt @@ -108,7 +108,7 @@ open class LazyClassMemberScope( override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) { val declaration = DescriptorToSourceUtils.descriptorToDeclaration(fromCurrent) as? KtDeclaration ?: error("fromCurrent can not be a fake override") - trace.report(Errors.CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString())) + trace.report(Errors.CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromSuper)) } }) OverrideResolver.resolveUnknownVisibilities(result, trace) diff --git a/compiler/testData/cli/jvm/conflictingOverloads.out b/compiler/testData/cli/jvm/conflictingOverloads.out index 426e908948c..51b79f53071 100644 --- a/compiler/testData/cli/jvm/conflictingOverloads.out +++ b/compiler/testData/cli/jvm/conflictingOverloads.out @@ -1,7 +1,7 @@ -compiler/testData/cli/jvm/conflictingOverloads.kt:1:1: error: 'public fun a(): kotlin.collections.List' is already defined in root package +compiler/testData/cli/jvm/conflictingOverloads.kt:1:1: error: 'public fun a(): kotlin.collections.List' conflicts with another declaration: public fun a(): kotlin.collections.List fun a(): List = null!! ^ -compiler/testData/cli/jvm/conflictingOverloads.kt:2:1: error: 'public fun a(): kotlin.collections.List' is already defined in root package +compiler/testData/cli/jvm/conflictingOverloads.kt:2:1: error: 'public fun a(): kotlin.collections.List' conflicts with another declaration: public fun a(): kotlin.collections.List fun a(): List = null!! ^ COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt index 751d8489e2a..0d8919d3ec8 100644 --- a/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/missingNames.kt @@ -1,5 +1,5 @@ // !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES -fun () { +fun () { } diff --git a/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.kt b/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.kt index 7b317d75391..3768e6f9a09 100644 --- a/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.kt +++ b/compiler/testData/diagnostics/tests/recovery/namelessToplevelDeclarations.kt @@ -2,7 +2,7 @@ package -fun () { +fun () { } diff --git a/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.kt b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.kt new file mode 100644 index 00000000000..ea1aab8e583 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.kt @@ -0,0 +1,10 @@ +// FILE: test1.kt +class A +class B(val x: Int) { + constructor(x: Int, y: Int): this(x + y) +} + +// FILE: test2.kt +fun A() {} +fun B(x: Int) = x +fun B(x: Int, y: Int) = x + y \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.txt b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.txt new file mode 100644 index 00000000000..b1097183788 --- /dev/null +++ b/compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.txt @@ -0,0 +1,21 @@ +package + +public fun A(): kotlin.Unit +public fun B(/*0*/ x: kotlin.Int): kotlin.Int +public fun B(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int): kotlin.Int + +public final class A { + public constructor A() + 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 B { + public constructor B(/*0*/ x: kotlin.Int) + public constructor B(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int) + public final val x: kotlin.Int + 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 4ef04b8b9ba..79c07c9fcee 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13083,6 +13083,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("FunVsCtorInDifferentFiles.kt") + public void testFunVsCtorInDifferentFiles() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/redeclarations/FunVsCtorInDifferentFiles.kt"); + doTest(fileName); + } + @TestMetadata("kt2418.kt") public void testKt2418() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/redeclarations/kt2418.kt"); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java index f54515c2335..02b602daaaa 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java @@ -137,8 +137,8 @@ public class IdeErrorMessages { MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1}
because it inherits many implementations of it", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.HTML); - MAP.put(CONFLICTING_OVERLOADS, "''{0}''
is already defined in {1}", - IdeRenderers.HTML_COMPACT_WITH_MODIFIERS, STRING); + MAP.put(CONFLICTING_OVERLOADS, "''{0}''
conflicts with another declaration: {1}", + IdeRenderers.HTML_COMPACT_WITH_MODIFIERS, IdeRenderers.HTML_COMPACT_WITH_MODIFIERS); MAP.put(RESULT_TYPE_MISMATCH, "Function return type mismatch." + "" + diff --git a/idea/testData/checker/custom/conflictingOverloadsMultifile1a.kt b/idea/testData/checker/custom/conflictingOverloadsMultifile1a.kt new file mode 100644 index 00000000000..9da2d5dae2a --- /dev/null +++ b/idea/testData/checker/custom/conflictingOverloadsMultifile1a.kt @@ -0,0 +1,3 @@ +class A(val x: Int) { + constructor(): this(0) +} diff --git a/idea/testData/checker/custom/conflictingOverloadsMultifile1b.kt b/idea/testData/checker/custom/conflictingOverloadsMultifile1b.kt new file mode 100644 index 00000000000..80d95f7d79b --- /dev/null +++ b/idea/testData/checker/custom/conflictingOverloadsMultifile1b.kt @@ -0,0 +1,2 @@ +fun A() {} +fun A(x: Int) = x diff --git a/idea/testData/checker/custom/conflictingOverloadsMultifile2a.kt b/idea/testData/checker/custom/conflictingOverloadsMultifile2a.kt new file mode 100644 index 00000000000..b464fa79938 --- /dev/null +++ b/idea/testData/checker/custom/conflictingOverloadsMultifile2a.kt @@ -0,0 +1,2 @@ +fun A() {} +fun A(x: Int) = x diff --git a/idea/testData/checker/custom/conflictingOverloadsMultifile2b.kt b/idea/testData/checker/custom/conflictingOverloadsMultifile2b.kt new file mode 100644 index 00000000000..af39bd8b02f --- /dev/null +++ b/idea/testData/checker/custom/conflictingOverloadsMultifile2b.kt @@ -0,0 +1,3 @@ +class A(val x: Int) { + constructor(): this(0) +} diff --git a/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after b/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after index d7c6ee6de1b..f6647ea4237 100644 --- a/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after +++ b/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after @@ -1,5 +1,5 @@ -// ERROR: 'public open fun foo(): kotlin.Unit' is already defined in C -// ERROR: 'public open fun foo(): kotlin.Unit' is already defined in C +// ERROR: 'public open fun foo(): kotlin.Unit' conflicts with another declaration: public open fun foo(): kotlin.Unit +// ERROR: 'public open fun foo(): kotlin.Unit' conflicts with another declaration: public open fun foo(): kotlin.Unit interface I { open fun foo(){} } diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html b/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html index 04e9376eab8..53268043a68 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html +++ b/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html @@ -1,3 +1,3 @@ -'publicfinalfun lol(x: kotlin.Int): kotlin.Int'
is already defined in conflictingOverloads \ No newline at end of file +'publicfinalfun lol(x: kotlin.Int): kotlin.Int'
conflicts with another declaration: publicfinalfun lol(y: kotlin.Int): kotlin.Int \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html b/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html index e8fca6ad5c7..c1d67ac84fe 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html +++ b/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html @@ -1,3 +1,3 @@ -'publicfinalfun lol(y: kotlin.Int): kotlin.Int'
is already defined in conflictingOverloads \ No newline at end of file +'publicfinalfun lol(y: kotlin.Int): kotlin.Int'
conflicts with another declaration: publicfinalfun lol(x: kotlin.Int): kotlin.Int \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt index 283271018b8..42a2a4d5103 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt +++ b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt @@ -1,2 +1,2 @@ -'public fun foo(x: kotlin.Int): kotlin.Int' is already defined in root package \ No newline at end of file +'public fun foo(x: kotlin.Int): kotlin.Int' conflicts with another declaration: public fun foo(y: kotlin.Int): kotlin.Int \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt index 00e3a11aeea..e3652a85914 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt +++ b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt @@ -1,2 +1,2 @@ -'public fun foo(y: kotlin.Int): kotlin.Int' is already defined in root package \ No newline at end of file +'public fun foo(y: kotlin.Int): kotlin.Int' conflicts with another declaration: public fun foo(x: kotlin.Int): kotlin.Int \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt b/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt index d8c271f71c5..dd7082a4cf0 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: kotlin.String)' is already defined in Element \ No newline at end of file +'public constructor Element(x: kotlin.String)' conflicts with another declaration: public constructor Element(x: kotlin.String) \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt b/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt index f5ece75ad73..cd8b41f5b85 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: kotlin.String)' is already defined in Element \ No newline at end of file +'public constructor Element(x: kotlin.String)' conflicts with another declaration: public constructor Element(x: kotlin.String) \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt index 6343216a27d..0ca4910816e 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt @@ -1,2 +1,2 @@ -'public fun Element(x: kotlin.String): kotlin.Unit' is already defined in root package \ No newline at end of file +'public fun Element(x: kotlin.String): kotlin.Unit' conflicts with another declaration: public constructor Element(x: kotlin.String) \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt index fc0b9a78128..a27264502e9 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: kotlin.String)' is already defined in Element \ No newline at end of file +'public constructor Element(x: kotlin.String)' conflicts with another declaration: public fun Element(x: kotlin.String): kotlin.Unit \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/checkers/AbstractPsiCheckerTest.java b/idea/tests/org/jetbrains/kotlin/checkers/AbstractPsiCheckerTest.java index 3a44f6e7030..dec50b3ab51 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/AbstractPsiCheckerTest.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/AbstractPsiCheckerTest.java @@ -31,6 +31,11 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu checkHighlighting(true, false, false); } + public void doTest(@NotNull String... filePath) throws Exception { + myFixture.configureByFiles(filePath); + checkHighlighting(true, false, false); + } + public void doTestWithInfos(@NotNull String filePath) throws Exception { try { myFixture.configureByFile(filePath); diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt index 6bed912190b..2f56e94f0c2 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt @@ -23,10 +23,22 @@ class PsiCheckerCustomTest : AbstractPsiCheckerTest() { val testAnnotation = "MyTestAnnotation" EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.add(testAnnotation) try { - doTest("idea/testData/checker/custom/noUnusedParameterWhenCustom.kt") + doTest(getTestDataFile("noUnusedParameterWhenCustom.kt")) } finally { EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.remove(testAnnotation) } } + + fun testConflictingOverloadsMultifile1() { + doTest(getTestDataFile("conflictingOverloadsMultifile1a.kt"), + getTestDataFile("conflictingOverloadsMultifile1b.kt")) + } + + fun testConflictingOverloadsMultifile2() { + doTest(getTestDataFile("conflictingOverloadsMultifile2a.kt"), + getTestDataFile("conflictingOverloadsMultifile2b.kt")) + } + + private fun getTestDataFile(localName: String) = "idea/testData/checker/custom/$localName" } \ No newline at end of file diff --git a/jps-plugin/test/org/jetbrains/kotlin/jps/build/ExperimentalIncrementalJpsTestGenerated.java b/jps-plugin/test/org/jetbrains/kotlin/jps/build/ExperimentalIncrementalJpsTestGenerated.java index 2ee8fd46724..ab67536190b 100644 --- a/jps-plugin/test/org/jetbrains/kotlin/jps/build/ExperimentalIncrementalJpsTestGenerated.java +++ b/jps-plugin/test/org/jetbrains/kotlin/jps/build/ExperimentalIncrementalJpsTestGenerated.java @@ -335,6 +335,12 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta doTest(fileName); } + @TestMetadata("funVsConstructorOverloadConflict") + public void testFunVsConstructorOverloadConflict() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/"); + doTest(fileName); + } + @TestMetadata("functionBecameInline") public void testFunctionBecameInline() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/functionBecameInline/"); diff --git a/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalJpsTestGenerated.java b/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalJpsTestGenerated.java index 49b4ef012aa..0d2f97b7183 100644 --- a/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalJpsTestGenerated.java +++ b/jps-plugin/test/org/jetbrains/kotlin/jps/build/IncrementalJpsTestGenerated.java @@ -335,6 +335,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest { doTest(fileName); } + @TestMetadata("funVsConstructorOverloadConflict") + public void testFunVsConstructorOverloadConflict() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/"); + doTest(fileName); + } + @TestMetadata("functionBecameInline") public void testFunctionBecameInline() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/functionBecameInline/"); diff --git a/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log b/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log index f9971a4960e..7122f36b6d3 100644 --- a/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log +++ b/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log @@ -4,9 +4,19 @@ End of files Compiling files: src/A.kt End of files +COMPILATION FAILED +'public constructor A(x: kotlin.String)' conflicts with another declaration: public constructor A(x: kotlin.String) + + +Cleaning output files: +out/production/module/AConstructorFunctionKt.class +out/production/module/META-INF/module.kotlin_module +End of files +Compiling files: +src/A.kt +End of files Cleaning output files: out/production/module/AChild.class -out/production/module/AConstructorFunctionKt.class out/production/module/CreateAFromIntKt.class out/production/module/CreateAFromStringKt.class out/production/module/META-INF/module.kotlin_module @@ -14,23 +24,6 @@ out/production/module/UseAKt.class End of files Compiling files: src/AChild.kt -src/AConstructorFunction.kt -src/createAFromInt.kt -src/createAFromString.kt -src/useA.kt -End of files -COMPILATION FAILED -Overload resolution ambiguity: -public constructor A(x: kotlin.String) defined in A -public fun A(x: kotlin.String): A defined in root package - - -Cleaning output files: -out/production/module/A.class -End of files -Compiling files: -src/A.kt -src/AChild.kt src/createAFromInt.kt src/createAFromString.kt src/useA.kt diff --git a/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log b/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log index 1e5f3f89482..1224d634ee4 100644 --- a/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log @@ -6,4 +6,4 @@ Compiling files: src/fun2.kt End of files COMPILATION FAILED -'public fun function(): kotlin.Unit' is already defined in test \ No newline at end of file +'public fun function(): kotlin.Unit' conflicts with another declaration: public fun function(): kotlin.Unit \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/build.log b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/build.log new file mode 100644 index 00000000000..e3d39a6b779 --- /dev/null +++ b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/build.log @@ -0,0 +1,9 @@ +Cleaning output files: +out/production/module/META-INF/module.kotlin_module +out/production/module/test/Fun2Kt.class +End of files +Compiling files: +src/fun2.kt +End of files +COMPILATION FAILED +'public constructor function()' conflicts with another declaration: public constructor function() \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun1.kt b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun1.kt new file mode 100644 index 00000000000..539d6344c39 --- /dev/null +++ b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun1.kt @@ -0,0 +1,5 @@ +package test + +fun function() { + +} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt new file mode 100644 index 00000000000..897d69e3641 --- /dev/null +++ b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt @@ -0,0 +1,3 @@ +package test + +val x = 1 diff --git a/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt.new b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt.new new file mode 100644 index 00000000000..bf81e8e2e1d --- /dev/null +++ b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/fun2.kt.new @@ -0,0 +1,5 @@ +package test + +val x = 1 + +class function \ No newline at end of file
Expected:{1}