From 60b18d7fc69e04da89f31794e9fcc9f5572b5a2a Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 20 Aug 2012 21:54:39 +0400 Subject: [PATCH] Fixed PIEAE caused by PyBuiltinCache.getStdlibType() (EA-37595) --- .../python/psi/impl/PyBuiltinCache.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java index 24f1f8b3147c..944a95fdaa67 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java @@ -318,8 +318,7 @@ public class PyBuiltinCache { synchronized (myStdlibTypeCache) { final Ref ref = myStdlibTypeCache.get(key); if (ref != null) { - final PyType pyType = ref.get(); - if (pyType instanceof PyClassType && !((PyClassType)pyType).isValid()) { + if (!isValid(ref.get())) { myStdlibTypeCache.clear(); return null; } @@ -328,6 +327,31 @@ public class PyBuiltinCache { } } + private static boolean isValid(@Nullable PyType type) { + if (type instanceof PyCollectionType) { + final PyType elementType = ((PyCollectionType)type).getElementType(TypeEvalContext.fastStubOnly(null)); + if (!isValid(elementType)) { + return false; + } + } + + if (type instanceof PyClassType) { + return ((PyClassType)type).isValid(); + } + else if (type instanceof PyUnionType) { + for (PyType member : ((PyUnionType)type).getMembers()) { + if (!isValid(member)) { + return false; + } + } + return true; + } + else if (type instanceof PyFunctionType) { + return ((PyFunctionType)type).getFunction().isValid(); + } + return true; + } + public void storeStdlibType(@NotNull String key, @Nullable PyType result) { synchronized (myStdlibTypeCache) { myStdlibTypeCache.put(key, new Ref(result));