From fc213e2d61c9ae6e643ddebf502c699abe4055e8 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sun, 28 Aug 2022 13:08:27 +0300 Subject: [PATCH] AstGen: add error for named function type Closes #12660 --- src/AstGen.zig | 4 ++++ test/cases/compile_errors/function_type_named.zig | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 test/cases/compile_errors/function_type_named.zig diff --git a/src/AstGen.zig b/src/AstGen.zig index 3398478266..943d0aad08 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1164,6 +1164,10 @@ fn fnProtoExpr( const tree = astgen.tree; const token_tags = tree.tokens.items(.tag); + if (fn_proto.name_token) |some| { + return astgen.failTok(some, "function type cannot have a name", .{}); + } + const is_extern = blk: { const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_extern_token] == .keyword_extern; diff --git a/test/cases/compile_errors/function_type_named.zig b/test/cases/compile_errors/function_type_named.zig new file mode 100644 index 0000000000..ad670fe88c --- /dev/null +++ b/test/cases/compile_errors/function_type_named.zig @@ -0,0 +1,7 @@ +const aFunc = fn someFunc(x: i32) void; + +// error +// backend=stage2 +// target=native +// +// :1:18: error: function type cannot have a name