@@ -285,9 +285,6 @@ TEST(Test_Variable_Analyzer_Type, type_use_does_not_see_non_type_variables) {
285
285
286
286
TEST (Test_Variable_Analyzer_Type,
287
287
interfaces_are_ignored_in_runtime_expressions) {
288
- using Diags_Matcher =
289
- testing::Matcher<const std::vector<Diag_Collector::Diag>&>;
290
-
291
288
static const Char8 outer_declaration[] = u8" I" ;
292
289
static const Char8 declaration[] = u8" I" ;
293
290
@@ -312,8 +309,15 @@ TEST(Test_Variable_Analyzer_Type,
312
309
//
313
310
// If no run-time variable exists with the same name as the interface,
314
311
// 'runtime_var_kind' is nullopt.
315
- Diags_Matcher (*get_diags_matcher)(
316
- std::optional<Variable_Kind> runtime_var_kind);
312
+ void (*check_diagnostics_impl)(
313
+ Diag_Collector& diags, std::optional<Variable_Kind> runtime_var_kind,
314
+ Source_Location caller);
315
+
316
+ void check_diagnostics (
317
+ Diag_Collector& diags, std::optional<Variable_Kind> runtime_var_kind,
318
+ Source_Location caller = Source_Location::current()) {
319
+ return this ->check_diagnostics_impl (diags, runtime_var_kind, caller);
320
+ }
317
321
};
318
322
319
323
Variable_Visit_Kind variable_visit_kinds[] = {
@@ -324,24 +328,31 @@ TEST(Test_Variable_Analyzer_Type,
324
328
l.visit_variable_assignment (identifier_of (assignment),
325
329
Variable_Assignment_Flags::none);
326
330
},
327
- .get_diags_matcher = [](std::optional<Variable_Kind> runtime_var_kind)
328
- -> Diags_Matcher {
331
+ .check_diagnostics_impl =
332
+ [](Diag_Collector& diags,
333
+ std::optional<Variable_Kind> runtime_var_kind,
334
+ Source_Location caller) -> void {
329
335
if (runtime_var_kind.has_value ()) {
330
336
if (*runtime_var_kind == Variable_Kind::_const) {
331
- return ElementsAreArray ({
332
- DIAG_TYPE_2_SPANS (Diag_Assignment_To_Const_Variable, //
333
- assignment, span_of (assignment), //
334
- declaration, span_of (outer_declaration)),
335
- });
337
+ EXPECT_THAT_AT_CALLER (
338
+ diags.errors ,
339
+ ElementsAreArray ({
340
+ DIAG_TYPE_2_SPANS (Diag_Assignment_To_Const_Variable, //
341
+ assignment, span_of (assignment), //
342
+ declaration,
343
+ span_of (outer_declaration)),
344
+ }));
336
345
} else {
337
- return IsEmpty ();
346
+ EXPECT_THAT_AT_CALLER (diags. errors , IsEmpty () );
338
347
}
339
348
} else {
340
349
// TODO(strager): Report a more helpful message.
341
- return ElementsAreArray ({
342
- DIAG_TYPE_SPAN (Diag_Assignment_To_Undeclared_Variable,
343
- assignment, span_of (assignment)),
344
- });
350
+ EXPECT_THAT_AT_CALLER (
351
+ diags.errors ,
352
+ ElementsAreArray ({
353
+ DIAG_TYPE_SPAN (Diag_Assignment_To_Undeclared_Variable,
354
+ assignment, span_of (assignment)),
355
+ }));
345
356
}
346
357
},
347
358
},
@@ -353,17 +364,21 @@ TEST(Test_Variable_Analyzer_Type,
353
364
l.visit_variable_delete_use (Identifier (deleted_variable_span),
354
365
delete_keyword_span);
355
366
},
356
- .get_diags_matcher = [](std::optional<Variable_Kind> runtime_var_kind)
357
- -> Diags_Matcher {
367
+ .check_diagnostics_impl =
368
+ [](Diag_Collector& diags,
369
+ std::optional<Variable_Kind> runtime_var_kind,
370
+ Source_Location caller) -> void {
358
371
if (runtime_var_kind.has_value ()) {
359
- return ElementsAreArray ({
360
- DIAG_TYPE_OFFSETS (
361
- &delete_expression,
362
- Diag_Redundant_Delete_Statement_On_Variable, //
363
- delete_expression, 0 , u8" delete I" _sv),
364
- });
372
+ EXPECT_THAT_AT_CALLER (
373
+ diags.errors ,
374
+ ElementsAreArray ({
375
+ DIAG_TYPE_OFFSETS (
376
+ &delete_expression,
377
+ Diag_Redundant_Delete_Statement_On_Variable, //
378
+ delete_expression, 0 , u8" delete I" _sv),
379
+ }));
365
380
} else {
366
- return IsEmpty ();
381
+ EXPECT_THAT_AT_CALLER (diags. errors , IsEmpty () );
367
382
}
368
383
},
369
384
},
@@ -373,16 +388,19 @@ TEST(Test_Variable_Analyzer_Type,
373
388
[](Variable_Analyzer& l) {
374
389
l.visit_variable_use (identifier_of (use));
375
390
},
376
- .get_diags_matcher =
377
- [](std::optional<Variable_Kind> runtime_var_kind) -> Diags_Matcher {
391
+ .check_diagnostics_impl =
392
+ [](Diag_Collector& diags,
393
+ std::optional<Variable_Kind> runtime_var_kind,
394
+ Source_Location caller) -> void {
378
395
if (runtime_var_kind.has_value ()) {
379
- return IsEmpty ();
396
+ EXPECT_THAT_AT_CALLER (diags. errors , IsEmpty () );
380
397
} else {
381
398
// TODO(strager): Report a more helpful message.
382
- return ElementsAreArray ({
383
- DIAG_TYPE_SPAN (Diag_Use_Of_Undeclared_Variable, name,
384
- span_of (use)),
385
- });
399
+ EXPECT_THAT_AT_CALLER (
400
+ diags.errors , ElementsAreArray ({
401
+ DIAG_TYPE_SPAN (Diag_Use_Of_Undeclared_Variable,
402
+ name, span_of (use)),
403
+ }));
386
404
}
387
405
}},
388
406
};
@@ -401,7 +419,7 @@ TEST(Test_Variable_Analyzer_Type,
401
419
visit_kind.visit (l);
402
420
l.visit_end_of_module ();
403
421
404
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( std::nullopt) );
422
+ visit_kind. check_diagnostics (v, std::nullopt);
405
423
}
406
424
407
425
{
@@ -419,7 +437,7 @@ TEST(Test_Variable_Analyzer_Type,
419
437
l.visit_exit_block_scope ();
420
438
l.visit_end_of_module ();
421
439
422
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( std::nullopt) );
440
+ visit_kind. check_diagnostics (v, std::nullopt);
423
441
}
424
442
425
443
{
@@ -443,7 +461,7 @@ TEST(Test_Variable_Analyzer_Type,
443
461
l.visit_exit_function_scope ();
444
462
l.visit_end_of_module ();
445
463
446
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( std::nullopt) );
464
+ visit_kind. check_diagnostics (v, std::nullopt);
447
465
}
448
466
449
467
for (Variable_Kind outer_kind : {
@@ -477,7 +495,7 @@ TEST(Test_Variable_Analyzer_Type,
477
495
l.visit_exit_block_scope ();
478
496
l.visit_end_of_module ();
479
497
480
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( outer_kind) );
498
+ visit_kind. check_diagnostics (v, outer_kind);
481
499
}
482
500
483
501
{
@@ -499,7 +517,7 @@ TEST(Test_Variable_Analyzer_Type,
499
517
l.visit_exit_block_scope ();
500
518
l.visit_end_of_module ();
501
519
502
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( outer_kind) );
520
+ visit_kind. check_diagnostics (v, outer_kind);
503
521
}
504
522
505
523
{
@@ -517,7 +535,7 @@ TEST(Test_Variable_Analyzer_Type,
517
535
visit_kind.visit (l);
518
536
l.visit_end_of_module ();
519
537
520
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( outer_kind) );
538
+ visit_kind. check_diagnostics (v, outer_kind);
521
539
}
522
540
523
541
{
@@ -535,7 +553,7 @@ TEST(Test_Variable_Analyzer_Type,
535
553
visit_kind.visit (l);
536
554
l.visit_end_of_module ();
537
555
538
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( outer_kind) );
556
+ visit_kind. check_diagnostics (v, outer_kind);
539
557
}
540
558
541
559
{
@@ -558,7 +576,7 @@ TEST(Test_Variable_Analyzer_Type,
558
576
Variable_Declaration_Flags::none);
559
577
l.visit_end_of_module ();
560
578
561
- EXPECT_THAT (v. errors , visit_kind. get_diags_matcher ( outer_kind) );
579
+ visit_kind. check_diagnostics (v, outer_kind);
562
580
}
563
581
}
564
582
}
0 commit comments