From 36a6a3ab654b8d7808d0d622a26ff8581e2e32c4 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 16 Apr 2020 20:25:50 +0300 Subject: [PATCH] Move the check that actual type is definition if type var is definition to the top of the corresponding method. GitOrigin-RevId: e2cfe01d00159b76bc3257df771b76bc2bec89fb --- .../com/jetbrains/python/psi/types/PyTypeChecker.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyTypeChecker.java b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyTypeChecker.java index 8ec4a54d6a5b..2f5e32da5e03 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyTypeChecker.java +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyTypeChecker.java @@ -180,11 +180,15 @@ public class PyTypeChecker { * The method mutates {@code context.substitutions} map adding new entries into it */ private static boolean match(@NotNull PyGenericType expected, @Nullable PyType actual, @NotNull MatchContext context) { + if (expected.isDefinition() && actual instanceof PyInstantiableType && !((PyInstantiableType)actual).isDefinition()) { + return false; + } + final PyType substitution = context.substitutions.get(expected); PyType bound = expected.getBound(); // Promote int in Type[TypeVar('T', int)] to Type[int] before checking that bounds match if (expected.isDefinition()) { - final Function toDefinition = t -> t instanceof PyInstantiableType ? ((PyInstantiableType)t).toClass() : t; + final Function toDefinition = t -> t instanceof PyInstantiableType ? ((PyInstantiableType)t).toClass() : t; bound = PyUnionType.union(PyTypeUtil.toStream(bound).map(toDefinition).toList()); } @@ -208,9 +212,6 @@ public class PyTypeChecker { } if (actual != null) { - if (expected.isDefinition() && !(actual instanceof PyInstantiableType && ((PyInstantiableType)actual).isDefinition())) { - return false; - } context.substitutions.put(expected, actual); } else if (bound != null) {