Commit 526d8425ab

Andrew Kelley <superjoe30@gmail.com>
2018-08-27 22:14:48
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.
1 parent 68e2794
Changed files (3)
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;
     }
 
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);
+}
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");