Skip to content

Least and greatest closures are incorrect for contravariant generic typedef  #44161

Closed
@iarkh

Description

@iarkh

Dart SDK version: 2.12.0-29.0.dev (dev) (Mon Nov 9 06:42:00 2020 -0800) on "windows_x64"

Here is a source code example:

Type? _capturedTypeArgument;

X captureTypeArgument<X>() {
  _capturedTypeArgument = X;
  throw "Error";
}

Type? get capturedTypeArgument {
  var result = _capturedTypeArgument;
  _capturedTypeArgument = null;
  return result;
}

typedef F<X> = void Function<Y extends X>();
F<X> toF<X>(X x) => <Y extends X>() {};
Type typeOf<X>() => X;

typedef check<X> = void Function(X x);

void main() {
  void f<X>(check<X> Function() g) => g();
  try { f(() => captureTypeArgument()); } catch(_) {};
  print (typeOf<check>());
  print(capturedTypeArgument);
}

Seems like Never should be substituted as a bound for the check and capturedTypeArgument here, however this is not so and sample output is:

(dynamic) => void
(Never) => void

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions