Skip to content

Compiler runs out of memory when this types are added to Array<T> methods #9707

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
sandersn opened this issue Jul 13, 2016 · 2 comments · Fixed by #10234
Closed

Compiler runs out of memory when this types are added to Array<T> methods #9707

sandersn opened this issue Jul 13, 2016 · 2 comments · Fixed by #10234
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@sandersn
Copy link
Member

sandersn commented Jul 13, 2016

TypeScript Version: master

Code

  1. In es5.d.ts, add this: this parameters to all Array methods
  2. Run inferringAnyFunctionType2 (reproduced below)
function f<T extends [(p1: number) => number]>(p: T): T {
    return p;
}

var v = f([x => x]);

Expected behavior:
The test passes

Actual behavior:
TypeScript runs out of memory.

It looks as if something about instantiating this types in a constraint evades the relation cache and keeps instantiating types. This might have something to do with the special handling of arrays and tuples, because I can't get the failure to repro when switching to a non built-in type.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 13, 2016
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.0.1 milestone Aug 1, 2016
@sandersn
Copy link
Member Author

sandersn commented Aug 8, 2016

Here is a self-contained repro thanks to @vladima, who showed me how to modify Array in a test file:

/// <reference no-default-lib="true"/>

interface Boolean {}
interface IArguments {}
interface Function {}
interface Number {}
interface RegExp {}
interface Object {}
declare class String { charCodeAt(a: number): number }

interface Array<T> {
    map<U>(arg: this): void;
    reduceRight<U>(arg: this): void;
    reduce<U>(arg: this): void;
    reduce2<U>(arg: this): void;
}

declare function f<T extends [(x: number) => number]>(a: T): void;
f([String.prototype.charCodeAt])

The bug still happens when you comment out all but one of the remaining Array methods, but it doesn't run out of memory until there are four of them.

@sandersn
Copy link
Member Author

Fix is up at #10234

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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

Successfully merging a pull request may close this issue.

3 participants