Skip to content

Fix crash due to unchecked cast in addImplementationSuccessElaboration #41017

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

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27335,7 +27335,7 @@ namespace ts {

const declCount = length(failed.declaration?.symbol.declarations);
const isOverload = declCount > 1;
const implDecl = isOverload ? find(failed.declaration?.symbol.declarations || emptyArray, d => nodeIsPresent((d as FunctionLikeDeclaration).body)) : undefined;
const implDecl = isOverload ? find(failed.declaration?.symbol.declarations || emptyArray, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
if (implDecl) {
const candidate = getSignatureFromDeclaration(implDecl as FunctionLikeDeclaration);
const isSingleNonGenericCandidate = !candidate.typeParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
tests/cases/compiler/index.ts(3,3): error TS2769: No overload matches this call.
Overload 1 of 2, '(opts?: Whatever): void', gave the following error.
Argument of type 'number' is not assignable to parameter of type 'Whatever'.
Overload 2 of 2, '(cb: Function, opts?: Whatever): void', gave the following error.
Argument of type 'number' is not assignable to parameter of type 'Function'.


==== tests/cases/compiler/index.ts (1 errors) ====
import X = require("./file");

X(0); // shouldn't cause a crash
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(opts?: Whatever): void', gave the following error.
!!! error TS2769: Argument of type 'number' is not assignable to parameter of type 'Whatever'.
!!! error TS2769: Overload 2 of 2, '(cb: Function, opts?: Whatever): void', gave the following error.
!!! error TS2769: Argument of type 'number' is not assignable to parameter of type 'Function'.
==== tests/cases/compiler/file.d.ts (0 errors) ====
declare namespace Foo {
interface Whatever {
prop: any;
}
}

declare function Foo(opts?: Foo.Whatever): void;
declare function Foo(cb: Function, opts?: Foo.Whatever): void;

export = Foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [tests/cases/compiler/namespaceMergedWithFunctionWithOverloadsUsage.ts] ////

//// [file.d.ts]
declare namespace Foo {
interface Whatever {
prop: any;
}
}

declare function Foo(opts?: Foo.Whatever): void;
declare function Foo(cb: Function, opts?: Foo.Whatever): void;

export = Foo;
//// [index.ts]
import X = require("./file");

X(0); // shouldn't cause a crash

//// [index.js]
"use strict";
exports.__esModule = true;
var X = require("./file");
X(0); // shouldn't cause a crash
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/compiler/index.ts ===
import X = require("./file");
>X : Symbol(X, Decl(index.ts, 0, 0))

X(0); // shouldn't cause a crash
>X : Symbol(X, Decl(index.ts, 0, 0))

=== tests/cases/compiler/file.d.ts ===
declare namespace Foo {
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))

interface Whatever {
>Whatever : Symbol(Whatever, Decl(file.d.ts, 0, 23))

prop: any;
>prop : Symbol(Whatever.prop, Decl(file.d.ts, 1, 24))
}
}

declare function Foo(opts?: Foo.Whatever): void;
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))
>opts : Symbol(opts, Decl(file.d.ts, 6, 21))
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))
>Whatever : Symbol(Foo.Whatever, Decl(file.d.ts, 0, 23))

declare function Foo(cb: Function, opts?: Foo.Whatever): void;
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))
>cb : Symbol(cb, Decl(file.d.ts, 7, 21))
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>opts : Symbol(opts, Decl(file.d.ts, 7, 34))
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))
>Whatever : Symbol(Foo.Whatever, Decl(file.d.ts, 0, 23))

export = Foo;
>Foo : Symbol(Foo, Decl(file.d.ts, 4, 1), Decl(file.d.ts, 6, 48), Decl(file.d.ts, 0, 0))

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/index.ts ===
import X = require("./file");
>X : { (opts?: X.Whatever): void; (cb: Function, opts?: X.Whatever): void; }

X(0); // shouldn't cause a crash
>X(0) : void
>X : { (opts?: X.Whatever): void; (cb: Function, opts?: X.Whatever): void; }
>0 : 0

=== tests/cases/compiler/file.d.ts ===
declare namespace Foo {
interface Whatever {
prop: any;
>prop : any
}
}

declare function Foo(opts?: Foo.Whatever): void;
>Foo : { (opts?: Foo.Whatever): void; (cb: Function, opts?: Foo.Whatever): void; }
>opts : Foo.Whatever
>Foo : any

declare function Foo(cb: Function, opts?: Foo.Whatever): void;
>Foo : { (opts?: Foo.Whatever): void; (cb: Function, opts?: Foo.Whatever): void; }
>cb : Function
>opts : Foo.Whatever
>Foo : any

export = Foo;
>Foo : { (opts?: Foo.Whatever): void; (cb: Function, opts?: Foo.Whatever): void; }

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @filename: file.d.ts
declare namespace Foo {
interface Whatever {
prop: any;
}
}

declare function Foo(opts?: Foo.Whatever): void;
declare function Foo(cb: Function, opts?: Foo.Whatever): void;

export = Foo;
// @filename: index.ts
import X = require("./file");

X(0); // shouldn't cause a crash