Fix error message regressed by #30916 (#31276)

This commit is contained in:
Wesley Wigham 2019-05-14 16:58:06 -07:00 committed by GitHub
parent fb6ae38ddf
commit 3885e3fcda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 4 deletions

View File

@ -12290,7 +12290,7 @@ namespace ts {
let depth = 0;
let expandingFlags = ExpandingFlags.None;
let overflow = false;
let suppressNextError = false;
let overrideNextErrorInfo: DiagnosticMessageChain | undefined;
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
@ -12571,10 +12571,14 @@ namespace ts {
}
if (!result && reportErrors) {
const maybeSuppress = suppressNextError;
suppressNextError = false;
let maybeSuppress = overrideNextErrorInfo;
overrideNextErrorInfo = undefined;
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
const currentError = errorInfo;
tryElaborateArrayLikeErrors(source, target, reportErrors);
if (errorInfo !== currentError) {
maybeSuppress = errorInfo;
}
}
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Primitive) {
tryElaborateErrorsForPrimitivesAndObjects(source, target);
@ -13506,9 +13510,10 @@ namespace ts {
if (unmatchedProperty) {
if (reportErrors) {
const props = arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false));
let shouldSkipElaboration = false;
if (!headMessage || (headMessage.code !== Diagnostics.Class_0_incorrectly_implements_interface_1.code &&
headMessage.code !== Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) {
suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it
shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it
}
if (props.length === 1) {
const propName = symbolToString(unmatchedProperty);
@ -13516,6 +13521,9 @@ namespace ts {
if (length(unmatchedProperty.declarations)) {
associateRelatedInfo(createDiagnosticForNode(unmatchedProperty.declarations[0], Diagnostics._0_is_declared_here, propName));
}
if (shouldSkipElaboration) {
overrideNextErrorInfo = errorInfo;
}
}
else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) {
if (props.length > 5) { // arbitrary cutoff for too-long list form
@ -13524,7 +13532,11 @@ namespace ts {
else {
reportError(Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), map(props, p => symbolToString(p)).join(", "));
}
if (shouldSkipElaboration) {
overrideNextErrorInfo = errorInfo;
}
}
// ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined)
}
return Ternary.False;
}

View File

@ -0,0 +1,8 @@
tests/cases/compiler/assigningFunctionToTupleIssuesError.ts(2,5): error TS2322: Type '() => void' is not assignable to type '[string]'.
==== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts (1 errors) ====
declare let a: () => void;
let b: [string] = a;
~
!!! error TS2322: Type '() => void' is not assignable to type '[string]'.

View File

@ -0,0 +1,6 @@
//// [assigningFunctionToTupleIssuesError.ts]
declare let a: () => void;
let b: [string] = a;
//// [assigningFunctionToTupleIssuesError.js]
var b = a;

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
declare let a: () => void;
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))
let b: [string] = a;
>b : Symbol(b, Decl(assigningFunctionToTupleIssuesError.ts, 1, 3))
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
declare let a: () => void;
>a : () => void
let b: [string] = a;
>b : [string]
>a : () => void

View File

@ -0,0 +1,2 @@
declare let a: () => void;
let b: [string] = a;