aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexandros Naskos <alex_naskos@hotmail.com>2018-05-03 04:43:07 +0300
committerAndrew Kelley <superjoe30@gmail.com>2018-05-02 21:43:07 -0400
commit131c133bb74eab2012158c8ecfaa78944db197c7 (patch)
treed02e9e5c9725ca18204d4e9658ad8069287e3c06 /test
parent02c1b9df3bcf2e0324adf02fd6c0ed56fe58c6d3 (diff)
downloadzig-131c133bb74eab2012158c8ecfaa78944db197c7.tar.gz
zig-131c133bb74eab2012158c8ecfaa78944db197c7.zip
Fixed inlining determination test (#972)
When deciding wether we should inline a scope, look up the parents until we get to a function definition scope
Diffstat (limited to 'test')
-rw-r--r--test/behavior.zig1
-rw-r--r--test/cases/fn_in_struct_in_comptime.zig17
2 files changed, 18 insertions, 0 deletions
diff --git a/test/behavior.zig b/test/behavior.zig
index 2c10c6d71b..3e540e0cf4 100644
--- a/test/behavior.zig
+++ b/test/behavior.zig
@@ -52,4 +52,5 @@ comptime {
_ = @import("cases/var_args.zig");
_ = @import("cases/void.zig");
_ = @import("cases/while.zig");
+ _ = @import("cases/fn_in_struct_in_comptime.zig");
}
diff --git a/test/cases/fn_in_struct_in_comptime.zig b/test/cases/fn_in_struct_in_comptime.zig
new file mode 100644
index 0000000000..4f181d7ffb
--- /dev/null
+++ b/test/cases/fn_in_struct_in_comptime.zig
@@ -0,0 +1,17 @@
+const assert = @import("std").debug.assert;
+
+fn get_foo() fn(&u8)usize {
+ comptime {
+ return struct {
+ fn func(ptr: &u8) usize {
+ var u = @ptrToInt(ptr);
+ return u;
+ }
+ }.func;
+ }
+}
+
+test "define a function in an anonymous struct in comptime" {
+ const foo = get_foo();
+ assert(foo(@intToPtr(&u8, 12345)) == 12345);
+}