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

Front end must infer top level types before filling in type inference details for top level initializers #29719

Closed
stereotype441 opened this issue May 24, 2017 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@stereotype441
Copy link
Member

Consider the following code:

class A implements B {
  var x;
  A.constructor(this.x);
  List<num> f() => [];
}
class B {
  var x = new A.constructor([1]).f();
}

The following pieces of information must be inferred by type inference, in order:

  • The type of B.x is List<num>
  • The type of A.x is List<num> (inherited from B.x because A implements B)
  • The type of A.constructor's x parameter is List<num> (determined by A.x because initializing formals without an explicit type get their type from the field)
  • The implicit type argument of the list [1] in B.x's initializer is <num> (determined by the type of A.constructor's x parameter)

Note that B.x appears both at the top and the bottom of the above list. This means that we can't do the type inference for B.x all at once. We have to do top level type inference first. Then at a later pass we can fill in type inference for subexpressions appearing in B.x's initializer.

This is going to require some rework of the front end type inference algorithm, since it currently assumes that it doesn't have to visit any field's initializer more than once.

@stereotype441 stereotype441 added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label May 24, 2017
@stereotype441 stereotype441 self-assigned this May 24, 2017
@kmillikin kmillikin added this to Incoming in Dart Front End Jan 3, 2018
@jensjoha
Copy link
Contributor

jensjoha commented Jan 9, 2018

Compiling the code with --strong gives me the following:

library;
import self as self;
import "dart:core" as core;

class A extends core::Object implements self::B {
  field core::List<core::num> x;
  constructor constructor(core::List<core::num> x) → void
    : self::A::x = x, super core::Object::•()
    ;
  method f() → core::List<core::num>
    return <core::num>[];
}
class B extends core::Object {
  field core::List<core::num> x = new self::A::constructor(<core::num>[1]).{self::A::f}();
  default constructor •() → void
    : super core::Object::•()
    ;
}

which makes it seem like this issue is fixed. Can we close?

@jensjoha jensjoha moved this from Incoming Untriaged to Verify Fixed in Dart Front End Jan 9, 2018
@stereotype441
Copy link
Member Author

Yes, this issue has been addressed and adequately regression tested.

@jensjoha jensjoha moved this from Verify Fixed to Done in Dart Front End Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.
Projects
Development

No branches or pull requests

2 participants