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

Use of ?: in static const #5558

Closed
DartBot opened this issue Sep 28, 2012 · 6 comments
Closed

Use of ?: in static const #5558

DartBot opened this issue Sep 28, 2012 · 6 comments
Assignees
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

@DartBot
Copy link

DartBot commented Sep 28, 2012

This issue was originally filed by Rupert....@gmail.com


Would it be possible to allow use of ?: operator in static consts?
This allows them to be used a little like cpp's #ifdef.

const bool GRAVITY_ENABLED = true;
const num GRAVITY_Y = GRAVITY_ENABLED ? -9.81 : 0;

Per forum discussion https://groups.google.com/a/dartlang.org/d/topic/misc/RaFkab2-oU8/discussion

(FAO Gilad.)

@DartBot
Copy link
Author

DartBot commented Sep 28, 2012

This comment was originally written by ladicek@gmail.com


I think that the ?: ternary operator could easily be made compile-time constant, provided that its operands are also constants (and the condition is bool). This would increate expressivity of compile-time constants a lot.

In other words, I want this added to section 11.1 of the spec:

  A constant expression is one of the following:

  - ...
  - ...
  - An expression of the form e1 ? e2 : e3 where e1 is a constant expression that evaluates to a boolean value and e2 and e3 are constant expressions.

@kasperl
Copy link

kasperl commented Oct 5, 2012

cc @floitschG.
Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Nov 7, 2012

It's perfectly doable. Of course, the effect is just a rather minor convenience.


Set owner to @gbracha.
Removed Type-Defect label.
Added Type-Enhancement, Accepted labels.

@floitschG
Copy link
Contributor

Issue #12981 has been merged into this issue.

@rakudrama
Copy link
Member

I have on several occasions needed something like this.
The latest example was trying to pick between a VM and dart2js implementation of a class.

@gbracha
Copy link
Contributor

gbracha commented Aug 25, 2014

Added Done label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 25, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
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

7 participants