diff --git a/test/lints/avoid_unnecessary_return_variable/avoid_unnecessary_return_variable_rule_test.dart b/test/lints/avoid_unnecessary_return_variable/avoid_unnecessary_return_variable_rule_test.dart index 704cc16d..c112a617 100644 --- a/test/lints/avoid_unnecessary_return_variable/avoid_unnecessary_return_variable_rule_test.dart +++ b/test/lints/avoid_unnecessary_return_variable/avoid_unnecessary_return_variable_rule_test.dart @@ -213,7 +213,7 @@ int test() { ); } - void test_does_not_report_if_return_is_cached_and_used_after_return_nested_block() async { + void test_does_not_report_if_cached_and_used_after_nested_block() async { await assertNoDiagnostics(r''' int test(bool b) { final a = 3; @@ -224,5 +224,33 @@ int test(bool b) { } '''); } + + void test_does_not_report_if_type_promoted() async { + await assertNoDiagnostics(r''' +class Test { + final Map _map = {}; + + T get(String key) { + final value = _map[key]; + if (value is T) { + // local variable is promoted to T + return value; + } + + throw Exception('value is not of type $T'); + } } +'''); + } + void test_does_not_report_if_used_in_other_return_statement() async { + await assertNoDiagnostics(r''' +String test(bool someCondition) { + final a = 'test'; + if (someCondition) return a; + + return 'something $a'; +} +'''); + } +}