Skip to content
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

Dart compilers reify Null and bottom inconsistently #36832

Closed
vsmenon opened this issue May 2, 2019 · 5 comments
Closed

Dart compilers reify Null and bottom inconsistently #36832

vsmenon opened this issue May 2, 2019 · 5 comments
Assignees
Milestone

Comments

@vsmenon
Copy link
Member

vsmenon commented May 2, 2019

Here are a couple examples:

class A {
  var x = () => throw 'Hi';
  var y = () => null;
}

Null f() => null;
main() {
  A a = new A();
  print(a.x.runtimeType);
  print(a.y.runtimeType);
  a.y = a.x;
  // a.x = f;  Static error in CFE, ok in analyzer
  a.x = (f as dynamic);
  print(a.x.runtimeType);
  print(a.y.runtimeType);
}

On VM and Dart2JS, this prints:

() => Null
() => Null
() => Null
() => Null

On DDC and DDK, this prints:

() => bottom
() => Null
() => Null
() => bottom

For this example:

void Function(E) eventHandler<E, F extends E>(void Function(F) handler) {
  return (E e) {
    print(E);
    print(F);
  };
}

void main() {
  void Function(int) f = eventHandler((String s) {});
  f(42);
}

On VM, Dart2JS, and DDC:

int
Null

On DDK:

int
bottom

The simplest answer is to always reify as Null regardless of what the CFE or Analyzer passes in. If so, we can change DDC / DDK accordingly.

@vsmenon
Copy link
Member Author

vsmenon commented May 2, 2019

@sigmundch @alexmarkov - do Dart2JS and/or the VM ever reify bottom? Or do they just map it to Null?

fyi - @leafpetersen

@leonsenft
Copy link

The simplest answer is to always reify as Null regardless of what the CFE or Analyzer passes in. If so, we can change DDC / DDK accordingly.

I think this is necessary as bottom isn't a user visible type (at least not yet), so there's no way to test for it like you can for Null.

@alexmarkov
Copy link
Contributor

VM maps kernel Bottom type to Null when reading dill files. There is no runtime representation for bottom type in VM.

@sigmundch
Copy link
Member

dart2js as well, we map bottom to null and there is no reified notion of bottom.

I agree that DDC/DDK should do the same.

@vsmenon
Copy link
Member Author

vsmenon commented May 2, 2019

Thanks! Let's go forward with the DDC/K change to be consistent.

@vsmenon vsmenon self-assigned this May 2, 2019
@vsmenon vsmenon added this to the D24 Release milestone May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants