Skip to content

Invalid property access in quick info relating to type arguments #4616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Sep 3, 2015 · 2 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

type MixinCtor<A> = new () => A & { constructor: MixinCtor</**/A> };

Hover over the A at /**/.

Expected: A in MixinCtor<A>
Actual: The language service tries to get length off of undefined, crashes.

Description:

getQuickInfoAtPosition('C:\Users\drosen\AppData\Local\Temp\~vsBEB5.ts', 61)

Message:

StackTrace:

TypeError: Unable to get property 'length' of undefined or null reference
   at getSignatureFromDeclaration (:16096:33)
   at getSymbolDisplayPartsDocumentationAndSymbolKind (:44944:25)
   at getQuickInfoAtPosition (:45136:13)
   at Anonymous function (:48843:17)
   at simpleForwardCall (:48683:9)
   at forwardJSONCall (:48699:13)
   at forwardJSONCall (:48745:13)
   at getQuickInfoAtPosition (:48842:13)
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Sep 3, 2015
@weswigham
Copy link
Member

This happens with the following SyntaxKinds in the definition:

SyntaxKind.ConstructorType,
SyntaxKind.ConstructSignature,
SyntaxKind.IndexSignature,
SyntaxKind.CallSignature,
SyntaxKind.MethodSignature

Since all of those are 'isFunctionLike`, and are returned by getContainingFunction but are not the node on which that type parameter lies. (I believe)

Here's a comprehensive set of tests exposing the issues:

///<reference path="fourslash.ts" />

//// type Ctor<AA> = new () => A/*1*/A;
//// type MixinCtor<AA> = new () => AA & { constructor: MixinCtor<A/*2*/A> };
//// type NestedCtor<AA> = new() => AA & (new () => AA & { constructor: NestedCtor<A/*3*/A> });
//// type Method<AA> = { method(): A/*4*/A };
//// type Construct<AA> = { new(): A/*5*/A };
//// type Call<AA> = { (): A/*6*/A };
//// type Index<AA> = {[foo: string]: A/*7*/A};
//// type GenericMethod<AA> = { method<BB>(): A/*8*/A & B/*9*/B }

goTo.marker('1');
verify.quickInfoIs('(type parameter) AA in type Ctor<AA>');
goTo.marker('2');
verify.quickInfoIs('(type parameter) AA in type MixinCtor<AA>');
goTo.marker('3');
verify.quickInfoIs('(type parameter) AA in type NestedCtor<AA>');
goTo.marker('4');
verify.quickInfoIs('(type parameter) AA in type Method<AA>');
goTo.marker('5');
verify.quickInfoIs('(type parameter) AA in type Construct<AA>');
goTo.marker('6');
verify.quickInfoIs('(type parameter) AA in type Call<AA>');
goTo.marker('7');
verify.quickInfoIs('(type parameter) AA in type Index<AA>');
goTo.marker('8');
verify.quickInfoIs('(type parameter) AA in type GenericMethod<AA>');
goTo.marker('9');
verify.quickInfoIs('(type parameter) BB in method<BB>(): AA & BB');

The issue is on ~line 4228 of services.ts. We call getContainingFunction(location) when what we really want is something else. What we want to know if the type parameter is derived from its enclosing function or its enclosing type alias, and the presence of a containing function-like node is not enough information to determine that.

@weswigham
Copy link
Member

I also advise checking against the quick infos for this, in additon to those in the test above:

type Nesting<T> = {method<U>(): new <W>() => T & U & W};

On 4a85546 this errors on T (as above), U is correct, and claims W is on an anonymous function rather than a ctor (missing the new keyword). (Which is possibly a formatting bug for that kind of ctor type signature, but could be indicative of something else)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants