Fixed inlining determination test (#972)
When deciding wether we should inline a scope, look up the parents until we get to a function definition scopemaster
parent
02c1b9df3b
commit
131c133bb7
|
@ -145,6 +145,8 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
|
|||
while (scope != nullptr) {
|
||||
if (scope->id == ScopeIdCompTime)
|
||||
return true;
|
||||
if (scope->id == ScopeIdFnDef)
|
||||
break;
|
||||
scope = scope->parent;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue