From c6f0a296e2751854eee2fbc6b0c915885ee79d6f Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 11 Apr 2016 17:26:01 +0300 Subject: [PATCH] PY-19047 Fixed: Exception on interpreter indexing PyResolveProcessor had a bug with resolving imports locally --- .../jetbrains/python/psi/resolve/PyResolveProcessor.java | 7 +++++-- python/testData/indexing/Py19047/__init__.py | 3 +++ python/testData/indexing/Py19047/a.py | 0 python/testData/indexing/Py19047/func.py | 2 ++ python/testSrc/com/jetbrains/python/PyIndexingTest.java | 9 ++++++++- 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 python/testData/indexing/Py19047/__init__.py create mode 100644 python/testData/indexing/Py19047/a.py create mode 100644 python/testData/indexing/Py19047/func.py diff --git a/python/src/com/jetbrains/python/psi/resolve/PyResolveProcessor.java b/python/src/com/jetbrains/python/psi/resolve/PyResolveProcessor.java index 1e9bf5306cf9..57d7a4119336 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PyResolveProcessor.java +++ b/python/src/com/jetbrains/python/psi/resolve/PyResolveProcessor.java @@ -23,7 +23,10 @@ import com.intellij.psi.ResolveState; import com.intellij.psi.scope.PsiScopeProcessor; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; -import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.PyFromImportStatement; +import com.jetbrains.python.psi.PyImportElement; +import com.jetbrains.python.psi.PyImportedNameDefiner; +import com.jetbrains.python.psi.PyUtil; import com.jetbrains.python.psi.impl.ResolveResultList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -114,7 +117,7 @@ public class PyResolveProcessor implements PsiScopeProcessor { if (importElement != null) { return ResolveResultList.to(importElement.getElementNamed(myName, false)); } - else if (definer instanceof PyStarImportElement) { + else { return Collections.emptyList(); } } diff --git a/python/testData/indexing/Py19047/__init__.py b/python/testData/indexing/Py19047/__init__.py new file mode 100644 index 000000000000..46dcc93a4346 --- /dev/null +++ b/python/testData/indexing/Py19047/__init__.py @@ -0,0 +1,3 @@ +from .func import func + +m = func() \ No newline at end of file diff --git a/python/testData/indexing/Py19047/a.py b/python/testData/indexing/Py19047/a.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testData/indexing/Py19047/func.py b/python/testData/indexing/Py19047/func.py new file mode 100644 index 000000000000..a54c6fc834ed --- /dev/null +++ b/python/testData/indexing/Py19047/func.py @@ -0,0 +1,2 @@ +def func(): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyIndexingTest.java b/python/testSrc/com/jetbrains/python/PyIndexingTest.java index 03d3f6961816..dbffeebc9a95 100644 --- a/python/testSrc/com/jetbrains/python/PyIndexingTest.java +++ b/python/testSrc/com/jetbrains/python/PyIndexingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -15,6 +15,8 @@ */ package com.jetbrains.python; +import com.intellij.psi.stubs.StubUpdatingIndex; +import com.intellij.util.indexing.FileBasedIndex; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.stubs.PyModuleNameIndex; @@ -41,4 +43,9 @@ public class PyIndexingTest extends PyTestCase { assertDoesntContain(modules, "__init__"); assertDoesntContain(modules, "ModuleNameIndex_baz"); } + + // PY-19047 + public void testPy19047() { + FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, new Throwable()); + } }