Skip to content

@useResult annotation doesn't work when Callable class is invoked #48913

Closed
@maRci002

Description

@maRci002

@useResult annotation works fine when a callable class' instance is invoked explicitly by calling instance.call(...) however when the instance is invoked implicitly instance(...) the anyalazer won't complain.

class Foo {
  const Foo();

  @useResult
  int call() {
    return 42;
  }
}

void main() {
  final foo = const Foo();
  foo.call();
  foo(); // BAD: return value is silently ignored
}

dart --version

Dart SDK version: 2.16.2 (stable) (Tue Mar 22 13:15:13 2022 +0100) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions