From d45b5287116dcb4ab202b350817f11642f0cca43 Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 27 Jun 2024 18:00:49 +0000 Subject: [PATCH] [wildcards] `UNUSED_FIELD` tests Since `_` fields are binding, I think we want to treat `_`s like any other private field and report `UNUSED_FIELD`s accordingly. These tests confirm that our current implementation is WAI. Fixes: https://github.com/dart-lang/sdk/issues/55862 Change-Id: I2c8486a3b9e55d22c53989d74de974334477ec33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373405 Commit-Queue: Phil Quitslund Reviewed-by: Brian Wilkerson --- .../src/diagnostics/unused_field_test.dart | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/analyzer/test/src/diagnostics/unused_field_test.dart b/pkg/analyzer/test/src/diagnostics/unused_field_test.dart index 93183774ac3a..59de7d5e1660 100644 --- a/pkg/analyzer/test/src/diagnostics/unused_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/unused_field_test.dart @@ -288,6 +288,29 @@ class A { ]); } + test_notUsed_noReference_wildcard() async { + await assertErrorsInCode(r''' +class A { + int _ = 0; +} +''', [ + error(WarningCode.UNUSED_FIELD, 16, 1), + ]); + } + + test_notUsed_noReference_wildcard_preWildcards() async { + await assertErrorsInCode(r''' +// @dart = 3.4 +// (pre wildcard-variables) + +class A { + int _ = 0; +} +''', [ + error(WarningCode.UNUSED_FIELD, 60, 1), + ]); + } + test_notUsed_nullAssign() async { await assertNoErrorsInCode(r''' class A {