Comments (11)
This is just about how the type on the RHS of
??
is inferred, not how the type of the whole expression is inferred, right?
Correct, it's just about how the RHS of ??
is inferred.
As in:
T? nope<T>() => null; void main() { var x = nope<int>() ?? ''; // x is inferred to be Object rather than int, even after this change }
Yes. In fact, this code is unaffected by the change for two reasons: (1) because the type of the RHS (''
) is always String
, regardless of the context in which it's inferred, and (2) since the variable declaration has an implicit type, the context for the whole if-null expression nope<int>() ?? ''
is _
, not dynamic
.
from sdk.
@Hixie @grouma @vsmenon for review as a follow on to #55418.
from sdk.
This is just about how the type on the RHS of ??
is inferred, not how the type of the whole expression is inferred, right?
As in:
T? nope<T>() => null;
void main() {
var x = nope<int>() ?? ''; // x is inferred to be Object rather than int, even after this change
}
Assuming I understand correctly, SGTM.
from sdk.
lgtm
from sdk.
(Shouldn't the context type of e2
be NonNull(S) where S is the static type of e1
, not just the type itself? It does seem to consistently be the static type itself, but that means that
void main() async {
List<int>? maybeList = null as dynamic;
var x = maybeList ?? (await Future.value([]));
print([x].runtimeType);
}
gives x
a static type of List<int>?
for no good reason. Probably not something to fix in this "consistency CL", since it's something both implementations agree on today.)
from sdk.
(Shouldn't the context type of
e2
be NonNull(S) where S is the static type ofe1
, not just the type itself? It does seem to consistently be the static type itself, but that means thatvoid main() async { List<int>? maybeList = null as dynamic; var x = maybeList ?? (await Future.value([])); print([x].runtimeType); }gives
x
a static type ofList<int>?
for no good reason.
Yeah, considering that this is an example of an aspirational context, I agree. It makes sense to do something as close as possible to what we think the user probably wants, and NonNull(S) seems like a better model of what the user probably wants than S.
Probably not something to fix in this "consistency CL", since it's something both implementations agree on today.)
Agreed 😃
from sdk.
@grouma ping
from sdk.
cc @leonsenft who will handle breaking change requests for ACX going forward.
from sdk.
LGTM assuming
A prototype of this change caused zero test failures in Google's internal codebase
holds.
from sdk.
LGTM assuming
A prototype of this change caused zero test failures in Google's internal codebase
holds.
I will recheck before landing the change.
from sdk.
@stereotype441 lock it in!
from sdk.
Related Issues (20)
- [dartfuzz] runtime/vm/code_patcher_x64.cc: 80: error: Expected `call [CODE_REG + offs]`
- [dartfuzz] runtime/vm/instructions_riscv.cc: 215: error: unreachable code
- [dartfuzz] runtime/vm/object.h: 4278: error: expected: ptr() != null()
- [dartfuzz] runtime/vm/object.cc: 17505: error: expected: !is_megamorphic || result.NumberOfChecks() >= FLAG_max_polymorphic_checks
- "Cannot invoke a native callback outside of an isolate" Flutter FFI HOT 4
- Failures on [ package:vm_service ] Automatically invoke VmService.dispose() when the service connection closes...[dart2wasm] Move type parameter bounds checks & parameter type check logic together with logic setting up variables HOT 1
- Hide `@nonVirtual` methods in autocomplete? HOT 2
- Connect to the Dart Tooling Daemon from the Analysis Server
- Dart code does not always appear in traces in devtools HOT 6
- [analyzer] Crash type 'AugmentedExpressionImpl' is not a subtype of type 'SimpleIdentifierImpl' in type cast
- [analyzer] Unsupported operation: Unhandled AugmentedExpressionImpl in identifier.
- [analyzer] No error if a local variable named `augmented` is declared inside of augmenting function
- [analyzer] No error to tear-off `augmented` inside of augmenting function
- `ConstructorDefinitionBuilder.augment` cannot augment factory constructor
- [vm] Dart AOT runtime should refuse to run snapshots with incompatible sanitizers HOT 2
- [vm] gen_snapshot without santizers should be able to create AOT snapshots to be used with AOT runtimes with sanitizers HOT 1
- [CRASH] `dart run` fails logging `Compilation did not produce any result...` and crashes with `PathNotFoundException` HOT 5
- allow to destructure record types with positional fields HOT 8
- [analyzer] add warning when abstract interface class has unused implementation.
- [analyzer] incorrectly marking as dead code when accessing record property in ternary HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.