소스 검색

More focused diagnostic notes for parameters (#4420)

Geoff Romer 1 년 전
부모
커밋
5a795db0de

+ 7 - 12
toolchain/check/convert.cpp

@@ -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;
@@ -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) {

+ 4 - 4
toolchain/check/testdata/class/fail_incomplete.carbon

@@ -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);
 
@@ -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({});
 }

+ 2 - 2
toolchain/check/testdata/deduce/array.carbon

@@ -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);
 }

+ 2 - 2
toolchain/check/testdata/function/call/fail_param_type.carbon

@@ -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);
 }
 

+ 2 - 2
toolchain/check/testdata/operators/overloaded/eq.carbon

@@ -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;
 }

+ 4 - 4
toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon

@@ -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;
 }
@@ -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;
 }