RFR: 8269738: AssertionError when combining pattern maching and function closure

Guoxiong Li gli at openjdk.java.net
Sat Jul 3 19:37:02 UTC 2021


Hi all,

The method `TransPatterns.BasicBindingContext::bindingDeclared` uses `varSymbol.owner` to construct a new `VarSymbol`. 


     res = new VarSymbol(varSymbol.flags(), varSymbol.name, varSymbol.type, varSymbol.owner);


But the `varSymbol.owner` may be also a `VarSymbol` when it is at the `init` clause of the static variables or instance variables.
You can see the following code. The `owner` of the `Interger i` is `staticNum1` or `instanceNum1` which is `VarSymbol`.


    static Number num1 = 1;
    static Number staticNum1 = (num1 instanceof Integer i) ? ((Supplier<Integer>) () -> i).get() : null;
    Number instanceNum1 = (num1 instanceof Integer i) ? ((Supplier<Integer>) () -> i).get() : null;


Then, the class `LambdaToMethod` can't capture the expected variables `Integer i` and the following phases such as `Gen` may fail or throw exceptions.

This patch uses the `currentMethodSym` which means a class or instance field initializer to replace `varSymbol.owner` and adds the corresponding test.

---

And I have a problem:

> The `owner` of the `Interger i` is `staticNum1` or `instanceNum1` which is `VarSymbol`.

The statement above means the `env.info.scope.owner` in the method `Attr::visitBindingPattern` is a `VarSymbol`. Is it a expected result? Or the original `env.info.scope.owner` should be modified to a class or instance field initializer which the following phases need.


    // Attr.java
    public void visitBindingPattern(JCBindingPattern tree) {
        ......
        BindingSymbol v = new BindingSymbol(tree.var.mods.flags, tree.var.name, tree.var.vartype.type, env.info.scope.owner);
        ......
    }


---

Thanks for taking the time to review.

Best Regards,
-- Guoxiong

-------------

Commit messages:
 - 8269738: AssertionError when combining pattern maching and function closure

Changes: https://git.openjdk.java.net/jdk/pull/4678/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4678&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8269738
  Stats: 20 lines in 2 files changed: 18 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/4678.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/4678/head:pull/4678

PR: https://git.openjdk.java.net/jdk/pull/4678


More information about the compiler-dev mailing list