Skip to content

Commit fe126ea

Browse files
committed
Add tests for check order dependence
These tests record checker results that depend on the order in which files, declarations, and queries are checked, so that each later fix shows up as a reviewable baseline change. Most list several checkOrder variants; where the variants disagree, that disagreement is the bug. Some existing tests also gain the typesfirst order, as asking for types and symbols first changes what they report. The cases cover: - variance measured through cycles of recursive references, which depended on which type in the cycle was measured first (64891, and a reduction of the react-relay DefinitelyTyped tests); - circularities whose blamed location is whichever use resolved first: circular type parameter defaults and constraints, a cycle through namespace spreads, awaiting a promise that refers back to itself, and import elision computing types before checking; - instantiation limit and excessive depth errors, reported only in whichever file reached the limit first; - late-bound members, computed enum members, and aliased module.exports members, which differ when queried before checking; - relation results cached against truncated or in-progress comparisons; - the order of types in unions, which followed type ids, and so creation order, for object literals, rest types, indexed accesses, type parameters, and iterator method types; - return type cycles through callbacks and subtype reduction, JSDoc type tags on contextually typed functions, a scope whose thunks refer to the scope, a never narrowing after a loop, and a const assertion inferred before its binding pattern (seen in OmniRoute, effect, webpack, arktype, uglify-js, and check order fuzzing). The circularity tests from PR 64834 are copied unchanged, to compare against how that PR handles the same cases.
1 parent 105bdd3 commit fe126ea

501 files changed

Lines changed: 24464 additions & 17 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tsc/internal/testrunner/compiler_runner.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,21 @@ func (r *CompilerBaselineRunner) runTest(t *testing.T, filename string) {
167167
}
168168
}
169169

