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
3 changes: 0 additions & 3 deletions docs/how/wasm/test/wasm_skips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ internals.ts # inline_asm with x86 instructions
00cppvtable_hidden_return.ts # a @cpp class returning a struct needs the MSVC or a 64-bit Itanium ABI (excluded on i686 too)
fetch.ts # (default library) fetch(): the host has no network, so the request throws

# compiler gaps on wasm, each to be fixed and taken off this list
path.ts # a field of Readonly<Path> read through Maybe<...> is read wrong: the loop never ends

# fails natively under the same model too (not run natively under it by ctest)
01tuple.ts own # frees a block it does not own (native own: the program does not finish either)
00global_interface_initializer.ts own # asserts "a field read" (native own: the same assert)
5 changes: 4 additions & 1 deletion tslang/lib/TypeScript/MLIRGenCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,10 @@ namespace mlirgen
// not the default of its union (a zeroed value, read as null or as T's fields) - below
auto missingValueToString =
isa<mlir_ts::StringType>(type) && MLIRTypeHelper::getMissingValueElement(optType);
if (isa<mlir_ts::UnionType>(optType.getElementType()) && !missingValueToString)
// ...nor its truth: the default of a union is zeroed, its type "undefined", and that is
// not null, so `while (curr)` over a `null | { ... }` that has none was true (below, a
// missing value is false)
if (isa<mlir_ts::UnionType>(optType.getElementType()) && !missingValueToString && !isa<mlir_ts::BooleanType>(type))
{
auto val = V(builder.create<mlir_ts::ValueOrDefaultOp>(location, optType.getElementType(), value));
CAST_A(unwrappedValue, location, type, val, genContext);
Expand Down
3 changes: 3 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ tslang_add_test(NAME test-compile-00-declare-function-twice COMMAND test-runner
tslang_add_test(NAME test-compile-00-function-overloads COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00function_overloads.ts")
tslang_add_test(NAME test-compile-00-class-override-arity COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00class_override_arity.ts")
tslang_add_test(NAME test-compile-00-bound-method-wider-callback COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00bound_method_wider_callback.ts")
tslang_add_test(NAME test-compile-00-optional-union-truthiness COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00optional_union_truthiness.ts")
tslang_add_test(NAME test-compile-00-gc-allocations-distinct COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00gc_allocations_distinct.ts")
tslang_add_test(NAME test-compile-00-assert-message COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00assert_message.ts")
tslang_add_test(NAME test-compile-01-funcs-vararg COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/01funcs_vararg.ts")
Expand Down Expand Up @@ -980,6 +981,7 @@ tslang_add_test(NAME test-jit-00-declare-function-twice COMMAND test-runner -jit
tslang_add_test(NAME test-jit-00-function-overloads COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00function_overloads.ts")
tslang_add_test(NAME test-jit-00-class-override-arity COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00class_override_arity.ts")
tslang_add_test(NAME test-jit-00-bound-method-wider-callback COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00bound_method_wider_callback.ts")
tslang_add_test(NAME test-jit-00-optional-union-truthiness COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00optional_union_truthiness.ts")
tslang_add_test(NAME test-jit-00-gc-allocations-distinct COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00gc_allocations_distinct.ts")
tslang_add_test(NAME test-jit-00-assert-message COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00assert_message.ts")
tslang_add_test(NAME test-jit-01-funcs-vararg COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/01funcs_vararg.ts")
Expand Down Expand Up @@ -2599,6 +2601,7 @@ set(TSLANG_CORPUS
00function_overloads.ts
00class_override_arity.ts
00bound_method_wider_callback.ts
00optional_union_truthiness.ts
00gc_allocations_distinct.ts
00assert_message.ts
00funcs.ts
Expand Down
43 changes: 43 additions & 0 deletions tslang/test/tester/tests/00optional_union_truthiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// `null | undefined | { ... }` with no value is false in a condition. The optional's default, a
// zeroed union whose type is "undefined", is not null, and it was read as true: the loop never ended.
// (path.ts got this type from the default library's Readonly<Path>.)

interface Path {
readonly prev: Path | undefined;
readonly key: string | number;
}

type PathLike = null | undefined | { key: string | number, prev: Path | undefined };

function pathToArray(path: PathLike): (string | number)[] {
let curr = path;
let flattened = <(string | number)[]>[];
while (curr) {
flattened.push(curr.key);
curr = curr.prev;
}
return flattened;
}

function count(p: PathLike) {
let n = 0;
if (p) n++;
if (!p) n += 10;
return p ? n + 100 : n;
}

function main() {
const keys = pathToArray({ key: "path", prev: { key: 2, prev: undefined } });
assert(keys.length == 2);
assert(keys[0] == "path");
assert(keys[1] == 2);

assert(pathToArray(undefined).length == 0);
assert(pathToArray(null).length == 0);

assert(count(undefined) == 10);
assert(count(null) == 10);
assert(count({ key: 1, prev: undefined }) == 101);

print("done.");
}
Loading