Skip to content

Callable class has incorrect return type #33194

Closed
@DanTup

Description

@DanTup

Given this code:

class Test {
  T get<T>() {
    return null;
  }

  T call<T>() {
    return get<T>();
  }
}

main() {
  var test = new Test();
  var a = test.get<String>();
  var b = test<String>();
  var c = test.call<String>();
}

a and c are typed as String, but b is typed as T (even though no such class exists, and there are no warnings in this code). If I remove the T as the return type from the call method, then the type becomes dynamic.

I presume this should work, but I couldn't find any info on it. I found a couple of open issues about callable classes, but I don't think any are describing this.

Tested with the latest analyzer that's in Flutter master.

Metadata

Metadata

Labels

legacy-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