authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-27 16:14:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-27 16:14:48-04:00
log526d8425abf91b33e828b964f7d55d70e17780bf
treeb19d4b1a31d66d6a1f30f32506249c016b6e0e9b
parent68e2794e1543f91ab8f984127018820897cc0521
signaturelock-open Commit is signed but in an unrecognized format.

fix false negative determining if function is generic

This solves the smaller test case of #1421 but the other test case is still an assertion failure.

3 files changed, 21 insertions(+), 1 deletions(-)

src/analyze.cpp+6-1
......@@ -1575,7 +1575,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15751575
15761576 switch (type_entry->id) {
15771577 case TypeTableEntryIdInvalid:
1578 return g->builtin_types.entry_invalid;
1578 zig_unreachable();
15791579 case TypeTableEntryIdUnreachable:
15801580 case TypeTableEntryIdUndefined:
15811581 case TypeTableEntryIdNull:
......@@ -1703,6 +1703,11 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
17031703 case TypeTableEntryIdUnion:
17041704 case TypeTableEntryIdFn:
17051705 case TypeTableEntryIdPromise:
1706 if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
1707 return g->builtin_types.entry_invalid;
1708 if (type_requires_comptime(fn_type_id.return_type)) {
1709 return get_generic_fn_type(g, &fn_type_id);
1710 }
17061711 break;
17071712 }
17081713
test/behavior.zig+1
......@@ -11,6 +11,7 @@ comptime {
1111 _ = @import("cases/bugs/1111.zig");
1212 _ = @import("cases/bugs/1230.zig");
1313 _ = @import("cases/bugs/1277.zig");
14 _ = @import("cases/bugs/1421.zig");
1415 _ = @import("cases/bugs/394.zig");
1516 _ = @import("cases/bugs/655.zig");
1617 _ = @import("cases/bugs/656.zig");
test/cases/bugs/1421.zig created+14
......@@ -0,0 +1,14 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const assert = std.debug.assert;
4
5const S = struct {
6 fn method() builtin.TypeInfo {
7 return @typeInfo(S);
8 }
9};
10
11test "functions with return type required to be comptime are generic" {
12 const ti = S.method();
13 assert(builtin.TypeId(ti) == builtin.TypeId.Struct);
14}