Skip to content

Callstack exceeded in typescript @ next #27142

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
paulvanbrenk opened this issue Sep 17, 2018 · 7 comments · Fixed by #27161
Closed

Callstack exceeded in typescript @ next #27142

paulvanbrenk opened this issue Sep 17, 2018 · 7 comments · Fixed by #27161
Assignees
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue

Comments

@paulvanbrenk
Copy link
Contributor

I haven't been able to reproduce using a small repro, but when I remove the jsdoc-s from all of our enums the issue goes away. Further this started happening when I removed an invalid type from the jsdocs.

original code:

    /**
     * @enum {String} Renderer2dEnums.LineEndCapStyle
     * Indicates how the end points of every line are drawn.
     * See *[CanvasRendering2dContext.lineCap property][1]* for more.
     *
     * [1]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.lineCap
     */
    export const enum LineEndCapStyle
    {
        /** Ends of lines are squared off at endpoints */
        BUTT,

        /** Ends of lines are rounded */
        ROUND,

        /** Ends of lines are squared off by adding a box with an equal
         * width and half the height of the line's thickness */
        SQUARE
    }

Fix invalid type, which causes callstack issue:

    /**
     * @enum Renderer2dEnums.LineEndCapStyle
     * Indicates how the end points of every line are drawn.
     * See *[CanvasRendering2dContext.lineCap property][1]* for more.
     *
     * [1]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.lineCap
     */
    export const enum LineEndCapStyle
    {
        /** Ends of lines are squared off at endpoints */
        BUTT,

        /** Ends of lines are rounded */
        ROUND,

        /** Ends of lines are squared off by adding a box with an equal
         * width and half the height of the line's thickness */
        SQUARE
    }

Code that compiles without issue:

    /**
     * Indicates how the end points of every line are drawn.
     * See *[CanvasRendering2dContext.lineCap property][1]* for more.
     *
     * [1]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.lineCap
     */
    export const enum LineEndCapStyle
    {
        /** Ends of lines are squared off at endpoints */
        BUTT,

        /** Ends of lines are rounded */
        ROUND,

        /** Ends of lines are squared off by adding a box with an equal
         * width and half the height of the line's thickness */
        SQUARE
    }

Stack:

Using tsc v3.1.0-dev.20180915
c:\src\oven\node_modules\typescript\lib\tsc.js:69191
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at isSelfReferenceLocation (c:\src\oven\node_modules\typescript\lib\tsc.js:25741:41)
    at resolveNameHelper (c:\src\oven\node_modules\typescript\lib\tsc.js:25664:21)
    at resolveName (c:\src\oven\node_modules\typescript\lib\tsc.js:25496:20)
    at resolveEntityName (c:\src\oven\node_modules\typescript\lib\tsc.js:26184:26)
    at resolveEntityName (c:\src\oven\node_modules\typescript\lib\tsc.js:26192:33)
    at resolveTypeReferenceName (c:\src\oven\node_modules\typescript\lib\tsc.js:31180:20)
    at getTypeFromTypeReference (c:\src\oven\node_modules\typescript\lib\tsc.js:31338:30)
    at getTypeFromTypeNode (c:\src\oven\node_modules\typescript\lib\tsc.js:32602:28)
    at getTypeFromTypeNode (c:\src\oven\node_modules\typescript\lib\tsc.js:32627:28)
    at getTypeReferenceType (c:\src\oven\node_modules\typescript\lib\tsc.js:31193:49)
@ghost
Copy link

ghost commented Sep 17, 2018

@paulvanbrenk Any chance you could reproduce using node --stack-trace-limit=100 path/to/tsc.js? Hard to tell what the recursion is here.
#27076 Should have made it so the @enum tag has no effect in TS, but there may be other locations we forgot about. CC @sandersn

@paulvanbrenk
Copy link
Contributor Author

sure thing.... I cut of the output after the 4rd repetition:

RangeError: Maximum call stack size exceeded
    at resolveNameHelper (tsc.js:25569:38)
    at resolveName (tsc.js:25496:20)
    at resolveEntityName (tsc.js:26184:26)
    at resolveEntityName (tsc.js:26192:33)
    at resolveTypeReferenceName (tsc.js:31180:20)
    at getTypeFromTypeReference (tsc.js:31338:30)
    at getTypeFromTypeNode (tsc.js:32602:28)
    at getTypeFromTypeNode (tsc.js:32627:28)
    at getTypeReferenceType (tsc.js:31193:49)
    at getTypeFromTypeReference (tsc.js:31339:28)
    at getTypeFromTypeNode (tsc.js:32602:28)
    at getTypeFromTypeNode (tsc.js:32627:28)
    at getTypeReferenceType (tsc.js:31193:49)
    at getTypeFromTypeReference (tsc.js:31339:28)
    at getTypeFromTypeNode (tsc.js:32602:28)
    at getTypeFromTypeNode (tsc.js:32627:28)
    at getTypeReferenceType (tsc.js:31193:49)
    at getTypeFromTypeReference (tsc.js:31339:28)
    at getTypeFromTypeNode (tsc.js:32602:28)
    at getTypeFromTypeNode (tsc.js:32627:28)
    at getTypeReferenceType (tsc.js:31193:49)
    at getTypeFromTypeReference (tsc.js:31339:28)
    at getTypeFromTypeNode (tsc.js:32602:28)
    at getTypeFromTypeNode (tsc.js:32627:28)
    at getTypeReferenceType (tsc.js:31193:49)

@ghost
Copy link

ghost commented Sep 17, 2018

Thanks, I can reproduce this with:

/** @enum {E} */
const E = { x: 0 };

in JS. Don't have a TS repro but I notice that the code for const enumTag in getTypeReferenceType isn't guarded by testing whether we're in JS.

@ghost ghost assigned sandersn Sep 17, 2018
@ghost ghost added Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically Salsa checkJs Relates to checking JavaScript using TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation labels Sep 17, 2018
@paulvanbrenk
Copy link
Contributor Author

Thanks for the quick investigation @Andy-MS, as this would block us from adapting TS 3.1.

@sandersn
Copy link
Member

I have a fix, although it seems like it's abusing our existing circularity detection infrastructure. I'll send it out after I add a new error message.

@sandersn
Copy link
Member

Note that with checkJs on, my fix will add a new error "Enum type 'LineEndCapStyle' circularly references itself", because @enum's format is /** @enum {typeOfMembers} */, not /** @enum {EnumsNameAgain} */

@sandersn sandersn added the Fixed A PR has been merged for this issue label Sep 17, 2018
@paulvanbrenk
Copy link
Contributor Author

Thanks @Andy-MS and @sandersn this fixes my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants