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

Type inference: error-causing replacement node doesn't become invalid #35630

Closed
askeksa-google opened this issue Jan 11, 2019 · 3 comments
Closed
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@askeksa-google
Copy link

When a node is replaced by a different node during type inference, and the replacement node is then involved in an error condition (such as a type error), the erroneous node is kept in the tree, rather than being replaced by an invalid node, as it should.

For example, consider this program (with set literals enabled):

List<int> top = {};

main() {
  List<int> local = {};
  top = {};
  local = {};
  print(top);
  print(local);
}

The initializer of the local variable gets correctly replaced by an invalid node, but all of the other three assignments keep the set literal.

This issue causes the front-end test strong/inference/infer_from_complex_expressions_if_outer_most_value_is_precise to fail, as it is expecting the invalid node.

@askeksa-google askeksa-google added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Jan 11, 2019
@kmillikin
Copy link

This is a basic flaw in the Kernel shadow nodes. They have apparent "children" that are not really children of the shadow node in the sense the the child's parent pointer is the shadow node. Once we begin doing parent-based rewriting of the tree during type inference, we cannot safely use these shadow node "children" because they are stale.

A while ago I added a comment:

        // Do not use rhs after this point because it may be a Shadow node
        // that has been replaced in the tree with its desugaring.

There should be an identical comment just before this line:

      // Do not use rhs after this point because it may be a Shadow node
      // that has been replaced in the tree with its desugaring.
      var replacedRhs = inferrer.ensureAssignable(
          writeContext, rhsType, rhs, writeOffset,
          isVoidAllowed: writeContext is VoidType);
      _storeLetType(inferrer, replacedRhs ?? rhs, rhsType);

where the problem is that there are two occurrences of rhs after that.

@kmillikin
Copy link

(I should add that that comment is misleading. It is not only shadow nodes that are rewritten as part of type inference.)

@johnniwinther
Copy link
Member

Seems to be fixed now.

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
None yet
Development

No branches or pull requests

3 participants