fix #18225, fix error message on abstract class instance (#18368)

* fix #18225, fix error message on abstract class instance

abstract class check should be inside constructor call

* add new test and accept baseline
This commit is contained in:
Herrington Darkholme
2017-09-12 02:21:35 +08:00
committed by Mohamed Hegazy
parent eb80799ef0
commit 29d5e4dadd
4 changed files with 36 additions and 10 deletions

View File

@@ -16128,16 +16128,6 @@ namespace ts {
return resolveErrorCall(node);
}
// If the expression is a class of abstract type, then it cannot be instantiated.
// Note, only class declarations can be declared abstract.
// In the case of a merged class-module or class-interface declaration,
// only the class declaration node will have the Abstract flag set.
const valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol);
if (valueDecl && hasModifier(valueDecl, ModifierFlags.Abstract)) {
error(node, Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, declarationNameToString(getNameOfDeclaration(valueDecl)));
return resolveErrorCall(node);
}
// TS 1.0 spec: 4.11
// If expressionType is of type Any, Args can be any argument
// list and the result of the operation is of type Any.
@@ -16157,6 +16147,16 @@ namespace ts {
if (!isConstructorAccessible(node, constructSignatures[0])) {
return resolveErrorCall(node);
}
// If the expression is a class of abstract type, then it cannot be instantiated.
// Note, only class declarations can be declared abstract.
// In the case of a merged class-module or class-interface declaration,
// only the class declaration node will have the Abstract flag set.
const valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol);
if (valueDecl && hasModifier(valueDecl, ModifierFlags.Abstract)) {
error(node, Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, declarationNameToString(getNameOfDeclaration(valueDecl)));
return resolveErrorCall(node);
}
return resolveCall(node, constructSignatures, candidatesOutArray);
}