authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2023-03-04 12:51:16+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-04 22:52:57+02:00
log010596c93054543c3c218e7d4b045d5e46384dab
tree665532621c58f7eaa8fe323a352029869fefaf3a
parent653814f76ba5d678ebad91f140417cd5829c6aad

AstGen: compile-error on primitive value export

Fixes #14778 Co-authored-by: Veikka Tuominen <git@vexu.eu>

2 files changed, 33 insertions(+), 1 deletions(-)

src/AstGen.zig+4-1
...@@ -7976,6 +7976,9 @@ fn builtinCall(...@@ -7976,6 +7976,9 @@ fn builtinCall(
7976 switch (node_tags[params[0]]) {7976 switch (node_tags[params[0]]) {
7977 .identifier => {7977 .identifier => {
7978 const ident_token = main_tokens[params[0]];7978 const ident_token = main_tokens[params[0]];
7979 if (isPrimitive(tree.tokenSlice(ident_token))) {
7980 return astgen.failTok(ident_token, "unable to export primitive value", .{});
7981 }
7979 decl_name = try astgen.identAsString(ident_token);7982 decl_name = try astgen.identAsString(ident_token);
79807983
7981 var s = scope;7984 var s = scope;
...@@ -8988,7 +8991,7 @@ const primitive_instrs = std.ComptimeStringMap(Zir.Inst.Ref, .{...@@ -8988,7 +8991,7 @@ const primitive_instrs = std.ComptimeStringMap(Zir.Inst.Ref, .{
8988});8991});
89898992
8990comptime {8993comptime {
8991 // These checks ensure that std.zig.primitives stays in synce with the primitive->Zir map.8994 // These checks ensure that std.zig.primitives stays in sync with the primitive->Zir map.
8992 const primitives = std.zig.primitives;8995 const primitives = std.zig.primitives;
8993 for (primitive_instrs.kvs) |kv| {8996 for (primitive_instrs.kvs) |kv| {
8994 if (!primitives.isPrimitive(kv.key)) {8997 if (!primitives.isPrimitive(kv.key)) {
test/cases/compile_errors/exporting_primitive_values.zig created+29
...@@ -0,0 +1,29 @@
1pub export fn entry1() void {
2 @export(u100, .{ .name = "a" });
3}
4pub export fn entry3() void {
5 @export(undefined, .{ .name = "b" });
6}
7pub export fn entry4() void {
8 @export(null, .{ .name = "c" });
9}
10pub export fn entry5() void {
11 @export(false, .{ .name = "d" });
12}
13pub export fn entry6() void {
14 @export(u8, .{ .name = "e" });
15}
16pub export fn entry7() void {
17 @export(u65535, .{ .name = "f" });
18}
19
20// error
21// backend=llvm
22// target=native
23//
24// :2:13: error: unable to export primitive value
25// :5:13: error: unable to export primitive value
26// :8:13: error: unable to export primitive value
27// :11:13: error: unable to export primitive value
28// :14:13: error: unable to export primitive value
29// :17:13: error: unable to export primitive value