authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 02:39:43-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 02:39:43-05:00
log9d9201c3b48873e432dc6824d42b5ca96b236daa
treebdc43bc1b664450fee07884e59106a24b72aa2cd
parent27ba4f0baf5168b2fb8f0dd72b04f528092f075a

bring back code that uses export and fix tests

partial revert of 1fdebc1dc4881a00766f7c2b4b2d8ee6ad6e79b6

19 files changed, 443 insertions(+), 698 deletions(-)

doc/langref.html.in+6
...@@ -136,6 +136,7 @@...@@ -136,6 +136,7 @@
136 <li><a href="#builtin-divFloor">@divFloor</a></li>136 <li><a href="#builtin-divFloor">@divFloor</a></li>
137 <li><a href="#builtin-divTrunc">@divTrunc</a></li>137 <li><a href="#builtin-divTrunc">@divTrunc</a></li>
138 <li><a href="#builtin-embedFile">@embedFile</a></li>138 <li><a href="#builtin-embedFile">@embedFile</a></li>
139 <li><a href="#builtin-export">@export</a></li>
139 <li><a href="#builtin-tagName">@tagName</a></li>140 <li><a href="#builtin-tagName">@tagName</a></li>
140 <li><a href="#builtin-EnumTagType">@EnumTagType</a></li>141 <li><a href="#builtin-EnumTagType">@EnumTagType</a></li>
141 <li><a href="#builtin-errorName">@errorName</a></li>142 <li><a href="#builtin-errorName">@errorName</a></li>
...@@ -4368,6 +4369,11 @@ test.zig:6:2: error: found compile log statement...@@ -4368,6 +4369,11 @@ test.zig:6:2: error: found compile log statement
4368 <ul>4369 <ul>
4369 <li><a href="#builtin-import">@import</a></li>4370 <li><a href="#builtin-import">@import</a></li>
4370 </ul>4371 </ul>
4372 <h3 id="builtin-export">@export</h3>
4373 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>
4374 <p>
4375 Creates a symbol in the output object file.
4376 </p>
4371 <h3 id="builtin-tagName">@tagName</h3>4377 <h3 id="builtin-tagName">@tagName</h3>
4372 <pre><code class="zig">@tagName(value: var) -&gt; []const u8</code></pre>4378 <pre><code class="zig">@tagName(value: var) -&gt; []const u8</code></pre>
4373 <p>4379 <p>
example/hello_world/hello_libc.zig+2-6
...@@ -5,13 +5,9 @@ const c = @cImport({...@@ -5,13 +5,9 @@ const c = @cImport({
5 @cInclude("string.h");5 @cInclude("string.h");
6});6});
77
8comptime {8const msg = c"Hello, world!\n";
9 @export("main", main);
10}
11
12extern fn main(argc: c_int, argv: &&u8) -> c_int {
13 const msg = c"Hello, world!\n";
149
10export fn main(argc: c_int, argv: &&u8) -> c_int {
15 if (c.printf(msg) != c_int(c.strlen(msg)))11 if (c.printf(msg) != c_int(c.strlen(msg)))
16 return -1;12 return -1;
1713
example/mix_o_files/base64.zig+1-4
...@@ -1,9 +1,6 @@...@@ -1,9 +1,6 @@
1const base64 = @import("std").base64;1const base64 = @import("std").base64;
22
3comptime {3export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {
4 @export("decode_base_64", decode_base_64);
5}
6extern fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {
7 const src = source_ptr[0..source_len];4 const src = source_ptr[0..source_len];
8 const dest = dest_ptr[0..dest_len];5 const dest = dest_ptr[0..dest_len];
9 const base64_decoder = base64.standard_decoder_unsafe;6 const base64_decoder = base64.standard_decoder_unsafe;
example/shared_library/mathtest.zig+1-4
...@@ -1,6 +1,3 @@...@@ -1,6 +1,3 @@
1comptime {1export fn add(a: i32, b: i32) -> i32 {
2 @export("add", add);
3}
4extern fn add(a: i32, b: i32) -> i32 {
5 a + b2 a + b
6}3}
src/all_types.hpp-1
...@@ -1285,7 +1285,6 @@ enum BuiltinFnId {...@@ -1285,7 +1285,6 @@ enum BuiltinFnId {
1285 BuiltinFnIdSetAlignStack,1285 BuiltinFnIdSetAlignStack,
1286 BuiltinFnIdArgType,1286 BuiltinFnIdArgType,
1287 BuiltinFnIdExport,1287 BuiltinFnIdExport,
1288 BuiltinFnIdExportWithLinkage,
1289};1288};
12901289
1291struct BuiltinFnEntry {1290struct BuiltinFnEntry {
src/ast_render.cpp+6-1
...@@ -111,6 +111,10 @@ static const char *extern_string(bool is_extern) {...@@ -111,6 +111,10 @@ static const char *extern_string(bool is_extern) {
111 return is_extern ? "extern " : "";111 return is_extern ? "extern " : "";
112}112}
113113
114static const char *export_string(bool is_export) {
115 return is_export ? "export " : "";
116}
117
114//static const char *calling_convention_string(CallingConvention cc) {118//static const char *calling_convention_string(CallingConvention cc) {
115// switch (cc) {119// switch (cc) {
116// case CallingConventionUnspecified: return "";120// case CallingConventionUnspecified: return "";
...@@ -410,8 +414,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -410,8 +414,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
410 {414 {
411 const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);415 const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);
412 const char *extern_str = extern_string(node->data.fn_proto.is_extern);416 const char *extern_str = extern_string(node->data.fn_proto.is_extern);
417 const char *export_str = export_string(node->data.fn_proto.is_export);
413 const char *inline_str = inline_string(node->data.fn_proto.is_inline);418 const char *inline_str = inline_string(node->data.fn_proto.is_inline);
414 fprintf(ar->f, "%s%s%sfn", pub_str, inline_str, extern_str);419 fprintf(ar->f, "%s%s%s%sfn", pub_str, inline_str, export_str, extern_str);
415 if (node->data.fn_proto.name != nullptr) {420 if (node->data.fn_proto.name != nullptr) {
416 fprintf(ar->f, " ");421 fprintf(ar->f, " ");
417 print_symbol(ar, node->data.fn_proto.name);422 print_symbol(ar, node->data.fn_proto.name);
src/codegen.cpp+1-2
...@@ -5016,8 +5016,7 @@ static void define_builtin_fns(CodeGen *g) {...@@ -5016,8 +5016,7 @@ static void define_builtin_fns(CodeGen *g) {
5016 create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);5016 create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
5017 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);5017 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
5018 create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);5018 create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
5019 create_builtin_fn(g, BuiltinFnIdExport, "export", 2);5019 create_builtin_fn(g, BuiltinFnIdExport, "export", 3);
5020 create_builtin_fn(g, BuiltinFnIdExportWithLinkage, "exportWithLinkage", 3);
5021}5020}
50225021
5023static const char *bool_to_str(bool b) {5022static const char *bool_to_str(bool b) {
src/ir.cpp+4-10
...@@ -4739,7 +4739,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4739,7 +4739,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4739 return ir_build_arg_type(irb, scope, node, arg0_value, arg1_value);4739 return ir_build_arg_type(irb, scope, node, arg0_value, arg1_value);
4740 }4740 }
4741 case BuiltinFnIdExport:4741 case BuiltinFnIdExport:
4742 case BuiltinFnIdExportWithLinkage:
4743 {4742 {
4744 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4743 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4745 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);4744 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
...@@ -4751,15 +4750,10 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4751,15 +4750,10 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4751 if (arg1_value == irb->codegen->invalid_instruction)4750 if (arg1_value == irb->codegen->invalid_instruction)
4752 return arg1_value;4751 return arg1_value;
47534752
4754 IrInstruction *arg2_value;4753 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
4755 if (builtin_fn->id == BuiltinFnIdExportWithLinkage) {4754 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
4756 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);4755 if (arg2_value == irb->codegen->invalid_instruction)
4757 arg2_value = ir_gen_node(irb, arg2_node, scope);4756 return arg2_value;
4758 if (arg2_value == irb->codegen->invalid_instruction)
4759 return arg2_value;
4760 } else {
4761 arg2_value = nullptr;
4762 }
47634757
4764 return ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value);4758 return ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value);
4765 }4759 }
src/parser.cpp+26-4
...@@ -740,9 +740,21 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo...@@ -740,9 +740,21 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
740 return node;740 return node;
741 } else if (token->id == TokenIdAtSign) {741 } else if (token->id == TokenIdAtSign) {
742 *token_index += 1;742 *token_index += 1;
743 Token *name_tok = ast_eat_token(pc, token_index, TokenIdSymbol);743 Token *name_tok = &pc->tokens->at(*token_index);
744 Buf *name_buf;
745 if (name_tok->id == TokenIdKeywordExport) {
746 name_buf = buf_create_from_str("export");
747 *token_index += 1;
748 } else if (name_tok->id == TokenIdSymbol) {
749 name_buf = token_buf(name_tok);
750 *token_index += 1;
751 } else {
752 ast_expect_token(pc, name_tok, TokenIdSymbol);
753 zig_unreachable();
754 }
755
744 AstNode *name_node = ast_create_node(pc, NodeTypeSymbol, name_tok);756 AstNode *name_node = ast_create_node(pc, NodeTypeSymbol, name_tok);
745 name_node->data.symbol_expr.symbol = token_buf(name_tok);757 name_node->data.symbol_expr.symbol = name_buf;
746758
747 AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, token);759 AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, token);
748 node->data.fn_call_expr.fn_ref_expr = name_node;760 node->data.fn_call_expr.fn_ref_expr = name_node;
...@@ -2254,12 +2266,22 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m...@@ -2254,12 +2266,22 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
2254 fn_token = ast_eat_token(pc, token_index, TokenIdKeywordFn);2266 fn_token = ast_eat_token(pc, token_index, TokenIdKeywordFn);
2255 cc = CallingConventionStdcall;2267 cc = CallingConventionStdcall;
2256 } else if (first_token->id == TokenIdKeywordExtern) {2268 } else if (first_token->id == TokenIdKeywordExtern) {
2269 is_extern = true;
2257 *token_index += 1;2270 *token_index += 1;
2258 fn_token = ast_eat_token(pc, token_index, TokenIdKeywordFn);2271 Token *next_token = &pc->tokens->at(*token_index);
2272 if (next_token->id == TokenIdKeywordFn) {
2273 fn_token = next_token;
2274 *token_index += 1;
2275 } else if (mandatory) {
2276 ast_expect_token(pc, next_token, TokenIdKeywordFn);
2277 zig_unreachable();
2278 } else {
2279 *token_index -= 1;
2280 return nullptr;
2281 }
2259 cc = CallingConventionC;2282 cc = CallingConventionC;
2260 } else if (first_token->id == TokenIdKeywordFn) {2283 } else if (first_token->id == TokenIdKeywordFn) {
2261 fn_token = first_token;2284 fn_token = first_token;
2262 is_extern = true;
2263 *token_index += 1;2285 *token_index += 1;
2264 cc = CallingConventionUnspecified;2286 cc = CallingConventionUnspecified;
2265 } else if (mandatory) {2287 } else if (mandatory) {
src/translate_c.cpp+4-1
...@@ -73,6 +73,7 @@ struct Context {...@@ -73,6 +73,7 @@ struct Context {
73 ImportTableEntry *import;73 ImportTableEntry *import;
74 ZigList<ErrorMsg *> *errors;74 ZigList<ErrorMsg *> *errors;
75 VisibMod visib_mod;75 VisibMod visib_mod;
76 bool want_export;
76 AstNode *root;77 AstNode *root;
77 HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table;78 HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table;
78 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table;79 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table;
...@@ -3250,8 +3251,8 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {...@@ -3250,8 +3251,8 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
32503251
3251 StorageClass sc = fn_decl->getStorageClass();3252 StorageClass sc = fn_decl->getStorageClass();
3252 if (sc == SC_None) {3253 if (sc == SC_None) {
3253 // TODO add export decl
3254 proto_node->data.fn_proto.visib_mod = c->visib_mod;3254 proto_node->data.fn_proto.visib_mod = c->visib_mod;
3255 proto_node->data.fn_proto.is_export = fn_decl->hasBody() ? c->want_export : false;
3255 } else if (sc == SC_Extern || sc == SC_Static) {3256 } else if (sc == SC_Extern || sc == SC_Static) {
3256 proto_node->data.fn_proto.visib_mod = c->visib_mod;3257 proto_node->data.fn_proto.visib_mod = c->visib_mod;
3257 } else if (sc == SC_PrivateExtern) {3258 } else if (sc == SC_PrivateExtern) {
...@@ -4274,8 +4275,10 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch...@@ -4274,8 +4275,10 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
4274 c->errors = errors;4275 c->errors = errors;
4275 if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {4276 if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {
4276 c->visib_mod = VisibModPub;4277 c->visib_mod = VisibModPub;
4278 c->want_export = false;
4277 } else {4279 } else {
4278 c->visib_mod = VisibModPub;4280 c->visib_mod = VisibModPub;
4281 c->want_export = true;
4279 }4282 }
4280 c->decl_table.init(8);4283 c->decl_table.init(8);
4281 c->macro_table.init(8);4284 c->macro_table.init(8);
std/special/bootstrap.zig+4-3
...@@ -8,12 +8,13 @@ const builtin = @import("builtin");...@@ -8,12 +8,13 @@ const builtin = @import("builtin");
8var argc_ptr: &usize = undefined;8var argc_ptr: &usize = undefined;
99
10comptime {10comptime {
11 const strong_linkage = builtin.GlobalLinkage.Strong;
11 if (builtin.link_libc) {12 if (builtin.link_libc) {
12 @export("main", main);13 @export("main", main, strong_linkage);
13 } else if (builtin.os == builtin.Os.windows) {14 } else if (builtin.os == builtin.Os.windows) {
14 @export("WinMainCRTStartup", WinMainCRTStartup);15 @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage);
15 } else {16 } else {
16 @export("_start", _start);17 @export("_start", _start, strong_linkage);
17 }18 }
18}19}
1920
std/special/builtin.zig+13-22
...@@ -13,24 +13,10 @@ pub coldcc fn panic(msg: []const u8) -> noreturn {...@@ -13,24 +13,10 @@ pub coldcc fn panic(msg: []const u8) -> noreturn {
13 }13 }
14}14}
1515
16comptime {
17 @export("memset", memset);
18 @export("memcpy", memcpy);
19 @export("fmodf", fmodf);
20 @export("fmod", fmod);
21 @export("floorf", floorf);
22 @export("ceilf", ceilf);
23 @export("floor", floor);
24 @export("ceil", ceil);
25 if (builtin.mode != builtin.Mode.ReleaseFast and builtin.os != builtin.Os.windows) {
26 @export("__stack_chk_fail", __stack_chk_fail);
27 }
28}
29
30// Note that memset does not return `dest`, like the libc API.16// Note that memset does not return `dest`, like the libc API.
31// The semantics of memset is dictated by the corresponding17// The semantics of memset is dictated by the corresponding
32// LLVM intrinsics, not by the libc API.18// LLVM intrinsics, not by the libc API.
33extern fn memset(dest: ?&u8, c: u8, n: usize) {19export fn memset(dest: ?&u8, c: u8, n: usize) {
34 @setDebugSafety(this, false);20 @setDebugSafety(this, false);
3521
36 var index: usize = 0;22 var index: usize = 0;
...@@ -41,7 +27,7 @@ extern fn memset(dest: ?&u8, c: u8, n: usize) {...@@ -41,7 +27,7 @@ extern fn memset(dest: ?&u8, c: u8, n: usize) {
41// Note that memcpy does not return `dest`, like the libc API.27// Note that memcpy does not return `dest`, like the libc API.
42// The semantics of memcpy is dictated by the corresponding28// The semantics of memcpy is dictated by the corresponding
43// LLVM intrinsics, not by the libc API.29// LLVM intrinsics, not by the libc API.
44extern fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {30export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
45 @setDebugSafety(this, false);31 @setDebugSafety(this, false);
4632
47 var index: usize = 0;33 var index: usize = 0;
...@@ -49,21 +35,26 @@ extern fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {...@@ -49,21 +35,26 @@ extern fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
49 (??dest)[index] = (??src)[index];35 (??dest)[index] = (??src)[index];
50}36}
5137
38comptime {
39 if (builtin.mode != builtin.Mode.ReleaseFast and builtin.os != builtin.Os.windows) {
40 @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong);
41 }
42}
52extern fn __stack_chk_fail() -> noreturn {43extern fn __stack_chk_fail() -> noreturn {
53 @panic("stack smashing detected");44 @panic("stack smashing detected");
54}45}
5546
56const math = @import("../math/index.zig");47const math = @import("../math/index.zig");
5748
58extern fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }49export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }
59extern fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }50export fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }
6051
61// TODO add intrinsics for these (and probably the double version too)52// TODO add intrinsics for these (and probably the double version too)
62// and have the math stuff use the intrinsic. same as @mod and @rem53// and have the math stuff use the intrinsic. same as @mod and @rem
63extern fn floorf(x: f32) -> f32 { math.floor(x) }54export fn floorf(x: f32) -> f32 { math.floor(x) }
64extern fn ceilf(x: f32) -> f32 { math.ceil(x) }55export fn ceilf(x: f32) -> f32 { math.ceil(x) }
65extern fn floor(x: f64) -> f64 { math.floor(x) }56export fn floor(x: f64) -> f64 { math.floor(x) }
66extern fn ceil(x: f64) -> f64 { math.ceil(x) }57export fn ceil(x: f64) -> f64 { math.ceil(x) }
6758
68fn generic_fmod(comptime T: type, x: T, y: T) -> T {59fn generic_fmod(comptime T: type, x: T, y: T) -> T {
69 @setDebugSafety(this, false);60 @setDebugSafety(this, false);
std/special/compiler_rt/index.zig+34-34
...@@ -5,62 +5,62 @@ comptime {...@@ -5,62 +5,62 @@ comptime {
5 const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;5 const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;
6 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;6 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
77
8 @exportWithLinkage("__letf2", @import("comparetf2.zig").__letf2, linkage);8 @export("__letf2", @import("comparetf2.zig").__letf2, linkage);
9 @exportWithLinkage("__getf2", @import("comparetf2.zig").__getf2, linkage);9 @export("__getf2", @import("comparetf2.zig").__getf2, linkage);
1010
11 if (!is_test) {11 if (!is_test) {
12 // only create these aliases when not testing12 // only create these aliases when not testing
13 @exportWithLinkage("__cmptf2", @import("comparetf2.zig").__letf2, linkage);13 @export("__cmptf2", @import("comparetf2.zig").__letf2, linkage);
14 @exportWithLinkage("__eqtf2", @import("comparetf2.zig").__letf2, linkage);14 @export("__eqtf2", @import("comparetf2.zig").__letf2, linkage);
15 @exportWithLinkage("__lttf2", @import("comparetf2.zig").__letf2, linkage);15 @export("__lttf2", @import("comparetf2.zig").__letf2, linkage);
16 @exportWithLinkage("__netf2", @import("comparetf2.zig").__letf2, linkage);16 @export("__netf2", @import("comparetf2.zig").__letf2, linkage);
17 @exportWithLinkage("__gttf2", @import("comparetf2.zig").__getf2, linkage);17 @export("__gttf2", @import("comparetf2.zig").__getf2, linkage);
18 }18 }
1919
20 @exportWithLinkage("__unordtf2", @import("comparetf2.zig").__unordtf2, linkage);20 @export("__unordtf2", @import("comparetf2.zig").__unordtf2, linkage);
2121
22 @exportWithLinkage("__fixunssfsi", @import("fixunssfsi.zig").__fixunssfsi, linkage);22 @export("__fixunssfsi", @import("fixunssfsi.zig").__fixunssfsi, linkage);
23 @exportWithLinkage("__fixunssfdi", @import("fixunssfdi.zig").__fixunssfdi, linkage);23 @export("__fixunssfdi", @import("fixunssfdi.zig").__fixunssfdi, linkage);
24 @exportWithLinkage("__fixunssfti", @import("fixunssfti.zig").__fixunssfti, linkage);24 @export("__fixunssfti", @import("fixunssfti.zig").__fixunssfti, linkage);
2525
26 @exportWithLinkage("__fixunsdfsi", @import("fixunsdfsi.zig").__fixunsdfsi, linkage);26 @export("__fixunsdfsi", @import("fixunsdfsi.zig").__fixunsdfsi, linkage);
27 @exportWithLinkage("__fixunsdfdi", @import("fixunsdfdi.zig").__fixunsdfdi, linkage);27 @export("__fixunsdfdi", @import("fixunsdfdi.zig").__fixunsdfdi, linkage);
28 @exportWithLinkage("__fixunsdfti", @import("fixunsdfti.zig").__fixunsdfti, linkage);28 @export("__fixunsdfti", @import("fixunsdfti.zig").__fixunsdfti, linkage);
2929
30 @exportWithLinkage("__fixunstfsi", @import("fixunstfsi.zig").__fixunstfsi, linkage);30 @export("__fixunstfsi", @import("fixunstfsi.zig").__fixunstfsi, linkage);
31 @exportWithLinkage("__fixunstfdi", @import("fixunstfdi.zig").__fixunstfdi, linkage);31 @export("__fixunstfdi", @import("fixunstfdi.zig").__fixunstfdi, linkage);
32 @exportWithLinkage("__fixunstfti", @import("fixunstfti.zig").__fixunstfti, linkage);32 @export("__fixunstfti", @import("fixunstfti.zig").__fixunstfti, linkage);
3333
34 @exportWithLinkage("__udivmoddi4", @import("udivmoddi4.zig").__udivmoddi4, linkage);34 @export("__udivmoddi4", @import("udivmoddi4.zig").__udivmoddi4, linkage);
35 @exportWithLinkage("__udivmodti4", @import("udivmodti4.zig").__udivmodti4, linkage);35 @export("__udivmodti4", @import("udivmodti4.zig").__udivmodti4, linkage);
3636
37 @exportWithLinkage("__udivti3", @import("udivti3.zig").__udivti3, linkage);37 @export("__udivti3", @import("udivti3.zig").__udivti3, linkage);
38 @exportWithLinkage("__umodti3", @import("umodti3.zig").__umodti3, linkage);38 @export("__umodti3", @import("umodti3.zig").__umodti3, linkage);
3939
40 @exportWithLinkage("__udivsi3", __udivsi3, linkage);40 @export("__udivsi3", __udivsi3, linkage);
41 @exportWithLinkage("__udivdi3", __udivdi3, linkage);41 @export("__udivdi3", __udivdi3, linkage);
42 @exportWithLinkage("__umoddi3", __umoddi3, linkage);42 @export("__umoddi3", __umoddi3, linkage);
43 @exportWithLinkage("__udivmodsi4", __udivmodsi4, linkage);43 @export("__udivmodsi4", __udivmodsi4, linkage);
4444
45 if (isArmArch()) {45 if (isArmArch()) {
46 @exportWithLinkage("__aeabi_uldivmod", __aeabi_uldivmod, linkage);46 @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);
47 @exportWithLinkage("__aeabi_uidivmod", __aeabi_uidivmod, linkage);47 @export("__aeabi_uidivmod", __aeabi_uidivmod, linkage);
48 @exportWithLinkage("__aeabi_uidiv", __udivsi3, linkage);48 @export("__aeabi_uidiv", __udivsi3, linkage);
49 }49 }
50 if (builtin.os == builtin.Os.windows) {50 if (builtin.os == builtin.Os.windows) {
51 switch (builtin.arch) {51 switch (builtin.arch) {
52 builtin.Arch.i386 => {52 builtin.Arch.i386 => {
53 if (!builtin.link_libc) {53 if (!builtin.link_libc) {
54 @exportWithLinkage("_chkstk", _chkstk, strong_linkage);54 @export("_chkstk", _chkstk, strong_linkage);
55 @exportWithLinkage("__chkstk_ms", __chkstk_ms, linkage);55 @export("__chkstk_ms", __chkstk_ms, linkage);
56 }56 }
57 @exportWithLinkage("_aulldiv", @import("aulldiv.zig")._aulldiv, strong_linkage);57 @export("_aulldiv", @import("aulldiv.zig")._aulldiv, strong_linkage);
58 @exportWithLinkage("_aullrem", @import("aullrem.zig")._aullrem, strong_linkage);58 @export("_aullrem", @import("aullrem.zig")._aullrem, strong_linkage);
59 },59 },
60 builtin.Arch.x86_64 => {60 builtin.Arch.x86_64 => {
61 if (!builtin.link_libc) {61 if (!builtin.link_libc) {
62 @exportWithLinkage("__chkstk", __chkstk, strong_linkage);62 @export("__chkstk", __chkstk, strong_linkage);
63 @exportWithLinkage("___chkstk_ms", ___chkstk_ms, linkage);63 @export("___chkstk_ms", ___chkstk_ms, linkage);
64 }64 }
65 },65 },
66 else => {},66 else => {},
test/cases/asm.zig+6-7
...@@ -2,24 +2,23 @@ const config = @import("builtin");...@@ -2,24 +2,23 @@ const config = @import("builtin");
2const assert = @import("std").debug.assert;2const assert = @import("std").debug.assert;
33
4comptime {4comptime {
5 @export("derp", derp);
6 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {5 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
7 asm volatile (6 asm volatile (
8 \\.globl my_aoeu_symbol_asdf;7 \\.globl aoeu;
9 \\.type my_aoeu_symbol_asdf, @function;8 \\.type aoeu, @function;
10 \\.set my_aoeu_symbol_asdf, derp;9 \\.set aoeu, derp;
11 );10 );
12 }11 }
13}12}
1413
15test "module level assembly" {14test "module level assembly" {
16 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {15 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
17 assert(my_aoeu_symbol_asdf() == 1234);16 assert(aoeu() == 1234);
18 }17 }
19}18}
2019
21extern fn my_aoeu_symbol_asdf() -> i32;20extern fn aoeu() -> i32;
2221
23extern fn derp() -> i32 {22export fn derp() -> i32 {
24 return 1234;23 return 1234;
25}24}
test/cases/misc.zig+3-17
...@@ -13,8 +13,9 @@ test "empty function with comments" {...@@ -13,8 +13,9 @@ test "empty function with comments" {
13}13}
1414
15comptime {15comptime {
16 @exportWithLinkage("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal) 16 @export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal);
17}17}
18
18extern fn disabledExternFn() {19extern fn disabledExternFn() {
19}20}
2021
...@@ -535,10 +536,7 @@ var global_ptr = &gdt[0];...@@ -535,10 +536,7 @@ var global_ptr = &gdt[0];
535// can't really run this test but we can make sure it has no compile error536// can't really run this test but we can make sure it has no compile error
536// and generates code537// and generates code
537const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];538const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];
538comptime {539export fn writeToVRam() {
539 @export("writeToVRam", writeToVRam);
540}
541extern fn writeToVRam() {
542 vram[0] = 'X';540 vram[0] = 'X';
543}541}
544542
...@@ -562,15 +560,3 @@ fn hereIsAnOpaqueType(ptr: &OpaqueA) -> &OpaqueA {...@@ -562,15 +560,3 @@ fn hereIsAnOpaqueType(ptr: &OpaqueA) -> &OpaqueA {
562 var a = ptr;560 var a = ptr;
563 return a;561 return a;
564}562}
565
566test "function and variable in weird section" {
567 if (builtin.os == builtin.Os.linux or builtin.os == builtin.Os.windows) {
568 // macos can't handle this
569 assert(fnInWeirdSection() == 1234);
570 }
571}
572
573var varInWeirdSection: i32 section(".data2") = 1234;
574fn fnInWeirdSection() section(".text2") -> i32 {
575 return varInWeirdSection;
576}
test/compare_output.zig+5-11
...@@ -4,8 +4,7 @@ const tests = @import("tests.zig");...@@ -4,8 +4,7 @@ const tests = @import("tests.zig");
4pub fn addCases(cases: &tests.CompareOutputContext) {4pub fn addCases(cases: &tests.CompareOutputContext) {
5 cases.addC("hello world with libc",5 cases.addC("hello world with libc",
6 \\const c = @cImport(@cInclude("stdio.h"));6 \\const c = @cImport(@cInclude("stdio.h"));
7 \\comptime { @export("main", main); }7 \\export fn main(argc: c_int, argv: &&u8) -> c_int {
8 \\extern fn main(argc: c_int, argv: &&u8) -> c_int {
9 \\ _ = c.puts(c"Hello, world!");8 \\ _ = c.puts(c"Hello, world!");
10 \\ return 0;9 \\ return 0;
11 \\}10 \\}
...@@ -138,8 +137,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -138,8 +137,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
138 \\ @cInclude("stdio.h");137 \\ @cInclude("stdio.h");
139 \\});138 \\});
140 \\139 \\
141 \\comptime { @export("main", main); }140 \\export fn main(argc: c_int, argv: &&u8) -> c_int {
142 \\extern fn main(argc: c_int, argv: &&u8) -> c_int {
143 \\ if (is_windows) {141 \\ if (is_windows) {
144 \\ // we want actual \n, not \r\n142 \\ // we want actual \n, not \r\n
145 \\ _ = c._setmode(1, c._O_BINARY);143 \\ _ = c._setmode(1, c._O_BINARY);
...@@ -284,10 +282,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -284,10 +282,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
284 cases.addC("expose function pointer to C land",282 cases.addC("expose function pointer to C land",
285 \\const c = @cImport(@cInclude("stdlib.h"));283 \\const c = @cImport(@cInclude("stdlib.h"));
286 \\284 \\
287 \\comptime {285 \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
288 \\ @export("main", main);
289 \\}
290 \\extern fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
291 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);286 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
292 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);287 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
293 \\ if (*a_int < *b_int) {288 \\ if (*a_int < *b_int) {
...@@ -299,7 +294,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -299,7 +294,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
299 \\ }294 \\ }
300 \\}295 \\}
301 \\296 \\
302 \\extern fn main() -> c_int {297 \\export fn main() -> c_int {
303 \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };298 \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
304 \\299 \\
305 \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);300 \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
...@@ -327,8 +322,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -327,8 +322,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
327 \\ @cInclude("stdio.h");322 \\ @cInclude("stdio.h");
328 \\});323 \\});
329 \\324 \\
330 \\comptime { @export("main", main); }325 \\export fn main(argc: c_int, argv: &&u8) -> c_int {
331 \\extern fn main(argc: c_int, argv: &&u8) -> c_int {
332 \\ if (is_windows) {326 \\ if (is_windows) {
333 \\ // we want actual \n, not \r\n327 \\ // we want actual \n, not \r\n
334 \\ _ = c._setmode(1, c._O_BINARY);328 \\ _ = c._setmode(1, c._O_BINARY);
test/compile_errors.zig+294-535
...@@ -1,328 +1,253 @@...@@ -1,328 +1,253 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) {3pub fn addCases(cases: &tests.CompileErrorContext) {
4 cases.add("wrong return type for main",
5 \\pub fn main() { }
6 , ".tmp_source.zig:1:15: error: expected return type of main to be '%void', instead is 'void'");
7
8 cases.add("double ?? on main return value",
9 \\pub fn main() -> ??void {
10 \\}
11 , ".tmp_source.zig:1:18: error: expected return type of main to be '%void', instead is '??void'");
12
13 cases.add("setting a section on an extern variable",
14 \\extern var foo: i32 section(".text2");
15 \\extern fn entry() -> i32 {
16 \\ return foo;
17 \\}
18 \\comptime { @export("entry", entry); }
19 ,
20 ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'");
21
22 cases.add("setting a section on a local variable",
23 \\extern fn entry() -> i32 {
24 \\ var foo: i32 section(".text2") = 1234;
25 \\ return foo;
26 \\}
27 \\comptime { @export("entry", entry); }
28 ,
29 ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'");
30
31 cases.add("setting a section on an extern fn",
32 \\extern fn foo() section(".text2");
33 \\extern fn entry() {
34 \\ foo();
35 \\}
36 \\comptime { @export("entry", entry); }
37 ,
38 ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'");
39
40 cases.add("wrong types given to exportWithLinkage",
41 \\extern fn entry() { }
42 \\comptime {
43 \\ @exportWithLinkage("entry", entry, u32(1234));
44 \\}
45 ,
46 ".tmp_source.zig:3:43: error: expected type 'GlobalLinkage', found 'u32'");
47
48 cases.add("implicit semicolon - block statement",4 cases.add("implicit semicolon - block statement",
49 \\extern fn entry() {5 \\export fn entry() {
50 \\ {}6 \\ {}
51 \\ var good = {};7 \\ var good = {};
52 \\ ({})8 \\ ({})
53 \\ var bad = {};9 \\ var bad = {};
54 \\}10 \\}
55 \\comptime {@export("entry", entry);}
56 , ".tmp_source.zig:5:5: error: invalid token: 'var'");11 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
5712
58 cases.add("implicit semicolon - block expr",13 cases.add("implicit semicolon - block expr",
59 \\extern fn entry() {14 \\export fn entry() {
60 \\ _ = {};15 \\ _ = {};
61 \\ var good = {};16 \\ var good = {};
62 \\ _ = {}17 \\ _ = {}
63 \\ var bad = {};18 \\ var bad = {};
64 \\}19 \\}
65 \\comptime {@export("entry", entry);}
66 , ".tmp_source.zig:5:5: error: invalid token: 'var'");20 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
6721
68 cases.add("implicit semicolon - comptime statement",22 cases.add("implicit semicolon - comptime statement",
69 \\extern fn entry() {23 \\export fn entry() {
70 \\ comptime {}24 \\ comptime {}
71 \\ var good = {};25 \\ var good = {};
72 \\ comptime ({})26 \\ comptime ({})
73 \\ var bad = {};27 \\ var bad = {};
74 \\}28 \\}
75 \\comptime {@export("entry", entry);}
76 , ".tmp_source.zig:5:5: error: invalid token: 'var'");29 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
7730
78 cases.add("implicit semicolon - comptime expression",31 cases.add("implicit semicolon - comptime expression",
79 \\extern fn entry() {32 \\export fn entry() {
80 \\ _ = comptime {};33 \\ _ = comptime {};
81 \\ var good = {};34 \\ var good = {};
82 \\ _ = comptime {}35 \\ _ = comptime {}
83 \\ var bad = {};36 \\ var bad = {};
84 \\}37 \\}
85 \\comptime {@export("entry", entry);}
86 , ".tmp_source.zig:5:5: error: invalid token: 'var'");38 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
8739
88 cases.add("implicit semicolon - defer",40 cases.add("implicit semicolon - defer",
89 \\extern fn entry() {41 \\export fn entry() {
90 \\ defer {}42 \\ defer {}
91 \\ var good = {};43 \\ var good = {};
92 \\ defer ({})44 \\ defer ({})
93 \\ var bad = {};45 \\ var bad = {};
94 \\}46 \\}
95 \\comptime {@export("entry", entry);}
96 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");47 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
9748
98 cases.add("implicit semicolon - if statement",49 cases.add("implicit semicolon - if statement",
99 \\extern fn entry() {50 \\export fn entry() {
100 \\ if(true) {}51 \\ if(true) {}
101 \\ var good = {};52 \\ var good = {};
102 \\ if(true) ({})53 \\ if(true) ({})
103 \\ var bad = {};54 \\ var bad = {};
104 \\}55 \\}
105 \\comptime {@export("entry", entry);}
106 , ".tmp_source.zig:5:5: error: invalid token: 'var'");56 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
10757
108 cases.add("implicit semicolon - if expression",58 cases.add("implicit semicolon - if expression",
109 \\extern fn entry() {59 \\export fn entry() {
110 \\ _ = if(true) {};60 \\ _ = if(true) {};
111 \\ var good = {};61 \\ var good = {};
112 \\ _ = if(true) {}62 \\ _ = if(true) {}
113 \\ var bad = {};63 \\ var bad = {};
114 \\}64 \\}
115 \\comptime {@export("entry", entry);}
116 , ".tmp_source.zig:5:5: error: invalid token: 'var'");65 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
11766
118 cases.add("implicit semicolon - if-else statement",67 cases.add("implicit semicolon - if-else statement",
119 \\extern fn entry() {68 \\export fn entry() {
120 \\ if(true) {} else {}69 \\ if(true) {} else {}
121 \\ var good = {};70 \\ var good = {};
122 \\ if(true) ({}) else ({})71 \\ if(true) ({}) else ({})
123 \\ var bad = {};72 \\ var bad = {};
124 \\}73 \\}
125 \\comptime {@export("entry", entry);}
126 , ".tmp_source.zig:5:5: error: invalid token: 'var'");74 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
12775
128 cases.add("implicit semicolon - if-else expression",76 cases.add("implicit semicolon - if-else expression",
129 \\extern fn entry() {77 \\export fn entry() {
130 \\ _ = if(true) {} else {};78 \\ _ = if(true) {} else {};
131 \\ var good = {};79 \\ var good = {};
132 \\ _ = if(true) {} else {}80 \\ _ = if(true) {} else {}
133 \\ var bad = {};81 \\ var bad = {};
134 \\}82 \\}
135 \\comptime {@export("entry", entry);}
136 , ".tmp_source.zig:5:5: error: invalid token: 'var'");83 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
13784
138 cases.add("implicit semicolon - if-else-if statement",85 cases.add("implicit semicolon - if-else-if statement",
139 \\extern fn entry() {86 \\export fn entry() {
140 \\ if(true) {} else if(true) {}87 \\ if(true) {} else if(true) {}
141 \\ var good = {};88 \\ var good = {};
142 \\ if(true) ({}) else if(true) ({})89 \\ if(true) ({}) else if(true) ({})
143 \\ var bad = {};90 \\ var bad = {};
144 \\}91 \\}
145 \\comptime {@export("entry", entry);}
146 , ".tmp_source.zig:5:5: error: invalid token: 'var'");92 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
14793
148 cases.add("implicit semicolon - if-else-if expression",94 cases.add("implicit semicolon - if-else-if expression",
149 \\extern fn entry() {95 \\export fn entry() {
150 \\ _ = if(true) {} else if(true) {};96 \\ _ = if(true) {} else if(true) {};
151 \\ var good = {};97 \\ var good = {};
152 \\ _ = if(true) {} else if(true) {}98 \\ _ = if(true) {} else if(true) {}
153 \\ var bad = {};99 \\ var bad = {};
154 \\}100 \\}
155 \\comptime {@export("entry", entry);}
156 , ".tmp_source.zig:5:5: error: invalid token: 'var'");101 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
157102
158 cases.add("implicit semicolon - if-else-if-else statement",103 cases.add("implicit semicolon - if-else-if-else statement",
159 \\extern fn entry() {104 \\export fn entry() {
160 \\ if(true) {} else if(true) {} else {}105 \\ if(true) {} else if(true) {} else {}
161 \\ var good = {};106 \\ var good = {};
162 \\ if(true) ({}) else if(true) ({}) else ({})107 \\ if(true) ({}) else if(true) ({}) else ({})
163 \\ var bad = {};108 \\ var bad = {};
164 \\}109 \\}
165 \\comptime {@export("entry", entry);}
166 , ".tmp_source.zig:5:5: error: invalid token: 'var'");110 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
167111
168 cases.add("implicit semicolon - if-else-if-else expression",112 cases.add("implicit semicolon - if-else-if-else expression",
169 \\extern fn entry() {113 \\export fn entry() {
170 \\ _ = if(true) {} else if(true) {} else {};114 \\ _ = if(true) {} else if(true) {} else {};
171 \\ var good = {};115 \\ var good = {};
172 \\ _ = if(true) {} else if(true) {} else {}116 \\ _ = if(true) {} else if(true) {} else {}
173 \\ var bad = {};117 \\ var bad = {};
174 \\}118 \\}
175 \\comptime {@export("entry", entry);}
176 , ".tmp_source.zig:5:5: error: invalid token: 'var'");119 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
177120
178 cases.add("implicit semicolon - test statement",121 cases.add("implicit semicolon - test statement",
179 \\extern fn entry() {122 \\export fn entry() {
180 \\ if (foo()) |_| {}123 \\ if (foo()) |_| {}
181 \\ var good = {};124 \\ var good = {};
182 \\ if (foo()) |_| ({})125 \\ if (foo()) |_| ({})
183 \\ var bad = {};126 \\ var bad = {};
184 \\}127 \\}
185 \\comptime {@export("entry", entry);}
186 , ".tmp_source.zig:5:5: error: invalid token: 'var'");128 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
187129
188 cases.add("implicit semicolon - test expression",130 cases.add("implicit semicolon - test expression",
189 \\extern fn entry() {131 \\export fn entry() {
190 \\ _ = if (foo()) |_| {};132 \\ _ = if (foo()) |_| {};
191 \\ var good = {};133 \\ var good = {};
192 \\ _ = if (foo()) |_| {}134 \\ _ = if (foo()) |_| {}
193 \\ var bad = {};135 \\ var bad = {};
194 \\}136 \\}
195 \\comptime {@export("entry", entry);}
196 , ".tmp_source.zig:5:5: error: invalid token: 'var'");137 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
197138
198 cases.add("implicit semicolon - while statement",139 cases.add("implicit semicolon - while statement",
199 \\extern fn entry() {140 \\export fn entry() {
200 \\ while(true) {}141 \\ while(true) {}
201 \\ var good = {};142 \\ var good = {};
202 \\ while(true) ({})143 \\ while(true) ({})
203 \\ var bad = {};144 \\ var bad = {};
204 \\}145 \\}
205 \\comptime {@export("entry", entry);}
206 , ".tmp_source.zig:5:5: error: invalid token: 'var'");146 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
207147
208 cases.add("implicit semicolon - while expression",148 cases.add("implicit semicolon - while expression",
209 \\extern fn entry() {149 \\export fn entry() {
210 \\ _ = while(true) {};150 \\ _ = while(true) {};
211 \\ var good = {};151 \\ var good = {};
212 \\ _ = while(true) {}152 \\ _ = while(true) {}
213 \\ var bad = {};153 \\ var bad = {};
214 \\}154 \\}
215 \\comptime {@export("entry", entry);}
216 , ".tmp_source.zig:5:5: error: invalid token: 'var'");155 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
217156
218 cases.add("implicit semicolon - while-continue statement",157 cases.add("implicit semicolon - while-continue statement",
219 \\extern fn entry() {158 \\export fn entry() {
220 \\ while(true):({}) {}159 \\ while(true):({}) {}
221 \\ var good = {};160 \\ var good = {};
222 \\ while(true):({}) ({})161 \\ while(true):({}) ({})
223 \\ var bad = {};162 \\ var bad = {};
224 \\}163 \\}
225 \\comptime {@export("entry", entry);}
226 , ".tmp_source.zig:5:5: error: invalid token: 'var'");164 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
227165
228 cases.add("implicit semicolon - while-continue expression",166 cases.add("implicit semicolon - while-continue expression",
229 \\extern fn entry() {167 \\export fn entry() {
230 \\ _ = while(true):({}) {};168 \\ _ = while(true):({}) {};
231 \\ var good = {};169 \\ var good = {};
232 \\ _ = while(true):({}) {}170 \\ _ = while(true):({}) {}
233 \\ var bad = {};171 \\ var bad = {};
234 \\}172 \\}
235 \\comptime {@export("entry", entry);}
236 , ".tmp_source.zig:5:5: error: invalid token: 'var'");173 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
237174
238 cases.add("implicit semicolon - for statement",175 cases.add("implicit semicolon - for statement",
239 \\extern fn entry() {176 \\export fn entry() {
240 \\ for(foo()) {}177 \\ for(foo()) {}
241 \\ var good = {};178 \\ var good = {};
242 \\ for(foo()) ({})179 \\ for(foo()) ({})
243 \\ var bad = {};180 \\ var bad = {};
244 \\}181 \\}
245 \\comptime {@export("entry", entry);}
246 , ".tmp_source.zig:5:5: error: invalid token: 'var'");182 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
247183
248 cases.add("implicit semicolon - for expression",184 cases.add("implicit semicolon - for expression",
249 \\extern fn entry() {185 \\export fn entry() {
250 \\ _ = for(foo()) {};186 \\ _ = for(foo()) {};
251 \\ var good = {};187 \\ var good = {};
252 \\ _ = for(foo()) {}188 \\ _ = for(foo()) {}
253 \\ var bad = {};189 \\ var bad = {};
254 \\}190 \\}
255 \\comptime {@export("entry", entry);}
256 , ".tmp_source.zig:5:5: error: invalid token: 'var'");191 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
257192
258 cases.add("multiple function definitions",193 cases.add("multiple function definitions",
259 \\fn a() {}194 \\fn a() {}
260 \\fn a() {}195 \\fn a() {}
261 \\comptime {@export("entry", entry);}196 \\export fn entry() { a(); }
262 \\extern fn entry() { a(); }
263 , ".tmp_source.zig:2:1: error: redefinition of 'a'");197 , ".tmp_source.zig:2:1: error: redefinition of 'a'");
264198
265 cases.add("unreachable with return",199 cases.add("unreachable with return",
266 \\fn a() -> noreturn {return;}200 \\fn a() -> noreturn {return;}
267 \\comptime {@export("entry", entry);}201 \\export fn entry() { a(); }
268 \\extern fn entry() { a(); }
269 , ".tmp_source.zig:1:21: error: expected type 'noreturn', found 'void'");202 , ".tmp_source.zig:1:21: error: expected type 'noreturn', found 'void'");
270203
271 cases.add("control reaches end of non-void function",204 cases.add("control reaches end of non-void function",
272 \\fn a() -> i32 {}205 \\fn a() -> i32 {}
273 \\comptime {@export("entry", entry);}206 \\export fn entry() { _ = a(); }
274 \\extern fn entry() { _ = a(); }
275 , ".tmp_source.zig:1:15: error: expected type 'i32', found 'void'");207 , ".tmp_source.zig:1:15: error: expected type 'i32', found 'void'");
276208
277 cases.add("undefined function call",209 cases.add("undefined function call",
278 \\extern fn a() {210 \\export fn a() {
279 \\ b();211 \\ b();
280 \\}212 \\}
281 \\comptime {@export("a", a);}
282 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");213 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
283214
284 cases.add("wrong number of arguments",215 cases.add("wrong number of arguments",
285 \\extern fn a() {216 \\export fn a() {
286 \\ b(1);217 \\ b(1);
287 \\}218 \\}
288 \\fn b(a: i32, b: i32, c: i32) { }219 \\fn b(a: i32, b: i32, c: i32) { }
289 \\comptime {@export("a", a);}
290 , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1");220 , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1");
291221
292 cases.add("invalid type",222 cases.add("invalid type",
293 \\fn a() -> bogus {}223 \\fn a() -> bogus {}
294 \\comptime {@export("entry", entry);}224 \\export fn entry() { _ = a(); }
295 \\extern fn entry() { _ = a(); }
296 , ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'");225 , ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'");
297226
298 cases.add("pointer to unreachable",227 cases.add("pointer to unreachable",
299 \\fn a() -> &noreturn {}228 \\fn a() -> &noreturn {}
300 \\comptime {@export("entry", entry);}229 \\export fn entry() { _ = a(); }
301 \\extern fn entry() { _ = a(); }
302 , ".tmp_source.zig:1:12: error: pointer to unreachable not allowed");230 , ".tmp_source.zig:1:12: error: pointer to unreachable not allowed");
303231
304 cases.add("unreachable code",232 cases.add("unreachable code",
305 \\extern fn a() {233 \\export fn a() {
306 \\ return;234 \\ return;
307 \\ b();235 \\ b();
308 \\}236 \\}
309 \\237 \\
310 \\fn b() {}238 \\fn b() {}
311 \\comptime {@export("a", a);}
312 , ".tmp_source.zig:3:5: error: unreachable code");239 , ".tmp_source.zig:3:5: error: unreachable code");
313240
314 cases.add("bad import",241 cases.add("bad import",
315 \\const bogus = @import("bogus-does-not-exist.zig");242 \\const bogus = @import("bogus-does-not-exist.zig");
316 \\comptime {@export("entry", entry);}243 \\export fn entry() { bogus.bogo(); }
317 \\extern fn entry() { bogus.bogo(); }
318 , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'");244 , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'");
319245
320 cases.add("undeclared identifier",246 cases.add("undeclared identifier",
321 \\extern fn a() {247 \\export fn a() {
322 \\ b +248 \\ b +
323 \\ c249 \\ c
324 \\}250 \\}
325 \\comptime {@export("a", a);}
326 ,251 ,
327 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",252 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",
328 ".tmp_source.zig:3:5: error: use of undeclared identifier 'c'");253 ".tmp_source.zig:3:5: error: use of undeclared identifier 'c'");
...@@ -330,114 +255,99 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -330,114 +255,99 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
330 cases.add("parameter redeclaration",255 cases.add("parameter redeclaration",
331 \\fn f(a : i32, a : i32) {256 \\fn f(a : i32, a : i32) {
332 \\}257 \\}
333 \\comptime {@export("entry", entry);}258 \\export fn entry() { f(1, 2); }
334 \\extern fn entry() { f(1, 2); }
335 , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'");259 , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'");
336260
337 cases.add("local variable redeclaration",261 cases.add("local variable redeclaration",
338 \\extern fn f() {262 \\export fn f() {
339 \\ const a : i32 = 0;263 \\ const a : i32 = 0;
340 \\ const a = 0;264 \\ const a = 0;
341 \\}265 \\}
342 \\comptime {@export("f", f);}
343 , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");266 , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
344267
345 cases.add("local variable redeclares parameter",268 cases.add("local variable redeclares parameter",
346 \\fn f(a : i32) {269 \\fn f(a : i32) {
347 \\ const a = 0;270 \\ const a = 0;
348 \\}271 \\}
349 \\comptime {@export("entry", entry);}272 \\export fn entry() { f(1); }
350 \\extern fn entry() { f(1); }
351 , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'");273 , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'");
352274
353 cases.add("variable has wrong type",275 cases.add("variable has wrong type",
354 \\extern fn f() -> i32 {276 \\export fn f() -> i32 {
355 \\ const a = c"a";277 \\ const a = c"a";
356 \\ a278 \\ a
357 \\}279 \\}
358 \\comptime {@export("f", f);}
359 , ".tmp_source.zig:3:5: error: expected type 'i32', found '&const u8'");280 , ".tmp_source.zig:3:5: error: expected type 'i32', found '&const u8'");
360281
361 cases.add("if condition is bool, not int",282 cases.add("if condition is bool, not int",
362 \\extern fn f() {283 \\export fn f() {
363 \\ if (0) {}284 \\ if (0) {}
364 \\}285 \\}
365 \\comptime {@export("f", f);}
366 , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'");286 , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'");
367287
368 cases.add("assign unreachable",288 cases.add("assign unreachable",
369 \\extern fn f() {289 \\export fn f() {
370 \\ const a = return;290 \\ const a = return;
371 \\}291 \\}
372 \\comptime {@export("f", f);}
373 , ".tmp_source.zig:2:5: error: unreachable code");292 , ".tmp_source.zig:2:5: error: unreachable code");
374293
375 cases.add("unreachable variable",294 cases.add("unreachable variable",
376 \\extern fn f() {295 \\export fn f() {
377 \\ const a: noreturn = {};296 \\ const a: noreturn = {};
378 \\}297 \\}
379 \\comptime {@export("f", f);}
380 , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed");298 , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed");
381299
382 cases.add("unreachable parameter",300 cases.add("unreachable parameter",
383 \\fn f(a: noreturn) {}301 \\fn f(a: noreturn) {}
384 \\comptime {@export("entry", entry);}302 \\export fn entry() { f(); }
385 \\extern fn entry() { f(); }
386 , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed");303 , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed");
387304
388 cases.add("bad assignment target",305 cases.add("bad assignment target",
389 \\extern fn f() {306 \\export fn f() {
390 \\ 3 = 3;307 \\ 3 = 3;
391 \\}308 \\}
392 \\comptime {@export("f", f);}
393 , ".tmp_source.zig:2:7: error: cannot assign to constant");309 , ".tmp_source.zig:2:7: error: cannot assign to constant");
394310
395 cases.add("assign to constant variable",311 cases.add("assign to constant variable",
396 \\extern fn f() {312 \\export fn f() {
397 \\ const a = 3;313 \\ const a = 3;
398 \\ a = 4;314 \\ a = 4;
399 \\}315 \\}
400 \\comptime {@export("f", f);}
401 , ".tmp_source.zig:3:7: error: cannot assign to constant");316 , ".tmp_source.zig:3:7: error: cannot assign to constant");
402317
403 cases.add("use of undeclared identifier",318 cases.add("use of undeclared identifier",
404 \\extern fn f() {319 \\export fn f() {
405 \\ b = 3;320 \\ b = 3;
406 \\}321 \\}
407 \\comptime {@export("f", f);}
408 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");322 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
409323
410 cases.add("const is a statement, not an expression",324 cases.add("const is a statement, not an expression",
411 \\extern fn f() {325 \\export fn f() {
412 \\ (const a = 0);326 \\ (const a = 0);
413 \\}327 \\}
414 \\comptime {@export("f", f);}
415 , ".tmp_source.zig:2:6: error: invalid token: 'const'");328 , ".tmp_source.zig:2:6: error: invalid token: 'const'");
416329
417 cases.add("array access of undeclared identifier",330 cases.add("array access of undeclared identifier",
418 \\extern fn f() {331 \\export fn f() {
419 \\ i[i] = i[i];332 \\ i[i] = i[i];
420 \\}333 \\}
421 \\comptime {@export("f", f);}
422 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'",334 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'",
423 ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'");335 ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'");
424336
425 cases.add("array access of non array",337 cases.add("array access of non array",
426 \\extern fn f() {338 \\export fn f() {
427 \\ var bad : bool = undefined;339 \\ var bad : bool = undefined;
428 \\ bad[bad] = bad[bad];340 \\ bad[bad] = bad[bad];
429 \\}341 \\}
430 \\comptime {@export("f", f);}
431 , ".tmp_source.zig:3:8: error: array access of non-array type 'bool'",342 , ".tmp_source.zig:3:8: error: array access of non-array type 'bool'",
432 ".tmp_source.zig:3:19: error: array access of non-array type 'bool'");343 ".tmp_source.zig:3:19: error: array access of non-array type 'bool'");
433344
434 cases.add("array access with non integer index",345 cases.add("array access with non integer index",
435 \\extern fn f() {346 \\export fn f() {
436 \\ var array = "aoeu";347 \\ var array = "aoeu";
437 \\ var bad = false;348 \\ var bad = false;
438 \\ array[bad] = array[bad];349 \\ array[bad] = array[bad];
439 \\}350 \\}
440 \\comptime {@export("f", f);}
441 , ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'",351 , ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'",
442 ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'");352 ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'");
443353
...@@ -446,8 +356,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -446,8 +356,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
446 \\fn f() {356 \\fn f() {
447 \\ x = 1;357 \\ x = 1;
448 \\}358 \\}
449 \\extern fn entry() { f(); }359 \\export fn entry() { f(); }
450 \\comptime {@export("entry", entry);}
451 , ".tmp_source.zig:3:7: error: cannot assign to constant");360 , ".tmp_source.zig:3:7: error: cannot assign to constant");
452361
453362
...@@ -456,33 +365,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -456,33 +365,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
456 \\ const x : i32 = if (b) { 1 };365 \\ const x : i32 = if (b) { 1 };
457 \\ const y = if (b) { i32(1) };366 \\ const y = if (b) { i32(1) };
458 \\}367 \\}
459 \\extern fn entry() { f(true); }368 \\export fn entry() { f(true); }
460 \\comptime {@export("entry", entry);}
461 , ".tmp_source.zig:2:30: error: integer value 1 cannot be implicitly casted to type 'void'",369 , ".tmp_source.zig:2:30: error: integer value 1 cannot be implicitly casted to type 'void'",
462 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");370 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");
463371
464 cases.add("direct struct loop",372 cases.add("direct struct loop",
465 \\const A = struct { a : A, };373 \\const A = struct { a : A, };
466 \\extern fn entry() -> usize { @sizeOf(A) }374 \\export fn entry() -> usize { @sizeOf(A) }
467 \\comptime {@export("entry", entry);}
468 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");375 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
469376
470 cases.add("indirect struct loop",377 cases.add("indirect struct loop",
471 \\const A = struct { b : B, };378 \\const A = struct { b : B, };
472 \\const B = struct { c : C, };379 \\const B = struct { c : C, };
473 \\const C = struct { a : A, };380 \\const C = struct { a : A, };
474 \\extern fn entry() -> usize { @sizeOf(A) }381 \\export fn entry() -> usize { @sizeOf(A) }
475 \\comptime {@export("entry", entry);}
476 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");382 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
477383
478 cases.add("invalid struct field",384 cases.add("invalid struct field",
479 \\const A = struct { x : i32, };385 \\const A = struct { x : i32, };
480 \\extern fn f() {386 \\export fn f() {
481 \\ var a : A = undefined;387 \\ var a : A = undefined;
482 \\ a.foo = 1;388 \\ a.foo = 1;
483 \\ const y = a.bar;389 \\ const y = a.bar;
484 \\}390 \\}
485 \\comptime {@export("f", f);}
486 ,391 ,
487 ".tmp_source.zig:4:6: error: no member named 'foo' in struct 'A'",392 ".tmp_source.zig:4:6: error: no member named 'foo' in struct 'A'",
488 ".tmp_source.zig:5:16: error: no member named 'bar' in struct 'A'");393 ".tmp_source.zig:5:16: error: no member named 'bar' in struct 'A'");
...@@ -510,7 +415,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -510,7 +415,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
510 \\ y : i32,415 \\ y : i32,
511 \\ z : i32,416 \\ z : i32,
512 \\};417 \\};
513 \\extern fn f() {418 \\export fn f() {
514 \\ const a = A {419 \\ const a = A {
515 \\ .z = 1,420 \\ .z = 1,
516 \\ .y = 2,421 \\ .y = 2,
...@@ -518,7 +423,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -518,7 +423,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
518 \\ .z = 4,423 \\ .z = 4,
519 \\ };424 \\ };
520 \\}425 \\}
521 \\comptime {@export("f", f);}
522 , ".tmp_source.zig:11:9: error: duplicate field");426 , ".tmp_source.zig:11:9: error: duplicate field");
523427
524 cases.add("missing field in struct value expression",428 cases.add("missing field in struct value expression",
...@@ -527,7 +431,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -527,7 +431,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
527 \\ y : i32,431 \\ y : i32,
528 \\ z : i32,432 \\ z : i32,
529 \\};433 \\};
530 \\extern fn f() {434 \\export fn f() {
531 \\ // we want the error on the '{' not the 'A' because435 \\ // we want the error on the '{' not the 'A' because
532 \\ // the A could be a complicated expression436 \\ // the A could be a complicated expression
533 \\ const a = A {437 \\ const a = A {
...@@ -535,7 +439,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -535,7 +439,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
535 \\ .y = 2,439 \\ .y = 2,
536 \\ };440 \\ };
537 \\}441 \\}
538 \\comptime {@export("f", f);}
539 , ".tmp_source.zig:9:17: error: missing field: 'x'");442 , ".tmp_source.zig:9:17: error: missing field: 'x'");
540443
541 cases.add("invalid field in struct value expression",444 cases.add("invalid field in struct value expression",
...@@ -544,79 +447,69 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -544,79 +447,69 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
544 \\ y : i32,447 \\ y : i32,
545 \\ z : i32,448 \\ z : i32,
546 \\};449 \\};
547 \\extern fn f() {450 \\export fn f() {
548 \\ const a = A {451 \\ const a = A {
549 \\ .z = 4,452 \\ .z = 4,
550 \\ .y = 2,453 \\ .y = 2,
551 \\ .foo = 42,454 \\ .foo = 42,
552 \\ };455 \\ };
553 \\}456 \\}
554 \\comptime {@export("f", f);}
555 , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'");457 , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'");
556458
557 cases.add("invalid break expression",459 cases.add("invalid break expression",
558 \\extern fn f() {460 \\export fn f() {
559 \\ break;461 \\ break;
560 \\}462 \\}
561 \\comptime {@export("f", f);}
562 , ".tmp_source.zig:2:5: error: break expression outside loop");463 , ".tmp_source.zig:2:5: error: break expression outside loop");
563464
564 cases.add("invalid continue expression",465 cases.add("invalid continue expression",
565 \\extern fn f() {466 \\export fn f() {
566 \\ continue;467 \\ continue;
567 \\}468 \\}
568 \\comptime {@export("f", f);}
569 , ".tmp_source.zig:2:5: error: continue expression outside loop");469 , ".tmp_source.zig:2:5: error: continue expression outside loop");
570470
571 cases.add("invalid maybe type",471 cases.add("invalid maybe type",
572 \\extern fn f() {472 \\export fn f() {
573 \\ if (true) |x| { }473 \\ if (true) |x| { }
574 \\}474 \\}
575 \\comptime {@export("f", f);}
576 , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'");475 , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'");
577476
578 cases.add("cast unreachable",477 cases.add("cast unreachable",
579 \\fn f() -> i32 {478 \\fn f() -> i32 {
580 \\ i32(return 1)479 \\ i32(return 1)
581 \\}480 \\}
582 \\extern fn entry() { _ = f(); }481 \\export fn entry() { _ = f(); }
583 \\comptime {@export("entry", entry);}
584 , ".tmp_source.zig:2:8: error: unreachable code");482 , ".tmp_source.zig:2:8: error: unreachable code");
585483
586 cases.add("invalid builtin fn",484 cases.add("invalid builtin fn",
587 \\fn f() -> @bogus(foo) {485 \\fn f() -> @bogus(foo) {
588 \\}486 \\}
589 \\extern fn entry() { _ = f(); }487 \\export fn entry() { _ = f(); }
590 \\comptime {@export("entry", entry);}
591 , ".tmp_source.zig:1:11: error: invalid builtin function: 'bogus'");488 , ".tmp_source.zig:1:11: error: invalid builtin function: 'bogus'");
592489
593 cases.add("top level decl dependency loop",490 cases.add("top level decl dependency loop",
594 \\const a : @typeOf(b) = 0;491 \\const a : @typeOf(b) = 0;
595 \\const b : @typeOf(a) = 0;492 \\const b : @typeOf(a) = 0;
596 \\extern fn entry() {493 \\export fn entry() {
597 \\ const c = a + b;494 \\ const c = a + b;
598 \\}495 \\}
599 \\comptime {@export("entry", entry);}
600 , ".tmp_source.zig:1:1: error: 'a' depends on itself");496 , ".tmp_source.zig:1:1: error: 'a' depends on itself");
601497
602 cases.add("noalias on non pointer param",498 cases.add("noalias on non pointer param",
603 \\fn f(noalias x: i32) {}499 \\fn f(noalias x: i32) {}
604 \\extern fn entry() { f(1234); }500 \\export fn entry() { f(1234); }
605 \\comptime {@export("entry", entry);}
606 , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter");501 , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter");
607502
608 cases.add("struct init syntax for array",503 cases.add("struct init syntax for array",
609 \\const foo = []u16{.x = 1024,};504 \\const foo = []u16{.x = 1024,};
610 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }505 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
611 \\comptime {@export("entry", entry);}
612 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");506 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");
613507
614 cases.add("type variables must be constant",508 cases.add("type variables must be constant",
615 \\var foo = u8;509 \\var foo = u8;
616 \\extern fn entry() -> foo {510 \\export fn entry() -> foo {
617 \\ return 1;511 \\ return 1;
618 \\}512 \\}
619 \\comptime {@export("entry", entry);}
620 , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant");513 , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant");
621514
622515
...@@ -628,10 +521,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -628,10 +521,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
628 \\ var Bar : i32 = undefined;521 \\ var Bar : i32 = undefined;
629 \\}522 \\}
630 \\523 \\
631 \\extern fn entry() {524 \\export fn entry() {
632 \\ f(1234);525 \\ f(1234);
633 \\}526 \\}
634 \\comptime {@export("entry", entry);}
635 ,527 ,
636 ".tmp_source.zig:4:6: error: redefinition of 'Foo'",528 ".tmp_source.zig:4:6: error: redefinition of 'Foo'",
637 ".tmp_source.zig:1:1: note: previous definition is here",529 ".tmp_source.zig:1:1: note: previous definition is here",
...@@ -653,8 +545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -653,8 +545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
653 \\ }545 \\ }
654 \\}546 \\}
655 \\547 \\
656 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }548 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
657 \\comptime {@export("entry", entry);}
658 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");549 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");
659550
660 cases.add("switch expression - duplicate enumeration prong",551 cases.add("switch expression - duplicate enumeration prong",
...@@ -674,8 +565,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -674,8 +565,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
674 \\ }565 \\ }
675 \\}566 \\}
676 \\567 \\
677 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }568 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
678 \\comptime {@export("entry", entry);}
679 , ".tmp_source.zig:13:15: error: duplicate switch value",569 , ".tmp_source.zig:13:15: error: duplicate switch value",
680 ".tmp_source.zig:10:15: note: other value is here");570 ".tmp_source.zig:10:15: note: other value is here");
681571
...@@ -697,8 +587,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -697,8 +587,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
697 \\ }587 \\ }
698 \\}588 \\}
699 \\589 \\
700 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }590 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
701 \\comptime {@export("entry", entry);}
702 , ".tmp_source.zig:13:15: error: duplicate switch value",591 , ".tmp_source.zig:13:15: error: duplicate switch value",
703 ".tmp_source.zig:10:15: note: other value is here");592 ".tmp_source.zig:10:15: note: other value is here");
704593
...@@ -710,10 +599,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -710,10 +599,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
710 \\ else => true,599 \\ else => true,
711 \\ };600 \\ };
712 \\}601 \\}
713 \\extern fn entry() {602 \\export fn entry() {
714 \\ f(1234);603 \\ f(1234);
715 \\}604 \\}
716 \\comptime {@export("entry", entry);}
717 , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression");605 , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression");
718606
719 cases.add("switch expression - non exhaustive integer prongs",607 cases.add("switch expression - non exhaustive integer prongs",
...@@ -722,8 +610,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -722,8 +610,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
722 \\ 0 => {},610 \\ 0 => {},
723 \\ }611 \\ }
724 \\}612 \\}
725 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }613 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
726 \\comptime {@export("entry", entry);}
727 ,614 ,
728 ".tmp_source.zig:2:5: error: switch must handle all possibilities");615 ".tmp_source.zig:2:5: error: switch must handle all possibilities");
729616
...@@ -736,8 +623,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -736,8 +623,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
736 \\ 206 ... 255 => 3,623 \\ 206 ... 255 => 3,
737 \\ }624 \\ }
738 \\}625 \\}
739 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }626 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
740 \\comptime {@export("entry", entry);}
741 ,627 ,
742 ".tmp_source.zig:6:9: error: duplicate switch value",628 ".tmp_source.zig:6:9: error: duplicate switch value",
743 ".tmp_source.zig:5:14: note: previous value is here");629 ".tmp_source.zig:5:14: note: previous value is here");
...@@ -749,16 +635,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -749,16 +635,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
749 \\ }635 \\ }
750 \\}636 \\}
751 \\const y: u8 = 100;637 \\const y: u8 = 100;
752 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }638 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
753 \\comptime {@export("entry", entry);}
754 ,639 ,
755 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");640 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");
756641
757 cases.add("global variable initializer must be constant expression",642 cases.add("global variable initializer must be constant expression",
758 \\extern fn foo() -> i32;643 \\extern fn foo() -> i32;
759 \\const x = foo();644 \\const x = foo();
760 \\extern fn entry() -> i32 { x }645 \\export fn entry() -> i32 { x }
761 \\comptime {@export("entry", entry);}
762 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");646 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");
763647
764 cases.add("array concatenation with wrong type",648 cases.add("array concatenation with wrong type",
...@@ -766,8 +650,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -766,8 +650,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
766 \\const derp = usize(1234);650 \\const derp = usize(1234);
767 \\const a = derp ++ "foo";651 \\const a = derp ++ "foo";
768 \\652 \\
769 \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) }653 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
770 \\comptime {@export("entry", entry);}
771 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");654 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");
772655
773 cases.add("non compile time array concatenation",656 cases.add("non compile time array concatenation",
...@@ -775,14 +658,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -775,14 +658,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
775 \\ s ++ "foo"658 \\ s ++ "foo"
776 \\}659 \\}
777 \\var s: [10]u8 = undefined;660 \\var s: [10]u8 = undefined;
778 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }661 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
779 \\comptime {@export("entry", entry);}
780 , ".tmp_source.zig:2:5: error: unable to evaluate constant expression");662 , ".tmp_source.zig:2:5: error: unable to evaluate constant expression");
781663
782 cases.add("@cImport with bogus include",664 cases.add("@cImport with bogus include",
783 \\const c = @cImport(@cInclude("bogus.h"));665 \\const c = @cImport(@cInclude("bogus.h"));
784 \\extern fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) }666 \\export fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) }
785 \\comptime {@export("entry", entry);}
786 , ".tmp_source.zig:1:11: error: C import failed",667 , ".tmp_source.zig:1:11: error: C import failed",
787 ".h:1:10: note: 'bogus.h' file not found");668 ".h:1:10: note: 'bogus.h' file not found");
788669
...@@ -790,20 +671,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -790,20 +671,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
790 \\const x = 3;671 \\const x = 3;
791 \\const y = &x;672 \\const y = &x;
792 \\fn foo() -> &const i32 { y }673 \\fn foo() -> &const i32 { y }
793 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }674 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
794 \\comptime {@export("entry", entry);}
795 , ".tmp_source.zig:3:26: error: expected type '&const i32', found '&const (integer literal)'");675 , ".tmp_source.zig:3:26: error: expected type '&const i32', found '&const (integer literal)'");
796676
797 cases.add("integer overflow error",677 cases.add("integer overflow error",
798 \\const x : u8 = 300;678 \\const x : u8 = 300;
799 \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) }679 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
800 \\comptime {@export("entry", entry);}
801 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");680 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
802681
803 cases.add("incompatible number literals",682 cases.add("incompatible number literals",
804 \\const x = 2 == 2.0;683 \\const x = 2 == 2.0;
805 \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) }684 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
806 \\comptime {@export("entry", entry);}
807 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");685 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
808686
809 cases.add("missing function call param",687 cases.add("missing function call param",
...@@ -829,15 +707,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -829,15 +707,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
829 \\ const result = members[index]();707 \\ const result = members[index]();
830 \\}708 \\}
831 \\709 \\
832 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }710 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
833 \\comptime {@export("entry", entry);}
834 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");711 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");
835712
836 cases.add("missing function name and param name",713 cases.add("missing function name and param name",
837 \\fn () {}714 \\fn () {}
838 \\fn f(i32) {}715 \\fn f(i32) {}
839 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }716 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
840 \\comptime {@export("entry", entry);}
841 ,717 ,
842 ".tmp_source.zig:1:1: error: missing function name",718 ".tmp_source.zig:1:1: error: missing function name",
843 ".tmp_source.zig:2:6: error: missing parameter name");719 ".tmp_source.zig:2:6: error: missing parameter name");
...@@ -847,20 +723,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -847,20 +723,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
847 \\fn a() -> i32 {0}723 \\fn a() -> i32 {0}
848 \\fn b() -> i32 {1}724 \\fn b() -> i32 {1}
849 \\fn c() -> i32 {2}725 \\fn c() -> i32 {2}
850 \\extern fn entry() -> usize { @sizeOf(@typeOf(fns)) }726 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
851 \\comptime {@export("entry", entry);}
852 , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");727 , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");
853728
854 cases.add("extern function pointer mismatch",729 cases.add("extern function pointer mismatch",
855 \\const fns = [](fn(i32)->i32){ a, b, c };730 \\const fns = [](fn(i32)->i32){ a, b, c };
856 \\pub fn a(x: i32) -> i32 {x + 0}731 \\pub fn a(x: i32) -> i32 {x + 0}
857 \\pub fn b(x: i32) -> i32 {x + 1}732 \\pub fn b(x: i32) -> i32 {x + 1}
858 \\extern fn c(x: i32) -> i32 {x + 2}733 \\export fn c(x: i32) -> i32 {x + 2}
859 \\
860 \\extern fn entry() -> usize { @sizeOf(@typeOf(fns)) }
861 \\734 \\
862 \\comptime {@export("entry", entry);}735 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
863 \\comptime {@export("c", c);}
864 , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");736 , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
865737
866738
...@@ -868,16 +740,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -868,16 +740,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
868 \\const x : f64 = 1.0;740 \\const x : f64 = 1.0;
869 \\const y : f32 = x;741 \\const y : f32 = x;
870 \\742 \\
871 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }743 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
872 \\comptime {@export("entry", entry);}
873 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");744 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");
874745
875746
876 cases.add("colliding invalid top level functions",747 cases.add("colliding invalid top level functions",
877 \\fn func() -> bogus {}748 \\fn func() -> bogus {}
878 \\fn func() -> bogus {}749 \\fn func() -> bogus {}
879 \\extern fn entry() -> usize { @sizeOf(@typeOf(func)) }750 \\export fn entry() -> usize { @sizeOf(@typeOf(func)) }
880 \\comptime {@export("entry", entry);}
881 ,751 ,
882 ".tmp_source.zig:2:1: error: redefinition of 'func'",752 ".tmp_source.zig:2:1: error: redefinition of 'func'",
883 ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");753 ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");
...@@ -885,8 +755,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -885,8 +755,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
885755
886 cases.add("bogus compile var",756 cases.add("bogus compile var",
887 \\const x = @import("builtin").bogus;757 \\const x = @import("builtin").bogus;
888 \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) }758 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
889 \\comptime {@export("entry", entry);}
890 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");759 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");
891760
892761
...@@ -897,8 +766,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -897,8 +766,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
897 \\var global_var: usize = 1;766 \\var global_var: usize = 1;
898 \\fn get() -> usize { global_var }767 \\fn get() -> usize { global_var }
899 \\768 \\
900 \\extern fn entry() -> usize { @sizeOf(@typeOf(Foo)) }769 \\export fn entry() -> usize { @sizeOf(@typeOf(Foo)) }
901 \\comptime {@export("entry", entry);}
902 ,770 ,
903 ".tmp_source.zig:5:21: error: unable to evaluate constant expression",771 ".tmp_source.zig:5:21: error: unable to evaluate constant expression",
904 ".tmp_source.zig:2:12: note: called from here",772 ".tmp_source.zig:2:12: note: called from here",
...@@ -911,8 +779,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -911,8 +779,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
911 \\};779 \\};
912 \\const x = Foo {.field = 1} + Foo {.field = 2};780 \\const x = Foo {.field = 1} + Foo {.field = 2};
913 \\781 \\
914 \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) }782 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
915 \\comptime {@export("entry", entry);}
916 , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");783 , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");
917784
918785
...@@ -922,14 +789,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -922,14 +789,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
922 \\const int_x = u32(1) / u32(0);789 \\const int_x = u32(1) / u32(0);
923 \\const float_x = f32(1.0) / f32(0.0);790 \\const float_x = f32(1.0) / f32(0.0);
924 \\791 \\
925 \\extern fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }792 \\export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }
926 \\extern fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) }793 \\export fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) }
927 \\extern fn entry3() -> usize { @sizeOf(@typeOf(int_x)) }794 \\export fn entry3() -> usize { @sizeOf(@typeOf(int_x)) }
928 \\extern fn entry4() -> usize { @sizeOf(@typeOf(float_x)) }795 \\export fn entry4() -> usize { @sizeOf(@typeOf(float_x)) }
929 \\comptime {@export("entry1", entry1);}
930 \\comptime {@export("entry2", entry2);}
931 \\comptime {@export("entry3", entry3);}
932 \\comptime {@export("entry4", entry4);}
933 ,796 ,
934 ".tmp_source.zig:1:21: error: division by zero is undefined",797 ".tmp_source.zig:1:21: error: division by zero is undefined",
935 ".tmp_source.zig:2:25: error: division by zero is undefined",798 ".tmp_source.zig:2:25: error: division by zero is undefined",
...@@ -941,16 +804,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -941,16 +804,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
941 \\const foo = "a804 \\const foo = "a
942 \\b";805 \\b";
943 \\806 \\
944 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }807 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
945 \\comptime {@export("entry", entry);}
946 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");808 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");
947809
948 cases.add("invalid comparison for function pointers",810 cases.add("invalid comparison for function pointers",
949 \\fn foo() {}811 \\fn foo() {}
950 \\const invalid = foo > foo;812 \\const invalid = foo > foo;
951 \\813 \\
952 \\extern fn entry() -> usize { @sizeOf(@typeOf(invalid)) }814 \\export fn entry() -> usize { @sizeOf(@typeOf(invalid)) }
953 \\comptime {@export("entry", entry);}
954 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");815 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");
955816
956 cases.add("generic function instance with non-constant expression",817 cases.add("generic function instance with non-constant expression",
...@@ -959,18 +820,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -959,18 +820,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
959 \\ return foo(a, b);820 \\ return foo(a, b);
960 \\}821 \\}
961 \\822 \\
962 \\extern fn entry() -> usize { @sizeOf(@typeOf(test1)) }823 \\export fn entry() -> usize { @sizeOf(@typeOf(test1)) }
963 \\comptime {@export("entry", entry);}
964 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");824 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");
965825
966 cases.add("goto jumping into block",826 cases.add("goto jumping into block",
967 \\extern fn f() {827 \\export fn f() {
968 \\ {828 \\ {
969 \\a_label:829 \\a_label:
970 \\ }830 \\ }
971 \\ goto a_label;831 \\ goto a_label;
972 \\}832 \\}
973 \\comptime {@export("f", f);}
974 , ".tmp_source.zig:5:5: error: no label in scope named 'a_label'");833 , ".tmp_source.zig:5:5: error: no label in scope named 'a_label'");
975834
976 cases.add("goto jumping past a defer",835 cases.add("goto jumping past a defer",
...@@ -981,23 +840,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -981,23 +840,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
981 \\}840 \\}
982 \\fn derp(){}841 \\fn derp(){}
983 \\842 \\
984 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }843 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
985 \\comptime {@export("entry", entry);}
986 , ".tmp_source.zig:2:12: error: no label in scope named 'label'");844 , ".tmp_source.zig:2:12: error: no label in scope named 'label'");
987845
988 cases.add("assign null to non-nullable pointer",846 cases.add("assign null to non-nullable pointer",
989 \\const a: &u8 = null;847 \\const a: &u8 = null;
990 \\848 \\
991 \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) }849 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
992 \\comptime {@export("entry", entry);}
993 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");850 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");
994851
995 cases.add("indexing an array of size zero",852 cases.add("indexing an array of size zero",
996 \\const array = []u8{};853 \\const array = []u8{};
997 \\extern fn foo() {854 \\export fn foo() {
998 \\ const pointer = &array[0];855 \\ const pointer = &array[0];
999 \\}856 \\}
1000 \\comptime {@export("foo", foo);}
1001 , ".tmp_source.zig:3:27: error: index 0 outside array of size 0");857 , ".tmp_source.zig:3:27: error: index 0 outside array of size 0");
1002858
1003 cases.add("compile time division by zero",859 cases.add("compile time division by zero",
...@@ -1006,8 +862,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1006,8 +862,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1006 \\ 1 / x862 \\ 1 / x
1007 \\}863 \\}
1008 \\864 \\
1009 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }865 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1010 \\comptime {@export("entry", entry);}
1011 ,866 ,
1012 ".tmp_source.zig:3:7: error: division by zero is undefined",867 ".tmp_source.zig:3:7: error: division by zero is undefined",
1013 ".tmp_source.zig:1:14: note: called from here");868 ".tmp_source.zig:1:14: note: called from here");
...@@ -1015,8 +870,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1015,8 +870,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1015 cases.add("branch on undefined value",870 cases.add("branch on undefined value",
1016 \\const x = if (undefined) true else false;871 \\const x = if (undefined) true else false;
1017 \\872 \\
1018 \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) }873 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1019 \\comptime {@export("entry", entry);}
1020 , ".tmp_source.zig:1:15: error: use of undefined value");874 , ".tmp_source.zig:1:15: error: use of undefined value");
1021875
1022876
...@@ -1026,8 +880,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1026,8 +880,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1026 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);880 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
1027 \\}881 \\}
1028 \\882 \\
1029 \\comptime {@export("entry", entry);}883 \\export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }
1030 \\extern fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }
1031 ,884 ,
1032 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",885 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
1033 ".tmp_source.zig:3:21: note: called from here");886 ".tmp_source.zig:3:21: note: called from here");
...@@ -1035,8 +888,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1035,8 +888,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1035 cases.add("@embedFile with bogus file",888 cases.add("@embedFile with bogus file",
1036 \\const resource = @embedFile("bogus.txt");889 \\const resource = @embedFile("bogus.txt");
1037 \\890 \\
1038 \\comptime {@export("entry", entry);}891 \\export fn entry() -> usize { @sizeOf(@typeOf(resource)) }
1039 \\extern fn entry() -> usize { @sizeOf(@typeOf(resource)) }
1040 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");892 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");
1041893
1042 cases.add("non-const expression in struct literal outside function",894 cases.add("non-const expression in struct literal outside function",
...@@ -1046,8 +898,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1046,8 +898,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1046 \\const a = Foo {.x = get_it()};898 \\const a = Foo {.x = get_it()};
1047 \\extern fn get_it() -> i32;899 \\extern fn get_it() -> i32;
1048 \\900 \\
1049 \\comptime {@export("entry", entry);}901 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1050 \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) }
1051 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");902 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");
1052903
1053 cases.add("non-const expression function call with struct return value outside function",904 cases.add("non-const expression function call with struct return value outside function",
...@@ -1061,20 +912,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1061,20 +912,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1061 \\}912 \\}
1062 \\var global_side_effect = false;913 \\var global_side_effect = false;
1063 \\914 \\
1064 \\comptime {@export("entry", entry);}915 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1065 \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) }
1066 ,916 ,
1067 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",917 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",
1068 ".tmp_source.zig:4:17: note: called from here");918 ".tmp_source.zig:4:17: note: called from here");
1069919
1070 cases.add("undeclared identifier error should mark fn as impure",920 cases.add("undeclared identifier error should mark fn as impure",
1071 \\extern fn foo() {921 \\export fn foo() {
1072 \\ test_a_thing();922 \\ test_a_thing();
1073 \\}923 \\}
1074 \\fn test_a_thing() {924 \\fn test_a_thing() {
1075 \\ bad_fn_call();925 \\ bad_fn_call();
1076 \\}926 \\}
1077 \\comptime {@export("foo", foo);}
1078 , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'");927 , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'");
1079928
1080 cases.add("illegal comparison of types",929 cases.add("illegal comparison of types",
...@@ -1089,16 +938,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1089,16 +938,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1089 \\ *a == *b938 \\ *a == *b
1090 \\}939 \\}
1091 \\940 \\
1092 \\extern fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) }941 \\export fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) }
1093 \\extern fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) }942 \\export fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) }
1094 \\comptime {@export("entry1", entry1);}
1095 \\comptime {@export("entry2", entry2);}
1096 ,943 ,
1097 ".tmp_source.zig:2:7: error: operator not allowed for type '[]u8'",944 ".tmp_source.zig:2:7: error: operator not allowed for type '[]u8'",
1098 ".tmp_source.zig:9:8: error: operator not allowed for type 'EnumWithData'");945 ".tmp_source.zig:9:8: error: operator not allowed for type 'EnumWithData'");
1099946
1100 cases.add("non-const switch number literal",947 cases.add("non-const switch number literal",
1101 \\extern fn foo() {948 \\export fn foo() {
1102 \\ const x = switch (bar()) {949 \\ const x = switch (bar()) {
1103 \\ 1, 2 => 1,950 \\ 1, 2 => 1,
1104 \\ 3, 4 => 2,951 \\ 3, 4 => 2,
...@@ -1108,25 +955,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1108,25 +955,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1108 \\fn bar() -> i32 {955 \\fn bar() -> i32 {
1109 \\ 2956 \\ 2
1110 \\}957 \\}
1111 \\comptime {@export("foo", foo);}
1112 , ".tmp_source.zig:2:15: error: unable to infer expression type");958 , ".tmp_source.zig:2:15: error: unable to infer expression type");
1113959
1114 cases.add("atomic orderings of cmpxchg - failure stricter than success",960 cases.add("atomic orderings of cmpxchg - failure stricter than success",
1115 \\const AtomicOrder = @import("builtin").AtomicOrder;961 \\const AtomicOrder = @import("builtin").AtomicOrder;
1116 \\extern fn f() {962 \\export fn f() {
1117 \\ var x: i32 = 1234;963 \\ var x: i32 = 1234;
1118 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}964 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
1119 \\}965 \\}
1120 \\comptime {@export("f", f);}
1121 , ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success");966 , ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success");
1122967
1123 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",968 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
1124 \\const AtomicOrder = @import("builtin").AtomicOrder;969 \\const AtomicOrder = @import("builtin").AtomicOrder;
1125 \\extern fn f() {970 \\export fn f() {
1126 \\ var x: i32 = 1234;971 \\ var x: i32 = 1234;
1127 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}972 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
1128 \\}973 \\}
1129 \\comptime {@export("f", f);}
1130 , ".tmp_source.zig:4:49: error: success atomic ordering must be Monotonic or stricter");974 , ".tmp_source.zig:4:49: error: success atomic ordering must be Monotonic or stricter");
1131975
1132 cases.add("negation overflow in function evaluation",976 cases.add("negation overflow in function evaluation",
...@@ -1135,8 +979,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1135,8 +979,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1135 \\ -x979 \\ -x
1136 \\}980 \\}
1137 \\981 \\
1138 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }982 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1139 \\comptime {@export("entry", entry);}
1140 ,983 ,
1141 ".tmp_source.zig:3:5: error: negation caused overflow",984 ".tmp_source.zig:3:5: error: negation caused overflow",
1142 ".tmp_source.zig:1:14: note: called from here");985 ".tmp_source.zig:1:14: note: called from here");
...@@ -1147,8 +990,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1147,8 +990,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1147 \\ a + b990 \\ a + b
1148 \\}991 \\}
1149 \\992 \\
1150 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }993 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1151 \\comptime {@export("entry", entry);}
1152 ,994 ,
1153 ".tmp_source.zig:3:7: error: operation caused overflow",995 ".tmp_source.zig:3:7: error: operation caused overflow",
1154 ".tmp_source.zig:1:14: note: called from here");996 ".tmp_source.zig:1:14: note: called from here");
...@@ -1160,8 +1002,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1160,8 +1002,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1160 \\ a - b1002 \\ a - b
1161 \\}1003 \\}
1162 \\1004 \\
1163 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }1005 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1164 \\comptime {@export("entry", entry);}
1165 ,1006 ,
1166 ".tmp_source.zig:3:7: error: operation caused overflow",1007 ".tmp_source.zig:3:7: error: operation caused overflow",
1167 ".tmp_source.zig:1:14: note: called from here");1008 ".tmp_source.zig:1:14: note: called from here");
...@@ -1172,8 +1013,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1172,8 +1013,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1172 \\ a * b1013 \\ a * b
1173 \\}1014 \\}
1174 \\1015 \\
1175 \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) }1016 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1176 \\comptime {@export("entry", entry);}
1177 ,1017 ,
1178 ".tmp_source.zig:3:7: error: operation caused overflow",1018 ".tmp_source.zig:3:7: error: operation caused overflow",
1179 ".tmp_source.zig:1:14: note: called from here");1019 ".tmp_source.zig:1:14: note: called from here");
...@@ -1184,35 +1024,40 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1184,35 +1024,40 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1184 \\ @truncate(i8, x)1024 \\ @truncate(i8, x)
1185 \\}1025 \\}
1186 \\1026 \\
1187 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }1027 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1188 \\comptime {@export("entry", entry);}
1189 , ".tmp_source.zig:3:19: error: expected signed integer type, found 'u32'");1028 , ".tmp_source.zig:3:19: error: expected signed integer type, found 'u32'");
11901029
1191 cases.add("%return in function with non error return type",1030 cases.add("%return in function with non error return type",
1192 \\extern fn f() {1031 \\export fn f() {
1193 \\ %return something();1032 \\ %return something();
1194 \\}1033 \\}
1195 \\fn something() -> %void { }1034 \\fn something() -> %void { }
1196 \\comptime {@export("f", f);}
1197 ,1035 ,
1198 ".tmp_source.zig:2:5: error: expected type 'void', found 'error'");1036 ".tmp_source.zig:2:5: error: expected type 'void', found 'error'");
11991037
1038 cases.add("wrong return type for main",
1039 \\pub fn main() { }
1040 , ".tmp_source.zig:1:15: error: expected return type of main to be '%void', instead is 'void'");
1041
1042 cases.add("double ?? on main return value",
1043 \\pub fn main() -> ??void {
1044 \\}
1045 , ".tmp_source.zig:1:18: error: expected return type of main to be '%void', instead is '??void'");
1046
1200 cases.add("invalid pointer for var type",1047 cases.add("invalid pointer for var type",
1201 \\extern fn ext() -> usize;1048 \\extern fn ext() -> usize;
1202 \\var bytes: [ext()]u8 = undefined;1049 \\var bytes: [ext()]u8 = undefined;
1203 \\extern fn f() {1050 \\export fn f() {
1204 \\ for (bytes) |*b, i| {1051 \\ for (bytes) |*b, i| {
1205 \\ *b = u8(i);1052 \\ *b = u8(i);
1206 \\ }1053 \\ }
1207 \\}1054 \\}
1208 \\comptime {@export("f", f);}
1209 , ".tmp_source.zig:2:13: error: unable to evaluate constant expression");1055 , ".tmp_source.zig:2:13: error: unable to evaluate constant expression");
12101056
1211 cases.add("export function with comptime parameter",1057 cases.add("export function with comptime parameter",
1212 \\extern fn foo(comptime x: i32, y: i32) -> i32{1058 \\export fn foo(comptime x: i32, y: i32) -> i32{
1213 \\ x + y1059 \\ x + y
1214 \\}1060 \\}
1215 \\comptime {@export("foo", foo);}
1216 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");1061 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
12171062
1218 cases.add("extern function with comptime parameter",1063 cases.add("extern function with comptime parameter",
...@@ -1220,16 +1065,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1220,16 +1065,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1220 \\fn f() -> i32 {1065 \\fn f() -> i32 {
1221 \\ foo(1, 2)1066 \\ foo(1, 2)
1222 \\}1067 \\}
1223 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }1068 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1224 \\comptime {@export("entry", entry);}
1225 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");1069 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
12261070
1227 cases.add("convert fixed size array to slice with invalid size",1071 cases.add("convert fixed size array to slice with invalid size",
1228 \\extern fn f() {1072 \\export fn f() {
1229 \\ var array: [5]u8 = undefined;1073 \\ var array: [5]u8 = undefined;
1230 \\ var foo = ([]const u32)(array)[0];1074 \\ var foo = ([]const u32)(array)[0];
1231 \\}1075 \\}
1232 \\comptime {@export("f", f);}
1233 , ".tmp_source.zig:3:28: error: unable to convert [5]u8 to []const u32: size mismatch");1076 , ".tmp_source.zig:3:28: error: unable to convert [5]u8 to []const u32: size mismatch");
12341077
1235 cases.add("non-pure function returns type",1078 cases.add("non-pure function returns type",
...@@ -1247,11 +1090,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1247,11 +1090,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1247 \\ }1090 \\ }
1248 \\}1091 \\}
1249 \\1092 \\
1250 \\extern fn function_with_return_type_type() {1093 \\export fn function_with_return_type_type() {
1251 \\ var list: List(i32) = undefined;1094 \\ var list: List(i32) = undefined;
1252 \\ list.length = 10;1095 \\ list.length = 10;
1253 \\}1096 \\}
1254 \\comptime {@export("function_with_return_type_type", function_with_return_type_type);}
1255 , ".tmp_source.zig:3:7: error: unable to evaluate constant expression",1097 , ".tmp_source.zig:3:7: error: unable to evaluate constant expression",
1256 ".tmp_source.zig:16:19: note: called from here");1098 ".tmp_source.zig:16:19: note: called from here");
12571099
...@@ -1260,8 +1102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1260,8 +1102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1260 \\fn f(m: []const u8) {1102 \\fn f(m: []const u8) {
1261 \\ m.copy(u8, self[0..], m);1103 \\ m.copy(u8, self[0..], m);
1262 \\}1104 \\}
1263 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }1105 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1264 \\comptime {@export("entry", entry);}
1265 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");1106 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
12661107
1267 cases.add("wrong number of arguments for method fn call",1108 cases.add("wrong number of arguments for method fn call",
...@@ -1272,24 +1113,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1272,24 +1113,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1272 \\1113 \\
1273 \\ foo.method(1, 2);1114 \\ foo.method(1, 2);
1274 \\}1115 \\}
1275 \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) }1116 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1276 \\comptime {@export("entry", entry);}
1277 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");1117 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");
12781118
1279 cases.add("assign through constant pointer",1119 cases.add("assign through constant pointer",
1280 \\extern fn f() {1120 \\export fn f() {
1281 \\ var cstr = c"Hat";1121 \\ var cstr = c"Hat";
1282 \\ cstr[0] = 'W';1122 \\ cstr[0] = 'W';
1283 \\}1123 \\}
1284 \\comptime {@export("f", f);}
1285 , ".tmp_source.zig:3:11: error: cannot assign to constant");1124 , ".tmp_source.zig:3:11: error: cannot assign to constant");
12861125
1287 cases.add("assign through constant slice",1126 cases.add("assign through constant slice",
1288 \\extern fn f() {1127 \\export fn f() {
1289 \\ var cstr: []const u8 = "Hat";1128 \\ var cstr: []const u8 = "Hat";
1290 \\ cstr[0] = 'W';1129 \\ cstr[0] = 'W';
1291 \\}1130 \\}
1292 \\comptime {@export("f", f);}
1293 , ".tmp_source.zig:3:11: error: cannot assign to constant");1131 , ".tmp_source.zig:3:11: error: cannot assign to constant");
12941132
1295 cases.add("main function with bogus args type",1133 cases.add("main function with bogus args type",
...@@ -1300,8 +1138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1300,8 +1138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1300 \\fn foo(blah: []u8) {1138 \\fn foo(blah: []u8) {
1301 \\ for (blah) { }1139 \\ for (blah) { }
1302 \\}1140 \\}
1303 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1141 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1304 \\comptime {@export("entry", entry);}
1305 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");1142 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");
13061143
1307 cases.add("misspelled type with pointer only reference",1144 cases.add("misspelled type with pointer only reference",
...@@ -1334,8 +1171,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1334,8 +1171,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1334 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };1171 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
1335 \\}1172 \\}
1336 \\1173 \\
1337 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1174 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1338 \\comptime {@export("entry", entry);}
1339 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");1175 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");
13401176
1341 cases.add("method call with first arg type primitive",1177 cases.add("method call with first arg type primitive",
...@@ -1349,12 +1185,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1349,12 +1185,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1349 \\ }1185 \\ }
1350 \\};1186 \\};
1351 \\1187 \\
1352 \\extern fn f() {1188 \\export fn f() {
1353 \\ const derp = Foo.init(3);1189 \\ const derp = Foo.init(3);
1354 \\1190 \\
1355 \\ derp.init();1191 \\ derp.init();
1356 \\}1192 \\}
1357 \\comptime {@export("f", f);}
1358 , ".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'");1193 , ".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'");
13591194
1360 cases.add("method call with first arg type wrong container",1195 cases.add("method call with first arg type wrong container",
...@@ -1378,11 +1213,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1378,11 +1213,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1378 \\ field: i32,1213 \\ field: i32,
1379 \\};1214 \\};
1380 \\1215 \\
1381 \\extern fn foo() {1216 \\export fn foo() {
1382 \\ var x = List.init(&global_allocator);1217 \\ var x = List.init(&global_allocator);
1383 \\ x.init();1218 \\ x.init();
1384 \\}1219 \\}
1385 \\comptime {@export("foo", foo);}
1386 , ".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'");1220 , ".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'");
13871221
1388 cases.add("binary not on number literal",1222 cases.add("binary not on number literal",
...@@ -1390,18 +1224,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1390,18 +1224,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1390 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;1224 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
1391 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);1225 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
1392 \\1226 \\
1393 \\extern fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) }1227 \\export fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) }
1394 \\comptime {@export("entry", entry);}
1395 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");1228 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");
13961229
1397 cases.addCase({1230 cases.addCase({
1398 const tc = cases.create("multiple files with private function error",1231 const tc = cases.create("multiple files with private function error",
1399 \\const foo = @import("foo.zig");1232 \\const foo = @import("foo.zig");
1400 \\1233 \\
1401 \\extern fn callPrivFunction() {1234 \\export fn callPrivFunction() {
1402 \\ foo.privateFunction();1235 \\ foo.privateFunction();
1403 \\}1236 \\}
1404 \\comptime {@export("callPrivFunction", callPrivFunction);}
1405 ,1237 ,
1406 ".tmp_source.zig:4:8: error: 'privateFunction' is private",1238 ".tmp_source.zig:4:8: error: 'privateFunction' is private",
1407 "foo.zig:1:1: note: declared here");1239 "foo.zig:1:1: note: declared here");
...@@ -1417,19 +1249,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1417,19 +1249,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1417 \\const zero: i32 = 0;1249 \\const zero: i32 = 0;
1418 \\const a = zero{1};1250 \\const a = zero{1};
1419 \\1251 \\
1420 \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) }1252 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1421 \\comptime {@export("entry", entry);}
1422 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");1253 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");
14231254
1424 cases.add("assign to constant field",1255 cases.add("assign to constant field",
1425 \\const Foo = struct {1256 \\const Foo = struct {
1426 \\ field: i32,1257 \\ field: i32,
1427 \\};1258 \\};
1428 \\extern fn derp() {1259 \\export fn derp() {
1429 \\ const f = Foo {.field = 1234,};1260 \\ const f = Foo {.field = 1234,};
1430 \\ f.field = 0;1261 \\ f.field = 0;
1431 \\}1262 \\}
1432 \\comptime {@export("derp", derp);}
1433 , ".tmp_source.zig:6:13: error: cannot assign to constant");1263 , ".tmp_source.zig:6:13: error: cannot assign to constant");
14341264
1435 cases.add("return from defer expression",1265 cases.add("return from defer expression",
...@@ -1447,8 +1277,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1447,8 +1277,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1447 \\ return 0;1277 \\ return 0;
1448 \\}1278 \\}
1449 \\1279 \\
1450 \\extern fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) }1280 \\export fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) }
1451 \\comptime {@export("entry", entry);}
1452 , ".tmp_source.zig:4:11: error: cannot return from defer expression");1281 , ".tmp_source.zig:4:11: error: cannot return from defer expression");
14531282
1454 cases.add("attempt to access var args out of bounds",1283 cases.add("attempt to access var args out of bounds",
...@@ -1460,8 +1289,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1460,8 +1289,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1460 \\ add(i32(1234))1289 \\ add(i32(1234))
1461 \\}1290 \\}
1462 \\1291 \\
1463 \\comptime {@export("entry", entry);}1292 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1464 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1465 ,1293 ,
1466 ".tmp_source.zig:2:19: error: index 1 outside argument list of size 1",1294 ".tmp_source.zig:2:19: error: index 1 outside argument list of size 1",
1467 ".tmp_source.zig:6:8: note: called from here");1295 ".tmp_source.zig:6:8: note: called from here");
...@@ -1479,31 +1307,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1479,31 +1307,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1479 \\ add(1, 2, 3, 4)1307 \\ add(1, 2, 3, 4)
1480 \\}1308 \\}
1481 \\1309 \\
1482 \\comptime {@export("entry", entry);}1310 \\export fn entry() -> usize { @sizeOf(@typeOf(bar)) }
1483 \\extern fn entry() -> usize { @sizeOf(@typeOf(bar)) }
1484 , ".tmp_source.zig:10:9: error: parameter of type '(integer literal)' requires comptime");1311 , ".tmp_source.zig:10:9: error: parameter of type '(integer literal)' requires comptime");
14851312
1486 cases.add("assign too big number to u16",1313 cases.add("assign too big number to u16",
1487 \\extern fn foo() {1314 \\export fn foo() {
1488 \\ var vga_mem: u16 = 0xB8000;1315 \\ var vga_mem: u16 = 0xB8000;
1489 \\}1316 \\}
1490 \\comptime {@export("foo", foo);}
1491 , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");1317 , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
14921318
1493 cases.add("global variable alignment non power of 2",1319 cases.add("global variable alignment non power of 2",
1494 \\const some_data: [100]u8 align(3) = undefined;1320 \\const some_data: [100]u8 align(3) = undefined;
1495 \\extern fn entry() -> usize { @sizeOf(@typeOf(some_data)) }1321 \\export fn entry() -> usize { @sizeOf(@typeOf(some_data)) }
1496 \\comptime {@export("entry", entry);}
1497 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");1322 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
14981323
1499 cases.add("function alignment non power of 2",1324 cases.add("function alignment non power of 2",
1500 \\extern fn foo() align(3);1325 \\extern fn foo() align(3);
1501 \\extern fn entry() { foo() }1326 \\export fn entry() { foo() }
1502 \\comptime {@export("entry", entry);}
1503 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");1327 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
15041328
1505 cases.add("compile log",1329 cases.add("compile log",
1506 \\extern fn foo() {1330 \\export fn foo() {
1507 \\ comptime bar(12, "hi");1331 \\ comptime bar(12, "hi");
1508 \\}1332 \\}
1509 \\fn bar(a: i32, b: []const u8) {1333 \\fn bar(a: i32, b: []const u8) {
...@@ -1511,7 +1335,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1511,7 +1335,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1511 \\ @compileLog("a", a, "b", b);1335 \\ @compileLog("a", a, "b", b);
1512 \\ @compileLog("end");1336 \\ @compileLog("end");
1513 \\}1337 \\}
1514 \\comptime {@export("foo", foo);}
1515 ,1338 ,
1516 ".tmp_source.zig:5:5: error: found compile log statement",1339 ".tmp_source.zig:5:5: error: found compile log statement",
1517 ".tmp_source.zig:2:17: note: called from here",1340 ".tmp_source.zig:2:17: note: called from here",
...@@ -1535,8 +1358,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1535,8 +1358,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1535 \\ return *x;1358 \\ return *x;
1536 \\}1359 \\}
1537 \\1360 \\
1538 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1361 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1539 \\comptime {@export("entry", entry);}
1540 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");1362 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
15411363
1542 cases.add("referring to a struct that is invalid",1364 cases.add("referring to a struct that is invalid",
...@@ -1544,20 +1366,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1544,20 +1366,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1544 \\ Type: u8,1366 \\ Type: u8,
1545 \\};1367 \\};
1546 \\1368 \\
1547 \\extern fn foo() {1369 \\export fn foo() {
1548 \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);1370 \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
1549 \\}1371 \\}
1550 \\1372 \\
1551 \\fn assert(ok: bool) {1373 \\fn assert(ok: bool) {
1552 \\ if (!ok) unreachable;1374 \\ if (!ok) unreachable;
1553 \\}1375 \\}
1554 \\comptime {@export("foo", foo);}
1555 ,1376 ,
1556 ".tmp_source.zig:10:14: error: unable to evaluate constant expression",1377 ".tmp_source.zig:10:14: error: unable to evaluate constant expression",
1557 ".tmp_source.zig:6:20: note: called from here");1378 ".tmp_source.zig:6:20: note: called from here");
15581379
1559 cases.add("control flow uses comptime var at runtime",1380 cases.add("control flow uses comptime var at runtime",
1560 \\extern fn foo() {1381 \\export fn foo() {
1561 \\ comptime var i = 0;1382 \\ comptime var i = 0;
1562 \\ while (i < 5) : (i += 1) {1383 \\ while (i < 5) : (i += 1) {
1563 \\ bar();1384 \\ bar();
...@@ -1565,61 +1386,53 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1565,61 +1386,53 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1565 \\}1386 \\}
1566 \\1387 \\
1567 \\fn bar() { }1388 \\fn bar() { }
1568 \\comptime {@export("foo", foo);}
1569 ,1389 ,
1570 ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime",1390 ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
1571 ".tmp_source.zig:3:24: note: compile-time variable assigned here");1391 ".tmp_source.zig:3:24: note: compile-time variable assigned here");
15721392
1573 cases.add("ignored return value",1393 cases.add("ignored return value",
1574 \\extern fn foo() {1394 \\export fn foo() {
1575 \\ bar();1395 \\ bar();
1576 \\}1396 \\}
1577 \\fn bar() -> i32 { 0 }1397 \\fn bar() -> i32 { 0 }
1578 \\comptime {@export("foo", foo);}
1579 , ".tmp_source.zig:2:8: error: expression value is ignored");1398 , ".tmp_source.zig:2:8: error: expression value is ignored");
15801399
1581 cases.add("ignored assert-err-ok return value",1400 cases.add("ignored assert-err-ok return value",
1582 \\extern fn foo() {1401 \\export fn foo() {
1583 \\ %%bar();1402 \\ %%bar();
1584 \\}1403 \\}
1585 \\fn bar() -> %i32 { 0 }1404 \\fn bar() -> %i32 { 0 }
1586 \\comptime {@export("foo", foo);}
1587 , ".tmp_source.zig:2:5: error: expression value is ignored");1405 , ".tmp_source.zig:2:5: error: expression value is ignored");
15881406
1589 cases.add("ignored statement value",1407 cases.add("ignored statement value",
1590 \\extern fn foo() {1408 \\export fn foo() {
1591 \\ 1;1409 \\ 1;
1592 \\}1410 \\}
1593 \\comptime {@export("foo", foo);}
1594 , ".tmp_source.zig:2:5: error: expression value is ignored");1411 , ".tmp_source.zig:2:5: error: expression value is ignored");
15951412
1596 cases.add("ignored comptime statement value",1413 cases.add("ignored comptime statement value",
1597 \\extern fn foo() {1414 \\export fn foo() {
1598 \\ comptime {1;}1415 \\ comptime {1;}
1599 \\}1416 \\}
1600 \\comptime {@export("foo", foo);}
1601 , ".tmp_source.zig:2:15: error: expression value is ignored");1417 , ".tmp_source.zig:2:15: error: expression value is ignored");
16021418
1603 cases.add("ignored comptime value",1419 cases.add("ignored comptime value",
1604 \\extern fn foo() {1420 \\export fn foo() {
1605 \\ comptime 1;1421 \\ comptime 1;
1606 \\}1422 \\}
1607 \\comptime {@export("foo", foo);}
1608 , ".tmp_source.zig:2:5: error: expression value is ignored");1423 , ".tmp_source.zig:2:5: error: expression value is ignored");
16091424
1610 cases.add("ignored defered statement value",1425 cases.add("ignored defered statement value",
1611 \\extern fn foo() {1426 \\export fn foo() {
1612 \\ defer {1;}1427 \\ defer {1;}
1613 \\}1428 \\}
1614 \\comptime {@export("foo", foo);}
1615 , ".tmp_source.zig:2:12: error: expression value is ignored");1429 , ".tmp_source.zig:2:12: error: expression value is ignored");
16161430
1617 cases.add("ignored defered statement value",1431 cases.add("ignored defered statement value",
1618 \\extern fn foo() {1432 \\export fn foo() {
1619 \\ defer bar();1433 \\ defer bar();
1620 \\}1434 \\}
1621 \\fn bar() -> %i32 { 0 }1435 \\fn bar() -> %i32 { 0 }
1622 \\comptime {@export("foo", foo);}
1623 , ".tmp_source.zig:2:14: error: expression value is ignored");1436 , ".tmp_source.zig:2:14: error: expression value is ignored");
16241437
1625 cases.add("dereference an array",1438 cases.add("dereference an array",
...@@ -1630,8 +1443,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1630,8 +1443,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1630 \\ return (*out)[0..1];1443 \\ return (*out)[0..1];
1631 \\}1444 \\}
1632 \\1445 \\
1633 \\extern fn entry() -> usize { @sizeOf(@typeOf(pass)) }1446 \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) }
1634 \\comptime {@export("entry", entry);}
1635 , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");1447 , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");
16361448
1637 cases.add("pass const ptr to mutable ptr fn",1449 cases.add("pass const ptr to mutable ptr fn",
...@@ -1644,31 +1456,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1644,31 +1456,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1644 \\ return true;1456 \\ return true;
1645 \\}1457 \\}
1646 \\1458 \\
1647 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1459 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1648 \\comptime {@export("entry", entry);}
1649 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");1460 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");
16501461
1462 cases.addCase({
1463 const tc = cases.create("export collision",
1464 \\const foo = @import("foo.zig");
1465 \\
1466 \\export fn bar() -> usize {
1467 \\ return foo.baz;
1468 \\}
1469 ,
1470 "foo.zig:1:8: error: exported symbol collision: 'bar'",
1471 ".tmp_source.zig:3:8: note: other symbol here");
1472
1473 tc.addSourceFile("foo.zig",
1474 \\export fn bar() {}
1475 \\pub const baz = 1234;
1476 );
1477
1478 tc
1479 });
1480
1651 cases.add("pass non-copyable type by value to function",1481 cases.add("pass non-copyable type by value to function",
1652 \\const Point = struct { x: i32, y: i32, };1482 \\const Point = struct { x: i32, y: i32, };
1653 \\fn foo(p: Point) { }1483 \\fn foo(p: Point) { }
1654 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1484 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1655 \\comptime {@export("entry", entry);}
1656 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");1485 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");
16571486
1658 cases.add("implicit cast from array to mutable slice",1487 cases.add("implicit cast from array to mutable slice",
1659 \\var global_array: [10]i32 = undefined;1488 \\var global_array: [10]i32 = undefined;
1660 \\fn foo(param: []i32) {}1489 \\fn foo(param: []i32) {}
1661 \\extern fn entry() {1490 \\export fn entry() {
1662 \\ foo(global_array);1491 \\ foo(global_array);
1663 \\}1492 \\}
1664 \\comptime {@export("entry", entry);}
1665 , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'");1493 , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'");
16661494
1667 cases.add("ptrcast to non-pointer",1495 cases.add("ptrcast to non-pointer",
1668 \\extern fn entry(a: &i32) -> usize {1496 \\export fn entry(a: &i32) -> usize {
1669 \\ return @ptrCast(usize, a);1497 \\ return @ptrCast(usize, a);
1670 \\}1498 \\}
1671 \\comptime {@export("entry", entry);}
1672 , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");1499 , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");
16731500
1674 cases.add("too many error values to cast to small integer",1501 cases.add("too many error values to cast to small integer",
...@@ -1677,8 +1504,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1677,8 +1504,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1677 \\fn foo(e: error) -> u2 {1504 \\fn foo(e: error) -> u2 {
1678 \\ return u2(e);1505 \\ return u2(e);
1679 \\}1506 \\}
1680 \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) }1507 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1681 \\comptime {@export("entry", entry);}
1682 , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");1508 , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");
16831509
1684 cases.add("asm at compile time",1510 cases.add("asm at compile time",
...@@ -1697,46 +1523,41 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1697,46 +1523,41 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
16971523
1698 cases.add("invalid member of builtin enum",1524 cases.add("invalid member of builtin enum",
1699 \\const builtin = @import("builtin");1525 \\const builtin = @import("builtin");
1700 \\extern fn entry() {1526 \\export fn entry() {
1701 \\ const foo = builtin.Arch.x86;1527 \\ const foo = builtin.Arch.x86;
1702 \\}1528 \\}
1703 \\comptime {@export("entry", entry);}
1704 , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'");1529 , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'");
17051530
1706 cases.add("int to ptr of 0 bits",1531 cases.add("int to ptr of 0 bits",
1707 \\extern fn foo() {1532 \\export fn foo() {
1708 \\ var x: usize = 0x1000;1533 \\ var x: usize = 0x1000;
1709 \\ var y: &void = @intToPtr(&void, x);1534 \\ var y: &void = @intToPtr(&void, x);
1710 \\}1535 \\}
1711 \\comptime {@export("foo", foo);}
1712 , ".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information");1536 , ".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information");
17131537
1714 cases.add("@fieldParentPtr - non struct",1538 cases.add("@fieldParentPtr - non struct",
1715 \\const Foo = i32;1539 \\const Foo = i32;
1716 \\extern fn foo(a: &i32) -> &Foo {1540 \\export fn foo(a: &i32) -> &Foo {
1717 \\ return @fieldParentPtr(Foo, "a", a);1541 \\ return @fieldParentPtr(Foo, "a", a);
1718 \\}1542 \\}
1719 \\comptime {@export("foo", foo);}
1720 , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'");1543 , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'");
17211544
1722 cases.add("@fieldParentPtr - bad field name",1545 cases.add("@fieldParentPtr - bad field name",
1723 \\const Foo = struct {1546 \\const Foo = struct {
1724 \\ derp: i32,1547 \\ derp: i32,
1725 \\};1548 \\};
1726 \\extern fn foo(a: &i32) -> &Foo {1549 \\export fn foo(a: &i32) -> &Foo {
1727 \\ return @fieldParentPtr(Foo, "a", a);1550 \\ return @fieldParentPtr(Foo, "a", a);
1728 \\}1551 \\}
1729 \\comptime {@export("foo", foo);}
1730 , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'");1552 , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'");
17311553
1732 cases.add("@fieldParentPtr - field pointer is not pointer",1554 cases.add("@fieldParentPtr - field pointer is not pointer",
1733 \\const Foo = struct {1555 \\const Foo = struct {
1734 \\ a: i32,1556 \\ a: i32,
1735 \\};1557 \\};
1736 \\extern fn foo(a: i32) -> &Foo {1558 \\export fn foo(a: i32) -> &Foo {
1737 \\ return @fieldParentPtr(Foo, "a", a);1559 \\ return @fieldParentPtr(Foo, "a", a);
1738 \\}1560 \\}
1739 \\comptime {@export("foo", foo);}
1740 , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'");1561 , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'");
17411562
1742 cases.add("@fieldParentPtr - comptime field ptr not based on struct",1563 cases.add("@fieldParentPtr - comptime field ptr not based on struct",
...@@ -1766,20 +1587,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1766,20 +1587,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17661587
1767 cases.add("@offsetOf - non struct",1588 cases.add("@offsetOf - non struct",
1768 \\const Foo = i32;1589 \\const Foo = i32;
1769 \\extern fn foo() -> usize {1590 \\export fn foo() -> usize {
1770 \\ return @offsetOf(Foo, "a");1591 \\ return @offsetOf(Foo, "a");
1771 \\}1592 \\}
1772 \\comptime {@export("foo", foo);}
1773 , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'");1593 , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'");
17741594
1775 cases.add("@offsetOf - bad field name",1595 cases.add("@offsetOf - bad field name",
1776 \\const Foo = struct {1596 \\const Foo = struct {
1777 \\ derp: i32,1597 \\ derp: i32,
1778 \\};1598 \\};
1779 \\extern fn foo() -> usize {1599 \\export fn foo() -> usize {
1780 \\ return @offsetOf(Foo, "a");1600 \\ return @offsetOf(Foo, "a");
1781 \\}1601 \\}
1782 \\comptime {@export("foo", foo);}
1783 , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'");1602 , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'");
17841603
1785 cases.addExe("missing main fn in executable",1604 cases.addExe("missing main fn in executable",
...@@ -1792,22 +1611,44 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1792,22 +1611,44 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1792 "error: 'main' is private",1611 "error: 'main' is private",
1793 ".tmp_source.zig:1:1: note: declared here");1612 ".tmp_source.zig:1:1: note: declared here");
17941613
1614 cases.add("setting a section on an extern variable",
1615 \\extern var foo: i32 section(".text2");
1616 \\export fn entry() -> i32 {
1617 \\ return foo;
1618 \\}
1619 ,
1620 ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'");
1621
1622 cases.add("setting a section on a local variable",
1623 \\export fn entry() -> i32 {
1624 \\ var foo: i32 section(".text2") = 1234;
1625 \\ return foo;
1626 \\}
1627 ,
1628 ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'");
1629
1630 cases.add("setting a section on an extern fn",
1631 \\extern fn foo() section(".text2");
1632 \\export fn entry() {
1633 \\ foo();
1634 \\}
1635 ,
1636 ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'");
1637
1795 cases.add("returning address of local variable - simple",1638 cases.add("returning address of local variable - simple",
1796 \\extern fn foo() -> &i32 {1639 \\export fn foo() -> &i32 {
1797 \\ var a: i32 = undefined;1640 \\ var a: i32 = undefined;
1798 \\ return &a;1641 \\ return &a;
1799 \\}1642 \\}
1800 \\comptime {@export("foo", foo);}
1801 ,1643 ,
1802 ".tmp_source.zig:3:13: error: function returns address of local variable");1644 ".tmp_source.zig:3:13: error: function returns address of local variable");
18031645
1804 cases.add("returning address of local variable - phi",1646 cases.add("returning address of local variable - phi",
1805 \\extern fn foo(c: bool) -> &i32 {1647 \\export fn foo(c: bool) -> &i32 {
1806 \\ var a: i32 = undefined;1648 \\ var a: i32 = undefined;
1807 \\ var b: i32 = undefined;1649 \\ var b: i32 = undefined;
1808 \\ return if (c) &a else &b;1650 \\ return if (c) &a else &b;
1809 \\}1651 \\}
1810 \\comptime {@export("foo", foo);}
1811 ,1652 ,
1812 ".tmp_source.zig:4:12: error: function returns address of local variable");1653 ".tmp_source.zig:4:12: error: function returns address of local variable");
18131654
...@@ -1836,61 +1677,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1836,61 +1677,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1836 ".tmp_source.zig:5:9: note: previous definition is here");1677 ".tmp_source.zig:5:9: note: previous definition is here");
18371678
1838 cases.add("while expected bool, got nullable",1679 cases.add("while expected bool, got nullable",
1839 \\extern fn foo() {1680 \\export fn foo() {
1840 \\ while (bar()) {}1681 \\ while (bar()) {}
1841 \\}1682 \\}
1842 \\fn bar() -> ?i32 { 1 }1683 \\fn bar() -> ?i32 { 1 }
1843 \\comptime {@export("foo", foo);}
1844 ,1684 ,
1845 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");1685 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");
18461686
1847 cases.add("while expected bool, got error union",1687 cases.add("while expected bool, got error union",
1848 \\extern fn foo() {1688 \\export fn foo() {
1849 \\ while (bar()) {}1689 \\ while (bar()) {}
1850 \\}1690 \\}
1851 \\fn bar() -> %i32 { 1 }1691 \\fn bar() -> %i32 { 1 }
1852 \\comptime {@export("foo", foo);}
1853 ,1692 ,
1854 ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");1693 ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");
18551694
1856 cases.add("while expected nullable, got bool",1695 cases.add("while expected nullable, got bool",
1857 \\extern fn foo() {1696 \\export fn foo() {
1858 \\ while (bar()) |x| {}1697 \\ while (bar()) |x| {}
1859 \\}1698 \\}
1860 \\fn bar() -> bool { true }1699 \\fn bar() -> bool { true }
1861 \\comptime {@export("foo", foo);}
1862 ,1700 ,
1863 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");1701 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");
18641702
1865 cases.add("while expected nullable, got error union",1703 cases.add("while expected nullable, got error union",
1866 \\extern fn foo() {1704 \\export fn foo() {
1867 \\ while (bar()) |x| {}1705 \\ while (bar()) |x| {}
1868 \\}1706 \\}
1869 \\fn bar() -> %i32 { 1 }1707 \\fn bar() -> %i32 { 1 }
1870 \\comptime {@export("foo", foo);}
1871 ,1708 ,
1872 ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");1709 ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");
18731710
1874 cases.add("while expected error union, got bool",1711 cases.add("while expected error union, got bool",
1875 \\extern fn foo() {1712 \\export fn foo() {
1876 \\ while (bar()) |x| {} else |err| {}1713 \\ while (bar()) |x| {} else |err| {}
1877 \\}1714 \\}
1878 \\fn bar() -> bool { true }1715 \\fn bar() -> bool { true }
1879 \\comptime {@export("foo", foo);}
1880 ,1716 ,
1881 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");1717 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");
18821718
1883 cases.add("while expected error union, got nullable",1719 cases.add("while expected error union, got nullable",
1884 \\extern fn foo() {1720 \\export fn foo() {
1885 \\ while (bar()) |x| {} else |err| {}1721 \\ while (bar()) |x| {} else |err| {}
1886 \\}1722 \\}
1887 \\fn bar() -> ?i32 { 1 }1723 \\fn bar() -> ?i32 { 1 }
1888 \\comptime {@export("foo", foo);}
1889 ,1724 ,
1890 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");1725 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");
18911726
1892 cases.add("inline fn calls itself indirectly",1727 cases.add("inline fn calls itself indirectly",
1893 \\extern fn foo() {1728 \\export fn foo() {
1894 \\ bar();1729 \\ bar();
1895 \\}1730 \\}
1896 \\inline fn bar() {1731 \\inline fn bar() {
...@@ -1902,33 +1737,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1902,33 +1737,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1902 \\ quux();1737 \\ quux();
1903 \\}1738 \\}
1904 \\extern fn quux();1739 \\extern fn quux();
1905 \\comptime {@export("foo", foo);}
1906 ,1740 ,
1907 ".tmp_source.zig:4:8: error: unable to inline function");1741 ".tmp_source.zig:4:8: error: unable to inline function");
19081742
1909 cases.add("save reference to inline function",1743 cases.add("save reference to inline function",
1910 \\extern fn foo() {1744 \\export fn foo() {
1911 \\ quux(@ptrToInt(bar));1745 \\ quux(@ptrToInt(bar));
1912 \\}1746 \\}
1913 \\inline fn bar() { }1747 \\inline fn bar() { }
1914 \\extern fn quux(usize);1748 \\extern fn quux(usize);
1915 \\comptime {@export("foo", foo);}
1916 ,1749 ,
1917 ".tmp_source.zig:4:8: error: unable to inline function");1750 ".tmp_source.zig:4:8: error: unable to inline function");
19181751
1919 cases.add("signed integer division",1752 cases.add("signed integer division",
1920 \\extern fn foo(a: i32, b: i32) -> i32 {1753 \\export fn foo(a: i32, b: i32) -> i32 {
1921 \\ a / b1754 \\ a / b
1922 \\}1755 \\}
1923 \\comptime {@export("foo", foo);}
1924 ,1756 ,
1925 ".tmp_source.zig:2:7: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");1757 ".tmp_source.zig:2:7: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
19261758
1927 cases.add("signed integer remainder division",1759 cases.add("signed integer remainder division",
1928 \\extern fn foo(a: i32, b: i32) -> i32 {1760 \\export fn foo(a: i32, b: i32) -> i32 {
1929 \\ a % b1761 \\ a % b
1930 \\}1762 \\}
1931 \\comptime {@export("foo", foo);}
1932 ,1763 ,
1933 ".tmp_source.zig:2:7: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod");1764 ".tmp_source.zig:2:7: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod");
19341765
...@@ -1967,65 +1798,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1967,65 +1798,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1967 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");1798 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");
19681799
1969 cases.add("@setDebugSafety twice for same scope",1800 cases.add("@setDebugSafety twice for same scope",
1970 \\extern fn foo() {1801 \\export fn foo() {
1971 \\ @setDebugSafety(this, false);1802 \\ @setDebugSafety(this, false);
1972 \\ @setDebugSafety(this, false);1803 \\ @setDebugSafety(this, false);
1973 \\}1804 \\}
1974 \\comptime {@export("foo", foo);}
1975 ,1805 ,
1976 ".tmp_source.zig:3:5: error: debug safety set twice for same scope",1806 ".tmp_source.zig:3:5: error: debug safety set twice for same scope",
1977 ".tmp_source.zig:2:5: note: first set here");1807 ".tmp_source.zig:2:5: note: first set here");
19781808
1979 cases.add("@setFloatMode twice for same scope",1809 cases.add("@setFloatMode twice for same scope",
1980 \\extern fn foo() {1810 \\export fn foo() {
1981 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);1811 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
1982 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);1812 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
1983 \\}1813 \\}
1984 \\comptime {@export("foo", foo);}
1985 ,1814 ,
1986 ".tmp_source.zig:3:5: error: float mode set twice for same scope",1815 ".tmp_source.zig:3:5: error: float mode set twice for same scope",
1987 ".tmp_source.zig:2:5: note: first set here");1816 ".tmp_source.zig:2:5: note: first set here");
19881817
1989 cases.add("array access of type",1818 cases.add("array access of type",
1990 \\extern fn foo() {1819 \\export fn foo() {
1991 \\ var b: u8[40] = undefined;1820 \\ var b: u8[40] = undefined;
1992 \\}1821 \\}
1993 \\comptime {@export("foo", foo);}
1994 ,1822 ,
1995 ".tmp_source.zig:2:14: error: array access of non-array type 'type'");1823 ".tmp_source.zig:2:14: error: array access of non-array type 'type'");
19961824
1997 cases.add("cannot break out of defer expression",1825 cases.add("cannot break out of defer expression",
1998 \\extern fn foo() {1826 \\export fn foo() {
1999 \\ while (true) {1827 \\ while (true) {
2000 \\ defer {1828 \\ defer {
2001 \\ break;1829 \\ break;
2002 \\ }1830 \\ }
2003 \\ }1831 \\ }
2004 \\}1832 \\}
2005 \\comptime {@export("foo", foo);}
2006 ,1833 ,
2007 ".tmp_source.zig:4:13: error: cannot break out of defer expression");1834 ".tmp_source.zig:4:13: error: cannot break out of defer expression");
20081835
2009 cases.add("cannot continue out of defer expression",1836 cases.add("cannot continue out of defer expression",
2010 \\extern fn foo() {1837 \\export fn foo() {
2011 \\ while (true) {1838 \\ while (true) {
2012 \\ defer {1839 \\ defer {
2013 \\ continue;1840 \\ continue;
2014 \\ }1841 \\ }
2015 \\ }1842 \\ }
2016 \\}1843 \\}
2017 \\comptime {@export("foo", foo);}
2018 ,1844 ,
2019 ".tmp_source.zig:4:13: error: cannot continue out of defer expression");1845 ".tmp_source.zig:4:13: error: cannot continue out of defer expression");
20201846
2021 cases.add("cannot goto out of defer expression",1847 cases.add("cannot goto out of defer expression",
2022 \\extern fn foo() {1848 \\export fn foo() {
2023 \\ defer {1849 \\ defer {
2024 \\ goto label;1850 \\ goto label;
2025 \\ };1851 \\ };
2026 \\label:1852 \\label:
2027 \\}1853 \\}
2028 \\comptime {@export("foo", foo);}
2029 ,1854 ,
2030 ".tmp_source.zig:3:9: error: cannot goto out of defer expression");1855 ".tmp_source.zig:3:9: error: cannot goto out of defer expression");
20311856
...@@ -2059,10 +1884,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2059,10 +1884,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2059 \\const bar = baz + foo;1884 \\const bar = baz + foo;
2060 \\const baz = 1;1885 \\const baz = 1;
2061 \\1886 \\
2062 \\extern fn entry() -> i32 {1887 \\export fn entry() -> i32 {
2063 \\ return bar;1888 \\ return bar;
2064 \\}1889 \\}
2065 \\comptime {@export("entry", entry);}
2066 ,1890 ,
2067 ".tmp_source.zig:1:13: error: aoeu",1891 ".tmp_source.zig:1:13: error: aoeu",
2068 ".tmp_source.zig:3:19: note: referenced here",1892 ".tmp_source.zig:3:19: note: referenced here",
...@@ -2075,10 +1899,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2075,10 +1899,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2075 \\1899 \\
2076 \\var foo: Foo = undefined;1900 \\var foo: Foo = undefined;
2077 \\1901 \\
2078 \\extern fn entry() -> usize {1902 \\export fn entry() -> usize {
2079 \\ return @sizeOf(@typeOf(foo.x));1903 \\ return @sizeOf(@typeOf(foo.x));
2080 \\}1904 \\}
2081 \\comptime {@export("entry", entry);}
2082 ,1905 ,
2083 ".tmp_source.zig:1:13: error: struct 'Foo' contains itself");1906 ".tmp_source.zig:1:13: error: struct 'Foo' contains itself");
20841907
...@@ -2097,18 +1920,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2097,18 +1920,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2097 ".tmp_source.zig:2:15: error: float literal out of range of any type");1920 ".tmp_source.zig:2:15: error: float literal out of range of any type");
20981921
2099 cases.add("explicit cast float literal to integer when there is a fraction component",1922 cases.add("explicit cast float literal to integer when there is a fraction component",
2100 \\extern fn entry() -> i32 {1923 \\export fn entry() -> i32 {
2101 \\ i32(12.34)1924 \\ i32(12.34)
2102 \\}1925 \\}
2103 \\comptime {@export("entry", entry);}
2104 ,1926 ,
2105 ".tmp_source.zig:2:9: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");1927 ".tmp_source.zig:2:9: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");
21061928
2107 cases.add("non pointer given to @ptrToInt",1929 cases.add("non pointer given to @ptrToInt",
2108 \\extern fn entry(x: i32) -> usize {1930 \\export fn entry(x: i32) -> usize {
2109 \\ @ptrToInt(x)1931 \\ @ptrToInt(x)
2110 \\}1932 \\}
2111 \\comptime {@export("entry", entry);}
2112 ,1933 ,
2113 ".tmp_source.zig:2:15: error: expected pointer, found 'i32'");1934 ".tmp_source.zig:2:15: error: expected pointer, found 'i32'");
21141935
...@@ -2127,27 +1948,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2127,27 +1948,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2127 ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits");1948 ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits");
21281949
2129 cases.add("shifting without int type or comptime known",1950 cases.add("shifting without int type or comptime known",
2130 \\extern fn entry(x: u8) -> u8 {1951 \\export fn entry(x: u8) -> u8 {
2131 \\ return 0x11 << x;1952 \\ return 0x11 << x;
2132 \\}1953 \\}
2133 \\comptime {@export("entry", entry);}
2134 ,1954 ,
2135 ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known");1955 ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known");
21361956
2137 cases.add("shifting RHS is log2 of LHS int bit width",1957 cases.add("shifting RHS is log2 of LHS int bit width",
2138 \\extern fn entry(x: u8, y: u8) -> u8 {1958 \\export fn entry(x: u8, y: u8) -> u8 {
2139 \\ return x << y;1959 \\ return x << y;
2140 \\}1960 \\}
2141 \\comptime {@export("entry", entry);}
2142 ,1961 ,
2143 ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'");1962 ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'");
21441963
2145 cases.add("globally shadowing a primitive type",1964 cases.add("globally shadowing a primitive type",
2146 \\const u16 = @intType(false, 8);1965 \\const u16 = @intType(false, 8);
2147 \\extern fn entry() {1966 \\export fn entry() {
2148 \\ const a: u16 = 300;1967 \\ const a: u16 = 300;
2149 \\}1968 \\}
2150 \\comptime {@export("entry", entry);}
2151 ,1969 ,
2152 ".tmp_source.zig:1:1: error: declaration shadows type 'u16'");1970 ".tmp_source.zig:1:1: error: declaration shadows type 'u16'");
21531971
...@@ -2157,7 +1975,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2157,7 +1975,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2157 \\ b: u32,1975 \\ b: u32,
2158 \\};1976 \\};
2159 \\1977 \\
2160 \\extern fn entry() {1978 \\export fn entry() {
2161 \\ var foo = Foo { .a = 1, .b = 10 };1979 \\ var foo = Foo { .a = 1, .b = 10 };
2162 \\ bar(&foo.b);1980 \\ bar(&foo.b);
2163 \\}1981 \\}
...@@ -2165,7 +1983,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2165,7 +1983,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2165 \\fn bar(x: &u32) {1983 \\fn bar(x: &u32) {
2166 \\ *x += 1;1984 \\ *x += 1;
2167 \\}1985 \\}
2168 \\comptime {@export("entry", entry);}
2169 ,1986 ,
2170 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'");1987 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'");
21711988
...@@ -2175,7 +1992,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2175,7 +1992,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2175 \\ b: u32,1992 \\ b: u32,
2176 \\};1993 \\};
2177 \\1994 \\
2178 \\extern fn entry() {1995 \\export fn entry() {
2179 \\ var foo = Foo { .a = 1, .b = 10 };1996 \\ var foo = Foo { .a = 1, .b = 10 };
2180 \\ foo.b += 1;1997 \\ foo.b += 1;
2181 \\ bar((&foo.b)[0..1]);1998 \\ bar((&foo.b)[0..1]);
...@@ -2184,61 +2001,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2184,61 +2001,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2184 \\fn bar(x: []u32) {2001 \\fn bar(x: []u32) {
2185 \\ x[0] += 1;2002 \\ x[0] += 1;
2186 \\}2003 \\}
2187 \\comptime {@export("entry", entry);}
2188 ,2004 ,
2189 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");2005 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");
21902006
2191 cases.add("increase pointer alignment in @ptrCast",2007 cases.add("increase pointer alignment in @ptrCast",
2192 \\extern fn entry() -> u32 {2008 \\export fn entry() -> u32 {
2193 \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};2009 \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
2194 \\ const ptr = @ptrCast(&u32, &bytes[0]);2010 \\ const ptr = @ptrCast(&u32, &bytes[0]);
2195 \\ return *ptr;2011 \\ return *ptr;
2196 \\}2012 \\}
2197 \\comptime {@export("entry", entry);}
2198 ,2013 ,
2199 ".tmp_source.zig:3:17: error: cast increases pointer alignment",2014 ".tmp_source.zig:3:17: error: cast increases pointer alignment",
2200 ".tmp_source.zig:3:38: note: '&u8' has alignment 1",2015 ".tmp_source.zig:3:38: note: '&u8' has alignment 1",
2201 ".tmp_source.zig:3:27: note: '&u32' has alignment 4");2016 ".tmp_source.zig:3:27: note: '&u32' has alignment 4");
22022017
2203 cases.add("increase pointer alignment in slice resize",2018 cases.add("increase pointer alignment in slice resize",
2204 \\extern fn entry() -> u32 {2019 \\export fn entry() -> u32 {
2205 \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04};2020 \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04};
2206 \\ return ([]u32)(bytes[0..])[0];2021 \\ return ([]u32)(bytes[0..])[0];
2207 \\}2022 \\}
2208 \\comptime {@export("entry", entry);}
2209 ,2023 ,
2210 ".tmp_source.zig:3:19: error: cast increases pointer alignment",2024 ".tmp_source.zig:3:19: error: cast increases pointer alignment",
2211 ".tmp_source.zig:3:19: note: '[]u8' has alignment 1",2025 ".tmp_source.zig:3:19: note: '[]u8' has alignment 1",
2212 ".tmp_source.zig:3:19: note: '[]u32' has alignment 4");2026 ".tmp_source.zig:3:19: note: '[]u32' has alignment 4");
22132027
2214 cases.add("@alignCast expects pointer or slice",2028 cases.add("@alignCast expects pointer or slice",
2215 \\extern fn entry() {2029 \\export fn entry() {
2216 \\ @alignCast(4, u32(3))2030 \\ @alignCast(4, u32(3))
2217 \\}2031 \\}
2218 \\comptime {@export("entry", entry);}
2219 ,2032 ,
2220 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");2033 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");
22212034
2222 cases.add("passing an under-aligned function pointer",2035 cases.add("passing an under-aligned function pointer",
2223 \\extern fn entry() {2036 \\export fn entry() {
2224 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);2037 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
2225 \\}2038 \\}
2226 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {2039 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
2227 \\ if (ptr() != answer) unreachable;2040 \\ if (ptr() != answer) unreachable;
2228 \\}2041 \\}
2229 \\fn alignedSmall() align(4) -> i32 { 1234 }2042 \\fn alignedSmall() align(4) -> i32 { 1234 }
2230 \\comptime {@export("entry", entry);}
2231 ,2043 ,
2232 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");2044 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");
22332045
2234 cases.add("passing a not-aligned-enough pointer to cmpxchg",2046 cases.add("passing a not-aligned-enough pointer to cmpxchg",
2235 \\const AtomicOrder = @import("builtin").AtomicOrder;2047 \\const AtomicOrder = @import("builtin").AtomicOrder;
2236 \\extern fn entry() -> bool {2048 \\export fn entry() -> bool {
2237 \\ var x: i32 align(1) = 1234;2049 \\ var x: i32 align(1) = 1234;
2238 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}2050 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
2239 \\ return x == 5678;2051 \\ return x == 5678;
2240 \\}2052 \\}
2241 \\comptime {@export("entry", entry);}
2242 ,2053 ,
2243 ".tmp_source.zig:4:23: error: expected pointer alignment of at least 4, found 1");2054 ".tmp_source.zig:4:23: error: expected pointer alignment of at least 4, found 1");
22442055
...@@ -2264,18 +2075,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2264,18 +2075,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2264 cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()",2075 cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()",
2265 \\const Derp = @OpaqueType();2076 \\const Derp = @OpaqueType();
2266 \\extern fn bar(d: &Derp);2077 \\extern fn bar(d: &Derp);
2267 \\extern fn foo() {2078 \\export fn foo() {
2268 \\ const x = u8(1);2079 \\ const x = u8(1);
2269 \\ bar(@ptrCast(&c_void, &x));2080 \\ bar(@ptrCast(&c_void, &x));
2270 \\}2081 \\}
2271 \\comptime {@export("foo", foo);}
2272 ,2082 ,
2273 ".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'");2083 ".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'");
22742084
2275 cases.add("non-const variables of things that require const variables",2085 cases.add("non-const variables of things that require const variables",
2276 \\const Opaque = @OpaqueType();2086 \\const Opaque = @OpaqueType();
2277 \\2087 \\
2278 \\extern fn entry(opaque: &Opaque) {2088 \\export fn entry(opaque: &Opaque) {
2279 \\ var m2 = &2;2089 \\ var m2 = &2;
2280 \\ const y: u32 = *m2;2090 \\ const y: u32 = *m2;
2281 \\2091 \\
...@@ -2295,7 +2105,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2295,7 +2105,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2295 \\const Foo = struct {2105 \\const Foo = struct {
2296 \\ fn bar(self: &const Foo) {}2106 \\ fn bar(self: &const Foo) {}
2297 \\};2107 \\};
2298 \\comptime {@export("entry", entry);}
2299 ,2108 ,
2300 ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",2109 ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",
2301 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",2110 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
...@@ -2310,14 +2119,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2310,14 +2119,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2310 ".tmp_source.zig:17:4: error: unreachable code");2119 ".tmp_source.zig:17:4: error: unreachable code");
23112120
2312 cases.add("wrong types given to atomic order args in cmpxchg",2121 cases.add("wrong types given to atomic order args in cmpxchg",
2313 \\extern fn entry() {2122 \\export fn entry() {
2314 \\ var x: i32 = 1234;2123 \\ var x: i32 = 1234;
2315 \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {}2124 \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {}
2316 \\}2125 \\}
2317 \\comptime {@export("entry", entry);}
2318 ,2126 ,
2319 ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'");2127 ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'");
23202128
2129 cases.add("wrong types given to @export",
2130 \\extern fn entry() { }
2131 \\comptime {
2132 \\ @export("entry", entry, u32(1234));
2133 \\}
2134 ,
2135 ".tmp_source.zig:3:32: error: expected type 'GlobalLinkage', found 'u32'");
2136
2321 cases.add("struct with invalid field",2137 cases.add("struct with invalid field",
2322 \\const std = @import("std");2138 \\const std = @import("std");
2323 \\const Allocator = std.mem.Allocator;2139 \\const Allocator = std.mem.Allocator;
...@@ -2336,13 +2152,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2336,13 +2152,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2336 \\ },2152 \\ },
2337 \\};2153 \\};
2338 \\2154 \\
2339 \\extern fn entry() {2155 \\export fn entry() {
2340 \\ const a = MdNode.Header {2156 \\ const a = MdNode.Header {
2341 \\ .text = MdText.init(&std.debug.global_allocator),2157 \\ .text = MdText.init(&std.debug.global_allocator),
2342 \\ .weight = HeaderWeight.H1,2158 \\ .weight = HeaderWeight.H1,
2343 \\ };2159 \\ };
2344 \\}2160 \\}
2345 \\comptime {@export("entry", entry);}
2346 ,2161 ,
2347 ".tmp_source.zig:14:17: error: use of undeclared identifier 'HeaderValue'");2162 ".tmp_source.zig:14:17: error: use of undeclared identifier 'HeaderValue'");
23482163
...@@ -2354,39 +2169,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2354,39 +2169,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2354 ".tmp_source.zig:2:5: error: @setAlignStack outside function");2169 ".tmp_source.zig:2:5: error: @setAlignStack outside function");
23552170
2356 cases.add("@setAlignStack in naked function",2171 cases.add("@setAlignStack in naked function",
2357 \\nakedcc fn entry() {2172 \\export nakedcc fn entry() {
2358 \\ @setAlignStack(16);2173 \\ @setAlignStack(16);
2359 \\}2174 \\}
2360 \\comptime {@export("entry", entry);}
2361 ,2175 ,
2362 ".tmp_source.zig:2:5: error: @setAlignStack in naked function");2176 ".tmp_source.zig:2:5: error: @setAlignStack in naked function");
23632177
2364 cases.add("@setAlignStack in inline function",2178 cases.add("@setAlignStack in inline function",
2365 \\extern fn entry() {2179 \\export fn entry() {
2366 \\ foo();2180 \\ foo();
2367 \\}2181 \\}
2368 \\inline fn foo() {2182 \\inline fn foo() {
2369 \\ @setAlignStack(16);2183 \\ @setAlignStack(16);
2370 \\}2184 \\}
2371 \\comptime {@export("entry", entry);}
2372 ,2185 ,
2373 ".tmp_source.zig:5:5: error: @setAlignStack in inline function");2186 ".tmp_source.zig:5:5: error: @setAlignStack in inline function");
23742187
2375 cases.add("@setAlignStack set twice",2188 cases.add("@setAlignStack set twice",
2376 \\extern fn entry() {2189 \\export fn entry() {
2377 \\ @setAlignStack(16);2190 \\ @setAlignStack(16);
2378 \\ @setAlignStack(16);2191 \\ @setAlignStack(16);
2379 \\}2192 \\}
2380 \\comptime {@export("entry", entry);}
2381 ,2193 ,
2382 ".tmp_source.zig:3:5: error: alignstack set twice",2194 ".tmp_source.zig:3:5: error: alignstack set twice",
2383 ".tmp_source.zig:2:5: note: first set here");2195 ".tmp_source.zig:2:5: note: first set here");
23842196
2385 cases.add("@setAlignStack too big",2197 cases.add("@setAlignStack too big",
2386 \\extern fn entry() {2198 \\export fn entry() {
2387 \\ @setAlignStack(511 + 1);2199 \\ @setAlignStack(511 + 1);
2388 \\}2200 \\}
2389 \\comptime {@export("entry", entry);}
2390 ,2201 ,
2391 ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256");2202 ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256");
23922203
...@@ -2417,7 +2228,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2417,7 +2228,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2417 \\ LinkLibC,2228 \\ LinkLibC,
2418 \\};2229 \\};
2419 \\2230 \\
2420 \\extern fn entry() {2231 \\export fn entry() {
2421 \\ const tests = []TestCase {2232 \\ const tests = []TestCase {
2422 \\ Free("001"),2233 \\ Free("001"),
2423 \\ Free("002"),2234 \\ Free("002"),
...@@ -2432,14 +2243,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2432,14 +2243,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2432 \\ }2243 \\ }
2433 \\ }2244 \\ }
2434 \\}2245 \\}
2435 \\comptime {@export("entry", entry);}
2436 ,2246 ,
2437 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");2247 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");
24382248
2439 cases.add("field access of opaque type",2249 cases.add("field access of opaque type",
2440 \\const MyType = @OpaqueType();2250 \\const MyType = @OpaqueType();
2441 \\2251 \\
2442 \\extern fn entry() -> bool {2252 \\export fn entry() -> bool {
2443 \\ var x: i32 = 1;2253 \\ var x: i32 = 1;
2444 \\ return bar(@ptrCast(&MyType, &x));2254 \\ return bar(@ptrCast(&MyType, &x));
2445 \\}2255 \\}
...@@ -2447,7 +2257,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2447,7 +2257,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2447 \\fn bar(x: &MyType) -> bool {2257 \\fn bar(x: &MyType) -> bool {
2448 \\ return x.blah;2258 \\ return x.blah;
2449 \\}2259 \\}
2450 \\comptime {@export("entry", entry);}
2451 ,2260 ,
2452 ".tmp_source.zig:9:13: error: type '&MyType' does not support field access");2261 ".tmp_source.zig:9:13: error: type '&MyType' does not support field access");
24532262
...@@ -2551,11 +2360,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2551,11 +2360,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2551 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");2360 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");
25522361
2553 cases.add("calling var args extern function, passing array instead of pointer",2362 cases.add("calling var args extern function, passing array instead of pointer",
2554 \\extern fn entry() {2363 \\export fn entry() {
2555 \\ foo("hello");2364 \\ foo("hello");
2556 \\}2365 \\}
2557 \\pub extern fn foo(format: &const u8, ...);2366 \\pub extern fn foo(format: &const u8, ...);
2558 \\comptime {@export("entry", entry);}
2559 ,2367 ,
2560 ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'");2368 ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'");
25612369
...@@ -2570,10 +2378,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2570,10 +2378,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2570 \\ }2378 \\ }
2571 \\}2379 \\}
2572 \\2380 \\
2573 \\extern fn entry() {2381 \\export fn entry() {
2574 \\ var allocator: ContextAllocator = undefined;2382 \\ var allocator: ContextAllocator = undefined;
2575 \\}2383 \\}
2576 \\comptime {@export("entry", entry);}
2577 ,2384 ,
2578 ".tmp_source.zig:4:25: error: aoeu",2385 ".tmp_source.zig:4:25: error: aoeu",
2579 ".tmp_source.zig:1:36: note: called from here",2386 ".tmp_source.zig:1:36: note: called from here",
...@@ -2588,10 +2395,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2588,10 +2395,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2588 \\ Five,2395 \\ Five,
2589 \\};2396 \\};
2590 \\2397 \\
2591 \\extern fn entry() {2398 \\export fn entry() {
2592 \\ var x = Small.One;2399 \\ var x = Small.One;
2593 \\}2400 \\}
2594 \\comptime {@export("entry", entry);}
2595 ,2401 ,
2596 ".tmp_source.zig:1:20: error: 'u2' too small to hold all bits; must be at least 'u3'");2402 ".tmp_source.zig:1:20: error: 'u2' too small to hold all bits; must be at least 'u3'");
25972403
...@@ -2602,10 +2408,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2602,10 +2408,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2602 \\ Three,2408 \\ Three,
2603 \\};2409 \\};
2604 \\2410 \\
2605 \\extern fn entry() {2411 \\export fn entry() {
2606 \\ var x = Small.One;2412 \\ var x = Small.One;
2607 \\}2413 \\}
2608 \\comptime {@export("entry", entry);}
2609 ,2414 ,
2610 ".tmp_source.zig:1:20: error: expected integer, found 'f32'");2415 ".tmp_source.zig:1:20: error: expected integer, found 'f32'");
26112416
...@@ -2617,10 +2422,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2617,10 +2422,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2617 \\ Four,2422 \\ Four,
2618 \\};2423 \\};
2619 \\2424 \\
2620 \\extern fn entry() {2425 \\export fn entry() {
2621 \\ var x: u2 = Small.Two;2426 \\ var x: u2 = Small.Two;
2622 \\}2427 \\}
2623 \\comptime {@export("entry", entry);}
2624 ,2428 ,
2625 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'");2429 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'");
26262430
...@@ -2632,10 +2436,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2632,10 +2436,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2632 \\ Four,2436 \\ Four,
2633 \\};2437 \\};
2634 \\2438 \\
2635 \\extern fn entry() {2439 \\export fn entry() {
2636 \\ var x = u3(Small.Two);2440 \\ var x = u3(Small.Two);
2637 \\}2441 \\}
2638 \\comptime {@export("entry", entry);}
2639 ,2442 ,
2640 ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'");2443 ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'");
26412444
...@@ -2647,11 +2450,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2647,11 +2450,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2647 \\ Four,2450 \\ Four,
2648 \\};2451 \\};
2649 \\2452 \\
2650 \\extern fn entry() {2453 \\export fn entry() {
2651 \\ var y = u3(3);2454 \\ var y = u3(3);
2652 \\ var x = Small(y);2455 \\ var x = Small(y);
2653 \\}2456 \\}
2654 \\comptime {@export("entry", entry);}
2655 ,2457 ,
2656 ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'");2458 ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'");
26572459
...@@ -2663,10 +2465,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2663,10 +2465,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2663 \\ Four,2465 \\ Four,
2664 \\};2466 \\};
2665 \\2467 \\
2666 \\extern fn entry() {2468 \\export fn entry() {
2667 \\ var y = Small.Two;2469 \\ var y = Small.Two;
2668 \\}2470 \\}
2669 \\comptime {@export("entry", entry);}
2670 ,2471 ,
2671 ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'");2472 ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'");
26722473
...@@ -2674,10 +2475,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2674,10 +2475,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2674 \\const MultipleChoice = struct {2475 \\const MultipleChoice = struct {
2675 \\ A: i32 = 20,2476 \\ A: i32 = 20,
2676 \\};2477 \\};
2677 \\extern fn entry() {2478 \\export fn entry() {
2678 \\ var x: MultipleChoice = undefined;2479 \\ var x: MultipleChoice = undefined;
2679 \\}2480 \\}
2680 \\comptime {@export("entry", entry);}
2681 ,2481 ,
2682 ".tmp_source.zig:2:14: error: enums, not structs, support field assignment");2482 ".tmp_source.zig:2:14: error: enums, not structs, support field assignment");
26832483
...@@ -2685,29 +2485,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2685,29 +2485,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2685 \\const MultipleChoice = union {2485 \\const MultipleChoice = union {
2686 \\ A: i32 = 20,2486 \\ A: i32 = 20,
2687 \\};2487 \\};
2688 \\extern fn entry() {2488 \\export fn entry() {
2689 \\ var x: MultipleChoice = undefined;2489 \\ var x: MultipleChoice = undefined;
2690 \\}2490 \\}
2691 \\comptime {@export("entry", entry);}
2692 ,2491 ,
2693 ".tmp_source.zig:2:14: error: non-enum union field assignment",2492 ".tmp_source.zig:2:14: error: non-enum union field assignment",
2694 ".tmp_source.zig:1:24: note: consider 'union(enum)' here");2493 ".tmp_source.zig:1:24: note: consider 'union(enum)' here");
26952494
2696 cases.add("enum with 0 fields",2495 cases.add("enum with 0 fields",
2697 \\const Foo = enum {};2496 \\const Foo = enum {};
2698 \\extern fn entry() -> usize {2497 \\export fn entry() -> usize {
2699 \\ return @sizeOf(Foo);2498 \\ return @sizeOf(Foo);
2700 \\}2499 \\}
2701 \\comptime {@export("entry", entry);}
2702 ,2500 ,
2703 ".tmp_source.zig:1:13: error: enums must have 1 or more fields");2501 ".tmp_source.zig:1:13: error: enums must have 1 or more fields");
27042502
2705 cases.add("union with 0 fields",2503 cases.add("union with 0 fields",
2706 \\const Foo = union {};2504 \\const Foo = union {};
2707 \\extern fn entry() -> usize {2505 \\export fn entry() -> usize {
2708 \\ return @sizeOf(Foo);2506 \\ return @sizeOf(Foo);
2709 \\}2507 \\}
2710 \\comptime {@export("entry", entry);}
2711 ,2508 ,
2712 ".tmp_source.zig:1:13: error: unions must have 1 or more fields");2509 ".tmp_source.zig:1:13: error: unions must have 1 or more fields");
27132510
...@@ -2719,10 +2516,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2719,10 +2516,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2719 \\ D = 1000,2516 \\ D = 1000,
2720 \\ E = 60,2517 \\ E = 60,
2721 \\};2518 \\};
2722 \\extern fn entry() {2519 \\export fn entry() {
2723 \\ var x = MultipleChoice.C;2520 \\ var x = MultipleChoice.C;
2724 \\}2521 \\}
2725 \\comptime {@export("entry", entry);}
2726 ,2522 ,
2727 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",2523 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",
2728 ".tmp_source.zig:4:9: note: other occurrence here");2524 ".tmp_source.zig:4:9: note: other occurrence here");
...@@ -2737,10 +2533,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2737,10 +2533,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2737 \\ A: i32,2533 \\ A: i32,
2738 \\ B: f64,2534 \\ B: f64,
2739 \\};2535 \\};
2740 \\extern fn entry() -> usize {2536 \\export fn entry() -> usize {
2741 \\ return @sizeOf(Payload);2537 \\ return @sizeOf(Payload);
2742 \\}2538 \\}
2743 \\comptime {@export("entry", entry);}
2744 ,2539 ,
2745 ".tmp_source.zig:6:17: error: enum field missing: 'C'",2540 ".tmp_source.zig:6:17: error: enum field missing: 'C'",
2746 ".tmp_source.zig:4:5: note: declared here");2541 ".tmp_source.zig:4:5: note: declared here");
...@@ -2749,10 +2544,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2749,10 +2544,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2749 \\const Foo = union {2544 \\const Foo = union {
2750 \\ A: i32,2545 \\ A: i32,
2751 \\};2546 \\};
2752 \\extern fn entry() {2547 \\export fn entry() {
2753 \\ const x = @TagType(Foo);2548 \\ const x = @TagType(Foo);
2754 \\}2549 \\}
2755 \\comptime {@export("entry", entry);}
2756 ,2550 ,
2757 ".tmp_source.zig:5:24: error: union 'Foo' has no tag",2551 ".tmp_source.zig:5:24: error: union 'Foo' has no tag",
2758 ".tmp_source.zig:1:13: note: consider 'union(enum)' here");2552 ".tmp_source.zig:1:13: note: consider 'union(enum)' here");
...@@ -2761,10 +2555,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2761,10 +2555,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2761 \\const Foo = union(enum(f32)) {2555 \\const Foo = union(enum(f32)) {
2762 \\ A: i32,2556 \\ A: i32,
2763 \\};2557 \\};
2764 \\extern fn entry() {2558 \\export fn entry() {
2765 \\ const x = @TagType(Foo);2559 \\ const x = @TagType(Foo);
2766 \\}2560 \\}
2767 \\comptime {@export("entry", entry);}
2768 ,2561 ,
2769 ".tmp_source.zig:1:23: error: expected integer tag type, found 'f32'");2562 ".tmp_source.zig:1:23: error: expected integer tag type, found 'f32'");
27702563
...@@ -2772,10 +2565,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2772,10 +2565,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2772 \\const Foo = union(u32) {2565 \\const Foo = union(u32) {
2773 \\ A: i32,2566 \\ A: i32,
2774 \\};2567 \\};
2775 \\extern fn entry() {2568 \\export fn entry() {
2776 \\ const x = @TagType(Foo);2569 \\ const x = @TagType(Foo);
2777 \\}2570 \\}
2778 \\comptime {@export("entry", entry);}
2779 ,2571 ,
2780 ".tmp_source.zig:1:18: error: expected enum tag type, found 'u32'");2572 ".tmp_source.zig:1:18: error: expected enum tag type, found 'u32'");
27812573
...@@ -2787,10 +2579,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2787,10 +2579,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2787 \\ D = 1000,2579 \\ D = 1000,
2788 \\ E = 60,2580 \\ E = 60,
2789 \\};2581 \\};
2790 \\extern fn entry() {2582 \\export fn entry() {
2791 \\ var x = MultipleChoice { .C = {} };2583 \\ var x = MultipleChoice { .C = {} };
2792 \\}2584 \\}
2793 \\comptime {@export("entry", entry);}
2794 ,2585 ,
2795 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",2586 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",
2796 ".tmp_source.zig:4:9: note: other occurrence here");2587 ".tmp_source.zig:4:9: note: other occurrence here");
...@@ -2807,10 +2598,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2807,10 +2598,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2807 \\ C: bool,2598 \\ C: bool,
2808 \\ D: bool,2599 \\ D: bool,
2809 \\};2600 \\};
2810 \\extern fn entry() {2601 \\export fn entry() {
2811 \\ var a = Payload {.A = 1234};2602 \\ var a = Payload {.A = 1234};
2812 \\}2603 \\}
2813 \\comptime {@export("entry", entry);}
2814 ,2604 ,
2815 ".tmp_source.zig:10:5: error: enum field not found: 'D'",2605 ".tmp_source.zig:10:5: error: enum field not found: 'D'",
2816 ".tmp_source.zig:1:16: note: enum declared here");2606 ".tmp_source.zig:1:16: note: enum declared here");
...@@ -2821,10 +2611,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2821,10 +2611,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2821 \\ B,2611 \\ B,
2822 \\ C,2612 \\ C,
2823 \\};2613 \\};
2824 \\extern fn entry() {2614 \\export fn entry() {
2825 \\ var b = Letter.B;2615 \\ var b = Letter.B;
2826 \\}2616 \\}
2827 \\comptime {@export("entry", entry);}
2828 ,2617 ,
2829 ".tmp_source.zig:2:8: error: structs and unions, not enums, support field types",2618 ".tmp_source.zig:2:8: error: structs and unions, not enums, support field types",
2830 ".tmp_source.zig:1:16: note: consider 'union(enum)' here");2619 ".tmp_source.zig:1:16: note: consider 'union(enum)' here");
...@@ -2833,10 +2622,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2833,10 +2622,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2833 \\const Letter = struct {2622 \\const Letter = struct {
2834 \\ A,2623 \\ A,
2835 \\};2624 \\};
2836 \\extern fn entry() {2625 \\export fn entry() {
2837 \\ var a = Letter { .A = {} };2626 \\ var a = Letter { .A = {} };
2838 \\}2627 \\}
2839 \\comptime {@export("entry", entry);}
2840 ,2628 ,
2841 ".tmp_source.zig:2:5: error: struct field missing type");2629 ".tmp_source.zig:2:5: error: struct field missing type");
28422630
...@@ -2844,10 +2632,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2844,10 +2632,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2844 \\const Letter = extern union {2632 \\const Letter = extern union {
2845 \\ A,2633 \\ A,
2846 \\};2634 \\};
2847 \\extern fn entry() {2635 \\export fn entry() {
2848 \\ var a = Letter { .A = {} };2636 \\ var a = Letter { .A = {} };
2849 \\}2637 \\}
2850 \\comptime {@export("entry", entry);}
2851 ,2638 ,
2852 ".tmp_source.zig:2:5: error: union field missing type");2639 ".tmp_source.zig:2:5: error: union field missing type");
28532640
...@@ -2862,10 +2649,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2862,10 +2649,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2862 \\ B: f64,2649 \\ B: f64,
2863 \\ C: bool,2650 \\ C: bool,
2864 \\};2651 \\};
2865 \\extern fn entry() {2652 \\export fn entry() {
2866 \\ var a = Payload { .A = { 1234 } };2653 \\ var a = Payload { .A = { 1234 } };
2867 \\}2654 \\}
2868 \\comptime {@export("entry", entry);}
2869 ,2655 ,
2870 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");2656 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");
28712657
...@@ -2880,10 +2666,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2880,10 +2666,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2880 \\ B: f64,2666 \\ B: f64,
2881 \\ C: bool,2667 \\ C: bool,
2882 \\};2668 \\};
2883 \\extern fn entry() {2669 \\export fn entry() {
2884 \\ var a = Payload { .A = { 1234 } };2670 \\ var a = Payload { .A = { 1234 } };
2885 \\}2671 \\}
2886 \\comptime {@export("entry", entry);}
2887 ,2672 ,
2888 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");2673 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");
28892674
...@@ -2893,7 +2678,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2893,7 +2678,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2893 \\ B: f64,2678 \\ B: f64,
2894 \\ C: bool,2679 \\ C: bool,
2895 \\};2680 \\};
2896 \\extern fn entry() {2681 \\export fn entry() {
2897 \\ const a = Payload { .A = { 1234 } };2682 \\ const a = Payload { .A = { 1234 } };
2898 \\ foo(a);2683 \\ foo(a);
2899 \\}2684 \\}
...@@ -2903,7 +2688,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2903,7 +2688,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2903 \\ else => unreachable,2688 \\ else => unreachable,
2904 \\ }2689 \\ }
2905 \\}2690 \\}
2906 \\comptime {@export("entry", entry);}
2907 ,2691 ,
2908 ".tmp_source.zig:11:13: error: switch on union which has no attached enum",2692 ".tmp_source.zig:11:13: error: switch on union which has no attached enum",
2909 ".tmp_source.zig:1:17: note: consider 'union(enum)' here");2693 ".tmp_source.zig:1:17: note: consider 'union(enum)' here");
...@@ -2913,10 +2697,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2913,10 +2697,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2913 \\ A = 10,2697 \\ A = 10,
2914 \\ B = 11,2698 \\ B = 11,
2915 \\};2699 \\};
2916 \\extern fn entry() {2700 \\export fn entry() {
2917 \\ var x = Foo(0);2701 \\ var x = Foo(0);
2918 \\}2702 \\}
2919 \\comptime {@export("entry", entry);}
2920 ,2703 ,
2921 ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0",2704 ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0",
2922 ".tmp_source.zig:1:13: note: 'Foo' declared here");2705 ".tmp_source.zig:1:13: note: 'Foo' declared here");
...@@ -2928,10 +2711,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2928,10 +2711,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2928 \\ B,2711 \\ B,
2929 \\ C,2712 \\ C,
2930 \\};2713 \\};
2931 \\extern fn entry() {2714 \\export fn entry() {
2932 \\ var x: Value = Letter.A;2715 \\ var x: Value = Letter.A;
2933 \\}2716 \\}
2934 \\comptime {@export("entry", entry);}
2935 ,2717 ,
2936 ".tmp_source.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",2718 ".tmp_source.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",
2937 ".tmp_source.zig:3:5: note: field 'A' declared here");2719 ".tmp_source.zig:3:5: note: field 'A' declared here");
...@@ -2943,36 +2725,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2943,36 +2725,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2943 \\ B,2725 \\ B,
2944 \\ C,2726 \\ C,
2945 \\};2727 \\};
2946 \\extern fn entry() {2728 \\export fn entry() {
2947 \\ foo(Letter.A);2729 \\ foo(Letter.A);
2948 \\}2730 \\}
2949 \\fn foo(l: Letter) {2731 \\fn foo(l: Letter) {
2950 \\ var x: Value = l;2732 \\ var x: Value = l;
2951 \\}2733 \\}
2952 \\comptime {@export("entry", entry);}
2953 ,2734 ,
2954 ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",2735 ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
2955 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'");2736 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'");
2956
2957 cases.addCase({
2958 const tc = cases.create("export collision",
2959 \\const foo = @import("foo.zig");
2960 \\
2961 \\comptime {@export("bar", bar);}
2962 \\extern fn bar() -> usize {
2963 \\ return foo.baz;
2964 \\}
2965 ,
2966 "foo.zig:2:11: error: exported symbol collision: 'bar'",
2967 ".tmp_source.zig:3:11: note: other symbol is here");
2968
2969 tc.addSourceFile("foo.zig",
2970 \\extern fn bar() {}
2971 \\comptime {@export("bar", bar);}
2972 \\pub const baz = 1234;
2973 );
2974
2975 tc
2976 });
2977
2978}2737}
test/standalone/issue_339/test.zig+1-4
...@@ -2,9 +2,6 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }...@@ -2,9 +2,6 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
22
3fn bar() -> %void {}3fn bar() -> %void {}
44
5comptime {5export fn foo() {
6 @export("foo", foo);
7}
8extern fn foo() {
9 %%bar();6 %%bar();
10}7}
test/translate_c.zig+32-32
...@@ -26,7 +26,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -26,7 +26,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
26 \\ return a < 0 ? -a : a;26 \\ return a < 0 ? -a : a;
27 \\}27 \\}
28 ,28 ,
29 \\pub fn abs(a: c_int) -> c_int {29 \\export fn abs(a: c_int) -> c_int {
30 \\ return if (a < 0) -a else a;30 \\ return if (a < 0) -a else a;
31 \\}31 \\}
32 );32 );
...@@ -325,12 +325,12 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -325,12 +325,12 @@ pub fn addCases(cases: &tests.TranslateCContext) {
325 \\ return a;325 \\ return a;
326 \\}326 \\}
327 ,327 ,
328 \\pub fn foo1(_arg_a: c_uint) -> c_uint {328 \\pub export fn foo1(_arg_a: c_uint) -> c_uint {
329 \\ var a = _arg_a;329 \\ var a = _arg_a;
330 \\ a +%= 1;330 \\ a +%= 1;
331 \\ return a;331 \\ return a;
332 \\}332 \\}
333 \\pub fn foo2(_arg_a: c_int) -> c_int {333 \\pub export fn foo2(_arg_a: c_int) -> c_int {
334 \\ var a = _arg_a;334 \\ var a = _arg_a;
335 \\ a += 1;335 \\ a += 1;
336 \\ return a;336 \\ return a;
...@@ -346,7 +346,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -346,7 +346,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
346 \\ return i;346 \\ return i;
347 \\}347 \\}
348 ,348 ,
349 \\pub fn log2(_arg_a: c_uint) -> c_int {349 \\pub export fn log2(_arg_a: c_uint) -> c_int {
350 \\ var a = _arg_a;350 \\ var a = _arg_a;
351 \\ var i: c_int = 0;351 \\ var i: c_int = 0;
352 \\ while (a > c_uint(0)) {352 \\ while (a > c_uint(0)) {
...@@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
367 \\ return a;367 \\ return a;
368 \\}368 \\}
369 ,369 ,
370 \\pub fn max(a: c_int, b: c_int) -> c_int {370 \\pub export fn max(a: c_int, b: c_int) -> c_int {
371 \\ if (a < b) return b;371 \\ if (a < b) return b;
372 \\ if (a < b) return b else return a;372 \\ if (a < b) return b else return a;
373 \\}373 \\}
...@@ -382,7 +382,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -382,7 +382,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
382 \\ return a;382 \\ return a;
383 \\}383 \\}
384 ,384 ,
385 \\pub fn max(a: c_int, b: c_int) -> c_int {385 \\pub export fn max(a: c_int, b: c_int) -> c_int {
386 \\ if (a == b) return a;386 \\ if (a == b) return a;
387 \\ if (a != b) return b;387 \\ if (a != b) return b;
388 \\ return a;388 \\ return a;
...@@ -407,7 +407,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -407,7 +407,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
407 \\ c = a % b;407 \\ c = a % b;
408 \\}408 \\}
409 ,409 ,
410 \\pub fn s(a: c_int, b: c_int) -> c_int {410 \\pub export fn s(a: c_int, b: c_int) -> c_int {
411 \\ var c: c_int;411 \\ var c: c_int;
412 \\ c = (a + b);412 \\ c = (a + b);
413 \\ c = (a - b);413 \\ c = (a - b);
...@@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
415 \\ c = @divTrunc(a, b);415 \\ c = @divTrunc(a, b);
416 \\ c = @rem(a, b);416 \\ c = @rem(a, b);
417 \\}417 \\}
418 \\pub fn u(a: c_uint, b: c_uint) -> c_uint {418 \\pub export fn u(a: c_uint, b: c_uint) -> c_uint {
419 \\ var c: c_uint;419 \\ var c: c_uint;
420 \\ c = (a +% b);420 \\ c = (a +% b);
421 \\ c = (a -% b);421 \\ c = (a -% b);
...@@ -430,7 +430,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -430,7 +430,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
430 \\ return (a & b) ^ (a | b);430 \\ return (a & b) ^ (a | b);
431 \\}431 \\}
432 ,432 ,
433 \\pub fn max(a: c_int, b: c_int) -> c_int {433 \\pub export fn max(a: c_int, b: c_int) -> c_int {
434 \\ return (a & b) ^ (a | b);434 \\ return (a & b) ^ (a | b);
435 \\}435 \\}
436 );436 );
...@@ -444,7 +444,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -444,7 +444,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
444 \\ return a;444 \\ return a;
445 \\}445 \\}
446 ,446 ,
447 \\pub fn max(a: c_int, b: c_int) -> c_int {447 \\pub export fn max(a: c_int, b: c_int) -> c_int {
448 \\ if ((a < b) or (a == b)) return b;448 \\ if ((a < b) or (a == b)) return b;
449 \\ if ((a >= b) and (a == b)) return a;449 \\ if ((a >= b) and (a == b)) return a;
450 \\ return a;450 \\ return a;
...@@ -458,7 +458,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -458,7 +458,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
458 \\ a = tmp;458 \\ a = tmp;
459 \\}459 \\}
460 ,460 ,
461 \\pub fn max(_arg_a: c_int) -> c_int {461 \\pub export fn max(_arg_a: c_int) -> c_int {
462 \\ var a = _arg_a;462 \\ var a = _arg_a;
463 \\ var tmp: c_int;463 \\ var tmp: c_int;
464 \\ tmp = a;464 \\ tmp = a;
...@@ -472,7 +472,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -472,7 +472,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
472 \\ c = b = a;472 \\ c = b = a;
473 \\}473 \\}
474 ,474 ,
475 \\pub fn max(a: c_int) {475 \\pub export fn max(a: c_int) {
476 \\ var b: c_int;476 \\ var b: c_int;
477 \\ var c: c_int;477 \\ var c: c_int;
478 \\ c = {478 \\ c = {
...@@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
493 \\ return i;493 \\ return i;
494 \\}494 \\}
495 ,495 ,
496 \\pub fn log2(_arg_a: u32) -> c_int {496 \\pub export fn log2(_arg_a: u32) -> c_int {
497 \\ var a = _arg_a;497 \\ var a = _arg_a;
498 \\ var i: c_int = 0;498 \\ var i: c_int = 0;
499 \\ while (a > c_uint(0)) {499 \\ while (a > c_uint(0)) {
...@@ -518,7 +518,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -518,7 +518,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
518 \\void foo(void) { bar(); }518 \\void foo(void) { bar(); }
519 ,519 ,
520 \\pub fn bar() {}520 \\pub fn bar() {}
521 \\pub fn foo() {521 \\pub export fn foo() {
522 \\ bar();522 \\ bar();
523 \\}523 \\}
524 );524 );
...@@ -534,7 +534,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -534,7 +534,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
534 \\pub const struct_Foo = extern struct {534 \\pub const struct_Foo = extern struct {
535 \\ field: c_int,535 \\ field: c_int,
536 \\};536 \\};
537 \\pub fn read_field(foo: ?&struct_Foo) -> c_int {537 \\pub export fn read_field(foo: ?&struct_Foo) -> c_int {
538 \\ return (??foo).field;538 \\ return (??foo).field;
539 \\}539 \\}
540 );540 );
...@@ -544,7 +544,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -544,7 +544,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
544 \\ ;;;;;544 \\ ;;;;;
545 \\}545 \\}
546 ,546 ,
547 \\pub fn foo() {}547 \\pub export fn foo() {}
548 );548 );
549549
550 cases.add("undefined array global",550 cases.add("undefined array global",
...@@ -560,7 +560,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -560,7 +560,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
560 \\}560 \\}
561 ,561 ,
562 \\pub var array: [100]c_int = undefined;562 \\pub var array: [100]c_int = undefined;
563 \\pub fn foo(index: c_int) -> c_int {563 \\pub export fn foo(index: c_int) -> c_int {
564 \\ return array[index];564 \\ return array[index];
565 \\}565 \\}
566 );566 );
...@@ -571,7 +571,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -571,7 +571,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
571 \\ return (int)a;571 \\ return (int)a;
572 \\}572 \\}
573 ,573 ,
574 \\pub fn float_to_int(a: f32) -> c_int {574 \\pub export fn float_to_int(a: f32) -> c_int {
575 \\ return c_int(a);575 \\ return c_int(a);
576 \\}576 \\}
577 );577 );
...@@ -581,7 +581,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -581,7 +581,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
581 \\ return x;581 \\ return x;
582 \\}582 \\}
583 ,583 ,
584 \\pub fn foo(x: ?&c_ushort) -> ?&c_void {584 \\pub export fn foo(x: ?&c_ushort) -> ?&c_void {
585 \\ return @ptrCast(?&c_void, x);585 \\ return @ptrCast(?&c_void, x);
586 \\}586 \\}
587 );587 );
...@@ -592,7 +592,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -592,7 +592,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
592 \\ return sizeof(int);592 \\ return sizeof(int);
593 \\}593 \\}
594 ,594 ,
595 \\pub fn size_of() -> usize {595 \\pub export fn size_of() -> usize {
596 \\ return @sizeOf(c_int);596 \\ return @sizeOf(c_int);
597 \\}597 \\}
598 );598 );
...@@ -602,7 +602,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -602,7 +602,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
602 \\ return 0;602 \\ return 0;
603 \\}603 \\}
604 ,604 ,
605 \\pub fn foo() -> ?&c_int {605 \\pub export fn foo() -> ?&c_int {
606 \\ return null;606 \\ return null;
607 \\}607 \\}
608 );608 );
...@@ -612,7 +612,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -612,7 +612,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
612 \\ return 1, 2;612 \\ return 1, 2;
613 \\}613 \\}
614 ,614 ,
615 \\pub fn foo() -> c_int {615 \\pub export fn foo() -> c_int {
616 \\ return {616 \\ return {
617 \\ _ = 1;617 \\ _ = 1;
618 \\ 2618 \\ 2
...@@ -625,7 +625,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -625,7 +625,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
625 \\ return (1 << 2) >> 1;625 \\ return (1 << 2) >> 1;
626 \\}626 \\}
627 ,627 ,
628 \\pub fn foo() -> c_int {628 \\pub export fn foo() -> c_int {
629 \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1);629 \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1);
630 \\}630 \\}
631 );631 );
...@@ -643,7 +643,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -643,7 +643,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
643 \\ a <<= (a <<= 1);643 \\ a <<= (a <<= 1);
644 \\}644 \\}
645 ,645 ,
646 \\pub fn foo() {646 \\pub export fn foo() {
647 \\ var a: c_int = 0;647 \\ var a: c_int = 0;
648 \\ a += {648 \\ a += {
649 \\ const _ref = &a;649 \\ const _ref = &a;
...@@ -701,7 +701,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -701,7 +701,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
701 \\ a <<= (a <<= 1);701 \\ a <<= (a <<= 1);
702 \\}702 \\}
703 ,703 ,
704 \\pub fn foo() {704 \\pub export fn foo() {
705 \\ var a: c_uint = c_uint(0);705 \\ var a: c_uint = c_uint(0);
706 \\ a +%= {706 \\ a +%= {
707 \\ const _ref = &a;707 \\ const _ref = &a;
...@@ -771,7 +771,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -771,7 +771,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
771 \\ u = u--;771 \\ u = u--;
772 \\}772 \\}
773 ,773 ,
774 \\pub fn foo() {774 \\pub export fn foo() {
775 \\ var i: c_int = 0;775 \\ var i: c_int = 0;
776 \\ var u: c_uint = c_uint(0);776 \\ var u: c_uint = c_uint(0);
777 \\ i += 1;777 \\ i += 1;
...@@ -819,7 +819,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -819,7 +819,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
819 \\ u = --u;819 \\ u = --u;
820 \\}820 \\}
821 ,821 ,
822 \\pub fn foo() {822 \\pub export fn foo() {
823 \\ var i: c_int = 0;823 \\ var i: c_int = 0;
824 \\ var u: c_uint = c_uint(0);824 \\ var u: c_uint = c_uint(0);
825 \\ i += 1;825 \\ i += 1;
...@@ -862,7 +862,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -862,7 +862,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
862 \\ while (b != 0);862 \\ while (b != 0);
863 \\}863 \\}
864 ,864 ,
865 \\pub fn foo() {865 \\pub export fn foo() {
866 \\ var a: c_int = 2;866 \\ var a: c_int = 2;
867 \\ while (true) {867 \\ while (true) {
868 \\ a -= 1;868 \\ a -= 1;
...@@ -886,9 +886,9 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -886,9 +886,9 @@ pub fn addCases(cases: &tests.TranslateCContext) {
886 \\ baz();886 \\ baz();
887 \\}887 \\}
888 ,888 ,
889 \\pub fn foo() {}889 \\pub export fn foo() {}
890 \\pub fn baz() {}890 \\pub export fn baz() {}
891 \\pub fn bar() {891 \\pub export fn bar() {
892 \\ var f: ?extern fn() = foo;892 \\ var f: ?extern fn() = foo;
893 \\ (??f)();893 \\ (??f)();
894 \\ (??f)();894 \\ (??f)();
...@@ -901,7 +901,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -901,7 +901,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
901 \\ *x = 1;901 \\ *x = 1;
902 \\}902 \\}
903 ,903 ,
904 \\pub fn foo(x: ?&c_int) {904 \\pub export fn foo(x: ?&c_int) {
905 \\ (*??x) = 1;905 \\ (*??x) = 1;
906 \\}906 \\}
907 );907 );