RFR: 8269738: AssertionError when combining pattern matching and function closure
Vicente Romero
vromero at openjdk.java.net
Thu Jul 8 03:49:48 UTC 2021
On Wed, 7 Jul 2021 18:51:52 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> 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
>
> lgtm
> @vicente-romero-oracle Thanks for your review. Should we raise this bug to `P3` and fix it in JDK 17?
yep, it makes sense to do it
-------------
PR: https://git.openjdk.java.net/jdk/pull/4678
More information about the compiler-dev
mailing list