Skip to content

Commit 09edcb8

Browse files
authored
Optimize resolution of single non-generic construct signatures (#1865)
1 parent a76fd60 commit 09edcb8

File tree

51 files changed

+617
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+617
-74
lines changed

internal/checker/checker.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7029,7 +7029,9 @@ func (c *Checker) getQuickTypeOfExpression(node *ast.Node) *Type {
70297029
if isCallChain(expr) {
70307030
return c.getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr)
70317031
}
7032-
return c.getReturnTypeOfSingleNonGenericCallSignature(c.checkNonNullExpression(expr.Expression()))
7032+
return c.getReturnTypeOfSingleNonGenericSignature(c.checkNonNullExpression(expr.Expression()), SignatureKindCall)
7033+
case ast.IsNewExpression(expr):
7034+
return c.getReturnTypeOfSingleNonGenericSignature(c.checkNonNullExpression(expr.Expression()), SignatureKindConstruct)
70337035
case ast.IsAssertionExpression(expr) && !ast.IsConstTypeReference(expr.Type()):
70347036
return c.getTypeFromTypeNode(expr.Type())
70357037
case ast.IsLiteralExpression(node) || ast.IsBooleanLiteral(node):
@@ -7038,8 +7040,8 @@ func (c *Checker) getQuickTypeOfExpression(node *ast.Node) *Type {
70387040
return nil
70397041
}
70407042

7041-
func (c *Checker) getReturnTypeOfSingleNonGenericCallSignature(funcType *Type) *Type {
7042-
signature := c.getSingleCallSignature(funcType)
7043+
func (c *Checker) getReturnTypeOfSingleNonGenericSignature(funcType *Type, kind SignatureKind) *Type {
7044+
signature := c.getSingleSignature(funcType, kind, true /*allowMembers*/)
70437045
if signature != nil && len(signature.typeParameters) == 0 {
70447046
return c.getReturnTypeOfSignature(signature)
70457047
}
@@ -7049,7 +7051,7 @@ func (c *Checker) getReturnTypeOfSingleNonGenericCallSignature(funcType *Type) *
70497051
func (c *Checker) getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr *ast.Node) *Type {
70507052
funcType := c.checkExpression(expr.Expression())
70517053
nonOptionalType := c.getOptionalExpressionType(funcType, expr.Expression())
7052-
returnType := c.getReturnTypeOfSingleNonGenericCallSignature(funcType)
7054+
returnType := c.getReturnTypeOfSingleNonGenericSignature(funcType, SignatureKindCall)
70537055
if returnType != nil {
70547056
return c.propagateOptionalTypeMarker(returnType, expr, nonOptionalType != funcType)
70557057
}

testdata/baselines/reference/submodule/compiler/abstractClassInLocalScopeIsAbstract.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
>A : A
1515

1616
new A();
17-
>new A() : any
17+
>new A() : A
1818
>A : typeof A
1919

2020
new B();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- old.abstractClassInLocalScopeIsAbstract.types
2+
+++ new.abstractClassInLocalScopeIsAbstract.types
3+
@@= skipped -13, +13 lines =@@
4+
>A : A
5+
6+
new A();
7+
->new A() : any
8+
+>new A() : A
9+
>A : typeof A
10+
11+
new B();

testdata/baselines/reference/submodule/compiler/newAbstractInstance2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import A from "./a";
99
>A : typeof A
1010

1111
new A();
12-
>new A() : any
12+
>new A() : A
1313
>A : typeof A
1414

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- old.newAbstractInstance2.types
2+
+++ new.newAbstractInstance2.types
3+
@@= skipped -8, +8 lines =@@
4+
>A : typeof A
5+
6+
new A();
7+
->new A() : any
8+
+>new A() : A
9+
>A : typeof A

testdata/baselines/reference/submodule/compiler/noCrashOnMixin.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CrashTrigger extends Mixin(Empty) {
4242
>trigger : () => void
4343

4444
new Concrete();
45-
>new Concrete() : any
45+
>new Concrete() : Concrete
4646
>Concrete : typeof Concrete
4747
}
4848
}

testdata/baselines/reference/submodule/compiler/noCrashOnMixin.types.diff

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@
2424
+>Mixin : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
2525
>Empty : typeof Empty
2626

27-
public trigger() {
27+
public trigger() {
28+
>trigger : () => void
29+
30+
new Concrete();
31+
->new Concrete() : any
32+
+>new Concrete() : Concrete
33+
>Concrete : typeof Concrete
34+
}
35+
}

testdata/baselines/reference/submodule/conformance/classAbstractConstructorAssignability.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ new AA;
3232
>AA : typeof A
3333

3434
new BB;
35-
>new BB : any
35+
>new BB : B
3636
>BB : typeof B
3737

3838
new CC;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- old.classAbstractConstructorAssignability.types
2+
+++ new.classAbstractConstructorAssignability.types
3+
@@= skipped -31, +31 lines =@@
4+
>AA : typeof A
5+
6+
new BB;
7+
->new BB : any
8+
+>new BB : B
9+
>BB : typeof B
10+
11+
new CC;

testdata/baselines/reference/submodule/conformance/classAbstractFactoryFunction.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function NewB(Factory: typeof B) {
2424
>B : typeof B
2525

2626
return new B;
27-
>new B : any
27+
>new B : B
2828
>B : typeof B
2929
}
3030

0 commit comments

Comments
 (0)