-
Notifications
You must be signed in to change notification settings - Fork 37
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
Cannot use TaskInvocation in Depends annotation. #318
Comments
Also, I am using grinder 0.8.1
|
I've tried to make I think this would fix the problem, but I don't have time to pull down the repo and test it at the moment. It would just require the use of the new class
Then in
|
Hello, @devoncarew! |
As a local work-around, there is a neat trick regarding const arguments you can use: declare a new class which class _TaskArgs2 implements TaskArgs {
@override
final String taskName;
final Map<String, bool> _flags;
final Map<String, String> _options;
const _TaskArgs2(this.taskName,
{Map<String, bool> flags, Map<String, String> options})
: _flags = flags,
_options = options;
@override
bool hasFlag(String name) => _flags.containsKey(name);
@override
bool getFlag(String name) => _flags[name] ?? false;
@override
bool hasOption(String name) => _options.containsKey(name);
@override
String getOption(String name) => _options[name];
@override
List<String> get arguments => throw UnimplementedError();
}
class _TaskInvocation2 implements TaskInvocation {
@override
final String name;
final TaskArgs _arguments;
const _TaskInvocation2(this.name, this._arguments);
@override
TaskArgs get arguments => _arguments;
}
const _localServerUrlArgs = _TaskArgs2('build', flags: {}, options: {
'option1': 'one',
'option2': 'two',
});
@Depends(_TaskInvocation2('build', _localServerUrlArgs))
run() {} In fact, if a non-breaking solution is preferred for this issue, it may be via subclasses like these. |
The Depends documentation states that a
TaskInvocation
can be used instead of aFunction
orString
in order to pass arguments to a dependent task. However, when trying to pass an instance ofTaskInvocation
toDepends
, dart throws an error for it not being a compile-time constant.error: line 11 pos 10: expression is not a valid compile-time constant @Depends(new TaskInvocation('print'))
When I try to make a constant
TaskInvocation
dart throws an error because it isn't a const constructor.error: line 11 pos 39: non-const constructor 'TaskInvocation' cannot be used in const object creation @Depends(const TaskInvocation('print'))
This is my
grind.dart
file. Am I using this correctly?The text was updated successfully, but these errors were encountered: