allow undefined to be resolved with other types

closes #295
This commit is contained in:
Andrew Kelley 2017-05-01 22:37:34 -04:00
parent cff5358f60
commit 9f92042da9
4 changed files with 31 additions and 34 deletions

View File

@ -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)
{

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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);
}
}