diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4cc0bb7953184..874b1c9c16499 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6807,7 +6807,7 @@ namespace ts { // Record a new minimum argument count if this is not an optional parameter const isOptionalParameter = param.initializer || param.questionToken || param.dotDotDotToken || - iife && parameters.length > iife.arguments.length && !param.type || + iife && parameters.length > iife.arguments.length && !param.type || param.type && param.type.kind === SyntaxKind.VoidKeyword || isJSDocOptionalParameter(param) || isUntypedSignatureInJSFile; if (!isOptionalParameter) { diff --git a/tests/baselines/reference/functionCallWithVoidParameter.errors.txt b/tests/baselines/reference/functionCallWithVoidParameter.errors.txt new file mode 100644 index 0000000000000..c80294ac45c1f --- /dev/null +++ b/tests/baselines/reference/functionCallWithVoidParameter.errors.txt @@ -0,0 +1,57 @@ +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(17,1): error TS2554: Expected 1-2 arguments, but got 0. +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(22,1): error TS2554: Expected 2 arguments, but got 0. +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(23,1): error TS2554: Expected 2 arguments, but got 1. +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(24,1): error TS2554: Expected 2 arguments, but got 1. +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(29,1): error TS2554: Expected 2 arguments, but got 0. +tests/cases/conformance/functions/functionCallWithVoidParameter.ts(30,1): error TS2554: Expected 2 arguments, but got 1. + + +==== tests/cases/conformance/functions/functionCallWithVoidParameter.ts (6 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) { } + + f1(1); + f1(1, void 0); + f2(); + f2(void 0); + f3(void 0, 1); + f4(1); + f4(void 0); + f5() + ~~~~ +!!! error TS2554: Expected 1-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); + \ No newline at end of file diff --git a/tests/baselines/reference/functionCallWithVoidParameter.js b/tests/baselines/reference/functionCallWithVoidParameter.js new file mode 100644 index 0000000000000..7ac60e7d5594e --- /dev/null +++ b/tests/baselines/reference/functionCallWithVoidParameter.js @@ -0,0 +1,73 @@ +//// [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) { } + +f1(1); +f1(1, void 0); +f2(); +f2(void 0); +f3(void 0, 1); +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); + + +//// [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) { } +f1(1); +f1(1, void 0); +f2(); +f2(void 0); +f3(void 0, 1); +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); diff --git a/tests/baselines/reference/functionCallWithVoidParameter.symbols b/tests/baselines/reference/functionCallWithVoidParameter.symbols new file mode 100644 index 0000000000000..6e210181825ab --- /dev/null +++ b/tests/baselines/reference/functionCallWithVoidParameter.symbols @@ -0,0 +1,117 @@ +=== 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, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 0, 23)) + +function f2 (a: void) { } +>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 36)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 1, 13)) + +function f3 (a: void, b: number) { } +>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 25)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 2, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 2, 21)) + +function f4 (a: number | void) { } +>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 3, 13)) + +function f5 (a: number | void, b: void) { } +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 4, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 4, 30)) + +function f6 (a: number | void, b: number | void) { } +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 5, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 5, 30)) + +function f7 (a: void, b: number | void) { } +>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 6, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 6, 21)) + +function f8 (a: void, b: void) { } +>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43)) +>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 7, 13)) +>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 7, 21)) + +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, 36)) + +f2(void 0); +>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 36)) + +f3(void 0, 1); +>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 25)) + +f4(1); +>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36)) + +f4(void 0); +>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36)) + +f5() +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) + +f5(1) +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) + +f5(1, void 0); +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) + +f5(void 0, void 0); +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) + +f5(void 0); +>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34)) + +f6(); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(1); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(void 0); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(1, 1); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(1, void 0); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(void 0, void 0); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f6(void 0, 1); +>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43)) + +f7(); +>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52)) + +f7(void 0); +>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52)) + +f7(void 0, 1); +>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52)) + +f7(void 0, void 0); +>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52)) + +f8(); +>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43)) + +f8(void 0); +>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43)) + +f8(void 0, void 0); +>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43)) + diff --git a/tests/baselines/reference/functionCallWithVoidParameter.types b/tests/baselines/reference/functionCallWithVoidParameter.types new file mode 100644 index 0000000000000..d74210b50a431 --- /dev/null +++ b/tests/baselines/reference/functionCallWithVoidParameter.types @@ -0,0 +1,195 @@ +=== tests/cases/conformance/functions/functionCallWithVoidParameter.ts === +function f1 (a: number, b: void) { } +>f1 : (a: number, b: void) => void +>a : number +>b : void + +function f2 (a: void) { } +>f2 : (a: void) => void +>a : void + +function f3 (a: void, b: number) { } +>f3 : (a: void, b: number) => void +>a : void +>b : number + +function f4 (a: number | void) { } +>f4 : (a: number | void) => void +>a : number | void + +function f5 (a: number | void, b: void) { } +>f5 : (a: number | void, b: void) => void +>a : number | void +>b : void + +function f6 (a: number | void, b: number | void) { } +>f6 : (a: number | void, b: number | void) => void +>a : number | void +>b : number | void + +function f7 (a: void, b: number | void) { } +>f7 : (a: void, b: number | void) => void +>a : void +>b : number | void + +function f8 (a: void, b: void) { } +>f8 : (a: void, b: void) => void +>a : void +>b : void + +f1(1); +>f1(1) : void +>f1 : (a: number, b: void) => void +>1 : 1 + +f1(1, void 0); +>f1(1, void 0) : void +>f1 : (a: number, b: void) => void +>1 : 1 +>void 0 : undefined +>0 : 0 + +f2(); +>f2() : void +>f2 : (a: void) => void + +f2(void 0); +>f2(void 0) : void +>f2 : (a: void) => void +>void 0 : undefined +>0 : 0 + +f3(void 0, 1); +>f3(void 0, 1) : void +>f3 : (a: void, b: number) => void +>void 0 : undefined +>0 : 0 +>1 : 1 + +f4(1); +>f4(1) : void +>f4 : (a: number | void) => void +>1 : 1 + +f4(void 0); +>f4(void 0) : void +>f4 : (a: number | void) => void +>void 0 : undefined +>0 : 0 + +f5() +>f5() : void +>f5 : (a: number | void, b: void) => void + +f5(1) +>f5(1) : void +>f5 : (a: number | void, b: void) => void +>1 : 1 + +f5(1, void 0); +>f5(1, void 0) : void +>f5 : (a: number | void, b: void) => void +>1 : 1 +>void 0 : undefined +>0 : 0 + +f5(void 0, void 0); +>f5(void 0, void 0) : void +>f5 : (a: number | void, b: void) => void +>void 0 : undefined +>0 : 0 +>void 0 : undefined +>0 : 0 + +f5(void 0); +>f5(void 0) : void +>f5 : (a: number | void, b: void) => void +>void 0 : undefined +>0 : 0 + +f6(); +>f6() : void +>f6 : (a: number | void, b: number | void) => void + +f6(1); +>f6(1) : void +>f6 : (a: number | void, b: number | void) => void +>1 : 1 + +f6(void 0); +>f6(void 0) : void +>f6 : (a: number | void, b: number | void) => void +>void 0 : undefined +>0 : 0 + +f6(1, 1); +>f6(1, 1) : void +>f6 : (a: number | void, b: number | void) => void +>1 : 1 +>1 : 1 + +f6(1, void 0); +>f6(1, void 0) : void +>f6 : (a: number | void, b: number | void) => void +>1 : 1 +>void 0 : undefined +>0 : 0 + +f6(void 0, void 0); +>f6(void 0, void 0) : void +>f6 : (a: number | void, b: number | void) => void +>void 0 : undefined +>0 : 0 +>void 0 : undefined +>0 : 0 + +f6(void 0, 1); +>f6(void 0, 1) : void +>f6 : (a: number | void, b: number | void) => void +>void 0 : undefined +>0 : 0 +>1 : 1 + +f7(); +>f7() : void +>f7 : (a: void, b: number | void) => void + +f7(void 0); +>f7(void 0) : void +>f7 : (a: void, b: number | void) => void +>void 0 : undefined +>0 : 0 + +f7(void 0, 1); +>f7(void 0, 1) : void +>f7 : (a: void, b: number | void) => void +>void 0 : undefined +>0 : 0 +>1 : 1 + +f7(void 0, void 0); +>f7(void 0, void 0) : void +>f7 : (a: void, b: number | void) => void +>void 0 : undefined +>0 : 0 +>void 0 : undefined +>0 : 0 + +f8(); +>f8() : void +>f8 : (a: void, b: void) => void + +f8(void 0); +>f8(void 0) : void +>f8 : (a: void, b: void) => void +>void 0 : undefined +>0 : 0 + +f8(void 0, void 0); +>f8(void 0, void 0) : void +>f8 : (a: void, b: void) => void +>void 0 : undefined +>0 : 0 +>void 0 : undefined +>0 : 0 + diff --git a/tests/cases/conformance/functions/functionCallWithVoidParameter.ts b/tests/cases/conformance/functions/functionCallWithVoidParameter.ts new file mode 100644 index 0000000000000..4af900e4ec234 --- /dev/null +++ b/tests/cases/conformance/functions/functionCallWithVoidParameter.ts @@ -0,0 +1,35 @@ +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) { } + +f1(1); +f1(1, void 0); +f2(); +f2(void 0); +f3(void 0, 1); +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);