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
16 changes: 16 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,22 @@ foreach(call_arity_case ${call_arity_cases})
FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed")
endforeach()

# An error reported by a pass that still returns success - a lowering pattern that cannot cast,
# says so and carries on - fails the compile. It used to be printed and then ignored: the object
# file was written, and under --emit=jit the program ran and crashed. Two tests because one
# property cannot say both things: the message is the error we meant, and the exit code is not 0.
set(lowering_error_file "${PROJECT_SOURCE_DIR}/test/tester/lowering-errors/cast_not_supported.ts")
add_test(NAME test-compile-lowering-error-message
COMMAND $<TARGET_FILE:tslang> --emit=obj --no-default-lib -mm=none "${lowering_error_file}"
-o "${CMAKE_CURRENT_BINARY_DIR}/lowering-error-message.obj")
set_tests_properties(test-compile-lowering-error-message
PROPERTIES PASS_REGULAR_EXPRESSION "cast from '!ts.array<!ts.number>' to '!ts.string' is not supported"
FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed")
add_test(NAME test-compile-lowering-error-exit
COMMAND $<TARGET_FILE:tslang> --emit=obj --no-default-lib -mm=none "${lowering_error_file}"
-o "${CMAKE_CURRENT_BINARY_DIR}/lowering-error-exit.obj")
set_tests_properties(test-compile-lowering-error-exit PROPERTIES WILL_FAIL TRUE)

# @dllname and @linkname are one decorator under two names, and a symbol is bound once: each
# case is a program the compiler must reject with the given message instead of binding
# something else or making the name unique.
Expand Down
6 changes: 6 additions & 0 deletions tslang/test/tester/lowering-errors/cast_not_supported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Lowering has no cast from an array to a string, and says so with an error. That error has to
// stop the compile: before it did, the program was emitted and run anyway and crashed.
function main() {
let a: number[] | null = [1, 2];
print("a=" + a);
}
8 changes: 8 additions & 0 deletions tslang/tslang/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ int runMLIRPasses(mlir::MLIRContext &context, llvm::SourceMgr &sourceMgr, mlir::
result = 4;
}

// A pass can report an error and still succeed - a lowering pattern that cannot cast says so
// and carries on with a value that is not one - so the run's result alone is not the answer.
// Without this the error was printed and the module compiled, linked and run anyway.
if (llvm::any_of(postponedMessages, [](auto &diag) { return diag->getSeverity() == mlir::DiagnosticSeverity::Error; }))
{
result = 4;
}

SourceMgrDiagnosticHandlerEx sourceMgrHandler(sourceMgr, &context);
printDiagnostics(sourceMgrHandler, postponedMessages, disableWarnings);
return result;
Expand Down
Loading