Fix NullReferenceException in hover for generic methods returning a TypeVar#16
Open
idanbd wants to merge 1 commit into
Open
Fix NullReferenceException in hover for generic methods returning a TypeVar#16idanbd wants to merge 1 commit into
idanbd wants to merge 1 commit into
Conversation
…ypeVar GetReturnDocumentation calls GetSpecificReturnType with a null argument set; for a TypeVar return this reaches CreateSpecificReturnFromTypeVar and calls CreateInstance(null). For the list/dict/tuple specializations CreateInstance dereferences the null argument set and throws. Guard CreateInstance against a null argument set by returning a plain instance; the call-resolution path (non-null args) is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Hovering a call to a generic method whose return type is a bare
TypeVar(e.g.def get(self) -> Ton aGeneric[T]class), where the type parameter resolves to a collection type, throws aNullReferenceExceptionwhile the server builds the return-type documentation:Cause
GetReturnDocumentationcallsGetSpecificReturnType(self, args: null)— there are no call arguments when producing documentation. For aTypeVarreturn on a generic instance this reachesCreateSpecificReturnFromTypeVar, which resolves the type parameter and callsspecificType.CreateInstance(null). For thelist/dict/tuplespecializations,CreateInstancedereferences the null argument set (ArgumentSetExtensions.Values<T>/CreateList) and throws.Fix
Guard
PythonClassType.CreateInstanceagainst a null argument set, returning a plain instance of the type. The normal call-resolution path (non-nullargs) is unchanged, and non-collection type parameters were already unaffected (they fall through to the samenew PythonInstance(this)).Test
Adds
HoverTests.GenericMethodReturningTypeVar: hovering aGeneric[T]method returningTresolved to a collection type no longer throws and returns the method's signature. (Complements the existingHoverGenericClass, which covers a non-collection type parameter.)