Use related spans for "implement abstract class" errors

This commit is contained in:
Ivan Arcuschin committed 2021-01-29 12:37:07 -03:00
1 parent 9dbfaeef2d
commit fca0b39f0c
13 files changed
+88 -56

No files matched your search

+22 -3
View File
@@ -36173,6 +36173,8 @@ namespace ts {
// NOTE: assignability is checked in checkClassDeclaration
const baseProperties = getPropertiesOfType(baseType);
const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!;
const inheritedAbstractMemberNotImplementedErrors: Diagnostic[] = [];
basePropertyCheck: for (const baseProperty of baseProperties) {
const base = getTargetSymbol(baseProperty);
@@ -36193,7 +36195,6 @@ namespace ts {
// type declaration, derived and base resolve to the same symbol even in the case of generic classes.
if (derived === base) {
// derived class inherits base without override/redeclaration
const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!;
// It is an error to inherit an abstract member without implementing it or being declared abstract.
// If there is no declaration for the derived class (as in the case of class expressions),
@@ -36212,12 +36213,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,
Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1,
symbolToString(baseProperty), typeToString(baseType));
inheritedAbstractMemberNotImplementedErrors.push(err);
}
else {
error(derivedClassDecl, Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2,
const err = createDiagnosticForNode(derivedClassDecl,
Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2,
typeToString(type), symbolToString(baseProperty), typeToString(baseType));
inheritedAbstractMemberNotImplementedErrors.push(err);
}
}
}
@@ -36293,6 +36298,20 @@ namespace ts {
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
}
}
if (inheritedAbstractMemberNotImplementedErrors.length) {
const err = error(
derivedClassDecl,
Diagnostics.Non_abstract_class_0_does_not_implement_all_abstract_members_of_1,
typeToString(type), typeToString(baseType));
for (const inheritedAbstractMemberNotImplementedError of inheritedAbstractMemberNotImplementedErrors) {
addRelatedInfo(
err,
inheritedAbstractMemberNotImplementedError,
);
}
}
}
function getNonInterhitedProperties(type: InterfaceType, baseTypes: BaseType[], properties: Symbol[]) {
+4
View File
@@ -6346,5 +6346,9 @@
"Invalid value for 'jsxFragmentFactory'. '{0}' is not a valid identifier or qualified-name.": {
"category": "Error",
"code": 18035
},
"Non-abstract class '{0}' does not implement all abstract members of '{1}'": {
"category": "Error",
"code": 18036
}
}
@@ -1,6 +1,7 @@
/* @internal */
namespace ts.codefix {
const errorCodes = [
Diagnostics.Non_abstract_class_0_does_not_implement_all_abstract_members_of_1.code,
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,
];