Use type argument for Future of nullable value in test #681
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a weird one, so I'm going to try to carefully explain the situation and my steps. Here is the code in question:
This code works today. It appears that the type of
Future.value(...)
inferred by CFE isFuture<Object?>
. AFuture<Object?>
constructed with thevalue
constructor, and anObject?
argument is sound. However, in dart-lang/language#3304, it was decided that CFE infers the wrong type here, and should inferFuture<Object>
.If and when CFE will change its behavior remains to be seen, but analyzer will start reporting an issue that an
Object?
argument was passed to aFuture.value
constructor for an argument type ofObject
, and that would be invalid. The situation there is thatFuture.value
's single parameter is optional, so it's type isT?
, but at runtime a null value will throw an exception, so we can pretend the parameter is both required and non-nullable whenT
is non-nullable.So to prepare for a CFE change, and support analyzer's new warning, we can just put an explicit type argument.
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.