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...@@ -6156,6 +6156,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
6156 {6156 {
6157 prev_inst = cur_inst;6157 prev_inst = cur_inst;
6158 continue;6158 continue;
6159 } else if (cur_type->id == TypeTableEntryIdUndefLit) {
6160 continue;
6161 } else if (prev_type->id == TypeTableEntryIdUndefLit) {
6162 prev_inst = cur_inst;
6163 continue;
6159 } else if (prev_type->id == TypeTableEntryIdNumLitInt ||6164 } else if (prev_type->id == TypeTableEntryIdNumLitInt ||
6160 prev_type->id == TypeTableEntryIdNumLitFloat)6165 prev_type->id == TypeTableEntryIdNumLitFloat)
6161 {6166 {
std/os/child_process.zig+8-24
...@@ -105,37 +105,21 @@ pub const ChildProcess = struct {...@@ -105,37 +105,21 @@ pub const ChildProcess = struct {
105 maybe_cwd: ?[]const u8, env_map: &const BufMap,105 maybe_cwd: ?[]const u8, env_map: &const BufMap,
106 stdin: StdIo, stdout: StdIo, stderr: StdIo, allocator: &Allocator) -> %ChildProcess106 stdin: StdIo, stdout: StdIo, stderr: StdIo, allocator: &Allocator) -> %ChildProcess
107 {107 {
108 // TODO issue #295108 const stdin_pipe = if (stdin == StdIo.Pipe) %return makePipe() else undefined;
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();
113 %defer if (stdin == StdIo.Pipe) { destroyPipe(stdin_pipe); };109 %defer if (stdin == StdIo.Pipe) { destroyPipe(stdin_pipe); };
114110
115 // TODO issue #295111 const stdout_pipe = if (stdout == StdIo.Pipe) %return makePipe() else undefined;
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();
120 %defer if (stdout == StdIo.Pipe) { destroyPipe(stdout_pipe); };112 %defer if (stdout == StdIo.Pipe) { destroyPipe(stdout_pipe); };
121113
122 // TODO issue #295114 const stderr_pipe = if (stderr == StdIo.Pipe) %return makePipe() else undefined;
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();
127 %defer if (stderr == StdIo.Pipe) { destroyPipe(stderr_pipe); };115 %defer if (stderr == StdIo.Pipe) { destroyPipe(stderr_pipe); };
128116
129 const any_ignore = (stdin == StdIo.Ignore or stdout == StdIo.Ignore or stderr == StdIo.Ignore);117 const any_ignore = (stdin == StdIo.Ignore or stdout == StdIo.Ignore or stderr == StdIo.Ignore);
130 // TODO issue #295118 const dev_null_fd = if (any_ignore) {
131 //const dev_null_fd = if (any_ignore) {119 %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)
132 // %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)120 } else {
133 //} else {121 undefined
134 // undefined122 };
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);
139123
140 // This pipe is used to communicate errors between the time of fork124 // This pipe is used to communicate errors between the time of fork
141 // and execve from the child process to the parent process.125 // 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 {...@@ -195,3 +195,14 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
195195
196 return slice[0...1];196 return slice[0...1];
197}197}
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 {...@@ -47,13 +47,10 @@ fn failIfTrue(ok: bool) -> %void {
47 }47 }
48}48}
4949
50// TODO50test "try then not executed with assignment" {
51//fn tryThenNotExecutedWithAssignment() {51 try (failIfTrue(true)) {
52// @setFnTest(this);52 unreachable;
53//53 } else |err| {
54// try (failIfTrue(true)) {54 assert(err == error.ItBroke);
55// unreachable;55 }
56// } else |err| {56}
57// assert(err == error.ItBroke);
58// }
59//}