Skip to content

Commit f70cfbc

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 0fd4db2 commit f70cfbc

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
@@ -6109,6 +6109,38 @@ export class Compiler extends DiagnosticEmitter {
61096109
}
61106110
break;
61116111
}
6112+
6113+
case ElementKind.IndexSignature: {
6114+
const functionExpr = expression.expression;
6115+
const type = this.resolver.getTypeOfElement(target);
6116+
assert(functionExpr.kind == NodeKind.ElementAccess);
6117+
6118+
if (!type) {
6119+
this.error(
6120+
DiagnosticCode.Expression_cannot_be_represented_by_a_type,
6121+
functionExpr.range
6122+
);
6123+
return module.unreachable();
6124+
}
6125+
6126+
if (!type.signatureReference) {
6127+
this.error(
6128+
DiagnosticCode.Type_0_has_no_call_signatures,
6129+
functionExpr.range,
6130+
type.toString()
6131+
);
6132+
return module.unreachable();
6133+
}
6134+
6135+
signature = type.signatureReference;
6136+
functionArg = this.compileElementAccessExpression(
6137+
<ElementAccessExpression>functionExpr,
6138+
contextualType,
6139+
Constraints.ConvImplicit
6140+
);
6141+
break;
6142+
}
6143+
61126144
case ElementKind.Class: {
61136145
let classInstance = <Class>target;
61146146
let typeArguments = classInstance.getTypeArgumentsTo(this.program.functionPrototype);

0 commit comments

Comments
 (0)