master
1#target=x86_64-linux-selfhosted
2#target=x86_64-windows-selfhosted
3#target=x86_64-linux-cbe
4#target=x86_64-windows-cbe
5
6#update=initial version
7#file=main.zig
8export fn foo() void {}
9const bar: u32 = 123;
10const other: u32 = 456;
11comptime {
12 @export(&bar, .{ .name = "bar" });
13}
14pub fn main() !void {
15 const S = struct {
16 extern fn foo() void;
17 extern const bar: u32;
18 };
19 S.foo();
20 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
21 try stdout_writer.interface.print("{}\n", .{S.bar});
22}
23const std = @import("std");
24#expect_stdout="123\n"
25
26#update=add conflict
27#file=main.zig
28export fn foo() void {}
29const bar: u32 = 123;
30const other: u32 = 456;
31comptime {
32 @export(&bar, .{ .name = "bar" });
33 @export(&other, .{ .name = "foo" });
34}
35pub fn main() !void {
36 const S = struct {
37 extern fn foo() void;
38 extern const bar: u32;
39 extern const other: u32;
40 };
41 S.foo();
42 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
43 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
44}
45const std = @import("std");
46#expect_error=main.zig:6:5: error: exported symbol collision: foo
47#expect_error=main.zig:1:1: note: other symbol here
48
49#update=resolve conflict
50#file=main.zig
51export fn foo() void {}
52const bar: u32 = 123;
53const other: u32 = 456;
54comptime {
55 @export(&bar, .{ .name = "bar" });
56 @export(&other, .{ .name = "other" });
57}
58pub fn main() !void {
59 const S = struct {
60 extern fn foo() void;
61 extern const bar: u32;
62 extern const other: u32;
63 };
64 S.foo();
65 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
66 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
67}
68const std = @import("std");
69#expect_stdout="123 456\n"
70
71#update=put exports in decl
72#file=main.zig
73export fn foo() void {}
74const bar: u32 = 123;
75const other: u32 = 456;
76const does_exports = {
77 @export(&bar, .{ .name = "bar" });
78 @export(&other, .{ .name = "other" });
79};
80comptime {
81 _ = does_exports;
82}
83pub fn main() !void {
84 const S = struct {
85 extern fn foo() void;
86 extern const bar: u32;
87 extern const other: u32;
88 };
89 S.foo();
90 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
91 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
92}
93const std = @import("std");
94#expect_stdout="123 456\n"
95
96#update=remove reference to exporting decl
97#file=main.zig
98export fn foo() void {}
99const bar: u32 = 123;
100const other: u32 = 456;
101const does_exports = {
102 @export(&bar, .{ .name = "bar" });
103 @export(&other, .{ .name = "other" });
104};
105comptime {
106 //_ = does_exports;
107}
108pub fn main() !void {
109 const S = struct {
110 extern fn foo() void;
111 };
112 S.foo();
113}
114const std = @import("std");
115#expect_stdout=""
116
117#update=mark consts as export
118#file=main.zig
119export fn foo() void {}
120export const bar: u32 = 123;
121export const other: u32 = 456;
122const does_exports = {
123 @export(&bar, .{ .name = "bar" });
124 @export(&other, .{ .name = "other" });
125};
126comptime {
127 //_ = does_exports;
128}
129pub fn main() !void {
130 const S = struct {
131 extern fn foo() void;
132 extern const bar: u32;
133 extern const other: u32;
134 };
135 S.foo();
136 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
137 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
138}
139const std = @import("std");
140#expect_stdout="123 456\n"
141
142#update=reintroduce reference to exporting decl, introducing conflict
143#file=main.zig
144export fn foo() void {}
145export const bar: u32 = 123;
146export const other: u32 = 456;
147const does_exports = {
148 @export(&bar, .{ .name = "bar" });
149 @export(&other, .{ .name = "other" });
150};
151comptime {
152 _ = does_exports;
153}
154pub fn main() !void {
155 const S = struct {
156 extern fn foo() void;
157 extern const bar: u32;
158 extern const other: u32;
159 };
160 S.foo();
161 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
162 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
163}
164const std = @import("std");
165#expect_error=main.zig:5:5: error: exported symbol collision: bar
166#expect_error=main.zig:2:1: note: other symbol here
167#expect_error=main.zig:6:5: error: exported symbol collision: other
168#expect_error=main.zig:3:1: note: other symbol here