Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce flattened error reporting for properties, call signatures, and construct signatures #33473

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update message, specialize output for argument-less signatures
  • Loading branch information
weswigham committed Sep 17, 2019
commit d4fcff280f1cd7a3e7e32d870b7f176fd1531196
30 changes: 22 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12801,11 +12801,19 @@ namespace ts {
path = path.length === 0 ? "new (...)" : `new ${path}(...)`;
break;
}
case Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types.code: {
path = path.length === 0 ? "()" : `${path}()`;
break;
}
case Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types.code: {
path = path.length === 0 ? "new ()" : `new ${path}()`;
break;
}
default:
return Debug.fail(`Unhandled Diagnostic: ${msg.code}`);
}
}
reportError(Diagnostics._0_is_incompatible_between_these_types, path);
reportError(Diagnostics.The_types_of_0_are_incompatible_between_these_types, path);
if (info) {
// Actually do the last relation error
reportRelationError(/*headMessage*/ undefined, ...info);
Expand Down Expand Up @@ -14253,7 +14261,7 @@ namespace ts {
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
// as they are known to always be the same.
for (let i = 0; i < targetSignatures.length; i++) {
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, incompatibleReporter);
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, incompatibleReporter(sourceSignatures[i], targetSignatures[i]));
if (!related) {
return Ternary.False;
}
Expand All @@ -14267,14 +14275,14 @@ namespace ts {
// this regardless of the number of signatures, but the potential costs are prohibitive due
// to the quadratic nature of the logic below.
const eraseGenerics = relation === comparableRelation || !!compilerOptions.noStrictGenericChecks;
result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors, incompatibleReporter);
result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors, incompatibleReporter(sourceSignatures[0], targetSignatures[0]));
}
else {
outer: for (const t of targetSignatures) {
// Only elaborate errors from the first failure
let shouldElaborateErrors = reportErrors;
for (const s of sourceSignatures) {
const related = signatureRelatedTo(s, t, /*erase*/ true, shouldElaborateErrors, incompatibleReporter);
const related = signatureRelatedTo(s, t, /*erase*/ true, shouldElaborateErrors, incompatibleReporter(s, t));
if (related) {
result &= related;
resetErrorInfo(saveErrorInfo);
Expand All @@ -14294,12 +14302,18 @@ namespace ts {
return result;
}

function reportIncompatibleCallSignatureReturn() {
reportIncompatibleError(Diagnostics.Call_signature_return_types_are_incompatible);
function reportIncompatibleCallSignatureReturn(siga: Signature, sigb: Signature) {
if (siga.parameters.length === 0 && sigb.parameters.length === 0) {
return () => reportIncompatibleError(Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types);
}
return () => reportIncompatibleError(Diagnostics.Call_signature_return_types_are_incompatible);
}

function reportIncompatibleConstructSignatureReturn() {
reportIncompatibleError(Diagnostics.Construct_signature_return_types_are_incompatible);
function reportIncompatibleConstructSignatureReturn(siga: Signature, sigb: Signature) {
if (siga.parameters.length === 0 && sigb.parameters.length === 0) {
return () => reportIncompatibleError(Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types);
}
return () => reportIncompatibleError(Diagnostics.Construct_signature_return_types_are_incompatible);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
"code": 1357
},

"'{0}' is incompatible between these types.": {
"The types of '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2200
},
Expand All @@ -1054,6 +1054,16 @@
"code": 2202,
"elidedInCompatabilityPyramid": true
},
"Call signatures with no arguments have incompatible return types.": {
"category": "Error",
"code": 2203,
"elidedInCompatabilityPyramid": true
},
"Construct signatures with no arguments have incompatible return types.": {
"category": "Error",
"code": 2204,
"elidedInCompatabilityPyramid": true
},

"Duplicate identifier '{0}'.": {
"category": "Error",
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayLiterals3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2739: Type '(number[] | string[])[]' is missing the following properties from type 'tup': 0, 1
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2739: Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
'pop(...)' is incompatible between these types.
The types of 'pop()' are incompatible between these types.
Type 'string | number' is not assignable to type 'Number'.
Type 'string' is not assignable to type 'Number'.

Expand Down Expand Up @@ -66,7 +66,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
~~
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
!!! error TS2322: 'pop(...)' is incompatible between these types.
!!! error TS2322: The types of 'pop()' are incompatible between these types.
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
!!! error TS2322: Type 'string' is not assignable to type 'Number'.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'readonly B[]'.
Property 'b' is missing in type 'A' but required in type 'B'.
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
'concat(...)' is incompatible between these types.
The types of 'concat(...)' are incompatible between these types.
Type 'A[]' is not assignable to type 'B[]'.
Type 'A' is not assignable to type 'B'.

Expand Down Expand Up @@ -31,7 +31,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
rrb = cra; // error: 'A' is not assignable to 'B'
~~~
!!! error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
!!! error TS2322: 'concat(...)' is incompatible between these types.
!!! error TS2322: The types of 'concat(...)' are incompatible between these types.
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
'valueOf(...)' is incompatible between these types.
The types of 'valueOf()' are incompatible between these types.
Type 'Object' is not assignable to type 'boolean'.
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'.
'boolean' is a primitive, but 'Boolean' is a wrapper object. Prefer using 'boolean' when possible.
Expand All @@ -23,7 +23,7 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(
a = b;
~
!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
!!! error TS2322: 'valueOf(...)' is incompatible between these types.
!!! error TS2322: The types of 'valueOf()' are incompatible between these types.
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.

b = a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,23): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
'(new (...)).then(...)' is incompatible between these types.
The types of '(new (...)).then(...)' are incompatible between these types.
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1058: The return type of an async function must either be a valid promise or must not contain a callable 'then' member.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1320: Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
Expand Down Expand Up @@ -36,7 +36,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
async function fn6(): Thenable { } // error
~~~~~~~~
!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
!!! error TS1055: '(new (...)).then(...)' is incompatible between these types.
!!! error TS1055: The types of '(new (...)).then(...)' are incompatible between these types.
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
async function fn7() { return; } // valid: Promise<void>
async function fn8() { return 1; } // valid: Promise<number>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/bigintWithLib.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tests/cases/compiler/bigintWithLib.ts(16,33): error TS2769: No overload matches
Argument of type 'number[]' is not assignable to parameter of type 'number'.
Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
'[Symbol.iterator](...).next(...)' is incompatible between these types.
The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
Expand Down Expand Up @@ -51,7 +51,7 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'number'.
!!! error TS2769: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
!!! error TS2769: '[Symbol.iterator](...).next(...)' is incompatible between these types.
!!! error TS2769: The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
!!! error TS2769: Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/booleanAssignment.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type '1' is not assignable to type 'Boolean'.
tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type '"a"' is not assignable to type 'Boolean'.
tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'.
'valueOf(...)' is incompatible between these types.
The types of 'valueOf()' are incompatible between these types.
Type 'Object' is not assignable to type 'boolean'.


Expand All @@ -16,7 +16,7 @@ tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not a
b = {}; // Error
~
!!! error TS2322: Type '{}' is not assignable to type 'Boolean'.
!!! error TS2322: 'valueOf(...)' is incompatible between these types.
!!! error TS2322: The types of 'valueOf()' are incompatible between these types.
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.

var o = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(57,15): error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
'a(...)' is incompatible between these types.
The types of 'a(...)' are incompatible between these types.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(63,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
'a2(...)' is incompatible between these types.
The types of 'a2(...)' are incompatible between these types.
Type 'string' is not assignable to type 'T'.
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

Expand Down Expand Up @@ -67,7 +67,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I2 extends Base2 {
~~
!!! error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
!!! error TS2430: 'a(...)' is incompatible between these types.
!!! error TS2430: The types of 'a(...)' are incompatible between these types.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
// N's
a: (x: number) => string; // error because base returns non-void;
Expand All @@ -77,7 +77,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I3 extends Base2 {
~~
!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
!!! error TS2430: 'a2(...)' is incompatible between these types.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'string' is not assignable to type 'T'.
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
// N's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(100,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'.
'a2(...)' is incompatible between these types.
The types of 'a2(...)' are incompatible between these types.
Type 'string[]' is not assignable to type 'T[]'.
Type 'string' is not assignable to type 'T'.
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(109,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'.
'a2(...)' is incompatible between these types.
The types of 'a2(...)' are incompatible between these types.
Type 'T[]' is not assignable to type 'string[]'.
Type 'T' is not assignable to type 'string'.

Expand Down Expand Up @@ -172,7 +172,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I6 extends B {
~~
!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'.
!!! error TS2430: 'a2(...)' is incompatible between these types.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'string[]' is not assignable to type 'T[]'.
!!! error TS2430: Type 'string' is not assignable to type 'T'.
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
Expand All @@ -187,7 +187,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I7 extends C {
~~
!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'.
!!! error TS2430: 'a2(...)' is incompatible between these types.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'T[]' is not assignable to type 'string[]'.
!!! error TS2430: Type 'T' is not assignable to type 'string'.
a2: <T>(x: T) => T[]; // error
Expand Down
Loading