Skip to content

Commit 0b97e33

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 0b97e33

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/compiler.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6214,6 +6214,37 @@ export class Compiler extends DiagnosticEmitter {
62146214
// fall-through
62156215
}
62166216

6217+
case ElementKind.INDEXSIGNATURE: {
6218+
const functionExpr = expression.expression;
6219+
const type = this.resolver.getTypeOfElement(target);
6220+
assert(functionExpr.kind == NodeKind.ELEMENTACCESS);
6221+
6222+
if (!type) {
6223+
this.error(
6224+
DiagnosticCode.Expression_cannot_be_represented_by_a_type,
6225+
functionExpr.range
6226+
);
6227+
return module.unreachable();
6228+
}
6229+
6230+
if (!type.signatureReference) {
6231+
this.error(
6232+
DiagnosticCode.Type_0_has_no_call_signatures,
6233+
functionExpr.range,
6234+
type.toString()
6235+
);
6236+
return module.unreachable();
6237+
}
6238+
6239+
signature = type.signatureReference;
6240+
functionArg = this.compileElementAccessExpression(
6241+
<ElementAccessExpression>functionExpr,
6242+
contextualType,
6243+
Constraints.CONV_IMPLICIT
6244+
);
6245+
break;
6246+
}
6247+
62176248
// not supported
62186249
default: {
62196250
let type = this.resolver.getTypeOfElement(target);

0 commit comments

Comments
 (0)