Skip to content

Commit aa58dcb

Browse files
committed
Adding noErrorTruncation compiler option
1 parent 9f3d83a commit aa58dcb

17 files changed

+86
-33
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ module ts {
3737

3838
var emptyArray: any[] = [];
3939
var emptySymbols: SymbolTable = {};
40-
40+
41+
var compilerOptions = program.getCompilerOptions();
42+
4143
var checker: TypeChecker = {
4244
getProgram: () => program,
4345
getDiagnostics: getDiagnostics,
@@ -972,7 +974,8 @@ module ts {
972974
}
973975

974976
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
975-
var stringWriter = createSingleLineTextWriter(flags & TypeFormatFlags.NoTruncation ? undefined : 100);
977+
var maxLength = compilerOptions.noErrorTruncation || flags & TypeFormatFlags.NoTruncation ? undefined : 100;
978+
var stringWriter = createSingleLineTextWriter(maxLength);
976979
// TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration
977980
writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter);
978981
return stringWriter.getText();
@@ -1364,7 +1367,7 @@ module ts {
13641367
return type;
13651368

13661369
function checkImplicitAny(type: Type) {
1367-
if (!fullTypeCheck || !program.getCompilerOptions().noImplicitAny) {
1370+
if (!fullTypeCheck || !compilerOptions.noImplicitAny) {
13681371
return;
13691372
}
13701373
// We need to have ended up with 'any', 'any[]', 'any[][]', etc.
@@ -1467,7 +1470,7 @@ module ts {
14671470
}
14681471
// Otherwise, fall back to 'any'.
14691472
else {
1470-
if (program.getCompilerOptions().noImplicitAny) {
1473+
if (compilerOptions.noImplicitAny) {
14711474
error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbol.name);
14721475
}
14731476

@@ -3159,7 +3162,7 @@ module ts {
31593162
if (propType !== widenedType) {
31603163
propTypeWasWidened = true;
31613164

3162-
if (program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
3165+
if (compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
31633166
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType));
31643167
}
31653168
}
@@ -3987,7 +3990,7 @@ module ts {
39873990
}
39883991

39893992
// Fall back to any.
3990-
if (program.getCompilerOptions().noImplicitAny && objectType !== anyType) {
3993+
if (compilerOptions.noImplicitAny && objectType !== anyType) {
39913994
error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type);
39923995
}
39933996

@@ -4332,7 +4335,7 @@ module ts {
43324335
var declaration = signature.declaration;
43334336
if (declaration && (declaration.kind !== SyntaxKind.Constructor && declaration.kind !== SyntaxKind.ConstructSignature)) {
43344337
// When resolved signature is a call signature (and not a construct signature) the result type is any
4335-
if (program.getCompilerOptions().noImplicitAny) {
4338+
if (compilerOptions.noImplicitAny) {
43364339
error(node, Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
43374340
}
43384341
return anyType;
@@ -4378,7 +4381,7 @@ module ts {
43784381
var unwidenedType = checkAndMarkExpression(func.body, contextualMapper);
43794382
var widenedType = getWidenedType(unwidenedType);
43804383

4381-
if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
4384+
if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
43824385
error(func, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType));
43834386
}
43844387

@@ -4400,7 +4403,7 @@ module ts {
44004403
var widenedType = getWidenedType(commonType);
44014404

44024405
// Check and report for noImplicitAny if the best common type implicitly gets widened to an 'any'/arrays-of-'any' type.
4403-
if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
4406+
if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
44044407
var typeName = typeToString(widenedType);
44054408

44064409
if (func.name) {
@@ -4976,7 +4979,7 @@ module ts {
49764979
checkCollisionWithCapturedThisVariable(node, node.name);
49774980
checkCollistionWithRequireExportsInGeneratedCode(node, node.name);
49784981
checkCollisionWithArgumentsInGeneratedCode(node);
4979-
if (program.getCompilerOptions().noImplicitAny && !node.type) {
4982+
if (compilerOptions.noImplicitAny && !node.type) {
49804983
switch (node.kind) {
49814984
case SyntaxKind.ConstructSignature:
49824985
error(node, Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
@@ -5532,7 +5535,7 @@ module ts {
55325535
}
55335536

55345537
// If there is no body and no explicit return type, then report an error.
5535-
if (fullTypeCheck && program.getCompilerOptions().noImplicitAny && !node.body && !node.type) {
5538+
if (fullTypeCheck && compilerOptions.noImplicitAny && !node.body && !node.type) {
55365539
// Ignore privates within ambient contexts; they exist purely for documentative purposes to avoid name clashing.
55375540
// (e.g. privates within .d.ts files do not expose type information)
55385541
if (!isPrivateWithinAmbient(node)) {
@@ -7177,7 +7180,7 @@ module ts {
71777180
function shouldEmitDeclarations() {
71787181
// If the declaration emit and there are no errors being reported in program or by checker
71797182
// declarations can be emitted
7180-
return program.getCompilerOptions().declaration &&
7183+
return compilerOptions.declaration &&
71817184
!program.getDiagnostics().length &&
71827185
!getDiagnostics().length;
71837186
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ module ts {
955955
locale?: string;
956956
mapRoot?: string;
957957
module?: ModuleKind;
958+
noErrorTruncation?: boolean;
958959
noImplicitAny?: boolean;
959960
noLib?: boolean;
960961
noLibCheck?: boolean;
@@ -967,7 +968,6 @@ module ts {
967968
target?: ScriptTarget;
968969
version?: boolean;
969970
watch?: boolean;
970-
971971
[option: string]: any;
972972
}
973973

src/harness/harness.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ module Harness {
622622
options = options || { noResolve: false };
623623
options.target = options.target || ts.ScriptTarget.ES3;
624624
options.module = options.module || ts.ModuleKind.None;
625+
options.noErrorTruncation = true;
625626

626627
if (settingsCallback) {
627628
settingsCallback(null);
@@ -725,6 +726,10 @@ module Harness {
725726
options.emitBOM = !!setting.value;
726727
break;
727728

729+
case 'errortruncation':
730+
options.noErrorTruncation = setting.value === 'false';
731+
break;
732+
728733
default:
729734
throw new Error('Unsupported compiler setting ' + setting.flag);
730735
}
@@ -1030,7 +1035,7 @@ module Harness {
10301035
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
10311036

10321037
// List of allowed metadata names
1033-
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom"];
1038+
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation"];
10341039

10351040
function extractCompilerSettings(content: string): CompilerSetting[] {
10361041

tests/baselines/reference/arrayTypeOfTypeOf.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
~
1111
!!! Expression expected.
1212
~~~
13-
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arr...':
13+
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }':
1414
!!! Property 'isArray' is missing in type 'Number'.
1515
var xs4: typeof Array<typeof x>;
1616
~
1717
!!! '=' expected.
1818
~
1919
!!! Expression expected.
2020
~~~
21-
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arr...'.
21+
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'.

tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
var b8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U;
5353
a8 = b8; // error, { foo: number } and Base are incompatible
5454
~~
55-
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
55+
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
5656
!!! Types of parameters 'y' and 'y' are incompatible:
5757
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
5858
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
@@ -61,7 +61,7 @@
6161
!!! Type 'number' is not assignable to type 'string'.
6262
b8 = a8; // error, { foo: number } and Base are incompatible
6363
~~
64-
!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...':
64+
!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U':
6565
!!! Types of parameters 'y' and 'y' are incompatible:
6666
!!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any':
6767
!!! Types of parameters 'arg2' and 'arg2' are incompatible:

tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
var b8: new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U;
5353
a8 = b8; // error, type mismatch
5454
~~
55-
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
55+
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
5656
!!! Types of parameters 'y' and 'y' are incompatible:
5757
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
5858
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
@@ -61,7 +61,7 @@
6161
!!! Type 'number' is not assignable to type 'string'.
6262
b8 = a8; // error
6363
~~
64-
!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...':
64+
!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U':
6565
!!! Types of parameters 'y' and 'y' are incompatible:
6666
!!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any':
6767
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
@@ -93,24 +93,24 @@
9393
var b16: new <T>(x: (a: T) => T) => T[];
9494
a16 = b16; // error
9595
~~~
96-
!!! Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...':
96+
!!! Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }':
9797
!!! Types of parameters 'x' and 'x' are incompatible:
9898
!!! Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'.
9999
b16 = a16; // error
100100
~~~
101-
!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...' is not assignable to type 'new <T>(x: (a: T) => T) => T[]':
101+
!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }' is not assignable to type 'new <T>(x: (a: T) => T) => T[]':
102102
!!! Types of parameters 'x' and 'x' are incompatible:
103103
!!! Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'.
104104

105105
var b17: new <T>(x: (a: T) => T) => any[];
106106
a17 = b17; // error
107107
~~~
108-
!!! Type 'new <T>(x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: {...':
108+
!!! Type 'new <T>(x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: { new <T extends Derived2>(a: T): T; new <T extends Base>(a: T): T; }): any[]; }':
109109
!!! Types of parameters 'x' and 'x' are incompatible:
110110
!!! Type '(a: any) => any' is not assignable to type '{ new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }'.
111111
b17 = a17; // error
112112
~~~
113-
!!! Type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: {...' is not assignable to type 'new <T>(x: (a: T) => T) => any[]':
113+
!!! Type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: { new <T extends Derived2>(a: T): T; new <T extends Base>(a: T): T; }): any[]; }' is not assignable to type 'new <T>(x: (a: T) => T) => any[]':
114114
!!! Types of parameters 'x' and 'x' are incompatible:
115115
!!! Type '{ new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }' is not assignable to type '(a: any) => any'.
116116
}

tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
~~
6969
!!! Interface 'I4' incorrectly extends interface 'A':
7070
!!! Types of property 'a8' are incompatible:
71-
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
71+
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
7272
!!! Types of parameters 'y' and 'y' are incompatible:
7373
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
7474
!!! Types of parameters 'arg2' and 'arg2' are incompatible:

tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
~~
5959
!!! Interface 'I4' incorrectly extends interface 'A':
6060
!!! Types of property 'a8' are incompatible:
61-
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
61+
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
6262
!!! Types of parameters 'y' and 'y' are incompatible:
6363
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
6464
!!! Types of parameters 'arg2' and 'arg2' are incompatible:

tests/baselines/reference/errorMessageOnObjectLiteralType.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
!!! Property 'getOwnPropertyNamess' does not exist on type '{ a: string; b: number; }'.
99
Object.getOwnPropertyNamess(null);
1010
~~~~~~~~~~~~~~~~~~~~
11-
!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any...'.
11+
!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
==== tests/cases/compiler/errorWithTruncatedType.ts (1 errors) ====
2+
3+
var x: {
4+
propertyWithAnExceedinglyLongName1: string;
5+
propertyWithAnExceedinglyLongName2: string;
6+
propertyWithAnExceedinglyLongName3: string;
7+
propertyWithAnExceedinglyLongName4: string;
8+
propertyWithAnExceedinglyLongName5: string;
9+
};
10+
11+
// String representation of type of 'x' should be truncated in error message
12+
var s: string = x;
13+
~
14+
!!! Type '{ propertyWithAnExceedinglyLongName1: string; propertyWithAnExceedinglyLongName2: string; propert...' is not assignable to type 'string'.
15+

0 commit comments

Comments
 (0)