Coder Social home page Coder Social logo

Comments (3)

eernstg avatar eernstg commented on May 23, 2024 1

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.

siahlooei avatar siahlooei commented on May 23, 2024

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.

bwilkerson avatar bwilkerson commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.