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.
This commit is contained in:
Andrew Kelley 2018-08-27 16:14:48 -04:00
parent 68e2794e15
commit 526d8425ab
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
3 changed files with 21 additions and 1 deletions

View File

@ -1575,7 +1575,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
switch (type_entry->id) {
case TypeTableEntryIdInvalid:
return g->builtin_types.entry_invalid;
zig_unreachable();
case TypeTableEntryIdUnreachable:
case TypeTableEntryIdUndefined:
case TypeTableEntryIdNull:
@ -1703,6 +1703,11 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
case TypeTableEntryIdUnion:
case TypeTableEntryIdFn:
case TypeTableEntryIdPromise:
if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
return g->builtin_types.entry_invalid;
if (type_requires_comptime(fn_type_id.return_type)) {
return get_generic_fn_type(g, &fn_type_id);
}
break;
}

View File

@ -11,6 +11,7 @@ comptime {
_ = @import("cases/bugs/1111.zig");
_ = @import("cases/bugs/1230.zig");
_ = @import("cases/bugs/1277.zig");
_ = @import("cases/bugs/1421.zig");
_ = @import("cases/bugs/394.zig");
_ = @import("cases/bugs/655.zig");
_ = @import("cases/bugs/656.zig");

14
test/cases/bugs/1421.zig Normal file
View File

@ -0,0 +1,14 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const S = struct {
fn method() builtin.TypeInfo {
return @typeInfo(S);
}
};
test "functions with return type required to be comptime are generic" {
const ti = S.method();
assert(builtin.TypeId(ti) == builtin.TypeId.Struct);
}