Skip to content

Commit

Permalink
More focused diagnostic notes for parameters (#4420)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffromer authored Oct 17, 2024
1 parent 2a36ff6 commit 5a795db
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
19 changes: 7 additions & 12 deletions toolchain/check/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,21 +1208,9 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,
}
}

int diag_param_index;
DiagnosticAnnotationScope annotate_diagnostics(
&context.emitter(), [&](auto& builder) {
CARBON_DIAGNOSTIC(
InCallToFunctionParam, Note,
"initializing parameter {0} of function declared here", int);
builder.Note(callee.callee_loc, InCallToFunctionParam,
diag_param_index + 1);
});

// Check type conversions per-element.
for (auto [i, arg_id, param_pattern_id] :
llvm::enumerate(arg_refs, param_patterns)) {
diag_param_index = i;

auto runtime_index = SemIR::Function::GetParamPatternInfoFromPatternId(
context.sem_ir(), param_pattern_id)
.inst.runtime_index;
Expand All @@ -1231,6 +1219,13 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,
continue;
}

DiagnosticAnnotationScope annotate_diagnostics(
&context.emitter(), [&](auto& builder) {
CARBON_DIAGNOSTIC(InCallToFunctionParam, Note,
"initializing function parameter");
builder.Note(param_pattern_id, InCallToFunctionParam);
});

auto converted_arg_id = CallerPatternMatch(context, callee_specific_id,
param_pattern_id, arg_id);
if (converted_arg_id == SemIR::InstId::BuiltinError) {
Expand Down
8 changes: 4 additions & 4 deletions toolchain/check/testdata/class/fail_incomplete.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ fn CallTakeIncomplete(p: Class*) {
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-92]]:1: note: class was forward declared here
// CHECK:STDERR: class Class;
// CHECK:STDERR: ^~~~~~~~~~~~
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-11]]:1: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-11]]:19: note: initializing function parameter
// CHECK:STDERR: fn TakeIncomplete(c: Class);
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
TakeIncomplete(*p);

Expand All @@ -115,9 +115,9 @@ fn CallTakeIncomplete(p: Class*) {
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-104]]:1: note: class was forward declared here
// CHECK:STDERR: class Class;
// CHECK:STDERR: ^~~~~~~~~~~~
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-23]]:1: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-23]]:19: note: initializing function parameter
// CHECK:STDERR: fn TakeIncomplete(c: Class);
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
TakeIncomplete({});
}
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/testdata/deduce/array.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ fn G() -> C {
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE+7]]:12: note: type `[C; 3]` does not implement interface `ImplicitAs`
// CHECK:STDERR: return F(a);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE-11]]:1: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_bound_mismatch.carbon:[[@LINE-11]]:16: note: initializing function parameter
// CHECK:STDERR: fn F[T:! type](a: [T; 2]) -> T { return a[0]; }
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~~
// CHECK:STDERR:
return F(a);
}
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/testdata/function/call/fail_param_type.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ fn F() {
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+6]]:5: note: type `f64` does not implement interface `ImplicitAs`
// CHECK:STDERR: G(1.0);
// CHECK:STDERR: ^~~
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:1: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:6: note: initializing function parameter
// CHECK:STDERR: fn G(a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~
G(1.0);
}

Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/testdata/operators/overloaded/eq.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ fn TestRhsBad(a: C, b: D) -> bool {
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+7]]:15: note: type `D` does not implement interface `ImplicitAs`
// CHECK:STDERR: return a == b;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-11]]:3: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-11]]:21: note: initializing function parameter
// CHECK:STDERR: fn Equal[self: C](other: C) -> bool;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
return a == b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ fn Test(a: C, b: D) -> C {
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE+7]]:14: note: type `D` does not implement interface `ImplicitAs`
// CHECK:STDERR: return a + b;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-13]]:3: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-13]]:18: note: initializing function parameter
// CHECK:STDERR: fn Op[self: C](other: C) -> C;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
return a + b;
}
Expand All @@ -42,9 +42,9 @@ fn TestAssign(b: D) {
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE+6]]:8: note: type `D` does not implement interface `ImplicitAs`
// CHECK:STDERR: a += b;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-25]]:3: note: initializing parameter 1 of function declared here
// CHECK:STDERR: fail_no_impl_for_arg.carbon:[[@LINE-25]]:24: note: initializing function parameter
// CHECK:STDERR: fn Op[addr self: C*](other: C);
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: ^~~~~~~~
a += b;
}

Expand Down

0 comments on commit 5a795db

Please sign in to comment.