authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-01 22:37:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-01 22:37:34-04:00
log9f92042da9a674bcef95f9ac18945371305e7f72
treeeae251be6cea0f18ab5c623bedbde540be270063
parentcff5358f60bac70728c9b738c8311e055e96d04a

allow undefined to be resolved with other types

closes #295

4 files changed, 31 insertions(+), 34 deletions(-)

src/ir.cpp+5
......@@ -6156,6 +6156,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
61566156 {
61576157 prev_inst = cur_inst;
61586158 continue;
6159 } else if (cur_type->id == TypeTableEntryIdUndefLit) {
6160 continue;
6161 } else if (prev_type->id == TypeTableEntryIdUndefLit) {
6162 prev_inst = cur_inst;
6163 continue;
61596164 } else if (prev_type->id == TypeTableEntryIdNumLitInt ||
61606165 prev_type->id == TypeTableEntryIdNumLitFloat)
61616166 {
std/os/child_process.zig+8-24
......@@ -105,37 +105,21 @@ pub const ChildProcess = struct {
105105 maybe_cwd: ?[]const u8, env_map: &const BufMap,
106106 stdin: StdIo, stdout: StdIo, stderr: StdIo, allocator: &Allocator) -> %ChildProcess
107107 {
108 // TODO issue #295
109 //const stdin_pipe = if (stdin == StdIo.Pipe) %return makePipe() else undefined;
110 var stdin_pipe: [2]i32 = undefined;
111 if (stdin == StdIo.Pipe)
112 stdin_pipe = %return makePipe();
108 const stdin_pipe = if (stdin == StdIo.Pipe) %return makePipe() else undefined;
113109 %defer if (stdin == StdIo.Pipe) { destroyPipe(stdin_pipe); };
114110
115 // TODO issue #295
116 //const stdout_pipe = if (stdout == StdIo.Pipe) %return makePipe() else undefined;
117 var stdout_pipe: [2]i32 = undefined;
118 if (stdout == StdIo.Pipe)
119 stdout_pipe = %return makePipe();
111 const stdout_pipe = if (stdout == StdIo.Pipe) %return makePipe() else undefined;
120112 %defer if (stdout == StdIo.Pipe) { destroyPipe(stdout_pipe); };
121113
122 // TODO issue #295
123 //const stderr_pipe = if (stderr == StdIo.Pipe) %return makePipe() else undefined;
124 var stderr_pipe: [2]i32 = undefined;
125 if (stderr == StdIo.Pipe)
126 stderr_pipe = %return makePipe();
114 const stderr_pipe = if (stderr == StdIo.Pipe) %return makePipe() else undefined;
127115 %defer if (stderr == StdIo.Pipe) { destroyPipe(stderr_pipe); };
128116
129117 const any_ignore = (stdin == StdIo.Ignore or stdout == StdIo.Ignore or stderr == StdIo.Ignore);
130 // TODO issue #295
131 //const dev_null_fd = if (any_ignore) {
132 // %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)
133 //} else {
134 // undefined
135 //};
136 var dev_null_fd: i32 = undefined;
137 if (any_ignore)
138 dev_null_fd = %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null);
118 const dev_null_fd = if (any_ignore) {
119 %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)
120 } else {
121 undefined
122 };
139123
140124 // This pipe is used to communicate errors between the time of fork
141125 // and execve from the child process to the parent process.
test/cases/cast.zig+11
......@@ -195,3 +195,14 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
195195
196196 return slice[0...1];
197197}
198
199test "resolve undefined with integer" {
200 testResolveUndefWithInt(true, 1234);
201 comptime testResolveUndefWithInt(true, 1234);
202}
203fn testResolveUndefWithInt(b: bool, x: i32) {
204 const value = if (b) x else undefined;
205 if (b) {
206 assert(value == x);
207 }
208}
test/cases/try.zig+7-10
......@@ -47,13 +47,10 @@ fn failIfTrue(ok: bool) -> %void {
4747 }
4848}
4949
50// TODO
51//fn tryThenNotExecutedWithAssignment() {
52// @setFnTest(this);
53//
54// try (failIfTrue(true)) {
55// unreachable;
56// } else |err| {
57// assert(err == error.ItBroke);
58// }
59//}
50test "try then not executed with assignment" {
51 try (failIfTrue(true)) {
52 unreachable;
53 } else |err| {
54 assert(err == error.ItBroke);
55 }
56}