Skip to content

Commit 7c22348

Browse files
authored
Add s plural format to IntAsSelect (#4423)
Per discussion on #toolchain, add "s" as a special-case for the common plural format. Note this removes periods from a few diagnostics; the periods shouldn't be there per message style. Also, while I'm ignoring llvm::StringLiteral uses, those should be addressed as #4416 -- this'll probably conflict and make me clean up one or the other.
1 parent 780dd3a commit 7c22348

26 files changed

+81
-62
lines changed

toolchain/check/call.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "toolchain/check/convert.h"
1010
#include "toolchain/check/deduce.h"
1111
#include "toolchain/check/function.h"
12+
#include "toolchain/diagnostics/format_providers.h"
1213
#include "toolchain/sem_ir/builtin_function_kind.h"
1314
#include "toolchain/sem_ir/builtin_inst_kind.h"
1415
#include "toolchain/sem_ir/entity_with_params_base.h"
@@ -42,9 +43,9 @@ static auto ResolveCalleeInCall(Context& context, SemIR::LocId loc_id,
4243
auto params = context.inst_blocks().GetOrEmpty(callee_info.param_refs_id);
4344
if (arg_ids.size() != params.size()) {
4445
CARBON_DIAGNOSTIC(CallArgCountMismatch, Error,
45-
"{0} argument(s) passed to {1} expecting "
46-
"{2} argument(s).",
47-
int, llvm::StringLiteral, int);
46+
"{0} argument{0:s} passed to {1} expecting "
47+
"{2} argument{2:s}",
48+
IntAsSelect, llvm::StringLiteral, IntAsSelect);
4849
CARBON_DIAGNOSTIC(InCallToEntity, Note, "calling {0} declared here",
4950
llvm::StringLiteral);
5051
context.emitter()

toolchain/check/convert.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
236236
if (tuple_elem_types.size() != array_bound) {
237237
CARBON_DIAGNOSTIC(
238238
ArrayInitFromLiteralArgCountMismatch, Error,
239-
"cannot initialize array of {0} element(s) from {1} initializer(s)",
240-
uint64_t, size_t);
239+
"cannot initialize array of {0} element{0:s} from {1} initializer{1:s}",
240+
IntAsSelect, IntAsSelect);
241241
CARBON_DIAGNOSTIC(ArrayInitFromExprArgCountMismatch, Error,
242-
"cannot initialize array of {0} element(s) from tuple "
243-
"with {1} element(s).",
244-
uint64_t, size_t);
242+
"cannot initialize array of {0} element{0:s} from tuple "
243+
"with {1} element{1:s}",
244+
IntAsSelect, IntAsSelect);
245245
context.emitter().Emit(value_loc_id,
246246
literal_elems.empty()
247247
? ArrayInitFromExprArgCountMismatch
@@ -320,9 +320,9 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
320320
// Check that the tuples are the same size.
321321
if (src_elem_types.size() != dest_elem_types.size()) {
322322
CARBON_DIAGNOSTIC(TupleInitElementCountMismatch, Error,
323-
"cannot initialize tuple of {0} element(s) from tuple "
324-
"with {1} element(s).",
325-
size_t, size_t);
323+
"cannot initialize tuple of {0} element{0:s} from tuple "
324+
"with {1} element{1:s}",
325+
IntAsSelect, IntAsSelect);
326326
context.emitter().Emit(value_loc_id, TupleInitElementCountMismatch,
327327
dest_elem_types.size(), src_elem_types.size());
328328
return SemIR::InstId::BuiltinError;
@@ -414,9 +414,9 @@ static auto ConvertStructToStructOrClass(Context& context,
414414
if (src_elem_fields.size() != dest_elem_fields.size()) {
415415
CARBON_DIAGNOSTIC(
416416
StructInitElementCountMismatch, Error,
417-
"cannot initialize {0:class|struct} with {1} field(s) from struct "
418-
"with {2} field(s).",
419-
BoolAsSelect, size_t, size_t);
417+
"cannot initialize {0:class|struct} with {1} field{1:s} from struct "
418+
"with {2} field{2:s}",
419+
BoolAsSelect, IntAsSelect, IntAsSelect);
420420
context.emitter().Emit(value_loc_id, StructInitElementCountMismatch,
421421
ToClass, dest_elem_fields.size(),
422422
src_elem_fields.size());

toolchain/check/testdata/array/fail_out_of_bound.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// TIP: To dump output, run:
99
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/fail_out_of_bound.carbon
1010

11-
// CHECK:STDERR: fail_out_of_bound.carbon:[[@LINE+3]]:19: error: cannot initialize array of 1 element(s) from 3 initializer(s)
11+
// CHECK:STDERR: fail_out_of_bound.carbon:[[@LINE+3]]:19: error: cannot initialize array of 1 element from 3 initializers
1212
// CHECK:STDERR: var a: [i32; 1] = (1, 2, 3);
1313
// CHECK:STDERR: ^~~~~~~~~
1414
var a: [i32; 1] = (1, 2, 3);

toolchain/check/testdata/array/fail_type_mismatch.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ var t1: (i32, String, String);
2727
// CHECK:STDERR:
2828
var b: [i32; 3] = t1;
2929

30-
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+4]]:19: error: cannot initialize array of 3 element(s) from 2 initializer(s)
30+
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+4]]:19: error: cannot initialize array of 3 elements from 2 initializers
3131
// CHECK:STDERR: var c: [i32; 3] = (1, 2);
3232
// CHECK:STDERR: ^~~~~~
3333
// CHECK:STDERR:
3434
var c: [i32; 3] = (1, 2);
3535

