mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 14:59:14 +00:00
parent
665eba93c1
commit
86e6acb37b
@ -3696,6 +3696,29 @@ fn fnDecl(
|
||||
if (param.anytype_ellipsis3) |tok| {
|
||||
return astgen.failTok(tok, "missing parameter name", .{});
|
||||
} else {
|
||||
ambiguous: {
|
||||
if (tree.nodes.items(.tag)[param.type_expr] != .identifier) break :ambiguous;
|
||||
const main_token = tree.nodes.items(.main_token)[param.type_expr];
|
||||
const identifier_str = tree.tokenSlice(main_token);
|
||||
if (isPrimitive(identifier_str)) break :ambiguous;
|
||||
return astgen.failNodeNotes(
|
||||
param.type_expr,
|
||||
"missing parameter name or type",
|
||||
.{},
|
||||
&[_]u32{
|
||||
try astgen.errNoteNode(
|
||||
param.type_expr,
|
||||
"if this is a name, annotate its type '{s}: T'",
|
||||
.{identifier_str},
|
||||
),
|
||||
try astgen.errNoteNode(
|
||||
param.type_expr,
|
||||
"if this is a type, give it a name '<name>: {s}'",
|
||||
.{identifier_str},
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
return astgen.failNode(param.type_expr, "missing parameter name", .{});
|
||||
}
|
||||
} else 0;
|
||||
|
||||
19
test/cases/compile_errors/missing_parameter_name.zig
Normal file
19
test/cases/compile_errors/missing_parameter_name.zig
Normal file
@ -0,0 +1,19 @@
|
||||
fn f2(u64) u64 {
|
||||
return x;
|
||||
}
|
||||
fn f3(*x) u64 {
|
||||
return x;
|
||||
}
|
||||
fn f1(x) u64 {
|
||||
return x;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :1:7: error: missing parameter name
|
||||
// :4:7: error: missing parameter name
|
||||
// :7:7: error: missing parameter name or type
|
||||
// :7:7: note: if this is a name, annotate its type 'x: T'
|
||||
// :7:7: note: if this is a type, give it a name '<name>: x'
|
||||
Loading…
x
Reference in New Issue
Block a user