Skip to content

Commit feb7e1d

Browse files
author
Arthur Ozga
committed
Fixed generic abstract class inheritance and some comments
1 parent 994b73f commit feb7e1d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,9 +3190,11 @@ namespace ts {
31903190
return type.flags & TypeFlags.Union ? getPropertiesOfUnionType(<UnionType>type) : getPropertiesOfObjectType(type);
31913191
}
31923192

3193-
// For a type parameter, return the base constraint of the type parameter. For the string, number,
3194-
// boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
3195-
// type itself. Note that the apparent type of a union type is the union type itself.
3193+
/**
3194+
* For a type parameter, return the base constraint of the type parameter. For the string, number,
3195+
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
3196+
* type itself. Note that the apparent type of a union type is the union type itself.
3197+
*/
31963198
function getApparentType(type: Type): Type {
31973199
if (type.flags & TypeFlags.Union) {
31983200
type = getReducedTypeOfUnionType(<UnionType>type);
@@ -8403,7 +8405,10 @@ namespace ts {
84038405
}
84048406

84058407
// If the expression is of abstract type, then it cannot be instantiated.
8406-
let valueDecl = expressionType.symbol && expressionType.symbol.valueDeclaration;
8408+
// Note, only class declarations can be declared abstract.
8409+
// In the case of a merged class-module or class-interface declaration,
8410+
// only the class declaration node will have the Abstract flag set.
8411+
let valueDecl = expressionType.symbol && getDeclarationOfKind(expressionType.symbol, SyntaxKind.ClassDeclaration);
84078412
if (valueDecl && valueDecl.flags & NodeFlags.Abstract) {
84088413
error(node, Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, declarationNameToString(valueDecl.name));
84098414
}
@@ -10253,7 +10258,8 @@ namespace ts {
1025310258
}
1025410259

1025510260
// Abstract methods can't have an implementation -- in particular, they don't need one.
10256-
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && !(lastSeenNonAmbientDeclaration.flags & NodeFlags.Abstract) ) {
10261+
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
10262+
!(lastSeenNonAmbientDeclaration.flags & NodeFlags.Abstract) ) {
1025710263
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
1025810264
}
1025910265

@@ -11699,6 +11705,9 @@ namespace ts {
1169911705
Debug.assert(!!derived, "derived should point to something, even if it is the base class' declaration.");
1170011706

1170111707
if (derived) {
11708+
// In order to resolve whether the inherited method was overriden in the base class or not,
11709+
// we compare the Symbols obtained. Since getTargetSymbol returns the symbol on the *uninstantiated*
11710+
// type declaration, derived and base resolve to the same symbol even in the case of generic classes.
1170211711
if (derived === base) {
1170311712
// derived class inherits base without override/redeclaration
1170411713

0 commit comments

Comments
 (0)