authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-05-03 04:43:07+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-02 21:43:07-04:00
log131c133bb74eab2012158c8ecfaa78944db197c7
treed02e9e5c9725ca18204d4e9658ad8069287e3c06
parent02c1b9df3bcf2e0324adf02fd6c0ed56fe58c6d3

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

3 files changed, 20 insertions(+), 0 deletions(-)

src/ir.cpp+2
......@@ -145,6 +145,8 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
145145 while (scope != nullptr) {
146146 if (scope->id == ScopeIdCompTime)
147147 return true;
148 if (scope->id == ScopeIdFnDef)
149 break;
148150 scope = scope->parent;
149151 }
150152 return false;
test/behavior.zig+1
......@@ -52,4 +52,5 @@ comptime {
5252 _ = @import("cases/var_args.zig");
5353 _ = @import("cases/void.zig");
5454 _ = @import("cases/while.zig");
55 _ = @import("cases/fn_in_struct_in_comptime.zig");
5556}
test/cases/fn_in_struct_in_comptime.zig created+17
......@@ -0,0 +1,17 @@
1const assert = @import("std").debug.assert;
2
3fn get_foo() fn(&u8)usize {
4 comptime {
5 return struct {
6 fn func(ptr: &u8) usize {
7 var u = @ptrToInt(ptr);
8 return u;
9 }
10 }.func;
11 }
12}
13
14test "define a function in an anonymous struct in comptime" {
15 const foo = get_foo();
16 assert(foo(@intToPtr(&u8, 12345)) == 12345);
17}