Commit 010596c930
Changed files (2)
src
test
cases
compile_errors
src/AstGen.zig
@@ -7976,6 +7976,9 @@ fn builtinCall(
switch (node_tags[params[0]]) {
.identifier => {
const ident_token = main_tokens[params[0]];
+ if (isPrimitive(tree.tokenSlice(ident_token))) {
+ return astgen.failTok(ident_token, "unable to export primitive value", .{});
+ }
decl_name = try astgen.identAsString(ident_token);
var s = scope;
@@ -8988,7 +8991,7 @@ const primitive_instrs = std.ComptimeStringMap(Zir.Inst.Ref, .{
});
comptime {
- // These checks ensure that std.zig.primitives stays in synce with the primitive->Zir map.
+ // These checks ensure that std.zig.primitives stays in sync with the primitive->Zir map.
const primitives = std.zig.primitives;
for (primitive_instrs.kvs) |kv| {
if (!primitives.isPrimitive(kv.key)) {
test/cases/compile_errors/exporting_primitive_values.zig
@@ -0,0 +1,29 @@
+pub export fn entry1() void {
+ @export(u100, .{ .name = "a" });
+}
+pub export fn entry3() void {
+ @export(undefined, .{ .name = "b" });
+}
+pub export fn entry4() void {
+ @export(null, .{ .name = "c" });
+}
+pub export fn entry5() void {
+ @export(false, .{ .name = "d" });
+}
+pub export fn entry6() void {
+ @export(u8, .{ .name = "e" });
+}
+pub export fn entry7() void {
+ @export(u65535, .{ .name = "f" });
+}
+
+// error
+// backend=llvm
+// target=native
+//
+// :2:13: error: unable to export primitive value
+// :5:13: error: unable to export primitive value
+// :8:13: error: unable to export primitive value
+// :11:13: error: unable to export primitive value
+// :14:13: error: unable to export primitive value
+// :17:13: error: unable to export primitive value