diff --git a/src/analyze.cpp b/src/analyze.cpp index a8b3ea713..54dd84f16 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -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; } diff --git a/test/behavior.zig b/test/behavior.zig index 5a26e206b..a09288909 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -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"); diff --git a/test/cases/bugs/1421.zig b/test/cases/bugs/1421.zig new file mode 100644 index 000000000..fcbb8b70e --- /dev/null +++ b/test/cases/bugs/1421.zig @@ -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); +}