| author | |
| committer | |
| log | 010596c93054543c3c218e7d4b045d5e46384dab |
| tree | 665532621c58f7eaa8fe323a352029869fefaf3a |
| parent | 653814f76ba5d678ebad91f140417cd5829c6aad |
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); |
| 7980 | 7983 | ||
| 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 | }); |
| 8989 | 8992 | ||
| 8990 | comptime { | 8993 | comptime { |
| 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 @@ | ||
| 1 | pub export fn entry1() void { | ||
| 2 | @export(u100, .{ .name = "a" }); | ||
| 3 | } | ||
| 4 | pub export fn entry3() void { | ||
| 5 | @export(undefined, .{ .name = "b" }); | ||
| 6 | } | ||
| 7 | pub export fn entry4() void { | ||
| 8 | @export(null, .{ .name = "c" }); | ||
| 9 | } | ||
| 10 | pub export fn entry5() void { | ||
| 11 | @export(false, .{ .name = "d" }); | ||
| 12 | } | ||
| 13 | pub export fn entry6() void { | ||
| 14 | @export(u8, .{ .name = "e" }); | ||
| 15 | } | ||
| 16 | pub 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 | ||