Skip to content

Commit 39ed3b8

Browse files
committed
Accept changes from new tests
1 parent edd66e5 commit 39ed3b8

9 files changed

+461
-72
lines changed

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt

+38-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(1,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
2-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(99,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
3-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(107,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
4-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(112,16): error TS2378: A 'get' accessor must return a value.
5-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(134,15): error TS18050: The value 'undefined' cannot be used here.
6-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(135,5): error TS1003: Identifier expected.
1+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(1,16): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
2+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(99,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
3+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(107,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
4+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(120,7): error TS2322: Type '() => void' is not assignable to type '() => number'.
5+
Type 'void' is not assignable to type 'number'.
6+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(124,7): error TS2322: Type '() => void' is not assignable to type '() => number'.
7+
Type 'void' is not assignable to type 'number'.
8+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(130,16): error TS2378: A 'get' accessor must return a value.
9+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(152,15): error TS18050: The value 'undefined' cannot be used here.
10+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(153,5): error TS1003: Identifier expected.
711

812

9-
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (6 errors) ====
13+
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (8 errors) ====
1014
function f1(): string {
1115
~~~~~~
12-
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
16+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
1317
// errors because there are no return statements
1418
}
1519

@@ -109,7 +113,7 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(135,5): e
109113

110114
function f21(): number | string {
111115
~~~~~~~~~~~~~~~
112-
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
116+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
113117
// Not okay; union does not contain void or any
114118
}
115119

@@ -119,10 +123,34 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(135,5): e
119123

120124
function f23(): undefined | number {
121125
~~~~~~~~~~~~~~~~~~
122-
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
126+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
123127
// Error; because `undefined | number` becomes `number` without strictNullChecks.
124128
}
125129

130+
const f30: () => undefined = () => {
131+
// Ok, contextual type for implicit return is `undefined`
132+
}
133+
134+
const f31: () => undefined = () => {
135+
// Ok, contextual type for expression-less return is `undefined`
136+
return;
137+
}
138+
139+
const f32: () => undefined | number = () => {
140+
~~~
141+
!!! error TS2322: Type '() => void' is not assignable to type '() => number'.
142+
!!! error TS2322: Type 'void' is not assignable to type 'number'.
143+
// Error, contextual type for implicit return isn't just `undefined`
144+
}
145+
146+
const f33: () => undefined | number = () => {
147+
~~~
148+
!!! error TS2322: Type '() => void' is not assignable to type '() => number'.
149+
!!! error TS2322: Type 'void' is not assignable to type 'number'.
150+
// Error, contextual type for expression-less return isn't just `undefined`
151+
return;
152+
}
153+
126154
class C {
127155
public get m1() {
128156
~~

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js

+32
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ function f23(): undefined | number {
109109
// Error; because `undefined | number` becomes `number` without strictNullChecks.
110110
}
111111

112+
const f30: () => undefined = () => {
113+
// Ok, contextual type for implicit return is `undefined`
114+
}
115+
116+
const f31: () => undefined = () => {
117+
// Ok, contextual type for expression-less return is `undefined`
118+
return;
119+
}
120+
121+
const f32: () => undefined | number = () => {
122+
// Error, contextual type for implicit return isn't just `undefined`
123+
}
124+
125+
const f33: () => undefined | number = () => {
126+
// Error, contextual type for expression-less return isn't just `undefined`
127+
return;
128+
}
129+
112130
class C {
113131
public get m1() {
114132
// Errors; get accessors must return a value.
@@ -224,6 +242,20 @@ function f22() {
224242
function f23() {
225243
// Error; because `undefined | number` becomes `number` without strictNullChecks.
226244
}
245+
var f30 = function () {
246+
// Ok, contextual type for implicit return is `undefined`
247+
};
248+
var f31 = function () {
249+
// Ok, contextual type for expression-less return is `undefined`
250+
return;
251+
};
252+
var f32 = function () {
253+
// Error, contextual type for implicit return isn't just `undefined`
254+
};
255+
var f33 = function () {
256+
// Error, contextual type for expression-less return isn't just `undefined`
257+
return;
258+
};
227259
var C = /** @class */ (function () {
228260
function C() {
229261
}

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.symbols

+32-6
Original file line numberDiff line numberDiff line change
@@ -164,37 +164,63 @@ function f23(): undefined | number {
164164
// Error; because `undefined | number` becomes `number` without strictNullChecks.
165165
}
166166

167+
const f30: () => undefined = () => {
168+
>f30 : Symbol(f30, Decl(functionsMissingReturnStatementsAndExpressions.ts, 110, 5))
169+
170+
// Ok, contextual type for implicit return is `undefined`
171+
}
172+
173+
const f31: () => undefined = () => {
174+
>f31 : Symbol(f31, Decl(functionsMissingReturnStatementsAndExpressions.ts, 114, 5))
175+
176+
// Ok, contextual type for expression-less return is `undefined`
177+
return;
178+
}
179+
180+
const f32: () => undefined | number = () => {
181+
>f32 : Symbol(f32, Decl(functionsMissingReturnStatementsAndExpressions.ts, 119, 5))
182+
183+
// Error, contextual type for implicit return isn't just `undefined`
184+
}
185+
186+
const f33: () => undefined | number = () => {
187+
>f33 : Symbol(f33, Decl(functionsMissingReturnStatementsAndExpressions.ts, 123, 5))
188+
189+
// Error, contextual type for expression-less return isn't just `undefined`
190+
return;
191+
}
192+
167193
class C {
168-
>C : Symbol(C, Decl(functionsMissingReturnStatementsAndExpressions.ts, 108, 1))
194+
>C : Symbol(C, Decl(functionsMissingReturnStatementsAndExpressions.ts, 126, 1))
169195

170196
public get m1() {
171-
>m1 : Symbol(C.m1, Decl(functionsMissingReturnStatementsAndExpressions.ts, 110, 9))
197+
>m1 : Symbol(C.m1, Decl(functionsMissingReturnStatementsAndExpressions.ts, 128, 9))
172198

173199
// Errors; get accessors must return a value.
174200
}
175201

176202
public get m2() {
177-
>m2 : Symbol(C.m2, Decl(functionsMissingReturnStatementsAndExpressions.ts, 113, 5))
203+
>m2 : Symbol(C.m2, Decl(functionsMissingReturnStatementsAndExpressions.ts, 131, 5))
178204

179205
// Permissible; returns undefined.
180206
return;
181207
}
182208

183209
public get m3() {
184-
>m3 : Symbol(C.m3, Decl(functionsMissingReturnStatementsAndExpressions.ts, 118, 5))
210+
>m3 : Symbol(C.m3, Decl(functionsMissingReturnStatementsAndExpressions.ts, 136, 5))
185211

186212
return "Okay, because this is a return expression.";
187213
}
188214

189215
public get m4() {
190-
>m4 : Symbol(C.m4, Decl(functionsMissingReturnStatementsAndExpressions.ts, 122, 5))
216+
>m4 : Symbol(C.m4, Decl(functionsMissingReturnStatementsAndExpressions.ts, 140, 5))
191217

192218
// Fine since this consists of a single throw statement.
193219
throw null;
194220
}
195221

196222
public get m5() {
197-
>m5 : Symbol(C.m5, Decl(functionsMissingReturnStatementsAndExpressions.ts, 127, 5))
223+
>m5 : Symbol(C.m5, Decl(functionsMissingReturnStatementsAndExpressions.ts, 145, 5))
198224

199225
// Not fine, since we can *only* consist of a single throw statement
200226
// if no return statements are present but we are a get accessor.

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.types

+30
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,36 @@ function f23(): undefined | number {
166166
// Error; because `undefined | number` becomes `number` without strictNullChecks.
167167
}
168168

169+
const f30: () => undefined = () => {
170+
>f30 : () => undefined
171+
>() => { // Ok, contextual type for implicit return is `undefined`} : () => undefined
172+
173+
// Ok, contextual type for implicit return is `undefined`
174+
}
175+
176+
const f31: () => undefined = () => {
177+
>f31 : () => undefined
178+
>() => { // Ok, contextual type for expression-less return is `undefined` return;} : () => undefined
179+
180+
// Ok, contextual type for expression-less return is `undefined`
181+
return;
182+
}
183+
184+
const f32: () => undefined | number = () => {
185+
>f32 : () => undefined | number
186+
>() => { // Error, contextual type for implicit return isn't just `undefined`} : () => void
187+
188+
// Error, contextual type for implicit return isn't just `undefined`
189+
}
190+
191+
const f33: () => undefined | number = () => {
192+
>f33 : () => undefined | number
193+
>() => { // Error, contextual type for expression-less return isn't just `undefined` return;} : () => void
194+
195+
// Error, contextual type for expression-less return isn't just `undefined`
196+
return;
197+
}
198+
169199
class C {
170200
>C : C
171201

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,88 @@
1-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(5,16): error TS2847: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
2-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(13,22): error TS2847: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
1+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(5,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
2+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(9,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
3+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(17,7): error TS2322: Type '() => void' is not assignable to type '() => number | undefined'.
4+
Type 'void' is not assignable to type 'number | undefined'.
5+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(21,7): error TS2322: Type '() => void' is not assignable to type '() => number'.
6+
Type 'void' is not assignable to type 'number'.
7+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(29,23): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
8+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(33,23): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
9+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts(52,3): error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => undefined'.
10+
Type 'void' is not assignable to type 'undefined'.
311

412

5-
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts (2 errors) ====
6-
function f1(): undefined | number {
7-
// Okay; return type allows implicit return of undefined
13+
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts (7 errors) ====
14+
function f10(): undefined {
15+
// Ok, return type allows implicit return of undefined
816
}
917

10-
function f2(): number {
11-
~~~~~~
12-
!!! error TS2847: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
13-
// Error; return type does not include undefined
18+
function f11(): undefined | number {
19+
~~~~~~~~~~~~~~~~~~
20+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
21+
// Error, return type isn't just undefined
1422
}
1523

16-
async function f3(): Promise<undefined | number> {
17-
// Okay; return type allows implicit return of undefined
24+
function f12(): number {
25+
~~~~~~
26+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
27+
// Error, return type doesn't include undefined
1828
}
1929

20-
async function f4(): Promise<number> {
21-
~~~~~~~~~~~~~~~
22-
!!! error TS2847: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
23-
// Error; return type does not include undefined
30+
const f20: () => undefined = () => {
31+
// Ok, contextual type for implicit return is undefined
2432
}
33+
34+
const f21: () => undefined | number = () => {
35+
~~~
36+
!!! error TS2322: Type '() => void' is not assignable to type '() => number | undefined'.
37+
!!! error TS2322: Type 'void' is not assignable to type 'number | undefined'.
38+
// Regular void function because contextual type for implicit return isn't just undefined
39+
}
40+
41+
const f22: () => number = () => {
42+
~~~
43+
!!! error TS2322: Type '() => void' is not assignable to type '() => number'.
44+
!!! error TS2322: Type 'void' is not assignable to type 'number'.
45+
// Regular void function because contextual type for implicit return isn't just undefined
46+
}
47+
48+
async function f30(): Promise<undefined> {
49+
// Ok, return type allows implicit return of undefined
50+
}
51+
52+
async function f31(): Promise<undefined | number> {
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
55+
// Error, return type isn't just undefined
56+
}
57+
58+
async function f32(): Promise<number> {
59+
~~~~~~~~~~~~~~~
60+
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
61+
// Error, return type doesn't include undefined
62+
}
63+
64+
// Examples from #36288
65+
66+
declare function f(a: () => undefined): void;
67+
68+
f(() => { });
69+
70+
f((): undefined => { });
71+
72+
const g1: () => undefined = () => { };
73+
74+
const g2 = (): undefined => { };
75+
76+
function h1() {
77+
}
78+
79+
f(h1); // Error
80+
~~
81+
!!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '() => undefined'.
82+
!!! error TS2345: Type 'void' is not assignable to type 'undefined'.
83+
84+
function h2(): undefined {
85+
}
86+
87+
f(h2);
2588

0 commit comments

Comments
 (0)