authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 22:09:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 22:09:47-04:00
log77a5f888be664f9ef09e2c93f52338448e992e00
tree55d417ed704efe65a406fc18c4a60fe6071ee2df
parent6b27290c681e3cc2acf71d2ef2d78830013bbccb
signaturelock-open Commit is signed but in an unrecognized format.

emit a compile error if a test becomes async

See #3117

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

src/analyze.cpp+1-1
......@@ -4195,7 +4195,7 @@ bool fn_is_async(ZigFn *fn) {
41954195 return fn->inferred_async_node != inferred_async_none;
41964196}
41974197
4198static void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
4198void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
41994199 assert(fn->inferred_async_node != nullptr);
42004200 assert(fn->inferred_async_node != inferred_async_checking);
42014201 assert(fn->inferred_async_node != inferred_async_none);
src/analyze.hpp+2
......@@ -256,4 +256,6 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
256256ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);
257257ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
258258
259void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);
260
259261#endif
src/codegen.cpp+10
......@@ -8905,6 +8905,15 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
89058905 for (size_t i = 0; i < g->test_fns.length; i += 1) {
89068906 ZigFn *test_fn_entry = g->test_fns.at(i);
89078907
8908 if (fn_is_async(test_fn_entry)) {
8909 ErrorMsg *msg = add_node_error(g, test_fn_entry->proto_node,
8910 buf_create_from_str("test functions cannot be async"));
8911 add_error_note(g, msg, test_fn_entry->proto_node,
8912 buf_sprintf("this restriction may be lifted in the future. See https://github.com/ziglang/zig/issues/3117 for more details"));
8913 add_async_error_notes(g, msg, test_fn_entry);
8914 continue;
8915 }
8916
89088917 ConstExprValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
89098918 this_val->special = ConstValSpecialStatic;
89108919 this_val->type = struct_type;
......@@ -8924,6 +8933,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
89248933 fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst;
89258934 fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry;
89268935 }
8936 report_errors_and_maybe_exit(g);
89278937
89288938 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
89298939