diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c7d40aecce3..ef4c901c869 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -65,7 +65,10 @@ public interface Errors { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - DiagnosticFactory1 REDECLARATION = DiagnosticFactory1.create(ERROR, FOR_REDECLARATION); + DiagnosticFactory1> REDECLARATION = + DiagnosticFactory1.create(ERROR, FOR_REDECLARATION); + DiagnosticFactory1 PACKAGE_OR_CLASSIFIER_REDECLARATION = + DiagnosticFactory1.create(ERROR, FOR_REDECLARATION); DiagnosticFactory1 UNRESOLVED_REFERENCE = DiagnosticFactory1.create(ERROR, FOR_UNRESOLVED_REFERENCE); @@ -315,8 +318,8 @@ public interface Errors { // Members - DiagnosticFactory2 CONFLICTING_OVERLOADS = - DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + DiagnosticFactory1> CONFLICTING_OVERLOADS = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory0 NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticFactory0.create(WARNING, modifierSetPosition( KtTokens.OPEN_KEYWORD)); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt index cc9601e137d..909cf619942 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt @@ -17,14 +17,16 @@ package org.jetbrains.kotlin.diagnostics import com.intellij.psi.PsiElement -import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.resolve.BindingTrace +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getEffectiveExpectedType import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.context.CallPosition @@ -139,3 +141,22 @@ fun ResolutionContext<*>.reportTypeMismatchDueToScalaLikeNamedFunctionSyntax( private fun isScalaLikeEqualsBlock(expression: KtElement): Boolean = expression is KtLambdaExpression && expression.parent.let { it is KtNamedFunction && it.equalsToken != null } + +inline fun reportOnDeclaration(trace: BindingTrace, descriptor: DeclarationDescriptor, what: (PsiElement) -> Diagnostic) { + DescriptorToSourceUtils.descriptorToDeclaration(descriptor)?.let { psiElement -> + trace.report(what(psiElement)) + } +} +inline fun reportOnDeclarationOrFail(trace: BindingTrace, descriptor: DeclarationDescriptor, what: (PsiElement) -> Diagnostic) { + DescriptorToSourceUtils.descriptorToDeclaration(descriptor)?.let { psiElement -> + trace.report(what(psiElement)) + } ?: throw AssertionError("No declaration for $descriptor") +} + +inline fun reportOnDeclarationAs(trace: BindingTrace, descriptor: DeclarationDescriptor, what: (T) -> Diagnostic) { + DescriptorToSourceUtils.descriptorToDeclaration(descriptor)?.let { psiElement -> + (psiElement as? T)?.let { + trace.report(what(it)) + } ?: throw AssertionError("Declaration for $descriptor is expected to be ${T::class.simpleName}, actual declaration: $psiElement") + } ?: throw AssertionError("No declaration for $descriptor") +} \ No newline at end of file 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 2043a7c5c24..54271fe67b8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -110,7 +110,9 @@ public class DefaultErrorMessages { MAP.put(INACCESSIBLE_TYPE, "Type {0} is inaccessible in this context due to: {1}", RENDER_TYPE, RENDER_COLLECTION_OF_TYPES); - MAP.put(REDECLARATION, "Redeclaration: {0}", STRING); + MAP.put(REDECLARATION, "Conflicting declarations: {0}", commaSeparated(COMPACT_WITH_MODIFIERS)); + MAP.put(PACKAGE_OR_CLASSIFIER_REDECLARATION, "Redeclaration: {0}", STRING); + MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING); MAP.put(ACCESSOR_PARAMETER_NAME_SHADOWING, "Accessor parameter name 'field' is shadowed by backing field variable"); @@ -631,8 +633,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}'' conflicts with another declaration in {1}", COMPACT_WITH_MODIFIERS, - DECLARATION_NAME_WITH_KIND); + MAP.put(CONFLICTING_OVERLOADS, "Conflicting overloads: {0}", commaSeparated(FQ_NAMES_IN_TYPES)); 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/DeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt index 9fa02286101..bff71caa8f5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationResolver.kt @@ -18,14 +18,13 @@ package org.jetbrains.kotlin.resolve import com.google.common.collect.HashMultimap import com.google.common.collect.Multimap -import com.google.common.collect.Sets -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors.REDECLARATION +import org.jetbrains.kotlin.diagnostics.reportOnDeclaration +import org.jetbrains.kotlin.diagnostics.reportOnDeclarationOrFail import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName @@ -60,40 +59,19 @@ class DeclarationResolver( } } - reportRedeclarations(descriptorMap) + reportRedeclarationsWithClassifiers(descriptorMap) } } - private fun reportRedeclarations(descriptorMap: Multimap) { - val redeclarations = Sets.newHashSet>() + private fun reportRedeclarationsWithClassifiers(descriptorMap: Multimap) { for (name in descriptorMap.keySet()) { val descriptors = descriptorMap[name] - if (descriptors.size <= 1) { - continue - } - // We mustn't compare PropertyDescriptor with PropertyDescriptor because we do this at OverloadResolver - for (descriptor in descriptors) { - if (descriptor is ClassifierDescriptor) { - for (descriptor2 in descriptors) { - if (descriptor === descriptor2) { - continue - } - - DescriptorToSourceUtils.getSourceFromDescriptor(descriptor)?.let { - redeclarations.add(Pair(it, descriptor.getName())) - } - if (descriptor2 is PropertyDescriptor) { - DescriptorToSourceUtils.descriptorToDeclaration(descriptor2)?.let { - redeclarations.add(Pair(it, descriptor2.getName())) - } - } - } + if (descriptors.size > 1 && descriptors.any { it is ClassifierDescriptor }) { + for (descriptor in descriptors) { + reportOnDeclaration(trace, descriptor) { REDECLARATION.on(it, descriptors) } } } } - for ((first, second) in redeclarations) { - trace.report(REDECLARATION.on(first, second.asString())) - } } fun checkRedeclarationsInPackages(topLevelDescriptorProvider: TopLevelDescriptorProvider, topLevelFqNames: Multimap) { @@ -107,7 +85,7 @@ class DeclarationResolver( val reportAt = if (declarationOrPackageDirective is KtPackageDirective) declarationOrPackageDirective.getNameIdentifier() else declarationOrPackageDirective - trace.report(Errors.REDECLARATION.on(reportAt!!, fqName.shortName().asString())) + trace.report(Errors.PACKAGE_OR_CLASSIFIER_REDECLARATION.on(reportAt!!, fqName.shortName().asString())) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt index 8a7bb868e26..705e2bac01c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.utils.singletonOrEmptyList +import java.util.* class OverloadChecker(val specificityComparator: TypeSpecificityComparator) { /** @@ -98,118 +99,4 @@ class OverloadChecker(val specificityComparator: TypeSpecificityComparator) { error("Unexpected declaration kind: $a") } - fun groupModulePackageMembersByFqName( - c: BodiesResolveContext, - overloadFilter: OverloadFilter - ): MultiMap { - val packageMembersByName = MultiMap() - - collectModulePackageMembersWithSameName( - packageMembersByName, - c.functions.values + c.declaredClasses.values + c.typeAliases.values, - overloadFilter - ) { - scope, name -> - val functions = scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) - val classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) - when (classifier) { - is ClassDescriptor -> - if (!classifier.kind.isSingleton) - functions + classifier.constructors - else - functions - is TypeAliasDescriptor -> - functions + classifier.getTypeAliasConstructors() - else -> - functions - } - } - - collectModulePackageMembersWithSameName(packageMembersByName, c.properties.values, overloadFilter) { - scope, name -> - val variables = scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) - val classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) - variables + classifier.singletonOrEmptyList() - } - - return packageMembersByName - } - - private inline fun collectModulePackageMembersWithSameName( - packageMembersByName: MultiMap, - interestingDescriptors: Collection, - overloadFilter: OverloadFilter, - getMembersByName: (MemberScope, Name) -> Collection - ) { - val observedFQNs = hashSetOf() - for (descriptor in interestingDescriptors) { - if (descriptor.containingDeclaration !is PackageFragmentDescriptor) continue - - val descriptorFQN = DescriptorUtils.getFqName(descriptor) - if (observedFQNs.contains(descriptorFQN)) continue - observedFQNs.add(descriptorFQN) - - val packageMembersWithSameName = getModulePackageMembersWithSameName(descriptor, overloadFilter, getMembersByName) - packageMembersByName.putValues(descriptorFQN, packageMembersWithSameName) - } - } - - private inline fun getModulePackageMembersWithSameName( - descriptor: DeclarationDescriptor, - overloadFilter: OverloadFilter, - getMembersByName: (MemberScope, Name) -> Collection - ): Collection { - val containingPackage = descriptor.containingDeclaration - if (containingPackage !is PackageFragmentDescriptor) { - throw AssertionError("$descriptor is not a top-level package member") - } - - 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, descriptor.name).filter { - // NB memberScope for PackageViewDescriptor includes module dependencies - DescriptorUtils.getContainingModule(it) == containingModule - } - - return overloadFilter.filterPackageMemberOverloads(possibleOverloads) - } - - private fun DeclarationDescriptor.isPrivate() = - this is DeclarationDescriptorWithVisibility && - Visibilities.isPrivate(this.visibility) - - fun getPossibleRedeclarationGroups( - members: Collection - ): Collection> { - val result = arrayListOf>() - - val nonPrivates = members.filter { !it.isPrivate() } - if (nonPrivates.size > 1) { - result.add(nonPrivates) - } - - val bySourceFile = MultiMap.createSmart() - for (member in members) { - val sourceFile = DescriptorUtils.getContainingSourceFile(member) - if (sourceFile != SourceFile.NO_SOURCE_FILE) { - bySourceFile.putValue(sourceFile, member) - } - } - - for ((sourceFile, membersInFile) in bySourceFile.entrySet()) { - // File member groups are interesting in redeclaration check if at least one file member is private. - if (membersInFile.size > 1 && membersInFile.any { it.isPrivate() }) { - result.add(membersInFile) - } - } - - return result - } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.kt index d82840546b4..2c31b3cefe2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadResolver.kt @@ -19,11 +19,15 @@ package org.jetbrains.kotlin.resolve import com.intellij.util.containers.MultiMap import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.diagnostics.reportOnDeclaration import org.jetbrains.kotlin.idea.MainFunctionDetector +import org.jetbrains.kotlin.incremental.components.NoLookupLocation +import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.calls.tower.getTypeAliasConstructors -import org.jetbrains.kotlin.utils.addToStdlib.check +import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.utils.singletonOrEmptyList +import java.util.* class OverloadResolver( private val trace: BindingTrace, @@ -73,13 +77,96 @@ class OverloadResolver( } private fun checkOverloadsInPackages(c: BodiesResolveContext) { - val membersByName = overloadChecker.groupModulePackageMembersByFqName(c, overloadFilter) + val membersByName = groupModulePackageMembersByFqName(c, overloadFilter) for (e in membersByName.entrySet()) { checkOverloadsInPackage(e.value) } } + private fun groupModulePackageMembersByFqName( + c: BodiesResolveContext, + overloadFilter: OverloadFilter + ): MultiMap { + val packageMembersByName = MultiMap() + + collectModulePackageMembersWithSameName( + packageMembersByName, + c.functions.values + c.declaredClasses.values + c.typeAliases.values, + overloadFilter + ) { + scope, name -> + val functions = scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + val classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + when (classifier) { + is ClassDescriptor -> + if (!classifier.kind.isSingleton) + functions + classifier.constructors + else + functions + is TypeAliasDescriptor -> + functions + classifier.getTypeAliasConstructors() + else -> + functions + } + } + + collectModulePackageMembersWithSameName(packageMembersByName, c.properties.values, overloadFilter) { + scope, name -> + val variables = scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + val classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_CHECK_REDECLARATIONS) + variables + classifier.singletonOrEmptyList() + } + + return packageMembersByName + } + + private inline fun collectModulePackageMembersWithSameName( + packageMembersByName: MultiMap, + interestingDescriptors: Collection, + overloadFilter: OverloadFilter, + getMembersByName: (MemberScope, Name) -> Collection + ) { + val observedFQNs = hashSetOf() + for (descriptor in interestingDescriptors) { + if (descriptor.containingDeclaration !is PackageFragmentDescriptor) continue + + val descriptorFQN = DescriptorUtils.getFqName(descriptor) + if (observedFQNs.contains(descriptorFQN)) continue + observedFQNs.add(descriptorFQN) + + val packageMembersWithSameName = getModulePackageMembersWithSameName(descriptor, overloadFilter, getMembersByName) + packageMembersByName.putValues(descriptorFQN, packageMembersWithSameName) + } + } + + private inline fun getModulePackageMembersWithSameName( + descriptor: DeclarationDescriptor, + overloadFilter: OverloadFilter, + getMembersByName: (MemberScope, Name) -> Collection + ): Collection { + val containingPackage = descriptor.containingDeclaration + if (containingPackage !is PackageFragmentDescriptor) { + throw AssertionError("$descriptor is not a top-level package member") + } + + 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, descriptor.name).filter { + // NB memberScope for PackageViewDescriptor includes module dependencies + DescriptorUtils.getContainingModule(it) == containingModule + } + + return overloadFilter.filterPackageMemberOverloads(possibleOverloads) + } + private fun checkOverloadsInClass( classDescriptor: ClassDescriptorWithResolutionScopes, nestedClassConstructors: Collection @@ -102,11 +189,52 @@ class OverloadResolver( private fun checkOverloadsInPackage(members: Collection) { if (members.size == 1) return - for (redeclarationGroup in overloadChecker.getPossibleRedeclarationGroups(members)) { - reportRedeclarations(findRedeclarations(redeclarationGroup)) + + val redeclarationsMap = LinkedHashMap>() + for (redeclarationGroup in getPossibleRedeclarationGroups(members)) { + val redeclarations = findRedeclarations(redeclarationGroup) + redeclarations.forEach { + redeclarationsMap.getOrPut(it) { LinkedHashSet() }.addAll(redeclarations) + } + } + + val reported = HashSet() + for ((member, conflicting) in redeclarationsMap) { + if (!reported.contains(member)) { + reported.addAll(conflicting) + reportRedeclarations(conflicting) + } } } + private fun getPossibleRedeclarationGroups(members: Collection): Collection> { + val result = arrayListOf>() + + val nonPrivates = members.filter { !it.isPrivate() } + + val bySourceFile = members.groupBy { DescriptorUtils.getContainingSourceFile(it) } + + var hasGroupIncludingNonPrivateMembers = false + for ((sourceFile, membersInFile) in bySourceFile) { + // File member groups are interesting in redeclaration check if at least one file member is private. + if (membersInFile.any { it.isPrivate() }) { + hasGroupIncludingNonPrivateMembers = true + val group = LinkedHashSet(nonPrivates) + membersInFile + result.add(group) + } + } + + if (!hasGroupIncludingNonPrivateMembers && nonPrivates.size > 1) { + result.add(nonPrivates) + } + + return result + } + + private fun DeclarationDescriptor.isPrivate() = + this is DeclarationDescriptorWithVisibility && + Visibilities.isPrivate(this.visibility) + private fun checkOverloadsInClass(members: Collection) { if (members.size == 1) return reportRedeclarations(findRedeclarations(members)) @@ -115,8 +243,8 @@ class OverloadResolver( private fun DeclarationDescriptor.isSynthesized() = this is CallableMemberDescriptor && kind == CallableMemberDescriptor.Kind.SYNTHESIZED - private fun findRedeclarations(members: Collection): Set> { - val redeclarations = linkedSetOf>() + private fun findRedeclarations(members: Collection): Collection { + val redeclarations = linkedSetOf() for (member1 in members) { if (member1.isSynthesized()) continue @@ -126,8 +254,7 @@ class OverloadResolver( if (isTopLevelMainInDifferentFiles(member1, member2)) continue if (!overloadChecker.isOverloadable(member1, member2)) { - val ktDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(member1) as KtDeclaration? - redeclarations.add(ktDeclaration to member1) + redeclarations.add(member1) } } } @@ -154,33 +281,16 @@ class OverloadResolver( return file1 == null || file2 == null || file1 !== file2 } - private fun reportRedeclarations(redeclarations: Set>) { + private fun reportRedeclarations(redeclarations: Collection) { if (redeclarations.isEmpty()) return - val redeclarationsIterator = redeclarations.iterator() - val firstRedeclarationDescriptor = redeclarationsIterator.next().second - val otherRedeclarationDescriptor = redeclarationsIterator.check { it.hasNext() }?.next()?.second - - for ((ktDeclaration, memberDescriptor) in redeclarations) { - if (ktDeclaration == null) continue - + for (memberDescriptor in redeclarations) { when (memberDescriptor) { is PropertyDescriptor, - is ClassifierDescriptor -> { - trace.report(Errors.REDECLARATION.on(ktDeclaration, memberDescriptor.name.asString())) - } - is FunctionDescriptor -> { - val redeclarationDescriptor = - if (otherRedeclarationDescriptor == null) - firstRedeclarationDescriptor - else if (memberDescriptor == firstRedeclarationDescriptor) - otherRedeclarationDescriptor - else - firstRedeclarationDescriptor - - trace.report(Errors.CONFLICTING_OVERLOADS.on(ktDeclaration, memberDescriptor, - redeclarationDescriptor.containingDeclaration)) - } + is ClassifierDescriptor -> + reportOnDeclaration(trace, memberDescriptor) { Errors.REDECLARATION.on(it, redeclarations) } + is FunctionDescriptor -> + reportOnDeclaration(trace, memberDescriptor) { Errors.CONFLICTING_OVERLOADS.on(it, redeclarations) } } } } 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 2b67c3746fa..00639f426d0 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 @@ -23,14 +23,13 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERR import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.diagnostics.reportOnDeclarationAs +import org.jetbrains.kotlin.diagnostics.reportOnDeclarationOrFail import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.incremental.record import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtClassOrObject -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.psi.KtProperty -import org.jetbrains.kotlin.psi.KtTypeReference +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.lazy.LazyClassContext import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider @@ -107,13 +106,13 @@ open class LazyClassMemberScope( } override fun overrideConflict(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, fromSuper.containingDeclaration)) + reportOnDeclarationOrFail(trace, fromCurrent) { Errors.CONFLICTING_OVERLOADS.on(it, listOf(fromCurrent, fromSuper)) } } override fun inheritanceConflict(first: CallableMemberDescriptor, second: CallableMemberDescriptor) { - val thisClassDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(thisDescriptor) as? KtClassOrObject ?: error("No class declaration") - trace.report(Errors.CONFLICTING_INHERITED_MEMBERS.on(thisClassDeclaration, thisDescriptor, listOf(first, second))) + reportOnDeclarationAs(trace, thisDescriptor) { ktClassOrObject -> + Errors.CONFLICTING_INHERITED_MEMBERS.on(ktClassOrObject, thisDescriptor, listOf(first, second)) + } } }) OverrideResolver.resolveUnknownVisibilities(result, trace) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LocalRedeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LocalRedeclarationChecker.kt index 1d008ac3ec2..02c50423539 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LocalRedeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LocalRedeclarationChecker.kt @@ -16,8 +16,12 @@ package org.jetbrains.kotlin.resolve.scopes +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1 import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.diagnostics.reportOnDeclarationOrFail import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils @@ -77,32 +81,12 @@ class ThrowingLocalRedeclarationChecker(overloadChecker: OverloadChecker) : Abst class TraceBasedLocalRedeclarationChecker(val trace: BindingTrace, overloadChecker: OverloadChecker): AbstractLocalRedeclarationChecker(overloadChecker) { override fun handleRedeclaration(first: DeclarationDescriptor, second: DeclarationDescriptor) { - reportRedeclaration(first) - reportRedeclaration(second) + reportOnDeclarationOrFail(trace, first) { Errors.REDECLARATION.on(it, listOf(first, second))} + reportOnDeclarationOrFail(trace, second) { Errors.REDECLARATION.on(it, listOf(first, second))} } override fun handleConflictingOverloads(first: CallableMemberDescriptor, second: CallableMemberDescriptor) { - reportConflictingOverloads(first, second.containingDeclaration) - reportConflictingOverloads(second, first.containingDeclaration) - } - - private fun reportConflictingOverloads(conflicting: CallableMemberDescriptor, withContainedIn: DeclarationDescriptor) { - val reportElement = DescriptorToSourceUtils.descriptorToDeclaration(conflicting) - if (reportElement != null) { - trace.report(Errors.CONFLICTING_OVERLOADS.on(reportElement, conflicting, withContainedIn)) - } - else { - throw IllegalStateException("No declaration found for " + conflicting) - } - } - - private fun reportRedeclaration(descriptor: DeclarationDescriptor) { - val firstElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) - if (firstElement != null) { - trace.report(Errors.REDECLARATION.on(firstElement, descriptor.name.asString())) - } - else { - throw IllegalStateException("No declaration found for " + descriptor) - } + reportOnDeclarationOrFail(trace, first) { Errors.CONFLICTING_OVERLOADS.on(it, listOf(first, second)) } + reportOnDeclarationOrFail(trace, second) { Errors.CONFLICTING_OVERLOADS.on(it, listOf(first, second)) } } } \ No newline at end of file diff --git a/compiler/testData/cli/jvm/conflictingOverloads.out b/compiler/testData/cli/jvm/conflictingOverloads.out index 3083e2f81bc..acd1aa4bc55 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(): List' conflicts with another declaration in package '' +compiler/testData/cli/jvm/conflictingOverloads.kt:1:1: error: conflicting overloads: public fun a(): List defined in root package, public fun a(): List defined in root package fun a(): List = null!! ^ -compiler/testData/cli/jvm/conflictingOverloads.kt:2:1: error: 'public fun a(): List' conflicts with another declaration in package '' +compiler/testData/cli/jvm/conflictingOverloads.kt:2:1: error: conflicting overloads: public fun a(): List defined in root package, public fun a(): List defined in root package fun a(): List = null!! ^ COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/testData/cli/jvm/diagnosticsOrder.out b/compiler/testData/cli/jvm/diagnosticsOrder.out index a7d5e872cb4..b522604e189 100644 --- a/compiler/testData/cli/jvm/diagnosticsOrder.out +++ b/compiler/testData/cli/jvm/diagnosticsOrder.out @@ -1,28 +1,28 @@ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:1:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:1:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:2:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:2:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:3:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:3:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:4:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:4:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:5:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:5:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:6:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:6:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder1.kt:7:5: error: redeclaration: x +compiler/testData/cli/jvm/diagnosticsOrder1.kt:7:5: error: conflicting declarations: public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int, public val x: Int val x = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder2.kt:1:5: error: redeclaration: y +compiler/testData/cli/jvm/diagnosticsOrder2.kt:1:5: error: conflicting declarations: public val y: Int, public val y: Int val y = 5 ^ -compiler/testData/cli/jvm/diagnosticsOrder2.kt:2:5: error: redeclaration: y +compiler/testData/cli/jvm/diagnosticsOrder2.kt:2:5: error: conflicting declarations: public val y: Int, public val y: Int val y = 5 ^ -COMPILATION_ERROR +COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt b/compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt index 668fe84e269..9f792a533f8 100644 --- a/compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt +++ b/compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt @@ -16,7 +16,7 @@ private fun overlapping() = "oops #1" @file:[JvmName("MultifileClass") JvmMultifileClass] package a -fun overlapping() = "OK" +private fun overlapping() = "OK" fun ok() = overlapping() diff --git a/compiler/testData/codegen/box/multifileClasses/optimized/overlappingVals.kt b/compiler/testData/codegen/box/multifileClasses/optimized/overlappingVals.kt index f3bb25d83fb..9db89171ce1 100644 --- a/compiler/testData/codegen/box/multifileClasses/optimized/overlappingVals.kt +++ b/compiler/testData/codegen/box/multifileClasses/optimized/overlappingVals.kt @@ -4,7 +4,7 @@ import a.* -fun box(): String = overlapping +fun box(): String = ok() // FILE: part1.kt @file:[JvmName("MultifileClass") JvmMultifileClass] @@ -16,7 +16,9 @@ private val overlapping = run { "oops #1" } @file:[JvmName("MultifileClass") JvmMultifileClass] package a -val overlapping = run { "OK" } +private val overlapping = run { "OK" } + +fun ok() = overlapping // FILE: part3.kt @file:[JvmName("MultifileClass") JvmMultifileClass] diff --git a/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.kt b/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.kt index b65ecb154d9..c75a5227949 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/ClassRedeclarationInDifferentFiles.kt @@ -1,11 +1,11 @@ // FILE: f1.kt package test -class A +class A class F1 // FILE: f2.kt package test -class A +class A class F2 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.kt b/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.kt index 40ac213b622..b56f906ba85 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/MultiFilePackageRedeclaration.kt @@ -1,7 +1,7 @@ // FILE: f.kt package a -class b {} +class b {} // FILE: f.kt -package a.b +package a.b // FILE: f.kt -package a.b \ No newline at end of file +package a.b \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.kt b/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.kt index 39a8126cfe8..23ea9548c8f 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/Redeclarations.kt @@ -1,15 +1,15 @@ // FILE: f.kt package redeclarations - object A { + object A { val x : Int = 0 val A = 1 } - class A {} + class A {} - val A = 1 + val A = 1 // FILE: f.kt - package redeclarations.A + package redeclarations.A class A {} diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.kt index ca6468232f5..f7eb20c819b 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.kt @@ -5,8 +5,14 @@ interface A interface B : A private fun validFun() {} +private val validVal = 1 -private val validProp = 1 +private fun invalidFun0() {} +private val invalidProp0 = 1 + +// NB invalidFun0 and invalidProp0 are conflicting overloads, since the following is an ambiguity: +fun useInvalidFun0() = invalidFun0() +fun useInvalidProp0() = invalidProp0 private fun invalidFun1() {} private fun invalidFun1() {} @@ -17,7 +23,7 @@ private val validProp = 1 public fun invalidFun3() {} private fun invalidFun4() {} -public fun invalidFun4() {} +public fun invalidFun4() {} public fun validFun2(a: A) = a public fun validFun2(b: B) = b @@ -26,8 +32,11 @@ public fun validFun2(b: B) = b package a private fun validFun() {} +private val validVal = 1 -private val validProp = 1 +private fun invalidFun0() {} + +private val invalidProp0 = 1 internal fun invalidFun3() {} internal fun invalidFun4() {} @@ -35,6 +44,6 @@ private val validProp = 1 // FILE: c.kt package a -public fun validFun() {} +public fun invalidFun0() {} -public val validProp = 1 \ No newline at end of file +public val invalidProp0 = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.txt b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.txt index 06394a5cc97..a9ea5823362 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.txt +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclaringPrivateToFile.txt @@ -1,9 +1,14 @@ package package a { - private val validProp: kotlin.Int = 1 - private val validProp: kotlin.Int = 1 - public val validProp: kotlin.Int = 1 + private val invalidProp0: kotlin.Int = 1 + private val invalidProp0: kotlin.Int = 1 + public val invalidProp0: kotlin.Int = 1 + private val validVal: kotlin.Int = 1 + private val validVal: kotlin.Int = 1 + private fun invalidFun0(): kotlin.Unit + private fun invalidFun0(): kotlin.Unit + public fun invalidFun0(): kotlin.Unit private fun invalidFun1(): kotlin.Unit private fun invalidFun1(): kotlin.Unit private fun invalidFun2(): kotlin.Unit @@ -13,9 +18,10 @@ package a { internal fun invalidFun4(): kotlin.Unit private fun invalidFun4(): kotlin.Unit public fun invalidFun4(): kotlin.Unit + public fun useInvalidFun0(): [ERROR : Error function type] + public fun useInvalidProp0(): [ERROR : Error function type] private fun validFun(): kotlin.Unit private fun validFun(): kotlin.Unit - public fun validFun(): kotlin.Unit public fun validFun2(/*0*/ a: a.A): a.A public fun validFun2(/*0*/ b: a.B): a.B diff --git a/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.kt b/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.kt index baaf284b31c..655c5d973ce 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.kt @@ -1,7 +1,7 @@ // FILE: f1.kt package test -class A +class A class F1 // FILE: A.kts diff --git a/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.kt b/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.kt index db613dee644..9b35fad7b90 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/TopLevelPropertyVsClassifier.kt @@ -7,7 +7,7 @@ interface Test2 val Test3 = null object Test3 -val Test4 = null -class Test4 -interface Test4 -object Test4 \ No newline at end of file +val Test4 = null +class Test4 +interface Test4 +object Test4 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt index 41ece3c7c86..91ca8217ae6 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt @@ -1,9 +1,9 @@ // FILE: file1.kt -class SomeClass +class SomeClass -typealias SomeClass = Any -typealias SomeClass = Any -typealias SomeClass = Any +typealias SomeClass = Any +typealias SomeClass = Any +typealias SomeClass = Any class Outer { class Nested @@ -14,4 +14,4 @@ class Outer { } // FILE: file2.kt -typealias SomeClass = Any \ No newline at end of file +typealias SomeClass = Any \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/Jet11.kt b/compiler/testData/diagnostics/tests/regressions/Jet11.kt index 562d0871d5b..fa244c155c8 100644 --- a/compiler/testData/diagnostics/tests/regressions/Jet11.kt +++ b/compiler/testData/diagnostics/tests/regressions/Jet11.kt @@ -1,4 +1,4 @@ // JET-11 Redeclaration & Forward reference for classes cause an exception -open class NoC +open class NoC class NoC1 : NoC() -open class NoC +open class NoC diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.kt index eb709c8a119..8391b02d6e3 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarationsOfConstructorsIgnored.kt @@ -1,5 +1,5 @@ -class A -class A { +class A +class A { constructor() } diff --git a/compiler/testData/diagnostics/tests/typealias/privateInFile.kt b/compiler/testData/diagnostics/tests/typealias/privateInFile.kt index 78502b782f8..ab48482a624 100644 --- a/compiler/testData/diagnostics/tests/typealias/privateInFile.kt +++ b/compiler/testData/diagnostics/tests/typealias/privateInFile.kt @@ -1,9 +1,9 @@ // FILE: file1.kt -private class C { +private class C { companion object } -private typealias TA = C +private typealias TA = C private val test1: C = C() private val test1co: C.Companion = C @@ -18,5 +18,5 @@ private val test1co: C.Companio private val test2: TA = TA() private val test2co = TA -private class C -private typealias TA = Int \ No newline at end of file +private class C +private typealias TA = Int \ No newline at end of file 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 dc856c556b7..25f23bfa9c1 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 @@ -135,8 +135,6 @@ 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, HTML); - MAP.put(CONFLICTING_OVERLOADS, "''{0}''
conflicts with another declaration in {1}", - IdeRenderers.HTML_COMPACT_WITH_MODIFIERS, Renderers.DECLARATION_NAME_WITH_KIND); MAP.put(RESULT_TYPE_MISMATCH, "Function return type mismatch." + "" + diff --git a/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after b/idea/testData/codeInsight/overrideImplement/ambiguousSuper.kt.after index ce5752c22d0..9ee7d98a582 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(): Unit' conflicts with another declaration in class 'C' -// ERROR: 'public open fun foo(): Unit' conflicts with another declaration in class 'C' +// ERROR: Conflicting overloads: public open fun foo(): Unit defined in C, public open fun foo(): Unit defined in C +// ERROR: Conflicting overloads: public open fun foo(): Unit defined in C, public open fun foo(): Unit defined in C interface I { open fun foo(){} } diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html b/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html deleted file mode 100644 index a4f2dd22017..00000000000 --- a/idea/testData/diagnosticMessage/conflictingOverloadsClass1.html +++ /dev/null @@ -1,3 +0,0 @@ - - -'publicfinalfun lol(x: Int): Int'
conflicts with another declaration in class 'conflictingOverloads' \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass1.txt b/idea/testData/diagnosticMessage/conflictingOverloadsClass1.txt new file mode 100644 index 00000000000..98d74b0d545 --- /dev/null +++ b/idea/testData/diagnosticMessage/conflictingOverloadsClass1.txt @@ -0,0 +1,2 @@ + +Conflicting overloads: public final fun lol(x: Int): Int defined in conflictingOverloads, public final fun lol(y: Int): Int defined in conflictingOverloads \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html b/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html deleted file mode 100644 index 3815c7db476..00000000000 --- a/idea/testData/diagnosticMessage/conflictingOverloadsClass2.html +++ /dev/null @@ -1,3 +0,0 @@ - - -'publicfinalfun lol(y: Int): Int'
conflicts with another declaration in class 'conflictingOverloads' \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsClass2.txt b/idea/testData/diagnosticMessage/conflictingOverloadsClass2.txt new file mode 100644 index 00000000000..131093feb05 --- /dev/null +++ b/idea/testData/diagnosticMessage/conflictingOverloadsClass2.txt @@ -0,0 +1,2 @@ + +Conflicting overloads: public final fun lol(x: Int): Int defined in conflictingOverloads, public final fun lol(y: Int): Int defined in conflictingOverloads \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt index e0b856fa6a7..3a3b139fa62 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt +++ b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage1.txt @@ -1,2 +1,2 @@ -'public fun foo(x: Int): Int' conflicts with another declaration in package '' \ No newline at end of file +Conflicting overloads: public fun foo(x: Int): Int defined in root package, public fun foo(y: Int): Int defined in root package \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt index 80b26da5f89..c717e1e525e 100644 --- a/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt +++ b/idea/testData/diagnosticMessage/conflictingOverloadsDefaultPackage2.txt @@ -1,2 +1,2 @@ -'public fun foo(y: Int): Int' conflicts with another declaration in package '' \ No newline at end of file +Conflicting overloads: public fun foo(x: Int): Int defined in root package, public fun foo(y: Int): Int defined in root package \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt b/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt index d2d48730976..64dafa38dc0 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclaration1.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: String)' conflicts with another declaration in class 'Element' \ No newline at end of file +Conflicting overloads: public constructor Element(x: String) defined in Element, public constructor Element(x: String) defined in Element \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt b/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt index c51e54b0b59..71d1bd8962b 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclaration2.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: String)' conflicts with another declaration in class 'Element' \ No newline at end of file +Conflicting overloads: public constructor Element(x: String) defined in Element, public constructor Element(x: String) defined in Element \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt index 548a927e869..461b2e88f11 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel1.txt @@ -1,2 +1,2 @@ -'public fun Element(x: String): Unit' conflicts with another declaration in class 'Element' \ No newline at end of file +Conflicting overloads: public fun Element(x: String): Unit defined in root package, public constructor Element(x: String) defined in Element \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt index b2c534364e5..34db820434d 100644 --- a/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt +++ b/idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel2.txt @@ -1,2 +1,2 @@ -'public constructor Element(x: String)' conflicts with another declaration in package '' \ No newline at end of file +Conflicting overloads: public fun Element(x: String): Unit defined in root package, public constructor Element(x: String) defined in Element \ No newline at end of file diff --git a/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt b/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt index 66683420ac6..2aa4fcf50a6 100644 --- a/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt +++ b/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt @@ -1,8 +1,8 @@ // "Add constructor parameters from Base(Int, Int, Any, String, String,...)" "true" -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String open class Base(p1: Int, private val p2: Int, p3: Any, p4: String, p5: T, p6: Int) class C(p: Int, p2: Int, p3: String, p4: Any, p5: String, val p6: Int) : Base diff --git a/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt.after b/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt.after index 74330cc5025..be2a520e7e6 100644 --- a/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt.after +++ b/idea/testData/quickfix/supertypeInitialization/someParametersAlreadyExist.kt.after @@ -1,8 +1,8 @@ // "Add constructor parameters from Base(Int, Int, Any, String, String,...)" "true" -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 -// ERROR: Redeclaration: p4 +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String +// ERROR: Conflicting declarations: value-parameter p4: Any, value-parameter p4: String open class Base(p1: Int, private val p2: Int, p3: Any, p4: String, p5: T, p6: Int) -class C(p: Int, p2: Int, p3: String, p4: Any, p5: String, val p6: Int, p1: Int, p4: String) : Base(p1, p2, p3, p4, p5, p6) +class C(p: Int, p2: Int, p3: String, p4: Any, p5: String, val p6: Int, p1: Int, p4: String) : Base(p1, p2, p3, p4, p5, p6) diff --git a/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log b/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log index 8ff9855fed1..97868ff01fe 100644 --- a/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log +++ b/jps-plugin/testData/incremental/classHierarchyAffected/secondaryConstructorAdded/build.log @@ -9,7 +9,7 @@ End of files Exit code: ABORT ------------------------------------------ COMPILATION FAILED -'public constructor A(x: String)' conflicts with another declaration in package '' +Conflicting overloads: public constructor A(x: String) defined in A, public fun A(x: String): A defined in root package ================ Step #2 ================= @@ -41,4 +41,4 @@ Compiling files: src/useA.kt End of files Exit code: OK ------------------------------------------- +------------------------------------------ \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/classRedeclaration/build.log b/jps-plugin/testData/incremental/pureKotlin/classRedeclaration/build.log index da4e0b01787..1e854056845 100644 --- a/jps-plugin/testData/incremental/pureKotlin/classRedeclaration/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/classRedeclaration/build.log @@ -16,4 +16,4 @@ Exit code: ABORT ------------------------------------------ COMPILATION FAILED Redeclaration: Klass -Redeclaration: Klass +Redeclaration: Klass \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log b/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log index cc75bbbadea..f79a79a7337 100644 --- a/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/funRedeclaration/build.log @@ -10,4 +10,4 @@ End of files Exit code: ABORT ------------------------------------------ COMPILATION FAILED -'public fun function(): Unit' conflicts with another declaration in package 'test' \ No newline at end of file +Conflicting overloads: public fun function(): Unit defined in test, public fun function(): Unit defined in test \ 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 index e9e9b9c7459..dab333be49e 100644 --- a/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/funVsConstructorOverloadConflict/build.log @@ -10,4 +10,4 @@ End of files Exit code: ABORT ------------------------------------------ COMPILATION FAILED -'public constructor function()' conflicts with another declaration in package 'test' +Conflicting overloads: public constructor function() defined in test.function, public fun function(): Unit defined in test \ No newline at end of file diff --git a/jps-plugin/testData/incremental/pureKotlin/propertyRedeclaration/build.log b/jps-plugin/testData/incremental/pureKotlin/propertyRedeclaration/build.log index bb32f37092f..7839df62fd5 100644 --- a/jps-plugin/testData/incremental/pureKotlin/propertyRedeclaration/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/propertyRedeclaration/build.log @@ -10,4 +10,4 @@ End of files Exit code: ABORT ------------------------------------------ COMPILATION FAILED -Redeclaration: property +Conflicting declarations: public val property: Int, public val property: Int \ No newline at end of file
Expected:{1}