Skip to content

Interchanging identical classes with generics causes Maximum call stack size exceeded #17148

Closed
@MarcusLongmuir

Description

@MarcusLongmuir

TypeScript Version: 2.4.1 and latest (2.5.0-dev.20170712) nightly. Not present in 2.4.0 (is a regression)

Code

class Foo {
  myFunc<T extends Foo>(arg: T) {}
}

class Bar {
  myFunc<T extends Bar>(arg: T) {}
}

const myVar: Foo = new Bar();

Expected behavior:
Should compile without error as it does on 2.4.0.

Actual behavior:

.../node_modules/typescript/lib/typescript.js:1553
                if (!callback(array[i], i)) {
                     ^
RangeError: Maximum call stack size exceeded
    at Object.every (.../node_modules/typescript/lib/typescript.js:1553:22)
    at isWeakType (.../node_modules/typescript/lib/typescript.js:35348:28)
    at isRelatedTo (.../node_modules/typescript/lib/typescript.js:34803:21)
    at checkTypeRelatedTo (.../node_modules/typescript/lib/typescript.js:34697:26)
    at isTypeRelatedTo (.../node_modules/typescript/lib/typescript.js:34673:24)
    at isTypeAssignableTo (.../node_modules/typescript/lib/typescript.js:34373:20)
    at getInferredType (.../node_modules/typescript/lib/typescript.js:36490:26)
    at getInferredTypes (.../node_modules/typescript/lib/typescript.js:36500:29)
    at instantiateSignatureInContextOf (.../node_modules/typescript/lib/typescript.js:40435:57)
    at compareSignaturesRelated (.../node_modules/typescript/lib/typescript.js:34423:26)

The example is rather contrived, but I arrived at this reproduction case by stripping away an entire library in which package A has a dependency installed that package B also has installed; in that case the class from the dependency is identical and package A expects to be able to call into package B, but to simplify the reproduction I've made two classes that are identical in all but name and it seems to result in the same error.

This seems related to #16533, #16221, and #15926, however those issues are present in 2.4.0 whereas this is not.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions