diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java index 8713b954327..711a6e3f2e9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/AbstractLazyMemberScope.java @@ -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} @@ -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); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java index 6615d31964a..f9360e2d37a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java @@ -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; + } } diff --git a/idea/testData/quickfix/autoImports/beforeNamelessClass.kt b/idea/testData/quickfix/autoImports/beforeNamelessClass.kt new file mode 100644 index 00000000000..83b50e7ee8b --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeNamelessClass.kt @@ -0,0 +1,6 @@ +// "Import Class" "false" +// ERROR: Unresolved reference: TTT + +class { + val t: TTT = null +} diff --git a/idea/testData/quickfix/autoImports/beforeNamelessFunction.kt b/idea/testData/quickfix/autoImports/beforeNamelessFunction.kt new file mode 100644 index 00000000000..7cc5b264f81 --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeNamelessFunction.kt @@ -0,0 +1,6 @@ +// "Import Class" "false" +// ERROR: Unresolved reference: TTTTT + +fun () { + val tttt : TTTTT = null +} diff --git a/idea/testData/quickfix/autoImports/beforeNamelessObject.kt b/idea/testData/quickfix/autoImports/beforeNamelessObject.kt new file mode 100644 index 00000000000..59af1db619f --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeNamelessObject.kt @@ -0,0 +1,6 @@ +// "Import Class" "false" +// ERROR: Unresolved reference: TTT + +object { + val t : TTT = null +} \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/beforeNamelessParameter.kt b/idea/testData/quickfix/autoImports/beforeNamelessParameter.kt new file mode 100644 index 00000000000..932463134a6 --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeNamelessParameter.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/beforeNamelessProperty.kt b/idea/testData/quickfix/autoImports/beforeNamelessProperty.kt new file mode 100644 index 00000000000..5b4f113db1a --- /dev/null +++ b/idea/testData/quickfix/autoImports/beforeNamelessProperty.kt @@ -0,0 +1,8 @@ +// "Import Class" "false" +// ERROR: Unresolved reference: TTT + +val : Int + get() { + val t : TTT = null + return 1 + } \ No newline at end of file