Skip to content

Commit 5a795db

Browse files
authored
More focused diagnostic notes for parameters (#4420)
1 parent 2a36ff6 commit 5a795db

File tree

6 files changed

+21
-26
lines changed

6 files changed

+21
-26
lines changed

toolchain/check/convert.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,21 +1208,9 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,
12081208
}
12091209
}
12101210

1211-
int diag_param_index;
1212-
DiagnosticAnnotationScope annotate_diagnostics(
1213-
&context.emitter(), [&](auto& builder) {
1214-
CARBON_DIAGNOSTIC(
1215-
InCallToFunctionParam, Note,
1216-
"initializing parameter {0} of function declared here", int);
1217-
builder.Note(callee.callee_loc, InCallToFunctionParam,
1218-
diag_param_index + 1);
1219-
});
1220-
12211211
// Check type conversions per-element.
12221212
for (auto [i, arg_id, param_pattern_id] :
12231213
llvm::enumerate(arg_refs, param_patterns)) {
1224-
diag_param_index = i;
1225-
12261214
auto runtime_index = SemIR::Function::GetParamPatternInfoFromPatternId(
12271215
context.sem_ir(), param_pattern_id)
12281216
.inst.runtime_index;
@@ -1231,6 +1219,13 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,
12311219
continue;
12321220
}
12331221

1222+
DiagnosticAnnotationScope annotate_diagnostics(
1223+
&context.emitter(), [&](auto& builder) {
1224+
CARBON_DIAGNOSTIC(InCallToFunctionParam, Note,
1225+
"initializing function parameter");
1226+
builder.Note(param_pattern_id, InCallToFunctionParam);
1227+
});
1228+
12341229
auto converted_arg_id = CallerPatternMatch(context, callee_specific_id,
12351230
param_pattern_id, arg_id);
12361231
if (converted_arg_id == SemIR::InstId::BuiltinError) {

toolchain/check/testdata/class/fail_incomplete.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ fn CallTakeIncomplete(p: Class*) {
103103
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-92]]:1: note: class was forward declared here
104104
// CHECK:STDERR: class Class;
105105
// CHECK:STDERR: ^~~~~~~~~~~~
106-
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-11]]:1: note: initializing parameter 1 of function declared here
106+
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-11]]:19: note: initializing function parameter
107107
// CHECK:STDERR: fn TakeIncomplete(c: Class);
108-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
108+
// CHECK:STDERR: ^~~~~~~~
109109
// CHECK:STDERR:
110110
TakeIncomplete(*p);
111111

@@ -115,9 +115,9 @@ fn CallTakeIncomplete(p: Class*) {
115115
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-104]]:1: note: class was forward declared here
116116
// CHECK:STDERR: class Class;
117117
// CHECK:STDERR: ^~~~~~~~~~~~
118-
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-23]]:1: note: initializing parameter 1 of function declared here
118+
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-23]]:19: note: initializing function parameter
119119
// CHECK:STDERR: fn TakeIncomplete(c: Class);
120-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
// CHECK:STDERR: ^~~~~~~~
121121
// CHECK:STDERR:
122122
TakeIncomplete({});
123123
}

toolchain/check/testdata/deduce/array.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ fn G() -> C {
7272
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE+7]]:12: note: type `[C; 3]` does not implement interface `ImplicitAs`
7373
// CHECK:STDERR: return F(a);
7474
// CHECK:STDERR: ^
75-
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE-11]]:1: note: initializing parameter 1 of function declared here
75+
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE-11]]:16: note: initializing function parameter
7676
// CHECK:STDERR: fn F[T:! type](a: [T; 2]) -> T { return a[0]; }
77-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77+
// CHECK:STDERR: ^~~~~~~~~
7878
// CHECK:STDERR:
7979
return F(a);
8080
}

toolchain/check/testdata/function/call/fail_param_type.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ fn F() {
1717
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+6]]:5: note: type `f64` does not implement interface `ImplicitAs`
1818
// CHECK:STDERR: G(1.0);
1919
// CHECK:STDERR: ^~~
20-
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:1: note: initializing parameter 1 of function declared here
20+
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:6: note: initializing function parameter
2121
// CHECK:STDERR: fn G(a: i32) {}
22-
// CHECK:STDERR: ^~~~~~~~~~~~~~
22+
// CHECK:STDERR: ^~~~~~
2323
G(1.0);
2424
}
2525

toolchain/check/testdata/operators/overloaded/eq.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ fn TestRhsBad(a: C, b: D) -> bool {
6868
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+7]]:15: note: type `D` does not implement interface `ImplicitAs`
6969
// CHECK:STDERR: return a == b;
7070
// CHECK:STDERR: ^
71-
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-11]]:3: note: initializing parameter 1 of function declared here
71+
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-11]]:21: note: initializing function parameter
7272
// CHECK:STDERR: fn Equal[self: C](other: C) -> bool;
73-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73+
// CHECK:STDERR: ^~~~~~~~
7474
// CHECK:STDERR:
7575
return a == b;
7676
}

toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ fn Test(a: C, b: D) -> C {
2727
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE+7]]:14: note: type `D` does not implement interface `ImplicitAs`
2828
// CHECK:STDERR: return a + b;
2929
// CHECK:STDERR: ^
30-
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-13]]:3: note: initializing parameter 1 of function declared here
30+
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-13]]:18: note: initializing function parameter
3131
// CHECK:STDERR: fn Op[self: C](other: C) -> C;
32-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32+
// CHECK:STDERR: ^~~~~~~~
3333
// CHECK:STDERR:
3434
return a + b;
3535
}
@@ -42,9 +42,9 @@ fn TestAssign(b: D) {
4242
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE+6]]:8: note: type `D` does not implement interface `ImplicitAs`
4343
// CHECK:STDERR: a += b;
4444
// CHECK:STDERR: ^
45-
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-25]]:3: note: initializing parameter 1 of function declared here
45+
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-25]]:24: note: initializing function parameter
4646
// CHECK:STDERR: fn Op[addr self: C*](other: C);
47-
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47+
// CHECK:STDERR: ^~~~~~~~
4848
a += b;
4949
}
5050

0 commit comments

Comments
 (0)