-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Should a downwards context of dynamic
be treated as empty during inference?
#32357
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
Comments
From the original issue, some examples: T foo<T>(T x) {
print(T);
return x;
}
List<T> bar<T>(T x) {
print(T);
return [x];
}
List<S> baz<S, T>(Map<S, T> x) {
print("S = $S, T = $T");
}
void main() {
var y0 = foo(4);
dynamic y1 = foo(4);
Object y2 = foo(4);
print("Bar");
var z0 = bar(4);
List<dynamic> z1 = bar(4);
List<Object> z2 = bar(4);
print("[foo]");
z1 = [foo(4)];
z2 = [foo(4)];
List<int> z3 = [foo(4)];
print("baz");
List<dynamic> a0 = baz({3: "hello"});
List<int> a1 = baz({3: "hello"});
List<num> a2 = baz({3: "hello"});
List<num> a3 = baz({3: "hello"} ?? {3: "hello"});
} Currently
|
And from @lrhn List<T> foo<T>(T x) { print(T); return <T>[x]; }
Object o1 = foo(42);
dynamic o2 = foo(42);
/// And how does FutureOr fit into this?
FutureOr<Object> o3 = foo(42);
FutureOr<dynamic> o3 = foo(42); |
Another example is parameters of type dynamic (which can be implicit): T foo<T>(T x) {
print('$T $x');
return x;
}
bar(/*implicit dynamic*/ x, dynamic y, Object z) {}
main() {
bar(foo(1), foo(2), foo(3));
// DDC/DDK print:
// int 1
// int 2
// Object 3
} |
We talked about this in person, but I'll capture my thoughts briefly here in case it's helpful. My feeling is that, no, My arguments are:
|
In discussions here: #32291 it came up that strong mode as implemented in the analyzer treats
dynamic
in a downwards inference context as an empty context. This is to discuss whether we want this behavior in Dart 2 or not.cc @lrhn @jmesserly @stereotype441 @munificent
The text was updated successfully, but these errors were encountered: