canCallWithoutArgs property
bool
get
canCallWithoutArgs
GEN-095 (D8f): true when the function can be called with no arguments,
i.e. it has no required positional parameters and no required-named
parameters. Used by the binary-expression visitor to decide whether to
auto-invoke a function value (legitimate for zero-arg thunks, wrong for
any callback that takes arguments — see semantics_gesture_delegate_test
where onHorizontalDrag == null was crashing because the comparison
auto-invoked the (DragUpdateDetails d) {} callback with []).
Implementation
bool get canCallWithoutArgs {
final params = _parameters?.parameters;
if (params == null || params.isEmpty) return true;
for (final param in params) {
// Optional positional is fine to omit; required-named
// (`{required ...}`) is not. A required `super.x` named parameter has
// never been counted as required here.
if (param.isOptionalPositional) continue;
if (param.isNamed) {
if (param.isRequired && param is! SSuperFormalParameter) return false;
continue;
}
// A required positional parameter of any shape.
return false;
}
return true;
}