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

Fix error message regressed by #30916 #31276

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/compiler/checker.ts
Expand Up @@ -12302,7 +12302,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 @@ -12589,10 +12589,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 @@ -13524,16 +13528,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 @@ -13542,7 +13550,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;