Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tslang/lib/TypeScript/MLIRGenAccessCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,14 @@ namespace mlirgen

auto result = mlirGenCallExpression(location, innerFuncRef, typeArguments, operands, genContext);
// a failed call (e.g. too few arguments) must fail the expression, not leave an
// empty branch behind - for a void callee that silently dropped the call
EXIT_IF_FAILED(result)
// empty branch behind - for a void callee that silently dropped the call. Nor may the
// half-built if stay in the IR for a caller that carries on (as in conditionalValue)
if (mlir::failed(result))
{
builder.setInsertionPoint(ifOp);
ifOp.erase();
return mlir::failure();
}
auto value = V(result);
if (value)
{
Expand Down
3 changes: 2 additions & 1 deletion tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,8 @@ set(call_arity_cases
"closure|Expected 2 arguments, but got 1\\."
"declared|Expected 2 arguments, but got 1\\."
"varargs|Expected at least 1 arguments, but got 0\\."
"optional_call|Expected 2 arguments, but got 1\\.")
"optional_call|Expected 2 arguments, but got 1\\."
"optional_call_value|Expected 2 arguments, but got 1\\.")
foreach(call_arity_case ${call_arity_cases})
string(FIND "${call_arity_case}" "|" call_arity_sep)
string(SUBSTRING "${call_arity_case}" 0 ${call_arity_sep} call_arity_name)
Expand Down
8 changes: 8 additions & 0 deletions tslang/test/tester/call-arity/optional_call_value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// An optional call whose result is used, inside a larger expression, at module level: the
// failed call must take its half-built `if` with it, not leave it in the global's initializer.
let f: ((a: number, b: number) => number) | undefined = (a: number, b: number) => a + b;
const r = `${f?.(1) ?? 0}`;

function main() {
print(r);
}
Loading