Skip to content

Analyzer doesn't catch that method argument has wrong signature #30052

@Hixie

Description

@Hixie

The analyzer doesn't catch this static type error:

void foo(bool callback()) { }

class Bar {
  void callFoo() {
    foo(method); // <-- this call is illegal ("method" has the wrong signature)
  }

  void method() { }
}

void main() {
  new Bar().callFoo();
}

Analyzer output:

  lint • Document all public members at test.dart:1:6 • public_member_api_docs
  lint • Document all public members at test.dart:3:7 • public_member_api_docs
  lint • Document all public members at test.dart:4:8 • public_member_api_docs
  lint • Document all public members at test.dart:8:8 • public_member_api_docs

VM output (checked mode):

Unhandled exception:
type '() => void' is not a subtype of type '() => bool' of 'callback'
#0      foo (test.dart:1:15)
#1      Bar.callFoo (test.dart:5:5)
#2      main (test.dart:12:13)
#3      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:265)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)

The analyzer does catch the problem if I make callFoo and method top-level functions or statics on the Bar class. It's only if they're methods that it's a problem.

Metadata

Metadata

Assignees

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

Relationships

None yet

Development

No branches or pull requests

Issue actions