Skip to content

Commit 99d640f

Browse files
author
Arthur Ozga
committed
Actually move check outside the loop
1 parent 35d2592 commit 99d640f

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

src/compiler/checker.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4763,40 +4763,35 @@ namespace ts {
47634763
let targetSignatures = getSignaturesOfType(target, kind);
47644764
let result = Ternary.True;
47654765
let saveErrorInfo = errorInfo;
4766+
4767+
// Because the "abstractness" of a class is the same across all construct signatures
4768+
// (internally we are checking the corresponding declaration), it is enough to perform
4769+
// the check and report an error once over all pairs of source and target construct signatures.
4770+
let sourceErasedSignature = getErasedSignature(s);
4771+
let targetErasedSignature = getErasedSignature(t);
4772+
4773+
let sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
4774+
let targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
4775+
4776+
let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getDeclarationOfKind(sourceReturnType.symbol, SyntaxKind.ClassDeclaration);
4777+
let targetReturnDecl = targetReturnType && targetReturnType.symbol && getDeclarationOfKind(targetReturnType.symbol, SyntaxKind.ClassDeclaration);
4778+
let sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
4779+
let targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
4780+
4781+
if (sourceIsAbstract && !targetIsAbstract) {
4782+
if (reportErrors) {
4783+
reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
4784+
}
4785+
result = Ternary.False;
4786+
}
4787+
47664788
outer: for (let t of targetSignatures) {
47674789
if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) {
47684790
let localErrors = reportErrors;
47694791
let checkedAbstractAssignability = false;
47704792
for (let s of sourceSignatures) {
47714793
if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) {
4772-
let related = Ternary.True;
4773-
4774-
// Because the "abstractness" of a class is the same across all construct signatures
4775-
// (internally we are checking the corresponding declaration), it is enough to perform
4776-
// the check and report an error once over all pairs of source and target construct signatures.
4777-
if (!checkedAbstractAssignability) {
4778-
checkedAbstractAssignability = true;
4779-
4780-
let sourceErasedSignature = getErasedSignature(s);
4781-
let targetErasedSignature = getErasedSignature(t);
4782-
4783-
let sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
4784-
let targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
4785-
4786-
let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getDeclarationOfKind(sourceReturnType.symbol, SyntaxKind.ClassDeclaration);
4787-
let targetReturnDecl = targetReturnType && targetReturnType.symbol && getDeclarationOfKind(targetReturnType.symbol, SyntaxKind.ClassDeclaration);
4788-
let sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
4789-
let targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
4790-
4791-
if (sourceIsAbstract && !targetIsAbstract) {
4792-
if (reportErrors) {
4793-
reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
4794-
}
4795-
related = Ternary.False;
4796-
}
4797-
}
4798-
4799-
related &= signatureRelatedTo(s, t, localErrors);
4794+
let related = signatureRelatedTo(s, t, localErrors);
48004795
if (related) {
48014796
result &= related;
48024797
errorInfo = saveErrorInfo;

0 commit comments

Comments
 (0)