diff --git a/cherrypick_generator/lib/src/bind_spec.dart b/cherrypick_generator/lib/src/bind_spec.dart index 6fc25c5..4046bc2 100644 --- a/cherrypick_generator/lib/src/bind_spec.dart +++ b/cherrypick_generator/lib/src/bind_spec.dart @@ -125,9 +125,11 @@ class BindSpec { final multiLine = fnArgs.length > 60 || fnArgs.contains('\n'); switch (bindingType) { case BindingType.instance: - return isAsyncInstance - ? '.toInstanceAsync(($fnArgs) => $methodName($fnArgs))' - : '.toInstance(($fnArgs) => $methodName($fnArgs))'; + throw StateError( + 'Internal error: _generateWithParamsProvideClause called for @instance binding with @params.'); + //return isAsyncInstance + // ? '.toInstanceAsync(($fnArgs) => $methodName($fnArgs))' + // : '.toInstance(($fnArgs) => $methodName($fnArgs))'; case BindingType.provide: default: if (isAsyncProvide) { @@ -218,6 +220,15 @@ class BindSpec { final bindingType = hasInstance ? BindingType.instance : BindingType.provide; + // PROHIBIT @params with @instance bindings! + if (bindingType == BindingType.instance && hasParams) { + throw InvalidGenerationSourceError( + '@params() (runtime arguments) cannot be used together with @instance() on method $methodName. ' + 'Use @provide() instead if you want runtime arguments.', + element: method, + ); + } + // -- Extract inner type for Future and set async flags. bool isAsyncInstance = false; bool isAsyncProvide = false;