Skip to content
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
14 changes: 13 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16335,8 +16335,20 @@ namespace ts {
return false;
}

let optionParametersCount = 0;
if (!signature.hasRestParameter) {
const len = signature.parameters.length;
for (let i = len - 1; i >= 0; i--) {
const type = getTypeAtPosition(signature, i);
if (type.flags !== TypeFlags.Void) {
break;
}
optionParametersCount++;
}
}

// If the call is incomplete, we should skip the lower bound check.
const hasEnoughArguments = argCount >= signature.minArgumentCount;
const hasEnoughArguments = argCount >= (signature.minArgumentCount - optionParametersCount);
return callIsIncomplete || hasEnoughArguments;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/arrayFrom.types
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const inputALike: ArrayLike<A> = { length: 0 };
const inputARand = getEither(inputA, inputALike);
>inputARand : ArrayLike<A> | Iterable<A>
>getEither(inputA, inputALike) : ArrayLike<A> | Iterable<A>
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => Iterable<T> | ArrayLike<T>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know why they swapped

>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => ArrayLike<T> | Iterable<T>
>inputA : A[]
>inputALike : ArrayLike<A>

Expand Down Expand Up @@ -153,7 +153,7 @@ const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
// even when the type is written as : Iterable<T>|ArrayLike<T>
function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => Iterable<T> | ArrayLike<T>
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => ArrayLike<T> | Iterable<T>
>T : T
>in1 : Iterable<T>
>Iterable : Iterable<T>
Expand All @@ -163,7 +163,7 @@ function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
>T : T

return Math.random() > 0.5 ? in1 : in2;
>Math.random() > 0.5 ? in1 : in2 : Iterable<T> | ArrayLike<T>
>Math.random() > 0.5 ? in1 : in2 : ArrayLike<T> | Iterable<T>
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
Expand Down
71 changes: 71 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(16,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(19,1): error TS2554: Expected 2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(24,1): error TS2554: Expected 2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(25,1): error TS2554: Expected 2 arguments, but got 1.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(26,1): error TS2554: Expected 2 arguments, but got 1.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(31,1): error TS2554: Expected 2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(32,1): error TS2554: Expected 2 arguments, but got 1.


==== tests/cases/conformance/functions/functionCallWithVoidParameter.ts (7 errors) ====
function f1(a: number, b: void) { }
function f2(a: void) { }
function f3(a: void, b: number) { }
function f4(a: number | void) { }
function f5(a: number | void, b: void) { }
function f6(a: number | void, b: number | void) { }
function f7(a: void, b: number | void) { }
function f8(a: void, b: void) { }
function f9<T, U>(a: T, b: U) {}

f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4();
~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
f4(1);
f4(void 0);
f5();
~~~~
!!! error TS2554: Expected 2 arguments, but got 0.
f5(1);
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
~~~~
!!! error TS2554: Expected 2 arguments, but got 0.
f6(1);
~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f6(void 0);
~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
~~~~
!!! error TS2554: Expected 2 arguments, but got 0.
f7(void 0);
~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);

class X<T>
{
f(t: T) { return { a: t }; }
}

var x2: X<void>;
const t2b = x2.f();
t2b.a = void 0;

95 changes: 95 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//// [functionCallWithVoidParameter.ts]
function f1(a: number, b: void) { }
function f2(a: void) { }
function f3(a: void, b: number) { }
function f4(a: number | void) { }
function f5(a: number | void, b: void) { }
function f6(a: number | void, b: number | void) { }
function f7(a: void, b: number | void) { }
function f8(a: void, b: void) { }
function f9<T, U>(a: T, b: U) {}

f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4();
f4(1);
f4(void 0);
f5();
f5(1);
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
f6(1);
f6(void 0);
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
f7(void 0);
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);

class X<T>
{
f(t: T) { return { a: t }; }
}

var x2: X<void>;
const t2b = x2.f();
t2b.a = void 0;


