Skip to content

Cannot use new Function syntax in const Map declaration #32933

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
kevmoo opened this issue Apr 20, 2018 · 2 comments
Closed

Cannot use new Function syntax in const Map declaration #32933

kevmoo opened this issue Apr 20, 2018 · 2 comments
Labels
analyzer-constants devexp-command Issues with the command-line dartanalyzer tool devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead.

Comments

@kevmoo
Copy link
Member

kevmoo commented Apr 20, 2018

Dart VM version: 2.0.0-dev.49.0

Could expect this to be fine.

enum ArgType { option, flag, multiOption, rest, wasParsed, command }

const specialTypes = const <ArgType, bool Function(FieldElement)>{
  ArgType.rest: _couldBeRestArg,
  ArgType.wasParsed: _couldBeWasParsedArg,
  ArgType.command: _couldBeCommand
};

Instead

Analyzing build_cli...
  error • Const variables must be initialized with a constant value at lib/src/arg_info.dart:29:38 • const_initialized_with_non_constant_value
1 error found.
@kevmoo kevmoo added legacy-area-analyzer Use area-devexp instead. devexp-server Issues related to some aspect of the analysis server devexp-command Issues with the command-line dartanalyzer tool analyzer-constants labels Apr 20, 2018
@kevmoo
Copy link
Member Author

kevmoo commented Apr 20, 2018

work-around

typedef _fieldChecker = bool Function(FieldElement);

const specialTypes = const <ArgType, _fieldChecker>{
  ArgType.rest: _couldBeRestArg,
  ArgType.wasParsed: _couldBeWasParsedArg,
  ArgType.command: _couldBeCommand
};

@natebosch
Copy link
Member

This is not surfacing any errors for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-constants devexp-command Issues with the command-line dartanalyzer tool devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

3 participants