Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit a91b233

Browse files
authored
failing test for unknown constant value (#3449)
1 parent c199514 commit a91b233

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/src/rules/avoid_redundant_argument_values.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ class _Visitor extends SimpleAstVisitor {
7575
continue;
7676
}
7777
var value = param.computeConstantValue();
78-
if (value != null) {
78+
if (value != null && value.hasKnownValue) {
7979
if (arg is NamedExpression) {
8080
arg = arg.expression;
8181
}
82-
var expressionValue = context.evaluateConstant(arg);
83-
if (expressionValue.value == value) {
82+
var expressionValue = context.evaluateConstant(arg).value;
83+
if ((expressionValue?.hasKnownValue ?? false) &&
84+
expressionValue == value) {
8485
rule.reportLint(arg);
8586
}
8687
}

test/rules/avoid_redundant_argument_values_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ class AvoidRedundantArgumentValuesTest extends LintRuleTest {
3939
@override
4040
String get lintRule => 'avoid_redundant_argument_values';
4141

42+
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3447')
43+
test_fromEnvironment() async {
44+
await assertNoDiagnostics(r'''
45+
const bool someDefine = bool.fromEnvironment('someDefine');
46+
47+
void f({bool test = true}) {}
48+
49+
void g() {
50+
f(
51+
test: !someDefine,
52+
);
53+
}
54+
''');
55+
}
56+
4257
test_requiredNullable() async {
4358
await assertNoDiagnostics(r'''
4459
void f({required int? x}) { }

0 commit comments

Comments
 (0)