Skip to content

Bug in subtyping with records and FutureOr #51731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lrhn opened this issue Mar 14, 2023 · 0 comments
Closed

Bug in subtyping with records and FutureOr #51731

lrhn opened this issue Mar 14, 2023 · 0 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 14, 2023

Running on tip-of-tree VM (5b3f387).

Example:

import "dart:async";
void main() {
  var o = (null, null, null, 42);
  (int?, String?, bool?, int?) nullable = o;
  FutureOr<(int?, String?, bool?, int?)> futornullable1 = nullable;
  FutureOr<(int?, String?, bool?, int?)> futornullable2 = o;  
}

yields

recchk.dart:6:59: Error: A value of type '(Null, Null, Null, int)' can't be assigned to a variable of type 'FutureOr<(int?, String?, bool?, int?)>'.
  FutureOr<(int?, String?, bool?, int?)> futornullable2 = o;
                                                          ^

There is no error on the previous lines, not even the = nullable one where the same value is assigned, with a different type.

Changing the 42 to Null makes no difference.

Changing the other values to non-nullable makes no difference:

recchk.dart:6:59: Error: A value of type '(int, String, bool, int)' can't be assigned to a variable of type 'FutureOr<(int?, String?, bool?, int?)>' because 'int?' is nullable and 'int' isn't.
  FutureOr<(int?, String?, bool?, int?)> futornullable2 = o;
                                                          ^

The argument here seems backwards, since we're assigning int to int?, so maybe a type-check is reversed somewhere, or maybe just a nullability check.

If I try to add:

  var fo = Future.value(o);
  FutureOr<(int?, String?, bool?, int?)> futornullable3 = fo;

I get an error in the first line, saying:

recchk.dart:8:25: Error: The argument type '(int, String, bool, int)' can't be assigned to the parameter type 'FutureOr<(int, String, bool, int)>?' because '(int, String, bool, int)?' is nullable and '(int, String, bool, int)' isn't.
  var fo = Future.value(o);
                        ^

Again, the record type cannot be assigned to FutureOr of the same record type, because ... something is nullable?

(And yes, it blocks my CL 😉)

@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. labels Mar 14, 2023
@lrhn lrhn added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants