From 1fa085a107f1722057dccedbc63e402b5d4572a4 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 22 Nov 2023 01:16:45 +0000 Subject: [PATCH] More places where Function() is too strict --- lib/src/core_matchers.dart | 5 +++-- test/core_matchers_test.dart | 3 ++- test/test_utils.dart | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/core_matchers.dart b/lib/src/core_matchers.dart index cd86765..bb4eddf 100644 --- a/lib/src/core_matchers.dart +++ b/lib/src/core_matchers.dart @@ -148,12 +148,13 @@ class isInstanceOf extends TypeMatcher { /// a wrapper will have to be created. const Matcher returnsNormally = _ReturnsNormally(); -class _ReturnsNormally extends FeatureMatcher { +class _ReturnsNormally extends FeatureMatcher { const _ReturnsNormally(); @override - bool typedMatches(Function() f, Map matchState) { + bool typedMatches(Function f, Map matchState) { try { + // ignore: avoid_dynamic_calls f(); return true; } catch (e, s) { diff --git a/test/core_matchers_test.dart b/test/core_matchers_test.dart index 7c14dc4..3a12934 100644 --- a/test/core_matchers_test.dart +++ b/test/core_matchers_test.dart @@ -96,6 +96,7 @@ void main() { test('returnsNormally', () { shouldPass(doesNotThrow, returnsNormally); + shouldPass(doesNotThrowGeneric, returnsNormally); shouldFail( doesThrow, returnsNormally, @@ -103,7 +104,7 @@ void main() { r' Actual: ' r' Which: threw StateError:')); shouldFail('not a function', returnsNormally, - contains('not an dynamic\'>')); + contains('not an ')); }); test('hasLength', () { diff --git a/test/test_utils.dart b/test/test_utils.dart index 67b61a1..b4cc5f5 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -28,6 +28,7 @@ void shouldPass(Object? value, Matcher matcher) { } void doesNotThrow() {} +void doesNotThrowGeneric() {} void doesThrow() { throw StateError('X'); }