Fix DescriptorUtils.isLocal semantics
Non-member descriptors, e.g. type parameters, value parameters that defined in local function should be local too Otherwise a lot of exceptions happens when resolving references within anonymous objects
This commit is contained in:
@@ -69,8 +69,8 @@ public class DescriptorUtils {
|
||||
*/
|
||||
public static boolean isLocal(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor current = descriptor;
|
||||
while (current instanceof MemberDescriptor) {
|
||||
if (isAnonymousObject(current) || ((DeclarationDescriptorWithVisibility) current).getVisibility() == Visibilities.LOCAL) {
|
||||
while (current != null) {
|
||||
if (isAnonymousObject(current) || isDescriptorWithLocalVisibility(current)) {
|
||||
return true;
|
||||
}
|
||||
current = current.getContainingDeclaration();
|
||||
@@ -78,6 +78,11 @@ public class DescriptorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isDescriptorWithLocalVisibility(DeclarationDescriptor current) {
|
||||
return current instanceof DeclarationDescriptorWithVisibility &&
|
||||
((DeclarationDescriptorWithVisibility) current).getVisibility() == Visibilities.LOCAL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
|
||||
FqName safe = getFqNameSafeIfPossible(descriptor);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
val prop = object {
|
||||
private fun <K> foo(x: <caret>K) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// REF: K
|
||||
@@ -0,0 +1,9 @@
|
||||
open class B
|
||||
class A
|
||||
val prop = object : B() {
|
||||
private fun foo(x: A): A {
|
||||
return <caret>x
|
||||
}
|
||||
}
|
||||
|
||||
// REF: x
|
||||
@@ -347,12 +347,24 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TypeParameterInAnonymousObject.kt")
|
||||
public void testTypeParameterInAnonymousObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/TypeParameterInAnonymousObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TypeParameterInFunctionLiteral.kt")
|
||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/TypeParameterInFunctionLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ValueParameter.kt")
|
||||
public void testValueParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/ValueParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WrongNumberOfTypeArguments.kt")
|
||||
public void testWrongNumberOfTypeArguments() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArguments.kt");
|
||||
|
||||
Reference in New Issue
Block a user