3636
var t2: (i32, i32);
37-
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+3]]:19: error: cannot initialize array of 3 element(s) from tuple with 2 element(s).
37+
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+3]]:19: error: cannot initialize array of 3 elements from tuple with 2 elements
3838
// CHECK:STDERR: var d: [i32; 3] = t2;
3939
// CHECK:STDERR: ^~
4040
var d: [i32; 3] = t2;

toolchain/check/testdata/builtins/float/negate.carbon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn BadReturnType(a: f64) -> bool = "float.negate";
4040
fn JustRight(a: f64) -> f64 = "float.negate";
4141

4242
fn RuntimeCallTooFew(a: f64) -> f64 {
43-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument(s) passed to function expecting 0 argument(s).
43+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument passed to function expecting 0 arguments
4444
// CHECK:STDERR: return TooFew(a);
4545
// CHECK:STDERR: ^~~~~~~
4646
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-17]]:1: note: calling function declared here
@@ -51,7 +51,7 @@ fn RuntimeCallTooFew(a: f64) -> f64 {
5151
}
5252

5353
fn RuntimeCallTooMany(a: f64, b: f64, c: f64) -> f64 {
54-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 argument(s) passed to function expecting 2 argument(s).
54+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 arguments passed to function expecting 2 arguments
5555
// CHECK:STDERR: return TooMany(a, b, c);
5656
// CHECK:STDERR: ^~~~~~~~
5757
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-23]]:1: note: calling function declared here
@@ -62,7 +62,7 @@ fn RuntimeCallTooMany(a: f64, b: f64, c: f64) -> f64 {
6262
}
6363

6464
fn RuntimeCallBadReturnType(a: f64, b: f64) -> bool {
65-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:10: error: 2 argument(s) passed to function expecting 1 argument(s).
65+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:10: error: 2 arguments passed to function expecting 1 argument
6666
// CHECK:STDERR: return BadReturnType(a, b);
6767
// CHECK:STDERR: ^~~~~~~~~~~~~~
6868
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-29]]:1: note: calling function declared here

toolchain/check/testdata/builtins/int/sadd.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var too_many: [i32; TooMany(1, 2, 3)];
5656
// CHECK:STDERR:
5757
var bad_return_type: [i32; BadReturnType(1, 2)];
5858

59-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 3 argument(s) passed to function expecting 2 argument(s).
59+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 3 arguments passed to function expecting 2 arguments
6060
// CHECK:STDERR: var bad_call: [i32; JustRight(1, 2, 3)];
6161
// CHECK:STDERR: ^~~~~~~~~~
6262
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-21]]:1: note: calling function declared here

toolchain/check/testdata/builtins/int/snegate.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var too_many: [i32; TooMany(1, 2)];
5858
// CHECK:STDERR:
5959
var bad_return_type: [i32; BadReturnType(1)];
6060

61-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 2 argument(s) passed to function expecting 1 argument(s).
61+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 2 arguments passed to function expecting 1 argument
6262
// CHECK:STDERR: var bad_call: [i32; JustRight(1, 2)];
6363
// CHECK:STDERR: ^~~~~~~~~~
6464
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-21]]:1: note: calling function declared here
@@ -68,7 +68,7 @@ var bad_return_type: [i32; BadReturnType(1)];
6868
var bad_call: [i32; JustRight(1, 2)];
6969

7070
fn RuntimeCallTooFew(a: i32) -> i32 {
71-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument(s) passed to function expecting 0 argument(s).
71+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument passed to function expecting 0 arguments
7272
// CHECK:STDERR: return TooFew(a);
7373
// CHECK:STDERR: ^~~~~~~
7474
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-42]]:1: note: calling function declared here
@@ -79,7 +79,7 @@ fn RuntimeCallTooFew(a: i32) -> i32 {
7979
}
8080

