Skip to content

Commit fe8083e

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 dc797a4 commit fe8083e

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
@@ -6202,6 +6202,38 @@ export class Compiler extends DiagnosticEmitter {
62026202
}
62036203
break;
62046204
}
6205+
6206+
case ElementKind.INDEXSIGNATURE: {
6207+
const functionExpr = expression.expression;
6208+
const type = this.resolver.getTypeOfElement(target);
6209+
assert(functionExpr.kind == NodeKind.ELEMENTACCESS);
6210+
6211+
if (!type) {
6212+
this.error(
6213+
DiagnosticCode.Expression_cannot_be_represented_by_a_type,
6214+
functionExpr.range
6215+
);
6216+
return module.unreachable();
6217+
}
6218+
6219+
if (!type.signatureReference) {
6220+
this.error(
6221+
DiagnosticCode.Type_0_has_no_call_signatures,
6222+
functionExpr.range,
6223+
type.toString()
6224+
);
6225+
return module.unreachable();
6226+
}
6227+
6228+
signature = type.signatureReference;
6229+
functionArg = this.compileElementAccessExpression(
6230+
<ElementAccessExpression>functionExpr,
6231+
contextualType,
6232+
Constraints.CONV_IMPLICIT
6233+
);
6234+
break;
6235+
}
6236+
62056237
case ElementKind.CLASS: {
62066238
let classInstance = <Class>target;
62076239
let typeArguments = classInstance.getTypeArgumentsTo(this.program.functionPrototype);

0 commit comments

Comments
 (0)