-
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
Analysis error comparing value in generic function: The operator '<' isn't defined for the type 'Object'. Try defining the operator '<'. #48952
Comments
Interestingly just found that this throws an error:
But this is fine:
And upon further testing, confirmed that the error only occurs when |
Note that When that function literal is passed to the Perhaps you meant to write something like this?: typedef SettingOrFunc<T> = int? Function(ContainsValue<T> tag);
class ContainsValue<T> {
final T val;
ContainsValue(this.val);
}
class UsesSetting<T> {
final SettingOrFunc<T>? setting;
UsesSetting({this.setting});
/// Do stuff with wrappedValue here,
/// for my project, if wrappedValue is/returns null,
/// default values are used otherwise uses the wrappedValue's return.
}
void main(List<String> args) {
UsesSetting<num>(
setting: (t) => t.val == 50 ? 0 : null, // is fine
);
UsesSetting<num>(
setting: (t) => t.val < 50 ? 0 : null,
);
} The reported analyzer behavior is basically working as intended: In However, it is somewhat surprising that the error message seems to imply that the type of @stereotype441, @scheglov, do you think there's a need to adjust this error message? |
Hmm, when I try the examples above, I see a slightly different behavior than what was reported:
The fact that the front end and the analyzer disagree about whether there is an error is definitely bad. I've opened a separate issue for it: #48955 |
Yes, I also expected for I will need to run this through google3 before landing. And so, we will report:
|
Ah - I definitely missed that. This helps me at least understand why the error is being thrown. I thought it was assigning
That was my intended behavior, however, I was specifically trying to avoid having the class generic but as I'm experimenting I'm not finding a way to do it :/. Might just bite the bullet and redesign some other stuff or maybe try something slightly different. Regardless - not related to this issue.
Personally, I agree - in hindsight, that's what led to my confusion in the first place.
Checked and confirmed not a typo, same as @eernstg , I only see |
Bug: #48952 Change-Id: I38add3e0d633f947640283eda46b5399f4559ef8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243702 Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Dart SDK version: 2.15.1 (stable) on windows_x64
I have a class that takes an object with some settings. I need the ability to override some settings with differing logic only in specific cases and have come up with a solution that the analyzer throws an error for. Here is a stripped-down version which demonstrates the problem:
Which throws the error (when run - or just highlighting from the analyzer):
At first, I thought this may have been because Dart is unsound and the value is within an object, but then slightly modified to just use the generic:
which throws (basically the same):
My belief is this shouldn't be throwing an error. If I highlight over the value (in the first example) or use code-completion inside the function body the analysis tools know the proper type. When not using the typedef it also has the same error.
The text was updated successfully, but these errors were encountered: