Open Hixie opened 2 years ago
Regarding the null
argument issue:
// a.dart
class A {
int f;
A({required this.f}) {
print('called');
// print(f.isEven); // this gives runtime error in either way!
}
}
// @dart=2.9
import 'a.dart';
void f() {
A(); // <-- should we have 'f: null'?
}
void main() {
f();
}
There are few things:
Whether the removal of required
argument is correct, or the fix to add it is incorrect.
Since the sample is executed without errors, that means is it redundant. So the removal is correct, but the suggestion to add it is incorrect.
AddMissingRequiredArgument is not configured for bulk, I guess this is because what the default value to add would be, so it is left to the user.
The parameter is not nullable, and using it will trigger a runtime error. However the caller is not NNBD (use at your own risk). I guess nothing to be done here.
Suggestion:
AddMissingRequiredArgument
should not be triggered in this case (when the caller is not NNBD)@bwilkerson
I think the language conceptually implies required parameters have no default value, even though at some level they sort of do. I would lean towards saying that if the parameter is marked required, the linter should never consider callers to have a matching redundant argument, even if the specified value does technically match the "actual" default value.
I agree. This sounds like an issue with the lint rule. @pq If you agree then we should move this issue to the linter's issue tracker.
This sounds like an issue with the lint rule.
Agreed.
STEPS TO REPRODUCE
git clone https://github.com/flutter/flutter.git
git checkout db426693c5901076b907b6b8de8d482522ffff1c
cd flutter/packages/flutter_tools
avoid_redundant_argument_values: true
to theanalysis_options.yaml
file.dart fix --apply
flutter analyze
EXPECTED RESULTS
No analyzer warnings.
ACTUAL RESULTS
You get several analyzer warnings. Some are because of https://github.com/dart-lang/sdk/issues/47398, some are interesting warnings like unused imports are optional parameters never being given, that kind of thing, which you would expect as a result of the fix.
However, a whole bunch of them are
missing_required_param
warnings, where null-safety-aware code with arguments of the formrequired Foo bar
which was being called from non-migrated code, with the argument set to null, now is causing a complaint because the argument was removed from the call. For example,test/integration.shard/plist_parser_test.dart
has this change applied:...even though
AnsiTerminal
is defined as:I tried to make a simple test case but none of my attempts succeeded; in controlled conditions, I was able to get the analyzer to give me the (bogus)
avoid_redundant_argument_values
lint but never able to getdart fix
to act on it.