Skip to content

Always call resolveErrorCall on overload failure to ensure subexpressions are checked #36745

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
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24899,7 +24899,9 @@ namespace ts {
}
}

return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
const resultSignature = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
resolveErrorCall(node); // Ensure that even if there's an arity error, subexpressions are checked
return resultSignature;

function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false) {
candidatesForArgumentError = undefined;
Expand Down
8 changes: 7 additions & 1 deletion tests/baselines/reference/baseCheck.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
tests/cases/compiler/baseCheck.ts(9,18): error TS2552: Cannot find name 'loc'. Did you mean 'ELoc'?
tests/cases/compiler/baseCheck.ts(17,53): error TS2554: Expected 2 arguments, but got 1.
tests/cases/compiler/baseCheck.ts(17,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(18,62): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'.
tests/cases/compiler/baseCheck.ts(19,68): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'.
tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'.
tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.


==== tests/cases/compiler/baseCheck.ts (7 errors) ====
==== tests/cases/compiler/baseCheck.ts (9 errors) ====
class C { constructor(x: number, y: number) { } }
class ELoc extends C {
constructor(x: number) {
Expand All @@ -31,12 +33,16 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
~~~~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
!!! related TS6210 tests/cases/compiler/baseCheck.ts:1:34: An argument for 'y' was not provided.
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
class E extends C { constructor(public z: number) { super(0, this.z) } }
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type
~~~~~~~
!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'.
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.

function f() {
if (x<10) {
Expand Down
14 changes: 13 additions & 1 deletion tests/baselines/reference/grammarAmbiguities1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
tests/cases/compiler/grammarAmbiguities1.ts(8,3): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
tests/cases/compiler/grammarAmbiguities1.ts(8,10): error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
tests/cases/compiler/grammarAmbiguities1.ts(8,10): error TS2554: Expected 1 arguments, but got 2.
tests/cases/compiler/grammarAmbiguities1.ts(9,3): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2554: Expected 1 arguments, but got 2.


==== tests/cases/compiler/grammarAmbiguities1.ts (2 errors) ====
==== tests/cases/compiler/grammarAmbiguities1.ts (6 errors) ====
class A { foo() { } }
class B { bar() { }}
function f(x) { return x; }
Expand All @@ -11,9 +15,17 @@ tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2554: Expected 1 argu

f(g<A, B>(7));
f(g < A, B > 7);
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
~~~~~
!!! error TS2554: Expected 1 arguments, but got 2.
f(g < A, B > +(7));
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
~~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 2.

Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,13 @@ var r7 = map<number, string>([1, ""], (x) => x.toString()); // error
>r7 : Symbol(r7, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 9, 3))
>map : Symbol(map, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 0, 0))
>x : Symbol(x, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 9, 39))
>x.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 9, 39))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

var r7b = map<number>([1, ""], (x) => x.toString()); // error
>r7b : Symbol(r7b, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 10, 3))
>map : Symbol(map, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 0, 0))
>x : Symbol(x, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 10, 32))
>x.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 10, 32))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

var r8 = map<any, string>([1, ""], (x) => x.toString());
>r8 : Symbol(r8, Decl(mismatchedExplicitTypeParameterAndArgumentType.ts, 11, 3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ var r7 = map<number, string>([1, ""], (x) => x.toString()); // error
>[1, ""] : (string | number)[]
>1 : 1
>"" : ""
>(x) => x.toString() : (x: number) => string
>x : number
>x.toString() : string
>x.toString : (radix?: number) => string
>x : number
>toString : (radix?: number) => string
>(x) => x.toString() : (x: any) => any
>x : any
>x.toString() : any
>x.toString : any
>x : any
>toString : any

var r7b = map<number>([1, ""], (x) => x.toString()); // error
>r7b : unknown[]
Expand All @@ -91,12 +91,12 @@ var r7b = map<number>([1, ""], (x) => x.toString()); // error
>[1, ""] : (string | number)[]
>1 : 1
>"" : ""
>(x) => x.toString() : (x: number) => string
>x : number
>x.toString() : string
>x.toString : (radix?: number) => string
>x : number
>toString : (radix?: number) => string
>(x) => x.toString() : (x: any) => any
>x : any
>x.toString() : any
>x.toString : any
>x : any
>toString : any

var r8 = map<any, string>([1, ""], (x) => x.toString());
>r8 : string[]
Expand Down
8 changes: 7 additions & 1 deletion tests/baselines/reference/noImplicitAnyLoopCrash.errors.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,16): error TS2556: Expected 0 arguments, but got 1 or more.
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'number' is not an array type.
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'undefined' is not an array type.


==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (1 errors) ====
==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (3 errors) ====
let foo = () => {};
let bar;
while (1) {
bar = ~foo(...bar);
~~~~~~
!!! error TS2556: Expected 0 arguments, but got 1 or more.
~~~
!!! error TS2461: Type 'number' is not an array type.
~~~
!!! error TS2461: Type 'undefined' is not an array type.
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class C {
>2 : 2
>3 : 3
>map : <U>(callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[]
>(x) => { return this; } : (x: number) => this
>x : number
>(x) => { return this; } : (x: any) => this
>x : any
>this : this
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ g("", 3, a => a);
>g : <T>(a: T, b: T, c: (t: T) => T) => T
>"" : ""
>3 : 3
>a => a : (a: "") => ""
>a : ""
>a : ""
>a => a : (a: any) => any
>a : any
>a : any

5 changes: 4 additions & 1 deletion tests/baselines/reference/undeclaredModuleError.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
tests/cases/compiler/undeclaredModuleError.ts(1,21): error TS2307: Cannot find module 'fs'.
tests/cases/compiler/undeclaredModuleError.ts(8,29): error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: any, name: string) => boolean'.
Type 'void' is not assignable to type 'boolean'.
tests/cases/compiler/undeclaredModuleError.ts(11,41): error TS2304: Cannot find name 'IDoNotExist'.


==== tests/cases/compiler/undeclaredModuleError.ts (2 errors) ====
==== tests/cases/compiler/undeclaredModuleError.ts (3 errors) ====
import fs = require('fs');
~~~~
!!! error TS2307: Cannot find module 'fs'.
Expand All @@ -20,6 +21,8 @@ tests/cases/compiler/undeclaredModuleError.ts(8,29): error TS2345: Argument of t
} , (error: Error, files: {}[]) => {
files.forEach((file) => {
var fullPath = join(IDoNotExist);
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'IDoNotExist'.
} );
} );
} );
Expand Down