Skip to content
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

int literals should be double literals #27678

Closed
Hixie opened this issue Oct 27, 2016 · 6 comments
Closed

int literals should be double literals #27678

Hixie opened this issue Oct 27, 2016 · 6 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@Hixie
Copy link
Contributor

Hixie commented Oct 27, 2016

The following isn't currently possible:

double i = 0;

We commonly get complaints from our users that they receive the runtime error "type 'int' is not a subtype of type 'double'", or the analyzer warning "A value of type 'int' cannot be assigned to a variable of type 'double'", whenever they put literal numerics in their code. Literal numerics are very common in Flutter code. The problem is caused by users using integer literals where we expect doubles.

We would like to be able to accept integer literals where doubles are expected, with no runtime overhead (i.e. with the conversion done at compile time).

It seems like this should be relatively straight-forward in a strong mode environment.

@lrhn
Copy link
Member

lrhn commented Oct 28, 2016

I can promise you that this is on our radar, and it is doable in a strongly typed setting - if you remember to type the variable.

var x = 0;
double y = x;  // whoops, x was probably inferred as int, definitely not as double.

@lrhn lrhn added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug labels Oct 28, 2016
@rmacnak-google
Copy link
Contributor

s/strongly/statically/

@lrhn
Copy link
Member

lrhn commented Nov 2, 2016

Indeed. I was trying to refer to "strong mode" colloquially, but that sentence actually means something else and it is indeed wrong.

Dart is strongly typed, and always has been. With "strong mode", it's also statically typed (except when the program is dynamic).

@natebosch
Copy link
Member

Relevant issue on the language repo: dart-lang/language#3
And solution proposal: dart-lang/language#4

Is it worth keeping this issue in the SDK open until the feature is implemented or should we close and track on the language repo?

@jayphelps
Copy link

This is supported in Dart 2.1

@mraleph
Copy link
Member

mraleph commented Nov 15, 2018

This is done ✅

@mraleph mraleph closed this as completed Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants