Skip to content

Implementation issue for Int-to-Double-conversion #20

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

Closed
JekCharlsonYu opened this issue Aug 24, 2018 · 9 comments
Closed

Implementation issue for Int-to-Double-conversion #20

JekCharlsonYu opened this issue Aug 24, 2018 · 9 comments
Assignees
Labels
implementation Track the implementation of a specific feature OBSOLETE: Please use SDK issue
Milestone

Comments

@JekCharlsonYu
Copy link

JekCharlsonYu commented Aug 24, 2018

This issue is for tracking implementation of Int-to-Double-conversion:

What: Issue for implementation for Int to Double Conversion

ETA: 10/15 in Dart Repo.

@lrhn
Copy link
Member

lrhn commented Sep 4, 2018

Issues filed as dart-lang/sdk#34355

@mit-mit mit-mit changed the title Issue for Int-to-Double-conversion Implementation issue for Int-to-Double-conversion Oct 17, 2018
@mit-mit mit-mit added this to the Dart 2.1 milestone Oct 17, 2018
@mit-mit mit-mit added the implementation Track the implementation of a specific feature OBSOLETE: Please use SDK issue label Oct 17, 2018
@mit-mit
Copy link
Member

mit-mit commented Nov 2, 2018

@JekCharlsonYu what remains on this feature?

@anisalibegic
Copy link

anisalibegic commented Apr 11, 2019

@mit-mit I have one thing that bothers me while developing Flutter applications. Are there any reasons why

Error: A value of type 'int' can't be assigned to a variable of type 'double'.

when assigning variable value instead of literal value?

Not working:

int integerValue = 3;
double doubleValue = integerValue;

Working:

double doubleValue = 3;

@lrhn
Copy link
Member

lrhn commented Apr 11, 2019

Yes, there is a reason.

Dart does not have implicit conversions between class instances. A value which is an int is not also a double, and there is no implicit way to convert it to a double, and so double doubleValue = integerValue; is an error. It's even a compile-time error because there is no way to assign something of type int to a double variable.

What Dart does have is the ability to treat integer literals (like 3) as a double literal (like 3.0) when the integer literal occurs in a place where a double is required. It only works for literals. There is no implicit conversion in that case, there was never any int object created. So double doubleValue = 3; is completely equivalent to double doubleValue = 3.0;, we just allow you to omit the .0 when you know that the numeral will be used as a double anyway.

@ParvinderjitSF
Copy link

Why dart is lacking basic features like implicit conversions ? My app getting crashed due to this basic feature

@mateusfccp
Copy link
Contributor

@ParvinderjitSF Can you give a concrete example of what is happening? Preferably a MRE.

@talski
Copy link

talski commented Aug 6, 2021

@ParvinderjitSF Can you give a concrete example of what is happening? Preferably a MRE.

double? doubleValue;
dynamic integerValue = 1;

doubleValue = integerValue;

On flutter windows I get type 'int' is not a subtype of type 'double?'.
On flutter web I got no errors.

Flutter @ master
Dart SDK version: 2.14.0-383.0.dev on "windows_x64"

@mateusfccp
Copy link
Contributor

@talski I can reproduce it on Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "macos_x64".

It seems that the web and VM behave differently in this case, which is undesirable.

@mit-mit
Copy link
Member

mit-mit commented Aug 9, 2021

This is a several years old historical issue. For new issues, kindly file a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implementation Track the implementation of a specific feature OBSOLETE: Please use SDK issue
Projects
None yet
Development

No branches or pull requests

8 participants