mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
AstGen: compile-error on primitive value export
Fixes #14778 Co-authored-by: Veikka Tuominen <git@vexu.eu>
This commit is contained in:
parent
653814f76b
commit
010596c930
@ -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)) {
|
||||
|
||||
29
test/cases/compile_errors/exporting_primitive_values.zig
Normal file
29
test/cases/compile_errors/exporting_primitive_values.zig
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user