Skip to content

Commit

Permalink
Fix error message regressed by #30916 (#31276)
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed May 14, 2019
1 parent fb6ae38 commit 3885e3f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/compiler/checker.ts
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -13506,16 +13510,20 @@ 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);
reportError(Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2, propName, ...getTypeNamesForErrorDisplay(source, target));
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
Expand All @@ -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;
}
Expand Down
@@ -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]'.
@@ -0,0 +1,6 @@
//// [assigningFunctionToTupleIssuesError.ts]
declare let a: () => void;
let b: [string] = a;

//// [assigningFunctionToTupleIssuesError.js]
var b = a;
@@ -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))

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

let b: [string] = a;
>b : [string]
>a : () => void

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

0 comments on commit 3885e3f

Please sign in to comment.