-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Use related spans for "implement abstract class" errors #48030
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
Use related spans for "implement abstract class" errors #48030
Conversation
thanks a lot, I'll try not to mess things up with git this time |
…tps://github.com/FlyingPumba/TypeScript; branch 'main' of https://github.com/microsoft/TypeScript into related-spans-for-implement-abstract-class-error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks reasonable. Just a couple of minor questions.
It's been a really long time since we last reviewed this, so if you're not interested in bringing this PR up-to-date, I understand.
src/compiler/diagnosticMessages.json
Outdated
@@ -7285,5 +7285,9 @@ | |||
"A 'return' statement cannot be used inside a class static block.": { | |||
"category": "Error", | |||
"code": 18041 | |||
}, | |||
"Non-abstract class '{0}' does not implement all abstract members of '{1}'": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Non-abstract class '{0}' does not implement all abstract members of '{1}'": { | |
"Non-abstract class '{0}' does not implement all inherited abstract members of '{1}'": { |
Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2.code, | ||
Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1.code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these needed anymore now that they're related spans? Is it even possible to fix just one missing member in the first place?
Edit: It's not, although I don't know how related spans display, so it's worth finding out whether the codefix can be invoked from a related span.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, of course. The related spans are not really related spans, just elaborations. So these are definitely not needed.
1. Lazily create top-level error instead of saving related errors in a list. addRelatedInfo already creates a list. 2. Remove unused errors in codefix trigger. 3. Related span points to base properties instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional things I noticed. I fixed them after I got this PR stuck in my head overnight.
Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2.code, | ||
Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1.code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, of course. The related spans are not really related spans, just elaborations. So these are definitely not needed.
src/compiler/checker.ts
Outdated
@@ -39533,12 +39534,16 @@ namespace ts { | |||
} | |||
|
|||
if (derivedClassDecl.kind === SyntaxKind.ClassExpression) { | |||
error(derivedClassDecl, Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, | |||
const err = createDiagnosticForNode(derivedClassDecl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use the base node for the related span
src/compiler/checker.ts
Outdated
@@ -39494,6 +39494,8 @@ namespace ts { | |||
|
|||
// NOTE: assignability is checked in checkClassDeclaration | |||
const baseProperties = getPropertiesOfType(baseType); | |||
const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!; | |||
const inheritedAbstractMemberNotImplementedErrors: Diagnostic[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of saving a list, create an error lazily and push onto that. It already has a list internally.
@gabritto Here is the PR again that was reverted. I didn't change the message. I don't actually remember how to do it correctly (it's a PR from one year ago after all 😅).
Old PR: #42546
Fixes #32848
Example compiling the following code.
Error message before:
Error message after:
cc: @DanielRosenwasser