AstGen: compile-error on primitive value export

Fixes #14778

Co-authored-by: Veikka Tuominen <git@vexu.eu>
This commit is contained in:
r00ster91 2023-03-04 12:51:16 +01:00 committed by Veikka Tuominen
parent 653814f76b
commit 010596c930
2 changed files with 33 additions and 1 deletions

View File

@ -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)) {

View File

@ -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