RFR: JDK-8191842: JShell: Inferred type information is lost when assigning types to a "var"
Jan Lahoda
jan.lahoda at oracle.com
Fri Jan 5 15:07:12 UTC 2018
Hi,
Thanks for the comments. An updated patch is here:
http://cr.openjdk.java.net/~jlahoda/8191842/webrev.01/
I addition to addressing the comments, it also fixes var behavior when
the inferred type is inaccessible - that is allowed during normal
compilation.
Feedback is welcome,
Jan
On 13.12.2017 23:31, Robert Field wrote:
> Part 2: tests
>
> ToolSimpleTest is missing the bug number.
>
> VariablesTest needs a copyright update.
>
> Please add tests for:
> * anon classes with added method access
> * anon class scratch var
>
> -Robert
>
>
> On 12/13/17 13:47, Robert Field wrote:
>> Nice generalization.
>>
>> Wrap:
>>
>> 90: this breaks array initialization -- this would no longer work:
>> int[] d = {1, 2, 3}
>>
>> Eval:
>>
>> 559: This code should be designed to work the same for automatically
>> created scratch variables -- aka $1, $2, ... -- they should also have
>> anonymous types.
>>
>> ? 322: Can ei.anonymousClasses be used rather than depending on the
>> naming added in Util.JSHELL_ANONYMOUS?
>>
>> 389, 419, 421, 486-493: the name "constructor" is confusing because it
>> contains other things and not the complete constructor. One of the
>> unwritten rules of wraps in that
>> they consist of a complete component, this code has several hanging
>> pieces. Note the two closing braces in 492, braces et. al. should
>> always be matched in a wrap.
>> The mixture of strings and wraps does make this challenging.
>> I'd suggest doing the bodyParts/extraInit computation first, then
>> build up each component as complete entities: constructor body, class
>> body, class -- all wraps.
>>
>> ExpressionToTypeInfo:
>>
>> 355: Seems fragile to assume that the constructor is first
>>
>> -Robert
>>
>>
>> On 12/13/17 02:02, Jan Lahoda wrote:
>>> Hi,
>>>
>>> When doing:
>>> var r = new Object() { String s; }
>>>
>>> the type of "r" is the anonymous class itself. JShell handles this by
>>> "upgrading" the anonymous class to be a member class, so that it can
>>> be properly used from other snippets.
>>>
>>> But JShell is not prepared for anonymous classes inside the
>>> expression (that are part of the resulting type), like:
>>> ---
>>> jshell> var list = Stream.of(1, 2, 3).map(j -> new Object() { int i =
>>> j; }).collect(Collectors.toList());
>>>
>>> jshell> list.forEach(a -> System.out.println(a.i));
>>> ---
>>>
>>> So, part of the proposed fix is to upgrade all anonymous classes to
>>> member classes if needed. Also, intersection types are cleared from
>>> fields before writing (the intersection types are installed to ensure
>>> var semantics for cases like:
>>> <Z extends Runnable & CharSequence> Z get1() { return null; }
>>> var i1 = get1();
>>> )
>>>
>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8191842
>>> Webrev: http://cr.openjdk.java.net/~jlahoda/8191842/webrev.00/
>>>
>>> Thanks,
>>> Jan
>>>
>>
>
More information about the kulla-dev
mailing list