From e9a6197a8ea38c228e2683d82cfbdbad8e7d912a Mon Sep 17 00:00:00 2001 From: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> Date: Sun, 5 Nov 2023 13:36:06 +0300 Subject: [PATCH] Sema: fix error notes with wrong extern type --- src/Sema.zig | 2 +- ...unction_with_unspecified_calling_convention.zig | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig diff --git a/src/Sema.zig b/src/Sema.zig index a90e55550b..4f557d33ac 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -25573,7 +25573,7 @@ fn explainWhyTypeIsNotExtern( try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)}); try sema.explainWhyTypeIsComptime(msg, src_loc, ty); } - try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, position); + try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other); } }, .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), diff --git a/test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig b/test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig new file mode 100644 index 0000000000..ead75eb43e --- /dev/null +++ b/test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig @@ -0,0 +1,14 @@ +const Foo = extern struct { + f: *const fn() void, +}; + +pub fn entry() void { + _ = (Foo{}).f; +} + +// error +// backend=stage2 +// target=native +// +// :2:8: error: extern structs cannot contain fields of type '*const fn () void' +// :2:8: note: extern function must specify calling convention