170+
// When a program checks its files on several checkers, these tests can see different results depending on which
171+
// checker answers a query first.
172+
var concurrentSkippedTests = map[string]string{
173+
"checkOrderCircularDefaults.ts": "Circular default results depend on which checker resolves the cycle first.",
174+
"checkOrderSpreadCycle.ts": "Spread cycle results depend on which checker resolves the cycle first.",
175+
"checkOrderStableInstantiationErrors.ts": "Instantiation limit errors depend on which checker instantiates first.",
176+
}
177+
170178
func (r *CompilerBaselineRunner) runSingleConfigTest(t *testing.T, testName string, test *compilerFileBasedTest, config *harnessutil.NamedTestConfiguration) {
171179
t.Parallel()
180+
if !testutil.TestProgramIsSingleThreaded() {
181+
if msg, ok := concurrentSkippedTests[tspath.GetBaseFileName(test.filename)]; ok {
182+
t.Skipf("Skipping in concurrent mode: %s", msg)
183+
}
184+
}
172185
defer testutil.RecoverAndFail(t, "Panic on compiler test "+test.filename)
173186

174187
payload := makeUnitsFromTest(test.content, test.filename)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
badExport.ts(1,10): error TS2304: Cannot find name 'foo'.
2+
badExport.ts(1,17): error TS1003: Identifier expected.
3+
badExport.ts(1,20): error TS1128: Declaration or statement expected.
4+
badExport2.ts(1,10): error TS1003: Identifier expected.
5+
badExport2.ts(1,16): error TS2304: Cannot find name 'foo'.
6+
badExport2.ts(1,20): error TS1128: Declaration or statement expected.
7+
badImport.ts(1,10): error TS1003: Identifier expected.
8+
badImport.ts(1,10): error TS1141: String literal expected.
9+
badImport.ts(1,20): error TS1128: Declaration or statement expected.
10+
badImport.ts(1,22): error TS1434: Unexpected keyword or identifier.
11+
badImport.ts(1,22): error TS2304: Cannot find name 'from'.
12+
badImport2.ts(1,17): error TS1003: Identifier expected.
13+
badImport2.ts(1,17): error TS1141: String literal expected.
14+
badImport2.ts(1,20): error TS1128: Declaration or statement expected.
15+
badImport2.ts(1,22): error TS1434: Unexpected keyword or identifier.
16+
badImport2.ts(1,22): error TS2304: Cannot find name 'from'.
17+
18+
19+
==== foo.ts (0 errors) ====
20+
const foo = 0n;
21+
export { foo as "0n" };
22+
23+
==== correctUse.ts (0 errors) ====
24+
import { "0n" as foo } from "./foo";
25+
export { foo as "0n" };
26+
27+
==== badImport.ts (5 errors) ====
28+
import { 0n as foo } from "./foo";
29+
~~
30+
!!! error TS1003: Identifier expected.
31+
~~~~~~~~~
32+
!!! error TS1141: String literal expected.
33+
~
34+
!!! error TS1128: Declaration or statement expected.
35+
~~~~
36+
!!! error TS1434: Unexpected keyword or identifier.
37+
~~~~
38+
!!! error TS2304: Cannot find name 'from'.
39+
40+
==== badImport2.ts (5 errors) ====
41+
import { foo as 0n } from "./foo";
42+
~~
43+
!!! error TS1003: Identifier expected.
44+
~~
45+
!!! error TS1141: String literal expected.
46+
~
47+
!!! error TS1128: Declaration or statement expected.
48+
~~~~
49+
!!! error TS1434: Unexpected keyword or identifier.
50+
~~~~
51+
!!! error TS2304: Cannot find name 'from'.
52+
53+
==== badExport.ts (3 errors) ====
54+
export { foo as 0n };
55+
~~~
56+
!!! error TS2304: Cannot find name 'foo'.
57+
~~
58+
!!! error TS1003: Identifier expected.
59+
~
60+
!!! error TS1128: Declaration or statement expected.
61+
62+
==== badExport2.ts (3 errors) ====
63+
export { 0n as foo };
64+
~~
65+
!!! error TS1003: Identifier expected.
66+
~~~
67+
!!! error TS2304: Cannot find name 'foo'.
68+
~
69+
!!! error TS1128: Declaration or statement expected.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] ////
2+
3+
//// [foo.ts]
4+
const foo = 0n;
5+
export { foo as "0n" };
6+
7+
//// [correctUse.ts]
8+
import { "0n" as foo } from "./foo";
9+
export { foo as "0n" };
10+
11+
//// [badImport.ts]
12+
import { 0n as foo } from "./foo";
13+
14+
//// [badImport2.ts]
15+
import { foo as 0n } from "./foo";
16+
17+
//// [badExport.ts]
18+
export { foo as 0n };
19+
20+
//// [badExport2.ts]
21+
export { 0n as foo };
22+
23+
//// [foo.js]
24+
const foo = 0n;
25+
export { foo as "0n" };
26+
//// [correctUse.js]
27+
import { "0n" as foo } from "./foo";
28+
export { foo as "0n" };
29+
//// [badImport.js]
30+
from;
31+
"./foo";
32+
export {};
33+
//// [badImport2.js]
34+
from;
35+
"./foo";
36+
export {};
37+
//// [badExport.js]
38+
export { foo as };
39+
0n;
40+
;
41+
//// [badExport2.js]
42+
0n;
43+
;
44+
export {};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] ////
2+
3+
=== foo.ts ===
4+
const foo = 0n;
5+
>foo : Symbol(foo, Decl(foo.ts, 0, 5))
6+
7+
export { foo as "0n" };
8+
>foo : Symbol(foo, Decl(foo.ts, 0, 5))
9+
>"0n" : Symbol("0n", Decl(foo.ts, 1, 8))
10+
11+
=== correctUse.ts ===
12+
import { "0n" as foo } from "./foo";
13+
>foo : Symbol(foo, Decl(correctUse.ts, 0, 8))
14+
15+
export { foo as "0n" };
16+
>foo : Symbol(foo, Decl(correctUse.ts, 0, 8))
17+
>"0n" : Symbol("0n", Decl(correctUse.ts, 1, 8))
18+
19+
=== badImport.ts ===
20+
import { 0n as foo } from "./foo";
21+
>foo : Symbol(foo)
22+
23+
=== badImport2.ts ===
24+
import { foo as 0n } from "./foo";
25+
> : Symbol((Missing), Decl(badImport2.ts, 0, 8))
26+
27+
=== badExport.ts ===
28+
export { foo as 0n };
29+
> : Symbol((Missing), Decl(badExport.ts, 0, 8))
30+
31+
=== badExport2.ts ===
32+
export { 0n as foo };
33+
>foo : Symbol(foo)
34+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] ////
2+
3+
=== foo.ts ===
4+
const foo = 0n;
5+
>foo : 0n
6+
>0n : 0n
7+
8+
export { foo as "0n" };
9+
>foo : 0n
10+
>"0n" : 0n
11+
12+
=== correctUse.ts ===
13+
import { "0n" as foo } from "./foo";
14+
>foo : 0n
15+
16+
export { foo as "0n" };
17+
>foo : 0n
18+
>"0n" : 0n
19+
20+
=== badImport.ts ===
21+
import { 0n as foo } from "./foo";
22+
>0n as foo : foo
23+
>0n : 0n
24+
>from : any
25+
>"./foo" : "./foo"
26+
27+
=== badImport2.ts ===
28+
import { foo as 0n } from "./foo";
29+
>foo : any
30+
> : any
31+
>from : any
32+
>"./foo" : "./foo"
33+
34+
=== badExport.ts ===
35+
export { foo as 0n };
36+
>foo : any
37+
> : any
38+
>0n : 0n
39+
40+
=== badExport2.ts ===
41+
export { 0n as foo };
42+
>0n as foo : foo
43+
>0n : 0n
44+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
badExport.ts(1,10): error TS2304: Cannot find name 'foo'.
2+
badExport.ts(1,17): error TS1003: Identifier expected.
3+
badExport.ts(1,20): error TS1128: Declaration or statement expected.
4+
badExport2.ts(1,10): error TS1003: Identifier expected.
5+
badExport2.ts(1,16): error TS2304: Cannot find name 'foo'.
6+
badExport2.ts(1,20): error TS1128: Declaration or statement expected.
7+
badImport.ts(1,10): error TS1003: Identifier expected.
8+
badImport.ts(1,10): error TS1141: String literal expected.
9+
badImport.ts(1,16): error TS2304: Cannot find name 'foo'.
10+
badImport.ts(1,20): error TS1128: Declaration or statement expected.
11+
badImport.ts(1,22): error TS1434: Unexpected keyword or identifier.
12+
badImport.ts(1,22): error TS2304: Cannot find name 'from'.
13+
badImport2.ts(1,17): error TS1003: Identifier expected.
14+
badImport2.ts(1,17): error TS1141: String literal expected.
15+
badImport2.ts(1,20): error TS1128: Declaration or statement expected.
16+
badImport2.ts(1,22): error TS1434: Unexpected keyword or identifier.
17+
badImport2.ts(1,22): error TS2304: Cannot find name 'from'.
18+
19+
20+
==== foo.ts (0 errors) ====
21+
const foo = 0n;
22+
export { foo as "0n" };
23+
24+
==== correctUse.ts (0 errors) ====
25+
import { "0n" as foo } from "./foo";
26+
export { foo as "0n" };
27+
28+
==== badImport.ts (6 errors) ====
29+
import { 0n as foo } from "./foo";
30+
~~
31+
!!! error TS1003: Identifier expected.
32+
~~~~~~~~~
33+
!!! error TS1141: String literal expected.
34+
~~~
35+
!!! error TS2304: Cannot find name 'foo'.
36+
~
37+
!!! error TS1128: Declaration or statement expected.
38+
~~~~
39+
!!! error TS1434: Unexpected keyword or identifier.
40+
~~~~
41+
!!! error TS2304: Cannot find name 'from'.
42+
43+
==== badImport2.ts (5 errors) ====
44+
import { foo as 0n } from "./foo";
45+
~~
46+
!!! error TS1003: Identifier expected.
47+
~~
48+
!!! error TS1141: String literal expected.
49+
~
50+
!!! error TS1128: Declaration or statement expected.
51+
~~~~
52+
!!! error TS1434: Unexpected keyword or identifier.
53+
~~~~
54+
!!! error TS2304: Cannot find name 'from'.
55+
56+
==== badExport.ts (3 errors) ====
57+
export { foo as 0n };
58+
~~~
59+
!!! error TS2304: Cannot find name 'foo'.
60+
~~
61+
!!! error TS1003: Identifier expected.
62+
~
63+
!!! error TS1128: Declaration or statement expected.
64+
65+
==== badExport2.ts (3 errors) ====
66+
export { 0n as foo };
67+
~~
68+
!!! error TS1003: Identifier expected.
69+
~~~
70+
!!! error TS2304: Cannot find name 'foo'.
71+
~
72+
!!! error TS1128: Declaration or statement expected.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] ////
2+
3+
//// [foo.ts]
4+
const foo = 0n;
5+
export { foo as "0n" };
6+
7+
//// [correctUse.ts]
8+
import { "0n" as foo } from "./foo";
9+
export { foo as "0n" };
10+
11+
//// [badImport.ts]
12+
import { 0n as foo } from "./foo";
13+
14+
//// [badImport2.ts]
15+
import { foo as 0n } from "./foo";
16+
17+
//// [badExport.ts]
18+
export { foo as 0n };
19+
20+
//// [badExport2.ts]
21+
export { 0n as foo };
22+
23+
//// [foo.js]
24+
const foo = 0n;
25+
export { foo as "0n" };
26+
//// [correctUse.js]
27+
import { "0n" as foo } from "./foo";
28+
export { foo as "0n" };
29+
//// [badImport.js]
30+
from;
31+
"./foo";
32+
export {};
33+
//// [badImport2.js]
34+
from;
35+
"./foo";
36+
export {};
37+
//// [badExport.js]
38+
export { foo as };
39+
0n;
40+
;
41+
//// [badExport2.js]
42+
0n;
43+
;
44+
export {};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] ////
2+
3+
=== foo.ts ===
4+
const foo = 0n;
5+
>foo : Symbol(foo, Decl(foo.ts, 0, 5))
6+
7+
export { foo as "0n" };
8+
>foo : Symbol(foo, Decl(foo.ts, 0, 5))
9+
>"0n" : Symbol("0n", Decl(foo.ts, 1, 8))
10+
11+
=== correctUse.ts ===
12+
import { "0n" as foo } from "./foo";
13+
>foo : Symbol(foo, Decl(correctUse.ts, 0, 8))
14+
15+
export { foo as "0n" };
16+
>foo : Symbol(foo, Decl(correctUse.ts, 0, 8))
17+
>"0n" : Symbol("0n", Decl(correctUse.ts, 1, 8))
18+
19+
=== badImport.ts ===
20+
import { 0n as foo } from "./foo";
21+
>foo : Symbol(foo)
22+
23+
=== badImport2.ts ===
24+
import { foo as 0n } from "./foo";
25+
> : Symbol((Missing), Decl(badImport2.ts, 0, 8))
26+
27+
=== badExport.ts ===
28+
export { foo as 0n };
29+
> : Symbol((Missing), Decl(badExport.ts, 0, 8))
30+
31+
=== badExport2.ts ===
32+
export { 0n as foo };
33+
>foo : Symbol(foo)
34+

0 commit comments

Comments
 (0)