Skip to content
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

Crash from tricky generics #908

Closed
tomblind opened this issue Jul 26, 2020 · 4 comments
Closed

Crash from tricky generics #908

tomblind opened this issue Jul 26, 2020 · 4 comments
Labels
bug scope: transformation Transformation of TS to Lua

Comments

@tomblind
Copy link
Collaborator

I was playing with generics and managed to crash TSTL. Here's my attempt at boiling it down to an isolated repro:

type Foo<A extends unknown[]> = (fn: (...args: A) => void) => void;

export function bar<A extends Foo<[]>[]>(...args: A) {
    type X = A extends Foo<infer T>[] ? Foo<T[]> : never;
    return (fn => {}) as X;
}

And here's the error:

TypeError: Cannot read property 'kind' of undefined
    at Object.parenthesizeArrayTypeMember (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:74192:24)
    at Object.createArrayTypeNode (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:70459:31)
    at typeReferenceToTypeNode (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:38969:44)
    at typeToTypeNodeHelper (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:38766:95)
    at serializeTypeForDeclaration (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:39870:30)
    at symbolToParameterDeclaration (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:39357:41)
    at node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:39305:101
    at Array.map (<anonymous>)
    at signatureToSignatureDeclarationHelper (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:39305:67)
    at createTypeNodeFromObjectType (node_modules/typescript-to-lua/node_modules/typescript/lib/typescript.js:38944:49)

Normal TS doesn't seem to have a problem with it, so it's TSTL-specific.

@Perryvw Perryvw added bug scope: transformation Transformation of TS to Lua labels Jul 27, 2020
@tomblind
Copy link
Collaborator Author

tomblind commented Aug 19, 2021

Additional info:
Tracing into TS leads to a return statement generating the offending undefined value with a comment that points to this issue: microsoft/TypeScript#18217
The offending line is here: https://github.dev/microsoft/TypeScript/blob/main/src/compiler/checker.ts#L5095

@tomblind
Copy link
Collaborator Author

Minimalist repro:

type Foo = (fn: (...args: [][]) => void) => void;
const foo: Foo = (bar => {});

It appears to be triggered by the vararg type of empty tuples (...args: [][]). The error occurs calling typeToTypeNode on the the type of the initializer (bar => {}).

Error:

Exception has occurred: TypeError: Cannot read property 'kind' of undefined
  at Object.parenthesizeElementTypeOfArrayType (node_modules\typescript\lib\typescript.js:20825:28)
    at Object.createArrayTypeNode (node_modules\typescript\lib\typescript.js:22343:53)
    at typeReferenceToTypeNode (node_modules\typescript\lib\typescript.js:49344:52)
    at typeToTypeNodeHelper (node_modules\typescript\lib\typescript.js:49085:95)
    at serializeTypeForDeclaration (node_modules\typescript\lib\typescript.js:50323:30)
    at symbolToParameterDeclaration (node_modules\typescript\lib\typescript.js:49803:41)
    at node_modules\typescript\lib\typescript.js:49725:263
    at Array.map (<anonymous>)
    at signatureToSignatureDeclarationHelper (node_modules\typescript\lib\typescript.js:49725:229)
    at createTypeNodeFromObjectType (node_modules\typescript\lib\typescript.js:49296:49)

@tomblind
Copy link
Collaborator Author

TS Issue

@Perryvw
Copy link
Member

Perryvw commented Feb 26, 2023

No longer reproduces

@Perryvw Perryvw closed this as completed Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug scope: transformation Transformation of TS to Lua
Projects
None yet
Development

No branches or pull requests

2 participants