8181
fn RuntimeCallTooMany(a: i32, b: i32, c: i32) -> i32 {
82-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 argument(s) passed to function expecting 2 argument(s).
82+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 arguments passed to function expecting 2 arguments
8383
// CHECK:STDERR: return TooMany(a, b, c);
8484
// CHECK:STDERR: ^~~~~~~~
8585
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-48]]:1: note: calling function declared here
@@ -90,7 +90,7 @@ fn RuntimeCallTooMany(a: i32, b: i32, c: i32) -> i32 {
9090
}
9191

9292
fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool {
93-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 2 argument(s) passed to function expecting 1 argument(s).
93+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 2 arguments passed to function expecting 1 argument
9494
// CHECK:STDERR: return BadReturnType(a, b);
9595
// CHECK:STDERR: ^~~~~~~~~~~~~~
9696
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-54]]:1: note: calling function declared here

toolchain/check/testdata/builtins/int/uadd.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var too_many: [i32; TooMany(1, 2, 3)];
5656
// CHECK:STDERR:
5757
var bad_return_type: [i32; BadReturnType(1, 2)];
5858

59-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:21: error: 3 argument(s) passed to function expecting 2 argument(s).
59+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:21: error: 3 arguments passed to function expecting 2 arguments
6060
// CHECK:STDERR: var bad_call: [i32; JustRight(1, 2, 3)];
6161
// CHECK:STDERR: ^~~~~~~~~~
6262
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-21]]:1: note: calling function declared here

toolchain/check/testdata/builtins/int/unegate.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var too_many: [i32; TooMany(1, 2)];
5858
// CHECK:STDERR:
5959
var bad_return_type: [i32; BadReturnType(1)];
6060

61-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 2 argument(s) passed to function expecting 1 argument(s).
61+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:21: error: 2 arguments passed to function expecting 1 argument
6262
// CHECK:STDERR: var bad_call: [i32; JustRight(1, 2)];
6363
// CHECK:STDERR: ^~~~~~~~~~
6464
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-21]]:1: note: calling function declared here
@@ -68,7 +68,7 @@ var bad_return_type: [i32; BadReturnType(1)];
6868
var bad_call: [i32; JustRight(1, 2)];
6969

7070
fn RuntimeCallTooFew(a: i32) -> i32 {
71-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument(s) passed to function expecting 0 argument(s).
71+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 1 argument passed to function expecting 0 arguments
7272
// CHECK:STDERR: return TooFew(a);
7373
// CHECK:STDERR: ^~~~~~~
7474
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-42]]:1: note: calling function declared here
@@ -79,7 +79,7 @@ fn RuntimeCallTooFew(a: i32) -> i32 {
7979
}
8080

8181
fn RuntimeCallTooMany(a: i32, b: i32, c: i32) -> i32 {
82-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 argument(s) passed to function expecting 2 argument(s).
82+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+7]]:10: error: 3 arguments passed to function expecting 2 arguments
8383
// CHECK:STDERR: return TooMany(a, b, c);
8484
// CHECK:STDERR: ^~~~~~~~
8585
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-48]]:1: note: calling function declared here
@@ -90,7 +90,7 @@ fn RuntimeCallTooMany(a: i32, b: i32, c: i32) -> i32 {
9090
}
9191

9292
fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool {
93-
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:10: error: 2 argument(s) passed to function expecting 1 argument(s).
93+
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+6]]:10: error: 2 arguments passed to function expecting 1 argument
9494
// CHECK:STDERR: return BadReturnType(a, b);
9595
// CHECK:STDERR: ^~~~~~~~~~~~~~
9696
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE-54]]:1: note: calling function declared here

toolchain/check/testdata/class/fail_init.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Class {
1414
}
1515

1616
fn F() {
17-
// CHECK:STDERR: fail_init.carbon:[[@LINE+4]]:3: error: cannot initialize class with 2 field(s) from struct with 1 field(s).
17+
// CHECK:STDERR: fail_init.carbon:[[@LINE+4]]:3: error: cannot initialize class with 2 fields from struct with 1 field
1818
// CHECK:STDERR: {.a = 1} as Class;
1919
// CHECK:STDERR: ^~~~~~~~
2020
// CHECK:STDERR:
@@ -24,7 +24,7 @@ fn F() {
2424
// CHECK:STDERR: ^~~~~~~~~~~~~~~~
2525
// CHECK:STDERR:
2626
{.a = 1, .c = 2} as Class;
27-
// CHECK:STDERR: fail_init.carbon:[[@LINE+3]]:3: error: cannot initialize class with 2 field(s) from struct with 3 field(s).
27+
// CHECK:STDERR: fail_init.carbon:[[@LINE+3]]:3: error: cannot initialize class with 2 fields from struct with 3 fields
2828
// CHECK:STDERR: {.a = 1, .b = 2, .c = 3} as Class;
2929
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
3030
{.a = 1, .b = 2, .c = 3} as Class;

0 commit comments

Comments
 (0)