diff --git a/src/ir.cpp b/src/ir.cpp index 3ebb7415c9..3c2d7b7d34 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6156,6 +6156,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod { prev_inst = cur_inst; continue; + } else if (cur_type->id == TypeTableEntryIdUndefLit) { + continue; + } else if (prev_type->id == TypeTableEntryIdUndefLit) { + prev_inst = cur_inst; + continue; } else if (prev_type->id == TypeTableEntryIdNumLitInt || prev_type->id == TypeTableEntryIdNumLitFloat) { diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 983f16f8f0..8f716daab6 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -105,37 +105,21 @@ pub const ChildProcess = struct { maybe_cwd: ?[]const u8, env_map: &const BufMap, stdin: StdIo, stdout: StdIo, stderr: StdIo, allocator: &Allocator) -> %ChildProcess { - // TODO issue #295 - //const stdin_pipe = if (stdin == StdIo.Pipe) %return makePipe() else undefined; - var stdin_pipe: [2]i32 = undefined; - if (stdin == StdIo.Pipe) - stdin_pipe = %return makePipe(); + const stdin_pipe = if (stdin == StdIo.Pipe) %return makePipe() else undefined; %defer if (stdin == StdIo.Pipe) { destroyPipe(stdin_pipe); }; - // TODO issue #295 - //const stdout_pipe = if (stdout == StdIo.Pipe) %return makePipe() else undefined; - var stdout_pipe: [2]i32 = undefined; - if (stdout == StdIo.Pipe) - stdout_pipe = %return makePipe(); + const stdout_pipe = if (stdout == StdIo.Pipe) %return makePipe() else undefined; %defer if (stdout == StdIo.Pipe) { destroyPipe(stdout_pipe); }; - // TODO issue #295 - //const stderr_pipe = if (stderr == StdIo.Pipe) %return makePipe() else undefined; - var stderr_pipe: [2]i32 = undefined; - if (stderr == StdIo.Pipe) - stderr_pipe = %return makePipe(); + const stderr_pipe = if (stderr == StdIo.Pipe) %return makePipe() else undefined; %defer if (stderr == StdIo.Pipe) { destroyPipe(stderr_pipe); }; const any_ignore = (stdin == StdIo.Ignore or stdout == StdIo.Ignore or stderr == StdIo.Ignore); - // TODO issue #295 - //const dev_null_fd = if (any_ignore) { - // %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null) - //} else { - // undefined - //}; - var dev_null_fd: i32 = undefined; - if (any_ignore) - dev_null_fd = %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null); + const dev_null_fd = if (any_ignore) { + %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null) + } else { + undefined + }; // This pipe is used to communicate errors between the time of fork // and execve from the child process to the parent process. diff --git a/test/cases/cast.zig b/test/cases/cast.zig index f51502257c..bc21ffa80f 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -195,3 +195,14 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 { return slice[0...1]; } + +test "resolve undefined with integer" { + testResolveUndefWithInt(true, 1234); + comptime testResolveUndefWithInt(true, 1234); +} +fn testResolveUndefWithInt(b: bool, x: i32) { + const value = if (b) x else undefined; + if (b) { + assert(value == x); + } +} diff --git a/test/cases/try.zig b/test/cases/try.zig index 98ed748f71..02c323e51a 100644 --- a/test/cases/try.zig +++ b/test/cases/try.zig @@ -47,13 +47,10 @@ fn failIfTrue(ok: bool) -> %void { } } -// TODO -//fn tryThenNotExecutedWithAssignment() { -// @setFnTest(this); -// -// try (failIfTrue(true)) { -// unreachable; -// } else |err| { -// assert(err == error.ItBroke); -// } -//} +test "try then not executed with assignment" { + try (failIfTrue(true)) { + unreachable; + } else |err| { + assert(err == error.ItBroke); + } +}