stage2: LLVM backend: implement wrap_optional AIR

and move over some passing tests
This commit is contained in:
Andrew Kelley
2021-10-14 22:16:26 -07:00
parent 55eea3b045
commit cacd5366a6
11 changed files with 428 additions and 402 deletions

View File

@@ -2,3 +2,37 @@ const std = @import("std");
const testing = std.testing;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
test "passing an optional integer as a parameter" {
const S = struct {
fn entry() bool {
var x: i32 = 1234;
return foo(x);
}
fn foo(x: ?i32) bool {
return x.? == 1234;
}
};
try expect(S.entry());
comptime try expect(S.entry());
}
test "self-referential struct through a slice of optional" {
const S = struct {
const Node = struct {
children: []?Node,
data: ?u8,
fn new() Node {
return Node{
.children = undefined,
.data = null,
};
}
};
};
var n = S.Node.new();
try expect(n.data == null);
}