Skip to content

Commit 0ce8c03

Browse files
committed
Allow element accesses to be called
This commit adds a case to compileCallExpression(), allowing element accesses to be used in function calls. This commit fixes #2525.
1 parent 5d18a71 commit 0ce8c03

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/compiler.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,6 +6172,38 @@ export class Compiler extends DiagnosticEmitter {
61726172
}
61736173
break;
61746174
}
6175+
6176+
case ElementKind.IndexSignature: {
6177+
const functionExpr = expression.expression;
6178+
const type = this.resolver.getTypeOfElement(target);
6179+
assert(functionExpr.kind == NodeKind.ElementAccess);
6180+
6181+
if (!type) {
6182+
this.error(
6183+
DiagnosticCode.Expression_cannot_be_represented_by_a_type,
6184+
functionExpr.range
6185+
);
6186+
return module.unreachable();
6187+
}
6188+
6189+
if (!type.signatureReference) {
6190+
this.error(
6191+
DiagnosticCode.Type_0_has_no_call_signatures,
6192+
functionExpr.range,
6193+
type.toString()
6194+
);
6195+
return module.unreachable();
6196+
}
6197+
6198+
signature = type.signatureReference;
6199+
functionArg = this.compileElementAccessExpression(
6200+
<ElementAccessExpression>functionExpr,
6201+
contextualType,
6202+
Constraints.ConvImplicit
6203+
);
6204+
break;
6205+
}
6206+
61756207
case ElementKind.Class: {
61766208
let classInstance = <Class>target;
61776209
let typeArguments = classInstance.getTypeArgumentsTo(this.program.functionPrototype);

0 commit comments

Comments
 (0)