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
Inference cannot solve for T?
== dynamic
#1035
Comments
This is a bug in the spec for constraint generation. We're missing the left top rule. Would you mind adding a language test for this if you get a chance? |
See dart-lang/language#1035 Change-Id: Ieb258a020d8212f5488cc3d73978b8132223353d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151760 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
Spec landed, tests are out, implementation issues filed. |
Fix to the fix landed above: #1200 (ordering was incorrect). |
Re-opening, since this is having difficulty landing. |
Ok, this seems to have landed and stuck. |
The following example seems to produce incorrect results still: void main() {
Future<Object?> bar1 = foo1(null); // Infers Object
Future<dynamic> bar2 = foo1(null); // Infers Object?
Future<Object?> bar3 = foo2(null); // Infers Object
Future<dynamic> bar4 = foo2(null); // Infers Object
}
Future<T?> foo1<T extends Object?>(T x) {
print('T is $T');
return Future<T?>.value(null);
}
Future<T?> foo2<T extends Object>(T x) {
print('T is $T');
return Future<T?>.value(null);
} I can't justify the results above based on the specification. @scheglov @johnniwinther the CFE and analyzer agree on this, but I can't reconcile this with the spec, am I missing something? @lrhn all of your tests use cc @goderbauer |
I think I was just testing the original issue, and wasn't aware that a bound of |
@leafpetersen Apparently, it happens after the constraints are gathered. If my analysis is correct, the constraint gathering for Here's the link of where that happens in the CFE: |
I think #1200 was about
The analyzer has similar to CFE code that adds the |
@scheglov yes, you are correct, thanks. I was just looking at the rules and realizing the same thing - the tests and the spec update here only account for one direction. |
Fix issue from #1035 . Update the algorithm for constraint solving to prefer decomposing the `dynamic` or `void` types on the left into `Object?` when matching against `Q?` for some `Q`.
Example:
This fails in
nullsafety.dartpad.dev
with the analyzer errors:Should we infer
Object
forT
here? We do so for<Object?>[]
, and in practicedynamic
andObject?
are equivalent types wrt. subtyping, so choosingT
asObject
would allow aList<dynamic>
as constructor argument.(I hit the issue with an extension not applying to a dynamic list, even though it applies to a
List<Object?>
).The text was updated successfully, but these errors were encountered: