-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[linter][discarded_futures] false positive #59949
Comments
@immutable
class _LutFoldersState {
final ISet<String> lutFolders;
final PersistentLutFoldersSet persistentLutFoldersSet;
final Future<List<DirectoryTree>> directoryTrees; // TODO: remove future
final bool isInitialized;
const _LutFoldersState(this.lutFolders, this.persistentLutFoldersSet,
this.directoryTrees, this.isInitialized);
_LutFoldersState.init()
: lutFolders = ISet({}),
persistentLutFoldersSet = PersistentLutFoldersSet(),
directoryTrees = Future.value([]),
isInitialized = false;
_LutFoldersState updateLutFolders(
ISet<String> lutFolders,
) {
return copyWith(
lutFolders: lutFolders,
// ignore: discarded_futures
directoryTrees: DirectoryTree.create(lutFolders.toSet()),
);
}
_LutFoldersState copyWith({
ISet<String>? lutFolders,
PersistentLutFoldersSet? persistentLutFoldersSet,
Future<List<DirectoryTree>>? directoryTrees,
bool? isInitialized,
}) {
return _LutFoldersState(
lutFolders ?? this.lutFolders,
persistentLutFoldersSet ?? this.persistentLutFoldersSet,
directoryTrees ?? this.directoryTrees,
isInitialized ?? this.isInitialized,
);
}
} same issue here in |
Hey, please take a look at #59887. There is a list of other issues that raise the same point about this lint. I'd consider this another duplicate. Either way, on that issue you can see a link to a CL that addresses this. |
@FMorschel, thanks for looking at this issue. It looks quite similar. Have you tested the CL on the provided code? |
As mentioned on #59887, I was still reviewing the test cases and the CL was still missing the binary expression (I do have a gist from Lasse that mentions every possibility for this that I'll take a look at yet, mentioned there). After handling binary expressions the
My current approach is that the variable must explicitly ask for a Your suggestion for handling this is another valid option still, but I'm unsure of what the team will prefer. If you fell like your suggestion is better, please feel free and comment on the mentioned issue so we can focus all discussions for it there.
A small side-note. Although I was able to add some code (below) to make your code stop having errors, I'd advise that for future issues (unless you really don't know how - there are cases where this is hard see #56911 and #59653 threads as an example) you provide a more concise code, containing everything necessary and removing boilerplate. This will help the team to debug your issues faster and they also can use your example as the test case. What I had to add to your code: extension type ISet<T>(Set<T> set) implements Set<T> {
Set<T> toSet() => set;
}
class PersistentLutFoldersSet {}
class DirectoryTree {
static Future<List<DirectoryTree>> create(Set<String> lutFolders) async {
return [];
}
} What I managed to create as an example of the false-positive you found: void foo() {
Future<int>? variable;
Future<int> _ = variable ?? g();
}
Future<int> g() async => 0; It'd be even more helpful if you could explain where is the false-positive happening (as you did) like saying "On line 3 you see the lint under ..." and maybe add a comment on the code (even more so when the repro is large) so it stands out on the code block like your |
The future created by
DirectoryTree.create
is not discarded, there is an assignment of the future.The text was updated successfully, but these errors were encountered: