Skip to content

Commit d58b1f6

Browse files
authored
mark error type in baselines very not-aggressively (microsoft#26346)
1 parent 56bac29 commit d58b1f6

File tree

84 files changed

+320
-270
lines changed

Some content is hidden

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

84 files changed

+320
-270
lines changed

src/harness/harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ namespace Harness {
14881488
!errors || (errors.length === 0) ? null : getErrorBaseline(inputFiles, errors, pretty));
14891489
}
14901490

1491-
export function doTypeAndSymbolBaseline(baselinePath: string, program: ts.Program, allFiles: {unitName: string, content: string}[], opts?: Baseline.BaselineOptions, multifile?: boolean, skipTypeBaselines?: boolean, skipSymbolBaselines?: boolean) {
1491+
export function doTypeAndSymbolBaseline(baselinePath: string, program: ts.Program, allFiles: {unitName: string, content: string}[], opts?: Baseline.BaselineOptions, multifile?: boolean, skipTypeBaselines?: boolean, skipSymbolBaselines?: boolean, hasErrorBaseline?: boolean) {
14921492
// The full walker simulates the types that you would get from doing a full
14931493
// compile. The pull walker simulates the types you get when you just do
14941494
// a type query for a random node (like how the LS would do it). Most of the
@@ -1504,7 +1504,7 @@ namespace Harness {
15041504
// These types are equivalent, but depend on what order the compiler observed
15051505
// certain parts of the program.
15061506

1507-
const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true);
1507+
const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true, !!hasErrorBaseline);
15081508

15091509
// Produce baselines. The first gives the types for all expressions.
15101510
// The second gives symbols for all identifiers.

src/harness/typeWriter.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TypeWriterWalker {
2525

2626
private checker: ts.TypeChecker;
2727

28-
constructor(private program: ts.Program, fullTypeCheck: boolean) {
28+
constructor(private program: ts.Program, fullTypeCheck: boolean, private hadErrorBaseline: boolean) {
2929
// Consider getting both the diagnostics checker and the non-diagnostics checker to verify
3030
// they are consistent.
3131
this.checker = fullTypeCheck
@@ -69,6 +69,26 @@ class TypeWriterWalker {
6969
}
7070
}
7171

72+
private isImportStatementName(node: ts.Node) {
73+
if (ts.isImportSpecifier(node.parent) && (node.parent.name === node || node.parent.propertyName === node)) return true;
74+
if (ts.isImportClause(node.parent) && node.parent.name === node) return true;
75+
if (ts.isImportEqualsDeclaration(node.parent) && node.parent.name === node) return true;
76+
return false;
77+
}
78+
79+
private isExportStatementName(node: ts.Node) {
80+
if (ts.isExportAssignment(node.parent) && node.parent.expression === node) return true;
81+
if (ts.isExportSpecifier(node.parent) && (node.parent.name === node || node.parent.propertyName === node)) return true;
82+
return false;
83+
}
84+
85+
private isIntrinsicJsxTag(node: ts.Node) {
86+
const p = node.parent;
87+
if (!(ts.isJsxOpeningElement(p) || ts.isJsxClosingElement(p) || ts.isJsxSelfClosingElement(p))) return false;
88+
if (p.tagName !== node) return false;
89+
return ts.isIntrinsicJsxName(node.getText());
90+
}
91+
7292
private writeTypeOrSymbol(node: ts.Node, isSymbolWalk: boolean): TypeWriterResult | undefined {
7393
const actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
7494
const lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
@@ -85,7 +105,31 @@ class TypeWriterWalker {
85105
// let type = this.checker.getTypeAtLocation(node);
86106
let type = ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent) ? this.checker.getTypeAtLocation(node.parent) : undefined;
87107
if (!type || type.flags & ts.TypeFlags.Any) type = this.checker.getTypeAtLocation(node);
88-
const typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
108+
const typeString =
109+
// Distinguish `errorType`s from `any`s; but only if the file has no errors.
110+
// Additionally,
111+
// * the LHS of a qualified name
112+
// * a binding pattern name
113+
// * labels
114+
// * the "global" in "declare global"
115+
// * the "target" in "new.target"
116+
// * names in import statements
117+
// * type-only names in export statements
118+
// * and intrinsic jsx tag names
119+
// return `error`s via `getTypeAtLocation`
120+
// But this is generally expected, so we don't call those out, either
121+
(!this.hadErrorBaseline &&
122+
type.flags & ts.TypeFlags.Any &&
123+
!ts.isBindingElement(node.parent) &&
124+
!ts.isPropertyAccessOrQualifiedName(node.parent) &&
125+
!ts.isLabelName(node) &&
126+
!(ts.isModuleDeclaration(node.parent) && ts.isGlobalScopeAugmentation(node.parent)) &&
127+
!ts.isMetaProperty(node.parent) &&
128+
!this.isImportStatementName(node) &&
129+
!this.isExportStatementName(node) &&
130+
!this.isIntrinsicJsxTag(node)) ?
131+
(type as ts.IntrinsicType).intrinsicName :
132+
this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
89133
return {
90134
line: lineAndCharacter.line,
91135
syntaxKind: node.kind,

src/testRunner/compilerRunner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ class CompilerTest {
253253
Harness.Compiler.doTypeAndSymbolBaseline(
254254
this.justName,
255255
this.result.program!,
256-
this.toBeCompiled.concat(this.otherFiles).filter(file => !!this.result.program!.getSourceFile(file.unitName)));
256+
this.toBeCompiled.concat(this.otherFiles).filter(file => !!this.result.program!.getSourceFile(file.unitName)),
257+
/*opts*/ undefined,
258+
/*multifile*/ undefined,
259+
/*skipTypeBaselines*/ undefined,
260+
/*skipSymbolBaselines*/ undefined,
261+
!!ts.length(this.result.diagnostics)
262+
);
257263
}
258264

259265
private makeUnitName(name: string, root: string) {

tests/baselines/reference/acceptableAlias1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module M {
66
}
77
export import X = N;
88
>X : any
9-
>N : any
9+
>N : error
1010
}
1111

1212
import r = M.X;

tests/baselines/reference/aliasInaccessibleModule.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ module M {
66
}
77
export import X = N;
88
>X : any
9-
>N : any
9+
>N : error
1010
}

tests/baselines/reference/checkJsFiles_skipDiagnostics.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ var x = 0;
66

77
/// @ts-ignore
88
x();
9-
>x() : any
9+
>x() : error
1010
>x : number
1111

1212
/// @ts-ignore
1313
x();
14-
>x() : any
14+
>x() : error
1515
>x : number
1616

1717
/// @ts-ignore
1818
x(
19-
>x( 2, 3) : any
19+
>x( 2, 3) : error
2020
>x : number
2121

2222
2,
@@ -34,13 +34,13 @@ x(
3434
// @another
3535

3636
x();
37-
>x() : any
37+
>x() : error
3838
>x : number
3939

4040

4141

4242
// @ts-ignore: no call signature
4343
x();
44-
>x() : any
44+
>x() : error
4545
>x : number
4646

tests/baselines/reference/declarationEmitNameConflictsWithAlias.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export module C { export interface I { } }
33
export import v = C;
44
>v : any
5-
>C : any
5+
>C : error
66

77
export module M {
88
>M : typeof M

tests/baselines/reference/doubleUnderscoreReactNamespace.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ declare var __foot: any;
1111
>__foot : any
1212

1313
const thing = <__foot />;
14-
>thing : any
15-
><__foot /> : any
14+
>thing : error
15+
><__foot /> : error
1616
>__foot : any
1717

1818
export {}

tests/baselines/reference/duplicateVarAndImport.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ var a;
77
module M { }
88
import a = M;
99
>a : any
10-
>M : any
10+
>M : error
1111

tests/baselines/reference/es3-jsx-preserve.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const React: any = null;
44
>null : null
55

66
const elem = <div></div>;
7-
>elem : any
8-
><div></div> : any
7+
>elem : error
8+
><div></div> : error
99
>div : any
1010
>div : any
1111

tests/baselines/reference/es3-jsx-react-native.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const React: any = null;
44
>null : null
55

66
const elem = <div></div>;
7-
>elem : any
8-
><div></div> : any
7+
>elem : error
8+
><div></div> : error
99
>div : any
1010
>div : any
1111

tests/baselines/reference/es3-jsx-react.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const React: any = null;
44
>null : null
55

66
const elem = <div></div>;
7-
>elem : any
8-
><div></div> : any
7+
>elem : error
8+
><div></div> : error
99
>div : any
1010
>div : any
1111

tests/baselines/reference/exportImportNonInstantiatedModule.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module B {
99

1010
export import A1 = A
1111
>A1 : any
12-
>A : any
12+
>A : error
1313

1414
}
1515

tests/baselines/reference/importHelpersInTsx.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ declare var o: any;
66
>o : any
77

88
export const x = <span {...o} />
9-
>x : any
10-
><span {...o} /> : any
9+
>x : error
10+
><span {...o} /> : error
1111
>span : any
1212
>o : any
1313

@@ -19,8 +19,8 @@ declare var o: any;
1919
>o : any
2020

2121
const x = <span {...o} />
22-
>x : any
23-
><span {...o} /> : any
22+
>x : error
23+
><span {...o} /> : error
2424
>span : any
2525
>o : any
2626

tests/baselines/reference/importUsedInGenericImportResolves.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export declare const theme: { a: string }
1212
=== tests/cases/compiler/test3.ts ===
1313
export const a: import("./test1").T<typeof import("./test2").theme> = null as any;
1414
>a : import("tests/cases/compiler/test1").T<{ a: string; }>
15-
>theme : any
15+
>theme : error
1616
>null as any : any
1717
>null : null
1818

tests/baselines/reference/importedModuleClassNameClash.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/importedModuleClassNameClash.ts ===
22
import foo = m1;
33
>foo : typeof foo
4-
>m1 : any
4+
>m1 : error
55

66
export module m1 { }
77

tests/baselines/reference/indexingTypesWithNever.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ declare function genericFn3<
6969

7070
// Should be never
7171
const result5 = genericFn3({ g: "gtest", h: "htest" }, "g", "h"); // 'g' & 'h' will reduce to never
72-
>result5 : any
73-
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : any
72+
>result5 : error
73+
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : error
7474
>genericFn3 : <T extends { [K in keyof T]: T[K]; }, U extends keyof T, V extends keyof T>(obj: T, u: U, v: V) => T[U & V]
7575
>{ g: "gtest", h: "htest" } : { g: string; h: string; }
7676
>g : string

tests/baselines/reference/inlineJsxFactoryDeclarations.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as React from "./renderer";
2828
>React : typeof React
2929

3030
<h></h>
31-
><h></h> : any
31+
><h></h> : error
3232
>h : any
3333
>h : any
3434

@@ -39,8 +39,8 @@ import { dom as h } from "./renderer"
3939
>h : () => void
4040

4141
export const prerendered = <h></h>;
42-
>prerendered : any
43-
><h></h> : any
42+
>prerendered : error
43+
><h></h> : error
4444
>h : () => void
4545
>h : () => void
4646

@@ -50,8 +50,8 @@ import { otherdom } from "./renderer"
5050
>otherdom : () => void
5151

5252
export const prerendered2 = <h></h>;
53-
>prerendered2 : any
54-
><h></h> : any
53+
>prerendered2 : error
54+
><h></h> : error
5555
>h : any
5656
>h : any
5757

@@ -60,8 +60,8 @@ import React from "./renderer"
6060
>React : () => void
6161

6262
export const prerendered3 = <h></h>;
63-
>prerendered3 : any
64-
><h></h> : any
63+
>prerendered3 : error
64+
><h></h> : error
6565
>h : any
6666
>h : any
6767

@@ -71,7 +71,7 @@ import { dom } from "./renderer"
7171
>dom : () => void
7272

7373
<h></h>
74-
><h></h> : any
74+
><h></h> : error
7575
>h : any
7676
>h : any
7777

tests/baselines/reference/inlineJsxFactoryOverridesCompilerOption.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {dom} from "./renderer";
2222
>dom : () => void
2323

2424
<h></h>
25-
><h></h> : any
25+
><h></h> : error
2626
>h : any
2727
>h : any
2828

@@ -31,7 +31,7 @@ import { p } from "./renderer";
3131
>p : () => void
3232

3333
<h></h>
34-
><h></h> : any
34+
><h></h> : error
3535
>h : any
3636
>h : any
3737

tests/baselines/reference/internalImportUnInstantiatedModuleNotReferencingInstanceNoConflict.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ module B {
1313

1414
import Y = A;
1515
>Y : any
16-
>A : any
16+
>A : error
1717
}
1818

tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function () {
1515
c: A.b = 1,
1616
>c : number
1717
>A.b = 1 : 1
18-
>A.b : any
18+
>A.b : error
1919
>A : typeof A
2020
>b : any
2121
>1 : 1

tests/baselines/reference/jsFileClassSelfReferencedProperty.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export class StackOverflowTest {
44

55
constructor () {
66
this.testStackOverflow = this.testStackOverflow.bind(this)
7-
>this.testStackOverflow = this.testStackOverflow.bind(this) : any
7+
>this.testStackOverflow = this.testStackOverflow.bind(this) : error
88
>this.testStackOverflow : any
99
>this : this
1010
>testStackOverflow : any
11-
>this.testStackOverflow.bind(this) : any
11+
>this.testStackOverflow.bind(this) : error
1212
>this.testStackOverflow.bind : any
1313
>this.testStackOverflow : any
1414
>this : this
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/compiler/a.js ===
22
@internal class C { }
3-
>internal : any
3+
>internal : error
44
>C : C
55

0 commit comments

Comments
 (0)