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

Constant Specification Update 2018 #61

Closed
mit-mit opened this issue Oct 25, 2018 · 3 comments

Comments

@mit-mit
Copy link
Member

commented Oct 25, 2018

This is the feature proposal for request #54. It improved the support for constant expressions, for example the ability to explicitly cast a value in a const expression:

class MyClass {
  final String value;
  const MyClass(Object o) : value = (o is! String) ? "$o" : (o as String);
}

The feature specification is:
https://github.com/dart-lang/language/blob/master/accepted/2.5/constant-update-2018/feature-specification.md

@mit-mit mit-mit added the feature label Oct 25, 2018
@mit-mit mit-mit added this to the Dart 2.2 milestone Oct 25, 2018
@mit-mit mit-mit referenced this issue Oct 25, 2018
2 of 18 tasks complete
@mit-mit mit-mit added this to Being implemented in Language funnel Nov 28, 2018
@jodinathan

This comment has been minimized.

Copy link

commented Jun 2, 2019

"https://dart-review.googlesource.com/c/sdk/+/36220 specified a number of changes to potentially constant and compile-time constant expressions;"

With this will it be possible to use functions in metadata?
eg:

class Foo {
  @Bar(() => 'foobar')
  String myProp;
}

today, the above is not possible, but this is

bar() => 'foobar';
class Foo {
  @Bar(bar)
  String myProp;
}
@lrhn

This comment has been minimized.

Copy link
Member

commented Jun 3, 2019

@jodinathan
No, there is no change to function literals in the listed changes, only small tweaks to include recently added operators and make the constant evaluation better match Dart 2 type semantics.

You have to do:

String kFooBar() => 'fooBar';
class Foo {
  @Bar(kFooBar)
  String myProp;
}

to tell the compiler that the function is a constant.

@mit-mit mit-mit removed the state-active label Aug 1, 2019
@mit-mit mit-mit modified the milestones: Dart 2.2, Dart 2.5 Sep 26, 2019
@mit-mit

This comment has been minimized.

Copy link
Member Author

commented Sep 26, 2019

This shipped in Dart 2.5

@mit-mit mit-mit closed this Sep 26, 2019
@eernstg eernstg moved this from Being implemented to Done in Language funnel Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3 participants
You can’t perform that action at this time.