Skip to content

Commit 43691b1

Browse files
committed
Adding test
1 parent c9a3ea6 commit 43691b1

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

tests/baselines/reference/controlFlowLoopAnalysis.errors.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,23 @@ tests/cases/compiler/controlFlowLoopAnalysis.ts(13,25): error TS2345: Argument o
3636
}
3737
}
3838
}
39+
40+
// Repro from #8511
41+
42+
function mapUntilCant<a, b>(
43+
values: a[],
44+
canTake: (value: a, index: number) => boolean,
45+
mapping: (value: a, index: number) => b
46+
): b[] {
47+
let result: b[] = [];
48+
for (let index = 0, length = values.length; index < length; index++) {
49+
let value = values[index];
50+
if (canTake(value, index)) {
51+
result.push(mapping(value, index));
52+
} else {
53+
return result;
54+
}
55+
}
56+
return result;
57+
}
3958

tests/baselines/reference/controlFlowLoopAnalysis.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ function test2() {
2929
}
3030
}
3131
}
32+
33+
// Repro from #8511
34+
35+
function mapUntilCant<a, b>(
36+
values: a[],
37+
canTake: (value: a, index: number) => boolean,
38+
mapping: (value: a, index: number) => b
39+
): b[] {
40+
let result: b[] = [];
41+
for (let index = 0, length = values.length; index < length; index++) {
42+
let value = values[index];
43+
if (canTake(value, index)) {
44+
result.push(mapping(value, index));
45+
} else {
46+
return result;
47+
}
48+
}
49+
return result;
50+
}
3251

3352

3453
//// [controlFlowLoopAnalysis.js]
@@ -56,3 +75,17 @@ function test2() {
5675
}
5776
}
5877
}
78+
// Repro from #8511
79+
function mapUntilCant(values, canTake, mapping) {
80+
var result = [];
81+
for (var index = 0, length = values.length; index < length; index++) {
82+
var value = values[index];
83+
if (canTake(value, index)) {
84+
result.push(mapping(value, index));
85+
}
86+
else {
87+
return result;
88+
}
89+
}
90+
return result;
91+
}

tests/cases/compiler/controlFlowLoopAnalysis.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @strictNullChecks: true
2+
// @noImplicitAny: true
23

34
// Repro from #8418
45

@@ -29,3 +30,22 @@ function test2() {
2930
}
3031
}
3132
}
33+
34+
// Repro from #8511
35+
36+
function mapUntilCant<a, b>(
37+
values: a[],
38+
canTake: (value: a, index: number) => boolean,
39+
mapping: (value: a, index: number) => b
40+
): b[] {
41+
let result: b[] = [];
42+
for (let index = 0, length = values.length; index < length; index++) {
43+
let value = values[index];
44+
if (canTake(value, index)) {
45+
result.push(mapping(value, index));
46+
} else {
47+
return result;
48+
}
49+
}
50+
return result;
51+
}

0 commit comments

Comments
 (0)