diff --git a/pkg/analyzer/test/src/diagnostics/unused_catch_clause_test.dart b/pkg/analyzer/test/src/diagnostics/unused_catch_clause_test.dart index 82b14009cde..004f729f476 100644 --- a/pkg/analyzer/test/src/diagnostics/unused_catch_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/unused_catch_clause_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/src/error/codes.g.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -10,6 +11,7 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UnusedCatchClauseTest); + defineReflectiveTests(UnusedCatchClauseTestWildCardVariablesTest); }); } @@ -27,6 +29,16 @@ main() { ]); } + test_on_unusedStack_wildcard() async { + await assertNoErrorsInCode(r''' +main() { + try { + } on String catch (exception, _) { + } +} +'''); + } + test_on_usedException() async { await assertNoErrorsInCode(r''' main() { @@ -48,6 +60,26 @@ main() { '''); } + test_unusedException_underscores() async { + await assertNoErrorsInCode(r''' +main() { + try { + } catch (__) { + } +} +'''); + } + + test_unusedException_wildcard() async { + await assertNoErrorsInCode(r''' +main() { + try { + } catch (_) { + } +} +'''); + } + test_usedException() async { await assertNoErrorsInCode(r''' main() { @@ -59,3 +91,24 @@ main() { '''); } } + +@reflectiveTest +class UnusedCatchClauseTestWildCardVariablesTest extends UnusedCatchClauseTest { + @override + List get experiments => [ + ...super.experiments, + Feature.wildcard_variables.enableString, + ]; + + test_on_unusedStack_underscores() async { + await assertErrorsInCode(r''' +main() { + try { + } on String catch (exception, __) { + } +} +''', [ + error(WarningCode.UNUSED_CATCH_STACK, 49, 2), + ]); + } +}