KT-4881 Annotation resolved to package should be compile-time error
#KT-4881 Fixed
This commit is contained in:
+40
-4
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.AbstractScopeAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
|
||||
@@ -156,8 +157,10 @@ public class QualifiedExpressionResolver {
|
||||
public Collection<DeclarationDescriptor> lookupDescriptorsForUserType(
|
||||
@NotNull JetUserType userType,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull BindingTrace trace
|
||||
@NotNull BindingTrace trace,
|
||||
boolean onlyClassifiers
|
||||
) {
|
||||
|
||||
if (userType.isAbsoluteInRootPackage()) {
|
||||
trace.report(Errors.UNSUPPORTED.on(userType, "package"));
|
||||
return Collections.emptyList();
|
||||
@@ -168,12 +171,45 @@ public class QualifiedExpressionResolver {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
JetUserType qualifier = userType.getQualifier();
|
||||
|
||||
// We do not want to resolve the last segment of a user type to a package
|
||||
JetScope filteredScope = filterOutPackagesIfNeeded(outerScope, onlyClassifiers);
|
||||
|
||||
if (qualifier == null) {
|
||||
return lookupDescriptorsForSimpleNameReference(referenceExpression, outerScope, outerScope, trace, LookupMode.ONLY_CLASSES_AND_PACKAGES,
|
||||
return lookupDescriptorsForSimpleNameReference(referenceExpression, filteredScope, outerScope, trace, LookupMode.ONLY_CLASSES_AND_PACKAGES,
|
||||
false, true);
|
||||
}
|
||||
Collection<DeclarationDescriptor> declarationDescriptors = lookupDescriptorsForUserType(qualifier, outerScope, trace);
|
||||
return lookupSelectorDescriptors(referenceExpression, declarationDescriptors, trace, outerScope, LookupMode.ONLY_CLASSES_AND_PACKAGES, true);
|
||||
Collection<DeclarationDescriptor> declarationDescriptors = lookupDescriptorsForUserType(qualifier, outerScope, trace, false);
|
||||
return lookupSelectorDescriptors(referenceExpression, declarationDescriptors, trace, filteredScope, LookupMode.ONLY_CLASSES_AND_PACKAGES, true);
|
||||
}
|
||||
|
||||
private static JetScope filterOutPackagesIfNeeded(final JetScope outerScope, boolean noPackages) {
|
||||
return !noPackages ? outerScope : new AbstractScopeAdapter() {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return outerScope;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
throw new UnsupportedOperationException("Should not be called, because it may be cached before filtering is applied");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||
throw new UnsupportedOperationException("Should not be called, because it may be cached before filtering is applied");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -288,7 +288,7 @@ public class TypeResolver(
|
||||
}
|
||||
|
||||
public fun resolveClass(scope: JetScope, userType: JetUserType, trace: BindingTrace): ClassifierDescriptor? {
|
||||
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace)
|
||||
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace, true)
|
||||
.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
if (classifierDescriptor != null) {
|
||||
ImportsResolver.reportPlatformClassMappedToKotlin(moduleDescriptor, trace, userType, classifierDescriptor)
|
||||
|
||||
@@ -6,7 +6,7 @@ fun sample(): Input {
|
||||
return Input("Hello", "World");
|
||||
}
|
||||
|
||||
test fun testForEachLine() {
|
||||
fun testForEachLine() {
|
||||
val list = ArrayList<String>()
|
||||
val reader = sample()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ fun sample(): Input {
|
||||
return Input("Hello", "World");
|
||||
}
|
||||
|
||||
test fun testForEachLine() {
|
||||
fun testForEachLine() {
|
||||
val list = ArrayList<String>()
|
||||
val reader = sample()
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
package foo
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
<!UNRESOLVED_REFERENCE!>foo<!> fun bar(p: <!UNRESOLVED_REFERENCE!>foo<!>): <!UNRESOLVED_REFERENCE!>foo<!> = null!!
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
[ERROR : foo]() internal fun bar(/*0*/ p: [ERROR : foo]): [ERROR : foo]
|
||||
|
||||
package foo {
|
||||
}
|
||||
@@ -340,6 +340,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PackageInTypePosition.kt")
|
||||
public void testPackageInTypePosition() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/PackageInTypePosition.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PackageQualified.kt")
|
||||
public void testPackageQualified() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/PackageQualified.kt");
|
||||
|
||||
@@ -478,7 +478,7 @@ public abstract class ElementResolver {
|
||||
if (qualifier != null) {
|
||||
JetScope resolutionScope = getExpressionResolutionScope(resolveSession, expression);
|
||||
Collection<DeclarationDescriptor> descriptors =
|
||||
qualifiedExpressionResolver.lookupDescriptorsForUserType(qualifier, resolutionScope, trace);
|
||||
qualifiedExpressionResolver.lookupDescriptorsForUserType(qualifier, resolutionScope, trace, false);
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
if (descriptor instanceof LazyPackageDescriptor) {
|
||||
return ((LazyPackageDescriptor) descriptor).getMemberScope();
|
||||
|
||||
@@ -2,7 +2,7 @@ package to
|
||||
|
||||
import a.a
|
||||
|
||||
fun f(i: a.a) {
|
||||
fun f(i: a) {
|
||||
a.a
|
||||
a()
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class ComplexSetJsTest : SetJsTest() {
|
||||
assertEquals(data, set)
|
||||
}
|
||||
|
||||
test override fun constructors() {
|
||||
Test override fun constructors() {
|
||||
doTest<String>()
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class ComplexSetJsTest : SetJsTest() {
|
||||
class PrimitiveSetJsTest : SetJsTest() {
|
||||
override fun createEmptyMutableSet(): MutableSet<String> = HashSet()
|
||||
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = HashSet()
|
||||
test override fun constructors() {
|
||||
Test override fun constructors() {
|
||||
HashSet<String>()
|
||||
HashSet<String>(3)
|
||||
HashSet<String>(3, 0.5f)
|
||||
@@ -43,7 +43,7 @@ class PrimitiveSetJsTest : SetJsTest() {
|
||||
class LinkedHashSetTest : SetJsTest() {
|
||||
override fun createEmptyMutableSet(): MutableSet<String> = LinkedHashSet()
|
||||
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = LinkedHashSet()
|
||||
test override fun constructors() {
|
||||
Test override fun constructors() {
|
||||
LinkedHashSet<String>()
|
||||
LinkedHashSet<String>(3)
|
||||
LinkedHashSet<String>(3, 0.5f)
|
||||
@@ -186,7 +186,7 @@ abstract class SetJsTest {
|
||||
}
|
||||
}
|
||||
|
||||
test abstract fun constructors()
|
||||
abstract fun constructors()
|
||||
|
||||
Test fun nullAsValue() {
|
||||
val set = createEmptyMutableSetWithNullableValues()
|
||||
|
||||
Reference in New Issue
Block a user