//// [functionCallWithVoidParameter.js]
function f1(a, b) { }
function f2(a) { }
function f3(a, b) { }
function f4(a) { }
function f5(a, b) { }
function f6(a, b) { }
function f7(a, b) { }
function f8(a, b) { }
function f9(a, b) { }
f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4();
f4(1);
f4(void 0);
f5();
f5(1);
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
f6(1);
f6(void 0);
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
f7(void 0);
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);
var X = /** @class */ (function () {
function X() {
}
X.prototype.f = function (t) { return { a: t }; };
return X;
}());
var x2;
var t2b = x2.f();
t2b.a = void 0;
156 changes: 156 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
=== tests/cases/conformance/functions/functionCallWithVoidParameter.ts ===
function f1(a: number, b: void) { }
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 0, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 0, 22))

function f2(a: void) { }
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 35))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 1, 12))

function f3(a: void, b: number) { }
>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 24))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 2, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 2, 20))

function f4(a: number | void) { }
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 35))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 3, 12))

function f5(a: number | void, b: void) { }
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 4, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 4, 29))

function f6(a: number | void, b: number | void) { }
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 5, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 5, 29))

function f7(a: void, b: number | void) { }
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 51))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 6, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 6, 20))

function f8(a: void, b: void) { }
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 42))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 7, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 7, 20))

function f9<T, U>(a: T, b: U) {}
>f9 : Symbol(f9, Decl(functionCallWithVoidParameter.ts, 7, 33))
>T : Symbol(T, Decl(functionCallWithVoidParameter.ts, 8, 12))
>U : Symbol(U, Decl(functionCallWithVoidParameter.ts, 8, 14))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 8, 18))
>T : Symbol(T, Decl(functionCallWithVoidParameter.ts, 8, 12))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 8, 23))
>U : Symbol(U, Decl(functionCallWithVoidParameter.ts, 8, 14))

f1(1);
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))

f1(1, void 0);
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))

f2();
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 35))

f2(void 0);
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 35))

f3(void 0, 1);
>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 24))

f4();
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 35))

f4(1);
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 35))

f4(void 0);
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 35))

f5();
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))

f5(1);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))

f5(1, void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))

f5(void 0, void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))

f5(void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 33))

f6();
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(1, 1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(1, void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(void 0, void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f6(void 0, 1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 42))

f7();
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 51))

f7(void 0);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 51))

f7(void 0, 1);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 51))

f7(void 0, void 0);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 51))

f8();
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 42))

f8(void 0);
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 42))

f8(void 0, void 0);
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 42))

class X<T>
>X : Symbol(X, Decl(functionCallWithVoidParameter.ts, 36, 19))
>T : Symbol(T, Decl(functionCallWithVoidParameter.ts, 38, 8))
{
f(t: T) { return { a: t }; }
>f : Symbol(X.f, Decl(functionCallWithVoidParameter.ts, 39, 1))
>t : Symbol(t, Decl(functionCallWithVoidParameter.ts, 40, 6))
>T : Symbol(T, Decl(functionCallWithVoidParameter.ts, 38, 8))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 40, 22))
>t : Symbol(t, Decl(functionCallWithVoidParameter.ts, 40, 6))
}

var x2: X<void>;
>x2 : Symbol(x2, Decl(functionCallWithVoidParameter.ts, 43, 3))
>X : Symbol(X, Decl(functionCallWithVoidParameter.ts, 36, 19))

const t2b = x2.f();
>t2b : Symbol(t2b, Decl(functionCallWithVoidParameter.ts, 44, 5))
>x2.f : Symbol(X.f, Decl(functionCallWithVoidParameter.ts, 39, 1))
>x2 : Symbol(x2, Decl(functionCallWithVoidParameter.ts, 43, 3))
>f : Symbol(X.f, Decl(functionCallWithVoidParameter.ts, 39, 1))

t2b.a = void 0;
>t2b.a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 40, 22))
>t2b : Symbol(t2b, Decl(functionCallWithVoidParameter.ts, 44, 5))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 40, 22))

Loading