fix: update instance generator code

This commit is contained in:
Sergey Penkovsky
2025-05-23 08:06:08 +03:00
parent 6d5537f068
commit 46c2939125

View File

@@ -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<T> and set async flags.
bool isAsyncInstance = false;
bool isAsyncProvide = false;