Comments (3)
You might just as well use an explicit type annotation in the variable declaration:
void main() {
num varNum = 0;
varNum = 2.3;
print(varNum);
}
The cast had no other purpose than changing the inferred type of the variable, and that's just a more complex way to make it a num
variable. You could just write it directly.
Also note that a type cast is dangerous in general: Nothing will prevent typos/thinkos from causing failures at run time:
void main() {
var varNum = 'Hello, world!' as num; // No errors/warnings, but throws at run time.
varNum = 2.3;
print(varNum);
}
from sdk.
A similar mistake occurs in these below commands:
dart fix --apply
dart fix --dry-run
dart fix --apply --code=unnecessary_cast
, and it is fixed incorrectly. In the fix made, this cast is removed wrongly and caused compile error.
from sdk.
A similar mistake occurs in these below commands ...
That's because dart fix
uses the diagnostics produced by dart analyze
to determine what needs to be fixed. It assumes that those diagnostics are correct, which is not true in this case.
from sdk.
Related Issues (20)
- Phantom errors with Dart analysis HOT 16
- Compiler crashes when compiling to WASM HOT 3
- Using JsonUtf8Encoder to write to a file, produces a sink that never closes HOT 1
- `dart fix` command changed my code but not correct HOT 4
- Consider using `WasmArray`s in maps and related data structures HOT 1
- Support for omitting bounds checks HOT 1
- Profiler streamer races with isolate shutdown
- pkg/test_runner/test/static_error_test.dart failures HOT 4
- Add `.records` getter to Map (as an extension method) HOT 3
- Dart Compiler fail HOT 7
- NoSuchMethodError: The method 'any' was called on null, cannot explain HOT 4
- [ddc/dart2js] Compilers assume constructors that are external, only contain named args, and are extension type members are object literal constructors HOT 4
- "Extract method" creates function-typed parameters with wrong syntax when encountering generics
- Consider exposing @vmIsolateUnsendable annotation HOT 1
- Add support of dart2wasm.status file for co19 tests
- [CP] <$ cd chat-server $ cargo r Finished dev [unoptimized + debuginfo] target(s) in 0.21s Running `wasm-p2p-chat/target/debug/chat-server` Local peer id: PeerId("12D3KooWDvqnZSJ7ZkUTLmr1A2qGBKt5wi11gArpANDZWf8Pn7bX") Listening on "/ip4/127.0.0.1/tcp/9876/ws" Listening on "/ip4/192.168.178.94/tcp/9876/ws">
- [dart2wasm] language/async_star/async_star_invalid_test/03 passes but expected RTE HOT 2
- [gardening] x64 AOT compilation in debug mode takes very long for co19/LibTest/collection/ListBase/ListBase_class_A01_t02 HOT 5
- When geolocation api is disabled, app fails to load in Firefox HOT 2
- Chicken and egg problem when evolving `dart:_macros` library HOT 20
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.