Skip to content

Give users more help in solving contravariance issues #33697

Closed
@matanlurey

Description

@matanlurey

See #33119 (comment) for background.

DDC throws with:

TypeError: Closure 'Manager_getResponse_closure': type '(SubContext) => Response<SubContext>' is not a subtype of type '(Context) => Response<Context>'

Unfortunately this doesn't really explain anything, and because most of Dart is based on covariance, I (incorrectly) thought "WTF, its a Response<SubContext>, that's even BETTER than Response<Context>". Of course, that is not the case...

  • Does our language tour or Dart 2 FAQ have anything to help here?
  • Can the error message call out "contravariance" or something to help the user?

In #33119 (comment) specifically, we are statically asking for a Callback<Response<Context>>, but at runtime getting Callback<Response<SubContext>>, which of course is contravariantly invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions