KT-3016 Exception during analyze when some function has no name
#KT-3016 Fixed
This commit is contained in:
+10
-10
@@ -30,6 +30,8 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -216,15 +218,15 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
for (JetDeclaration declaration : declarationProvider.getAllDeclarations()) {
|
||||
if (declaration instanceof JetEnumEntry) {
|
||||
JetEnumEntry jetEnumEntry = (JetEnumEntry) declaration;
|
||||
Name name = jetEnumEntry.getNameAsName();
|
||||
Name name = safeNameForLazyResolve(jetEnumEntry);
|
||||
if (name != null) {
|
||||
getProperties(name);
|
||||
getObjectDescriptor(name);
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetObjectDeclaration) {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||
Name name = classOrObject.getNameAsName();
|
||||
JetObjectDeclaration objectDeclaration = (JetObjectDeclaration) declaration;
|
||||
Name name = safeNameForLazyResolve(objectDeclaration.getNameAsDeclaration());
|
||||
if (name != null) {
|
||||
getProperties(name);
|
||||
getObjectDescriptor(name);
|
||||
@@ -232,25 +234,23 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||
Name name = classOrObject.getNameAsName();
|
||||
Name name = safeNameForLazyResolve(classOrObject.getNameAsName());
|
||||
if (name != null) {
|
||||
getClassifier(name);
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetFunction) {
|
||||
JetFunction function = (JetFunction) declaration;
|
||||
getFunctions(function.getNameAsSafeName());
|
||||
getFunctions(safeNameForLazyResolve(function));
|
||||
}
|
||||
else if (declaration instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) declaration;
|
||||
getProperties(property.getNameAsSafeName());
|
||||
getProperties(safeNameForLazyResolve(property));
|
||||
}
|
||||
else if (declaration instanceof JetParameter) {
|
||||
JetParameter parameter = (JetParameter) declaration;
|
||||
Name name = parameter.getNameAsName();
|
||||
if (name != null) {
|
||||
getProperties(name);
|
||||
}
|
||||
Name name = safeNameForLazyResolve(parameter);
|
||||
getProperties(name);
|
||||
}
|
||||
else if (declaration instanceof JetTypedef || declaration instanceof JetMultiDeclaration) {
|
||||
// Do nothing for typedefs as they are not supported.
|
||||
|
||||
+5
-3
@@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -54,15 +56,15 @@ public abstract class AbstractPsiBasedDeclarationProvider implements Declaration
|
||||
allDeclarations.add(declaration);
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
JetNamedFunction namedFunction = (JetNamedFunction) declaration;
|
||||
functions.put(namedFunction.getNameAsName(), namedFunction);
|
||||
functions.put(safeNameForLazyResolve(namedFunction), namedFunction);
|
||||
}
|
||||
else if (declaration instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) declaration;
|
||||
properties.put(property.getNameAsName(), property);
|
||||
properties.put(safeNameForLazyResolve(property), property);
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||
classesAndObjects.put(classOrObject.getNameAsName(), classOrObject);
|
||||
classesAndObjects.put(safeNameForLazyResolve(classOrObject.getNameAsName()), classOrObject);
|
||||
}
|
||||
else if (declaration instanceof JetParameter || declaration instanceof JetTypedef || declaration instanceof JetMultiDeclaration) {
|
||||
// Do nothing, just put it into allDeclarations is enough
|
||||
|
||||
@@ -36,6 +36,8 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -153,8 +155,7 @@ public class ResolveSession {
|
||||
return getClassObjectDescriptor((JetClassObject) classOrObject.getParent());
|
||||
}
|
||||
JetScope resolutionScope = getInjector().getScopeProvider().getResolutionScopeForDeclaration(classOrObject);
|
||||
Name name = classOrObject.getNameAsName();
|
||||
assert name != null : "Name is null for " + classOrObject + " " + classOrObject.getText();
|
||||
Name name = safeNameForLazyResolve(classOrObject.getNameAsName());
|
||||
|
||||
// Why not use the result here. Because it may be that there is a redeclaration:
|
||||
// class A {} class A { fun foo(): A<completion here>}
|
||||
@@ -252,7 +253,7 @@ public class ResolveSession {
|
||||
@Override
|
||||
public DeclarationDescriptor visitNamedFunction(JetNamedFunction function, Void data) {
|
||||
JetScope scopeForDeclaration = getInjector().getScopeProvider().getResolutionScopeForDeclaration(function);
|
||||
scopeForDeclaration.getFunctions(function.getNameAsName());
|
||||
scopeForDeclaration.getFunctions(safeNameForLazyResolve(function));
|
||||
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ public class ResolveSession {
|
||||
JetClass jetClass = (JetClass) grandFather;
|
||||
// This is a primary constructor parameter
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
getClassDescriptor(jetClass).getDefaultType().getMemberScope().getProperties(parameter.getNameAsName());
|
||||
getClassDescriptor(jetClass).getDefaultType().getMemberScope().getProperties(safeNameForLazyResolve(parameter));
|
||||
return getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
||||
}
|
||||
}
|
||||
@@ -273,15 +274,14 @@ public class ResolveSession {
|
||||
@Override
|
||||
public DeclarationDescriptor visitProperty(JetProperty property, Void data) {
|
||||
JetScope scopeForDeclaration = getInjector().getScopeProvider().getResolutionScopeForDeclaration(property);
|
||||
scopeForDeclaration.getProperties(property.getNameAsName());
|
||||
scopeForDeclaration.getProperties(safeNameForLazyResolve(property));
|
||||
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor visitObjectDeclarationName(JetObjectDeclarationName declarationName, Void data) {
|
||||
JetScope scopeForDeclaration = getInjector().getScopeProvider().getResolutionScopeForDeclaration(
|
||||
(JetDeclaration) declarationName.getParent());
|
||||
scopeForDeclaration.getProperties(declarationName.getNameAsName());
|
||||
JetScope scopeForDeclaration = getInjector().getScopeProvider().getResolutionScopeForDeclaration(declarationName.getParent());
|
||||
scopeForDeclaration.getProperties(safeNameForLazyResolve(declarationName));
|
||||
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, declarationName);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.di.InjectorForBodyResolve;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -42,6 +43,12 @@ import java.util.*;
|
||||
*/
|
||||
public class ResolveSessionUtils {
|
||||
|
||||
// This name is used as a key for the case when something has no name _due to a syntactic error_
|
||||
// Example: fun (x: Int) = 5
|
||||
// There's no name for this function in the PSI
|
||||
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
|
||||
public static final Name NO_NAME_FOR_LAZY_RESOLVE = Name.identifier("no_name_in_PSI_for_lazy_resolve_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
|
||||
|
||||
private ResolveSessionUtils() {
|
||||
}
|
||||
|
||||
@@ -392,4 +399,15 @@ public class ResolveSessionUtils {
|
||||
|
||||
return resultClassifierDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Name safeNameForLazyResolve(@NotNull JetNamed named) {
|
||||
Name name = named.getNameAsName();
|
||||
return safeNameForLazyResolve(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Name safeNameForLazyResolve(@Nullable Name name) {
|
||||
return name != null ? name : NO_NAME_FOR_LAZY_RESOLVE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Import Class" "false"
|
||||
// ERROR: Unresolved reference: TTT
|
||||
|
||||
class {
|
||||
val t: TTT = null
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Import Class" "false"
|
||||
// ERROR: Unresolved reference: TTTTT
|
||||
|
||||
fun () {
|
||||
val tttt : TTTTT = null
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Import Class" "false"
|
||||
// ERROR: Unresolved reference: TTT
|
||||
|
||||
object {
|
||||
val t : TTT = null
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Import Class" "false"
|
||||
// ERROR: Function 'f' must have a body
|
||||
// ERROR: Unresolved reference: TTT
|
||||
|
||||
fun f(: Int) {
|
||||
val t: TTT = null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Import Class" "false"
|
||||
// ERROR: Unresolved reference: TTT
|
||||
|
||||
val : Int
|
||||
get() {
|
||||
val t : TTT = null
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user