From f8a018ae27eec040264902d525dd3fba387c69de Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Sun, 13 Sep 2015 01:58:55 +0300 Subject: [PATCH] Introduced NewQualifiedExpressionResolver --- .../jetbrains/kotlin/diagnostics/Errors.java | 3 +- .../rendering/DefaultErrorMessages.java | 3 +- .../resolve/ImportDirectiveProcessor.kt | 204 --------------- .../resolve/NewQualifiedExpressionResolver.kt | 243 ++++++++++++++++++ .../resolve/QualifiedExpressionResolver.java | 8 +- .../kotlin/resolve/lazy/LazyImportScope.kt | 3 +- .../diagnostics/tests/imports/ClassClash.kt | 69 +++++ .../diagnostics/tests/imports/ClassClash.txt | 86 +++++++ .../tests/imports/ClassClashStarImport.kt | 63 +++++ .../tests/imports/ClassClashStarImport.txt | 85 ++++++ .../ExplicitPackageImportsAmbiguity.kt | 4 +- .../tests/imports/GenericClassVsPackage.kt | 67 +++++ .../tests/imports/GenericClassVsPackage.txt | 112 ++++++++ .../diagnostics/tests/imports/Imports.kt | 14 +- .../tests/imports/MalformedImports.kt | 2 +- .../tests/imports/NestedClassClash.kt | 31 +++ .../tests/imports/NestedClassClash.txt | 35 +++ .../tests/imports/PackageVsClass.kt | 128 +++++++++ .../tests/imports/PackageVsClass.txt | 101 ++++++++ .../tests/imports/TopLevelClassVsPackage.kt | 62 +++++ .../tests/imports/TopLevelClassVsPackage.txt | 67 +++++ .../checkers/JetDiagnosticsTestGenerated.java | 36 +++ 22 files changed, 1206 insertions(+), 220 deletions(-) delete mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportDirectiveProcessor.kt create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/NewQualifiedExpressionResolver.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClash.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClash.txt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClashStarImport.kt create mode 100644 compiler/testData/diagnostics/tests/imports/ClassClashStarImport.txt create mode 100644 compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.kt create mode 100644 compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.txt create mode 100644 compiler/testData/diagnostics/tests/imports/NestedClassClash.kt create mode 100644 compiler/testData/diagnostics/tests/imports/NestedClassClash.txt create mode 100644 compiler/testData/diagnostics/tests/imports/PackageVsClass.kt create mode 100644 compiler/testData/diagnostics/tests/imports/PackageVsClass.txt create mode 100644 compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.kt create mode 100644 compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 93d53ca06bf..6f833f0345d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -101,7 +101,6 @@ public interface Errors { // Imports - DiagnosticFactory1 CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 CANNOT_IMPORT_ON_DEMAND_FROM_SINGLETON = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR); @@ -410,6 +409,8 @@ public interface Errors { DiagnosticFactory1 ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR); + DiagnosticFactory0 SAFE_CALL_IN_QUALIFIER = DiagnosticFactory0.create(ERROR); + DiagnosticFactory2 FUNCTION_EXPECTED = DiagnosticFactory2.create(ERROR); DiagnosticFactory2 FUNCTION_CALL_EXPECTED = DiagnosticFactory2.create(ERROR, CALL_EXPRESSION); 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 708d89728bf..721efe767a6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -143,7 +143,6 @@ public class DefaultErrorMessages { MAP.put(LABEL_NAME_CLASH, "There is more than one label with such a name in this scope"); MAP.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, "Expression expected, but a package name found"); - MAP.put(CANNOT_IMPORT_FROM_ELEMENT, "Cannot import from ''{0}''", NAME); MAP.put(CANNOT_IMPORT_ON_DEMAND_FROM_SINGLETON, "Cannot import-on-demand from object ''{0}''", NAME); MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME); MAP.put(CONFLICTING_IMPORT, "Conflicting import, imported name ''{0}'' is ambiguous", STRING); @@ -427,6 +426,8 @@ public class DefaultErrorMessages { MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); + MAP.put(SAFE_CALL_IN_QUALIFIER, "Safe call is not allowed for qualifier"); + MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter"); MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportDirectiveProcessor.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportDirectiveProcessor.kt deleted file mode 100644 index 4c9d2c6f565..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ImportDirectiveProcessor.kt +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2010-2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve - -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PackageViewDescriptor -import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.resolve.scopes.JetScope -import java.util.ArrayList - -public class ImportDirectiveProcessor( - private val qualifiedExpressionResolver: QualifiedExpressionResolver -) { - public fun processImportReference( - importDirective: JetImportDirective, - moduleDescriptor: ModuleDescriptor, - trace: BindingTrace, - lookupMode: QualifiedExpressionResolver.LookupMode - ): JetScope { - if (importDirective.isAbsoluteInRootPackage()) { - trace.report(Errors.UNSUPPORTED.on(importDirective, "TypeHierarchyResolver")) // TODO - return JetScope.Empty - } - - val importedReference = importDirective.getImportedReference() ?: return JetScope.Empty - val importPath = importDirective.getImportPath() ?: return JetScope.Empty - val (packageViewDescriptor, selectorsToLookUp) = tryResolvePackagesFromRightToLeft( - moduleDescriptor, trace, importPath.fqnPart(), importedReference - ) - val descriptors = lookUpMembersFromLeftToRight(moduleDescriptor, trace, packageViewDescriptor, selectorsToLookUp, lookupMode) - - val referenceExpression = JetPsiUtil.getLastReference(importedReference) - if (importDirective.isAllUnder()) { - if (!canAllUnderImportFrom(descriptors) && referenceExpression != null) { - val toReportOn = descriptors.filterIsInstance().first() - trace.report(Errors.CANNOT_IMPORT_ON_DEMAND_FROM_SINGLETON.on(referenceExpression, toReportOn)) - } - - if (referenceExpression == null || !canImportMembersFrom(descriptors, referenceExpression, trace, lookupMode)) { - return JetScope.Empty - } - - val importsScope = AllUnderImportsScope() - for (descriptor in descriptors) { - importsScope.addAllUnderImport(descriptor) - } - return importsScope - } - else { - val aliasName = JetPsiUtil.getAliasName(importDirective) ?: return JetScope.Empty - return SingleImportScope(aliasName, descriptors) - } - } - - private fun tryResolvePackagesFromRightToLeft( - moduleDescriptor: ModuleDescriptor, - trace: BindingTrace, - fqName: FqName, - jetExpression: JetExpression? - ): Pair> { - val selectorsToLookUp = ArrayList() - - fun recTryResolvePackagesFromRightToLeft( - fqName: FqName, - jetExpression: JetExpression? - ): PackageViewDescriptor { - val packageView = moduleDescriptor.getPackage(fqName) - if (jetExpression == null) { - assert(fqName.isRoot()) - return packageView - } - return when { - !packageView.isEmpty() -> { - recordPackageViews(jetExpression, packageView, trace) - packageView - } - else -> { - assert(!fqName.isRoot()) - val (expressionRest, selector) = jetExpression.getReceiverAndSelector() - if (selector != null) { - selectorsToLookUp.add(selector) - } - recTryResolvePackagesFromRightToLeft(fqName.parent(), expressionRest) - } - } - } - - val packageView = recTryResolvePackagesFromRightToLeft(fqName, jetExpression) - return Pair(packageView, selectorsToLookUp.reverse()) - } - - private fun recordPackageViews(jetExpression: JetExpression, packageView: PackageViewDescriptor, trace: BindingTrace) { - trace.record(BindingContext.REFERENCE_TARGET, JetPsiUtil.getLastReference(jetExpression), packageView) - val containingView = packageView.getContainingDeclaration() - val (receiver, _) = jetExpression.getReceiverAndSelector() - if (containingView != null && receiver != null) { - recordPackageViews(receiver, containingView, trace) - } - } - - private fun lookUpMembersFromLeftToRight( - moduleDescriptor: ModuleDescriptor, - trace: BindingTrace, - packageView: PackageViewDescriptor, - selectorsToLookUp: List, - lookupMode: QualifiedExpressionResolver.LookupMode - ): Collection { - var currentDescriptors: Collection = listOf(packageView) - for ((i, selector) in selectorsToLookUp.withIndex()) { - currentDescriptors = qualifiedExpressionResolver.lookupSelectorDescriptors( - selector, currentDescriptors, trace, moduleDescriptor, lookupMode, lookupMode.isEverything() - ) - val isLastReference = i == selectorsToLookUp.size() - 1 - if (!isLastReference && !canImportMembersFrom(currentDescriptors, selector, trace, lookupMode)) { - return emptyList() - } - } - return currentDescriptors - } - - private fun JetExpression.getReceiverAndSelector(): Pair { - when (this) { - is JetDotQualifiedExpression -> { - return Pair(this.getReceiverExpression(), this.getSelectorExpression() as? JetSimpleNameExpression) - } - is JetSimpleNameExpression -> { - return Pair(null, this) - } - else -> { - throw AssertionError("Invalid expression in import $this of class ${this.javaClass}") - } - } - } - - public companion object { - public fun canAllUnderImportFrom(descriptors: Collection): Boolean { - if (descriptors.isEmpty()) { - return true - } - return descriptors.any { it !is ClassDescriptor || canAllUnderImportFromClass(it) } - } - - public fun canAllUnderImportFromClass(descriptor: ClassDescriptor): Boolean = !descriptor.getKind().isSingleton() - - @JvmStatic - public fun canImportMembersFrom( - descriptors: Collection, - reference: JetSimpleNameExpression, - trace: BindingTrace, - lookupMode: QualifiedExpressionResolver.LookupMode - ): Boolean { - if (lookupMode.isOnlyClassesAndPackages()) { - return true - } - - descriptors.singleOrNull()?.let { return canImportMembersFrom(it, reference, trace, lookupMode) } - - val temporaryTrace = TemporaryBindingTrace.create(trace, "trace to find out if members can be imported from", reference) - var canImport = false - for (descriptor in descriptors) { - canImport = canImport || canImportMembersFrom(descriptor, reference, temporaryTrace, lookupMode) - } - if (!canImport) { - temporaryTrace.commit() - } - return canImport - } - - private fun canImportMembersFrom( - descriptor: DeclarationDescriptor, - reference: JetSimpleNameExpression, - trace: BindingTrace, - lookupMode: QualifiedExpressionResolver.LookupMode - ): Boolean { - assert(lookupMode.isEverything()) - if (descriptor is PackageViewDescriptor || descriptor is ClassDescriptor) { - return true - } - trace.report(Errors.CANNOT_IMPORT_FROM_ELEMENT.on(reference, descriptor)) - return false - } - } -} - -private fun QualifiedExpressionResolver.LookupMode.isEverything() = this == QualifiedExpressionResolver.LookupMode.EVERYTHING -private fun QualifiedExpressionResolver.LookupMode.isOnlyClassesAndPackages() = this == QualifiedExpressionResolver.LookupMode.ONLY_CLASSES_AND_PACKAGES \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/NewQualifiedExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NewQualifiedExpressionResolver.kt new file mode 100644 index 00000000000..c865171390c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NewQualifiedExpressionResolver.kt @@ -0,0 +1,243 @@ +/* + * Copyright 2010-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve + +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.util.SmartList +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.incremental.KotlinLookupLocation +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.resolve.scopes.JetScope +import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver +import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue +import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator +import org.jetbrains.kotlin.utils.addIfNotNull + +public class NewQualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator) { + + public fun processImportReference( + importDirective: JetImportDirective, + moduleDescriptor: ModuleDescriptor, + trace: BindingTrace, + shouldBeVisibleFrom: DeclarationDescriptor + ): JetScope { + val importedReference = importDirective.importedReference ?: return JetScope.Empty + val path = importedReference.asQualifierPartList(trace) + val lastPart = path.lastOrNull() ?: return JetScope.Empty + + if (importDirective.isAllUnder) { + val packageOrClassDescriptor = resolveToPackageOrClass(path, moduleDescriptor, trace, shouldBeVisibleFrom) ?: return JetScope.Empty + if (packageOrClassDescriptor is ClassDescriptor && packageOrClassDescriptor.kind.isSingleton) { + trace.report(Errors.CANNOT_IMPORT_ON_DEMAND_FROM_SINGLETON.on(lastPart.expression, packageOrClassDescriptor)) + } + val scope = AllUnderImportsScope() + scope.addAllUnderImport(packageOrClassDescriptor) + return scope + } + else { + val packageOrClassDescriptor = resolveToPackageOrClass(path.subList(0, path.size() - 1), moduleDescriptor, trace, shouldBeVisibleFrom) + ?: return JetScope.Empty + val descriptors = SmartList() + + when (packageOrClassDescriptor) { + is PackageViewDescriptor -> { + val packageScope = packageOrClassDescriptor.memberScope + descriptors.addIfNotNull(packageScope.getClassifier(lastPart.name, lastPart.location)) + descriptors.addAll(packageScope.getProperties(lastPart.name, lastPart.location)) + descriptors.addAll(packageScope.getFunctions(lastPart.name, lastPart.location)) + } + is ClassDescriptor -> { + descriptors.addIfNotNull( + packageOrClassDescriptor.unsubstitutedInnerClassesScope.getClassifier(lastPart.name, lastPart.location) + ) + val staticClassScope = packageOrClassDescriptor.staticScope + descriptors.addAll(staticClassScope.getFunctions(lastPart.name, lastPart.location)) + descriptors.addAll(staticClassScope.getProperties(lastPart.name, lastPart.location)) + } + // todo assert? + else -> return JetScope.Empty + } + storageResult(trace, lastPart, descriptors, shouldBeVisibleFrom) + + val aliasName = JetPsiUtil.getAliasName(importDirective) ?: return JetScope.Empty + return SingleImportScope(aliasName, descriptors) + } + } + + private fun JetExpression.asQualifierPartList(trace: BindingTrace): List { + val result = SmartList() + var expression: JetExpression? = this + loop@ while (expression != null) { + when (expression) { + is JetSimpleNameExpression -> { + result add QualifierPart(expression.getReferencedNameAsName(), expression) + break@loop + } + is JetQualifiedExpression -> { + (expression.selectorExpression as? JetSimpleNameExpression)?.let { + result add QualifierPart(it.getReferencedNameAsName(), it) + } + expression = expression.receiverExpression + if (expression is JetSafeQualifiedExpression) { + trace.report(Errors.SAFE_CALL_IN_QUALIFIER.on(expression.operationTokenNode.psi)) + } + } + else -> expression = null + } + } + return result.asReversed() + } + + private data class QualifierPart( + val name: Name, + val expression: JetSimpleNameExpression, + val typeArguments: JetTypeArgumentList? = null + ) { + val location = KotlinLookupLocation(expression) + } + + private fun resolveToPackageOrClass( + path: List, + moduleDescriptor: ModuleDescriptor, + trace: BindingTrace, + shouldBeVisibleFrom: DeclarationDescriptor, + firstPartResolver: (QualifierPart) -> DeclarationDescriptor? = { null } + ): DeclarationDescriptor? { + if (path.isEmpty()) { + return moduleDescriptor.getPackage(FqName.ROOT) + } + + val (currentDescriptor, currentIndex) = firstPartResolver(path.first())?.let { + Pair(it, 1) + } ?: moduleDescriptor.quickResolveToPackage(path, trace, shouldBeVisibleFrom) + return path.subList(currentIndex, path.size()).fold(currentDescriptor) { + descriptor, qualifierPart -> + val nextDescriptor = when (descriptor) { + // TODO: support inner classes which captured type parameter from outer class + is ClassDescriptor -> + descriptor.unsubstitutedInnerClassesScope.getClassifier(qualifierPart.name, qualifierPart.location) + is PackageViewDescriptor -> { + val packageView = if (qualifierPart.typeArguments == null) { + moduleDescriptor.getPackage(descriptor.fqName.child(qualifierPart.name)) + } else null + + + if (packageView != null && !packageView.isEmpty()) { + packageView + } else { + descriptor.memberScope.getClassifier(qualifierPart.name, qualifierPart.location) + } + } + else -> null + } + storageResult(trace, qualifierPart, listOfNotNull(nextDescriptor), shouldBeVisibleFrom) + nextDescriptor + } + } + + private fun ModuleDescriptor.quickResolveToPackage( + path: List, + trace: BindingTrace, + shouldBeVisibleFrom: DeclarationDescriptor + ): Pair { + val possiblePackagePrefixSize = path.indexOfFirst { it.typeArguments != null }.let { if (it == -1) path.size() else it + 1 } + var fqName = path.subList(0, possiblePackagePrefixSize).fold(FqName.ROOT) { fqName, qualifierPart -> + fqName.child(qualifierPart.name) + } + var prefixSize = possiblePackagePrefixSize + while (!fqName.isRoot) { + val packageDescriptor = getPackage(fqName) + if (!packageDescriptor.isEmpty()) { + recordPackageViews(path.subList(0, prefixSize), packageDescriptor, trace, shouldBeVisibleFrom) + return Pair(packageDescriptor, prefixSize) + } + fqName = fqName.parent() + prefixSize-- + } + return Pair(getPackage(FqName.ROOT), 0) + } + + private fun recordPackageViews( + path: List, + packageView: PackageViewDescriptor, + trace: BindingTrace, + shouldBeVisibleFrom: DeclarationDescriptor + ) { + path.foldRight(packageView) { qualifierPart, currentView -> + storageResult(trace, qualifierPart, listOfNotNull(currentView), shouldBeVisibleFrom) + val parentView = currentView.containingDeclaration + assert(parentView != null) { + "Containing Declaration must be not null for package with fqName: ${currentView.fqName}, " + + "path: ${path.joinToString()}, packageView fqName: ${packageView.fqName}" + } + parentView!! + } + } + + private fun storageResult( + trace: BindingTrace, + qualifierPart: QualifierPart, + descriptors: Collection, + shouldBeVisibleFrom: DeclarationDescriptor + ) { + + val referenceExpression = qualifierPart.expression + if (descriptors.isEmpty()) { + trace.report(Errors.UNRESOLVED_REFERENCE.on(referenceExpression, referenceExpression)) + } + else if(descriptors.size() > 1) { + // todo all descriptors invisible - report specific error + trace.record(BindingContext.AMBIGUOUS_REFERENCE_TARGET, referenceExpression, descriptors) + } + else { + val descriptor = descriptors.single() + trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, descriptor) + if (descriptor is ClassifierDescriptor) { + symbolUsageValidator.validateTypeUsage(descriptor, trace, referenceExpression) + } + if (descriptor is DeclarationDescriptorWithVisibility) { + checkVisibility(descriptor, trace, referenceExpression, shouldBeVisibleFrom) + } + + storageQualifier(trace, qualifierPart.expression, descriptor) + } + } + + private fun storageQualifier(trace: BindingTrace, referenceExpression: JetSimpleNameExpression, descriptor: DeclarationDescriptor) { + if (descriptor is PackageViewDescriptor || descriptor is ClassifierDescriptor) { + val qualifier = QualifierReceiver(referenceExpression, descriptor as? PackageViewDescriptor, descriptor as? ClassifierDescriptor) + trace.record(BindingContext.QUALIFIER, qualifier.expression, qualifier) + } + } + + private fun checkVisibility( + descriptor: DeclarationDescriptorWithVisibility, + trace: BindingTrace, + referenceExpression: JetSimpleNameExpression, + shouldBeVisibleFrom: DeclarationDescriptor) { + val visibility = descriptor.visibility + if (PsiTreeUtil.getParentOfType(referenceExpression, JetImportDirective::class.java) != null && !visibility.mustCheckInImports()) { + return + } + if (!Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, shouldBeVisibleFrom)) { + trace.report(Errors.INVISIBLE_REFERENCE.on(referenceExpression, descriptor, visibility, descriptor.containingDeclaration!!)) + } + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.java index 61b86f3f405..a3c09d95eed 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.java @@ -42,10 +42,11 @@ import static org.jetbrains.kotlin.diagnostics.Errors.*; public class QualifiedExpressionResolver { @NotNull private final SymbolUsageValidator symbolUsageValidator; - @NotNull private final ImportDirectiveProcessor importDirectiveProcessor = new ImportDirectiveProcessor(this); + @NotNull private final NewQualifiedExpressionResolver newQualifiedExpressionResolver; - public QualifiedExpressionResolver(@NotNull SymbolUsageValidator symbolUsageValidator) { + public QualifiedExpressionResolver(@NotNull SymbolUsageValidator symbolUsageValidator, @NotNull NewQualifiedExpressionResolver newQualifiedExpressionResolver) { this.symbolUsageValidator = symbolUsageValidator; + this.newQualifiedExpressionResolver = newQualifiedExpressionResolver; } private static final Predicate CLASSIFIERS_AND_PACKAGE_VIEWS = new Predicate() { @@ -70,7 +71,8 @@ public class QualifiedExpressionResolver { @NotNull BindingTrace trace, @NotNull LookupMode lookupMode ) { - return importDirectiveProcessor.processImportReference(importDirective, moduleDescriptor, trace, lookupMode); + // todo fix shouldBeVisibleFrom + return newQualifiedExpressionResolver.processImportReference(importDirective, moduleDescriptor, trace, moduleDescriptor); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt index b43049a05d6..313160e4e47 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt @@ -85,7 +85,8 @@ class LazyImportResolver( @Volatile var importResolveStatus: ImportResolveStatus? = null - fun scopeForMode(mode: LookupMode): JetScope { + fun scopeForMode(realMode: LookupMode): JetScope { + val mode = LookupMode.EVERYTHING // todo val status = importResolveStatus if (status != null && (status.lookupMode == mode || status.lookupMode == LookupMode.EVERYTHING)) { return status.scope diff --git a/compiler/testData/diagnostics/tests/imports/ClassClash.kt b/compiler/testData/diagnostics/tests/imports/ClassClash.kt new file mode 100644 index 00000000000..7e40d56340f --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClash.kt @@ -0,0 +1,69 @@ +// MODULE: m1 +// FILE: a.kt +package a + +class B { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class B { + fun m2() {} +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.B + +fun test(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() + + val b_1: a.B = B() + b_1.m1() + + val b_2: B = a.B() + b_2.m1() +} + + +//----------------------------TOP LEVEL--------------------- +// MODULE: top_m1 +// FILE: top_a.kt +class B { + fun m1() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class B { + fun m2() {} +} + +// MODULE: top_m3(top_m1, top_m2) +// FILE: top_c.kt +import B + +fun test(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() +} + +// FILE: top_d.kt + +fun test2(b: B) { + b.m1() + b.m2() + + val b_: B = B() + b_.m1() +} diff --git a/compiler/testData/diagnostics/tests/imports/ClassClash.txt b/compiler/testData/diagnostics/tests/imports/ClassClash.txt new file mode 100644 index 00000000000..3248f3d00af --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClash.txt @@ -0,0 +1,86 @@ +// -- Module: -- +package + +package a { + + public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m1(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +package a { + + public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m2(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ b: a.B): kotlin.Unit + +package a { + + public final class B { + // -- Module: -- + } + + public final class B { + // -- Module: -- + } +} + + +// -- Module: -- +package + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m1(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + + +// -- Module: -- +package + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m2(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + + +// -- Module: -- +package + +public fun test(/*0*/ b: B): kotlin.Unit +public fun test2(/*0*/ b: B): kotlin.Unit + +public final class B { + // -- Module: -- +} + +public final class B { + // -- Module: -- +} + + diff --git a/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.kt b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.kt new file mode 100644 index 00000000000..bd6b53a9532 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.kt @@ -0,0 +1,63 @@ +// MODULE: m1 +// FILE: a.kt +package a + +class B { + fun m1() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class B { + fun m2() {} +} + +// MODULE: m3(m2, m1) +// FILE: b.kt +import a.* + + +fun test(b: B) { + b.m2() + b.m1() + + val b_: B = B() + b_.m2() + + val b_1: a.B = B() + b_1.m2() + + val b_2: B = a.B() + b_2.m2() +} + + +//----------------------------TOP LEVEL--------------------- + +// MODULE: top_m1 +// FILE: top_a.kt +class B { + fun m1() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class B { + fun m2() {} +} + +// MODULE: top_m3(top_m2, top_m1) +// FILE: top_c.kt + +fun test(b: B) { + b.m2() + b.m1() + + val b_: B = B() + b_.m2() + + val b_2 = B() + b_2.m2() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.txt b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.txt new file mode 100644 index 00000000000..24d52ca4f3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/ClassClashStarImport.txt @@ -0,0 +1,85 @@ +// -- Module: -- +package + +package a { + + public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m1(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +package a { + + public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m2(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ b: a.B): kotlin.Unit + +package a { + + public final class B { + // -- Module: -- + } + + public final class B { + // -- Module: -- + } +} + + +// -- Module: -- +package + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m1(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + + +// -- Module: -- +package + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun m2(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + + +// -- Module: -- +package + +public fun test(/*0*/ b: B): kotlin.Unit + +public final class B { + // -- Module: -- +} + +public final class B { + // -- Module: -- +} + + diff --git a/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.kt b/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.kt index 4c0e81da140..66c87c9bb00 100644 --- a/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.kt +++ b/compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.kt @@ -11,7 +11,7 @@ class X // FILE: c.kt package c -import a.x -import b.x +import a.x +import b.x class Y : x.X \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.kt b/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.kt new file mode 100644 index 00000000000..314b78e1c2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.kt @@ -0,0 +1,67 @@ +// MODULE: m1 +// FILE: a.kt +package a.b + +class c { + fun ab_c() {} +} + +// MODULE: m2 +// FILE: b.kt +package a + +class b { + class c { + fun a_bc() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.b.c + +fun test(ab_c: c) { + ab_c.ab_c() + + val ab_c2: a.b.c = a.b.c() + ab_c2.ab_c() +} + +fun test2(a_bc: a.b.c) { + a_bc.a_bc() // todo +} + + + +//---------------------------TOP LEVEL---------- +// MODULE: top_m1 +// FILE: top_a.kt +package a + +class b { + fun a_b() {} +} + +// MODULE: top_m2 +// FILE: top_b.kt +class a { + class b { + fun _ab() {} + } + fun _a() {} +} + +// MODULE: top_m3(top_m1, top_m2) +// FILE: top_c.kt +import a.b + +fun test(a_b: b) { + a_b.a_b() + + val a_b2: a.b = a.b() + a_b2.a_b() +} + +fun test2(_ab: a.b) { + _ab._ab() // todo +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.txt b/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.txt new file mode 100644 index 00000000000..24b7ef07d16 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.txt @@ -0,0 +1,112 @@ +// -- Module: -- +package + +package a { + + package a.b { + + public final class c { + public constructor c() + public final fun ab_c(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} + + +// -- Module: -- +package + +package a { + + public final class b { + public constructor b() + 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 c { + public constructor c() + public final fun a_bc(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ ab_c: a.b.c): kotlin.Unit +public fun test2(/*0*/ a_bc: a.b.c): kotlin.Unit + +package a { + + public final class b { + // -- Module: -- + } + + package a.b { + + public final class c { + // -- Module: -- + } + } +} + + +// -- Module: -- +package + +package a { + + public final class b { + public constructor b() + public final fun a_b(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +public final class a { + public constructor a() + public final fun _a(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class b { + public constructor b() + public final fun _ab(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ a_b: a.b): kotlin.Unit +public fun test2(/*0*/ _ab: a.b): kotlin.Unit + +public final class a { + // -- Module: -- +} + +package a { + + public final class b { + // -- Module: -- + } +} diff --git a/compiler/testData/diagnostics/tests/imports/Imports.kt b/compiler/testData/diagnostics/tests/imports/Imports.kt index e7b5fdd7a96..903863bb36d 100644 --- a/compiler/testData/diagnostics/tests/imports/Imports.kt +++ b/compiler/testData/diagnostics/tests/imports/Imports.kt @@ -5,16 +5,16 @@ import b.B //class import b.foo //function import b.ext //extension function import b.value //property -import b.C.Companion.bar //function from companion object -import b.C.Companion.cValue //property from companion object -import b.constant.fff //function from val -import b.constant.dValue //property from val +import b.C.Companion.bar //function from companion object +import b.C.Companion.cValue //property from companion object +import b.constant.fff //function from val +import b.constant.dValue //property from val import b.constant -import b.E.Companion.f //val from companion object +import b.E.Companion.f //val from companion object import smth.illegal import b.C.smth.illegal -import b.bar.smth -import b.bar.* +import b.bar.smth +import b.bar.* fun test(arg: B) { foo(value) diff --git a/compiler/testData/diagnostics/tests/imports/MalformedImports.kt b/compiler/testData/diagnostics/tests/imports/MalformedImports.kt index b03653e717d..80e10a47668 100644 --- a/compiler/testData/diagnostics/tests/imports/MalformedImports.kt +++ b/compiler/testData/diagnostics/tests/imports/MalformedImports.kt @@ -3,7 +3,7 @@ package test import some. import .some import .kotlin -import kotlin. +import kotlin. import import . import * \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/NestedClassClash.kt b/compiler/testData/diagnostics/tests/imports/NestedClassClash.kt new file mode 100644 index 00000000000..639bdbcba9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/NestedClassClash.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// FILE: a.kt +package a + +class A { + class B +} + +// FILE: b.kt +package a + +class D { + class B +} + +// FILE: c.kt +import a.A.B +import a.D.B + +fun test(b: B) { + B() +} + +// FILE: d.kt +import a.A.* +import a.D.* + +// todo ambiguvity here +fun test2(b: B) { + B() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/NestedClassClash.txt b/compiler/testData/diagnostics/tests/imports/NestedClassClash.txt new file mode 100644 index 00000000000..a3855afaaf8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/NestedClassClash.txt @@ -0,0 +1,35 @@ +package + +public fun test(/*0*/ b: [ERROR : B]): kotlin.Unit +public fun test2(/*0*/ b: [ERROR : B]): kotlin.Unit + +package a { + + 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() + 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 D { + public constructor D() + 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() + 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/testData/diagnostics/tests/imports/PackageVsClass.kt b/compiler/testData/diagnostics/tests/imports/PackageVsClass.kt new file mode 100644 index 00000000000..286276c3359 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PackageVsClass.kt @@ -0,0 +1,128 @@ +// MODULE: m1 +// FILE: a.kt +package a.b + +fun ab_fun() {} + +class c { + fun ab_c() {} + + class d { + fun ab_cd() {} + } +} + +// MODULE: m2 +// FILE: b.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.a_fun +import a.b + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + ab_fun() +} + +// FILE: d.kt +package a + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + ab_fun() +} + +//---- Changed dependence order +// MODULE: m4(m2, m1) +// FILE: c.kt +import a.a_fun +import a.b + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + ab_fun() +} + +// FILE: d.kt +package a + +import a.b.ab_fun +import a.b.c + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +fun test2(ab_c: c) { + ab_c.ab_c() + + val ab_cd: c.d = c.d() + ab_cd.ab_cd() + + ab_fun() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/PackageVsClass.txt b/compiler/testData/diagnostics/tests/imports/PackageVsClass.txt new file mode 100644 index 00000000000..55a6aa63adf --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/PackageVsClass.txt @@ -0,0 +1,101 @@ +// -- Module: -- +package + +package a { + + package a.b { + public fun ab_fun(): kotlin.Unit + + public final class c { + public constructor c() + public final fun ab_c(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class d { + public constructor d() + public final fun ab_cd(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } + } +} + + +// -- Module: -- +package + +package a { + public fun a_fun(): kotlin.Unit + + public final class b { + public constructor b() + public final fun a_b(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class c { + public constructor c() + public final fun a_bc(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ a_b: a.b): kotlin.Unit +public fun test2(/*0*/ ab_c: a.b.c): kotlin.Unit + +package a { + public fun a_fun(): kotlin.Unit + public fun test(/*0*/ a_b: a.b): kotlin.Unit + public fun test2(/*0*/ ab_c: a.b.c): kotlin.Unit + + public final class b { + // -- Module: -- + } + + package a.b { + public fun ab_fun(): kotlin.Unit + + public final class c { + // -- Module: -- + } + } +} + + +// -- Module: -- +package + +public fun test(/*0*/ a_b: a.b): kotlin.Unit +public fun test2(/*0*/ ab_c: a.b.c): kotlin.Unit + +package a { + public fun a_fun(): kotlin.Unit + public fun test(/*0*/ a_b: a.b): kotlin.Unit + public fun test2(/*0*/ ab_c: a.b.c): kotlin.Unit + + public final class b { + // -- Module: -- + } + + package a.b { + public fun ab_fun(): kotlin.Unit + + public final class c { + // -- Module: -- + } + } +} + + diff --git a/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.kt b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.kt new file mode 100644 index 00000000000..893cbe46e24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.kt @@ -0,0 +1,62 @@ +// MODULE: m1 +// FILE: a.kt +package a + +fun a_fun() {} + +class b { + fun a_b() {} + + class c { + fun a_bc() {} + } +} + +// MODULE: m2 +// FILE: b.kt +fun _fun() {} + +class a { + fun _a() {} + + class b { + fun _ab() {} + } +} + +// MODULE: m3(m1, m2) +// FILE: c.kt +import a.a_fun +import a.b + +fun test(a_b: b) { + a_b.a_b() + + val a_bc: b.c = b.c() + a_bc.a_bc() + + a_fun() +} + +// FILE: d.kt +fun test2(_a: a) { + _a._a() + + val _ab: a.b = a.b() + _ab._ab() // todo + + _fun() +} + +// FILE: e.kt +import a +import _fun + +fun test3(_a: a) { + _a._a() + + val _ab: a.b = a.b() + _ab._ab() // todo + + _fun() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.txt b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.txt new file mode 100644 index 00000000000..fed0172e891 --- /dev/null +++ b/compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.txt @@ -0,0 +1,67 @@ +// -- Module: -- +package + +package a { + public fun a_fun(): kotlin.Unit + + public final class b { + public constructor b() + public final fun a_b(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class c { + public constructor c() + public final fun a_bc(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} + + +// -- Module: -- +package + +public fun _fun(): kotlin.Unit + +public final class a { + public constructor a() + public final fun _a(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class b { + public constructor b() + public final fun _ab(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + + +// -- Module: -- +package + +public fun _fun(): kotlin.Unit +public fun test(/*0*/ a_b: a.b): kotlin.Unit +public fun test2(/*0*/ _a: a): kotlin.Unit +public fun test3(/*0*/ _a: a): kotlin.Unit + +public final class a { + // -- Module: -- +} + +package a { + public fun a_fun(): kotlin.Unit + + public final class b { + // -- Module: -- + } +} + + diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index df4a6cdf7c9..6f41a04a015 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -6489,6 +6489,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("ClassClash.kt") + public void testClassClash() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ClassClash.kt"); + doTest(fileName); + } + + @TestMetadata("ClassClashStarImport.kt") + public void testClassClashStarImport() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ClassClashStarImport.kt"); + doTest(fileName); + } + @TestMetadata("ClassImportsConflicting.kt") public void testClassImportsConflicting() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ClassImportsConflicting.kt"); @@ -6531,6 +6543,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("GenericClassVsPackage.kt") + public void testGenericClassVsPackage() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/GenericClassVsPackage.kt"); + doTest(fileName); + } + @TestMetadata("ImportFromCurrentWithDifferentName.kt") public void testImportFromCurrentWithDifferentName() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.kt"); @@ -6627,6 +6645,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("NestedClassClash.kt") + public void testNestedClassClash() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/NestedClassClash.kt"); + doTest(fileName); + } + @TestMetadata("PackageLocalClassNotImported.kt") public void testPackageLocalClassNotImported() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PackageLocalClassNotImported.kt"); @@ -6639,6 +6663,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("PackageVsClass.kt") + public void testPackageVsClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PackageVsClass.kt"); + doTest(fileName); + } + @TestMetadata("PrivateClassNotImported.kt") public void testPrivateClassNotImported() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/PrivateClassNotImported.kt"); @@ -6668,6 +6698,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/StarImportFromObject.kt"); doTest(fileName); } + + @TestMetadata("TopLevelClassVsPackage.kt") + public void testTopLevelClassVsPackage() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/TopLevelClassVsPackage.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/tests/incompleteCode")